| 1613 | |
| 1614 | @given(**hu.gcs_cpu_only) |
| 1615 | def test_tt_sls_layer(self, gc, dc): |
| 1616 | seed = 1234 |
| 1617 | np.random.seed(seed) |
| 1618 | |
| 1619 | factor_voc = [10, 10, 10] |
| 1620 | factor_width = [2, 2, 2] |
| 1621 | |
| 1622 | op = core.CreateOperator( |
| 1623 | "TTSparseLengthsSum", |
| 1624 | ["core0", "core1", "core2", "index", "lengths"], |
| 1625 | ["Y", "core0_output", "core1_output", "indices"], |
| 1626 | factor_i=factor_voc, |
| 1627 | factor_j=factor_width, |
| 1628 | ranks=[1, 16, 16, 1], |
| 1629 | emb_size=8 |
| 1630 | ) |
| 1631 | c0 = np.ones([10, 1, 2, 16]).astype(np.float32) |
| 1632 | c1 = np.ones([10, 16, 2, 16]).astype(np.float32) |
| 1633 | c2 = np.ones([10, 16, 2, 1]).astype(np.float32) |
| 1634 | # index = np.array([0, 1, 2, 1, 4], dtype=int) |
| 1635 | # lengths = np.array([3, 2], dtype=int) |
| 1636 | index = np.array([0, 1, 2, 1, 4], np.int64) |
| 1637 | lengths = np.array([3, 2], np.int32) |
| 1638 | |
| 1639 | self.ws.create_blob("core0").feed(c0) |
| 1640 | self.ws.create_blob("core1").feed(c1) |
| 1641 | self.ws.create_blob("core2").feed(c2) |
| 1642 | self.ws.create_blob("index").feed(index) |
| 1643 | self.ws.create_blob("lengths").feed(lengths) |
| 1644 | |
| 1645 | self.ws.run(op) |
| 1646 | Y = self.ws.blobs[("Y")].fetch() |
| 1647 | self.assertEqual(list(Y.shape), [2, 8]) |
| 1648 | |
| 1649 | golden = np.array([[768, 768, 768, 768, 768, 768, 768, 768], |
| 1650 | [512, 512, 512, 512, 512, 512, 512, 512]]) |
| 1651 | |
| 1652 | self.assertAlmostEqual(np.linalg.norm(golden - Y), 0, delta=0) |
| 1653 | |
| 1654 | @given(**hu.gcs_cpu_only) |
| 1655 | def test_tt_sls_gradientop(self, gc, dc): |