MCPcopy Create free account
hub / github.com/pytorch/pytorch / test_tt_layer

Method test_tt_layer

caffe2/python/hypothesis_test.py:1571–1612  ·  view source on GitHub ↗
(self, gc, dc)

Source from the content-addressed store, hash-verified

1569 @given(**hu.gcs_cpu_only)
1570 @settings(deadline=10000)
1571 def test_tt_layer(self, gc, dc):
1572 seed = 1234
1573 np.random.seed(seed)
1574
1575 inp_sizes = [2, 2, 2, 2]
1576 out_sizes = [2, 2, 2, 2]
1577 tt_ranks = [1, 3, 3, 3, 1]
1578
1579 op = core.CreateOperator(
1580 "TT",
1581 ["X", "b", "cores"],
1582 ["Y"],
1583 inp_sizes=inp_sizes,
1584 out_sizes=out_sizes,
1585 tt_ranks=tt_ranks,
1586 )
1587
1588 X = np.expand_dims(
1589 np.random.rand(16).astype(np.float32), axis=0)
1590 b = np.array([0] * 16).astype(np.float32)
1591 cores = tt_core.init_tt_cores(inp_sizes, out_sizes, tt_ranks)
1592
1593 self.ws.create_blob("X").feed(X)
1594 self.ws.create_blob("b").feed(b)
1595 self.ws.create_blob("cores").feed(cores)
1596 self.ws.run(op)
1597
1598 Y = self.ws.blobs[("Y")].fetch()
1599 Y = Y.reshape([16])
1600
1601 golden = np.array([-9.51763490e-07, -1.28442286e-06,
1602 -2.86281141e-07, 2.28865644e-07,
1603 -1.96180017e-06, -1.78920531e-06,
1604 9.31094666e-07, -2.04273989e-07,
1605 1.70017107e-06, 1.64845711e-06,
1606 -1.06099132e-06, -4.69111137e-07,
1607 6.57552358e-08, -1.28942040e-08,
1608 -2.29114004e-07, -1.04262714e-06])
1609
1610 # This golden array is dependent on the specified inp_sizes, out_sizes,
1611 # tt_ranks, and seed. Changing these will cause the test to fail.
1612 self.assertAlmostEqual(np.linalg.norm(golden - Y), 0, delta=1e-10)
1613
1614 @given(**hu.gcs_cpu_only)
1615 def test_tt_sls_layer(self, gc, dc):

Callers

nothing calls this directly

Calls 7

astypeMethod · 0.80
seedMethod · 0.45
randMethod · 0.45
runMethod · 0.45
fetchMethod · 0.45
reshapeMethod · 0.45
normMethod · 0.45

Tested by

no test coverage detected