Ejemplo n.º 1
0
    def test_triu_square(self):
        node = onnx.helper.make_node(
            'Trilu',
            inputs=['x'],
            outputs=['y'],
            domain="com.microsoft",
        )

        x = np.random.randn(3, 5, 5).astype(np.float32)
        y = triu_reference_implementation(x)
        expect(node, inputs=[x], outputs=[y], name='test_triu_square')
Ejemplo n.º 2
0
    def test_triu(self):
        node = onnx.helper.make_node(
            "Trilu",
            inputs=["x"],
            outputs=["y"],
            domain="com.microsoft",
        )

        x = np.random.randn(3, 4, 5).astype(np.float32)
        y = triu_reference_implementation(x)
        expect(node, inputs=[x], outputs=[y], name="test_triu")
    def test_torch_embedding(self):
        node = onnx.helper.make_node(
            'TorchEmbedding',
            inputs=['w', 'x'],
            outputs=['y'],
            domain="com.microsoft",
        )

        x = np.random.randn(2, 4).astype(np.int64)
        w = np.random.randn(10, 3).astype(np.float32)
        y = torch_embedding_reference_implementation(w, x)
        expect(node, inputs=[w, x], outputs=[y], name='test_torch_embedding')
Ejemplo n.º 4
0
    def test_triu_square_neg(self):
        node = onnx.helper.make_node(
            'Trilu',
            inputs=['x', 'k'],
            outputs=['y'],
            domain="com.microsoft",
        )

        x = np.random.randn(3, 5, 5).astype(np.float32)
        k = np.array([-1]).astype(np.int64)
        y = triu_reference_implementation(x, k)
        expect(node, inputs=[x, k], outputs=[y], name='test_triu_square_neg')
Ejemplo n.º 5
0
    def test_triu_out_pos(self):
        node = onnx.helper.make_node(
            "Trilu",
            inputs=["x", "k"],
            outputs=["y"],
            domain="com.microsoft",
        )

        x = np.random.randn(3, 4, 5).astype(np.float32)
        k = np.array([6]).astype(np.int64)
        y = triu_reference_implementation(x, k)
        expect(node, inputs=[x, k], outputs=[y], name="test_triu_out_pos")
Ejemplo n.º 6
0
    def test_tril_one_row_neg(self):
        node = onnx.helper.make_node(
            "Trilu",
            inputs=["x", "k"],
            outputs=["y"],
            upper=0,
            domain="com.microsoft",
        )

        x = np.random.randn(3, 1, 5).astype(np.float32)
        k = np.array([-7]).astype(np.int64)
        y = tril_reference_implementation(x, k)
        expect(node, inputs=[x, k], outputs=[y], name="test_tril_one_row_neg")
Ejemplo n.º 7
0
    def test_torch_embedding_zero_dim(self):
        node = onnx.helper.make_node(
            "TorchEmbedding",
            inputs=["w", "x"],
            outputs=["y"],
            domain="com.microsoft",
        )

        x = np.random.randn(0, 4).astype(np.int64)
        w = np.random.randn(10, 3).astype(np.float32)
        y = torch_embedding_reference_implementation(w, x)
        expect(node,
               inputs=[w, x],
               outputs=[y],
               name="test_torch_embedding_zero_dim")
    def test_torch_embedding_scale_grad_by_freq(self):
        node = onnx.helper.make_node(
            'TorchEmbedding',
            inputs=['w', 'x', 'padding_idx', 'scale'],
            outputs=['y'],
            domain="com.microsoft",
        )

        x = np.random.randn(3, 4).astype(np.int64)
        w = np.random.randn(10, 3).astype(np.float32)
        padding_idx = np.random.randint(3, size=1).astype(np.int64)
        scale = np.array([1]).astype(np.bool)
        y = torch_embedding_reference_implementation(w, x, padding_idx, scale)
        expect(node,
               inputs=[w, x, padding_idx, scale],
               outputs=[y],
               name='test_torch_embedding_scale_grad_by_freq')
Ejemplo n.º 9
0
    def test_torch_embedding_padding_idx(self):
        node = onnx.helper.make_node(
            "TorchEmbedding",
            inputs=["w", "x", "padding_idx"],
            outputs=["y"],
            domain="com.microsoft",
        )

        x = np.random.randn(3, 4).astype(np.int64)
        w = np.random.randn(10, 3).astype(np.float32)
        padding_idx = np.random.randint(3, size=1).astype(np.int64)
        y = torch_embedding_reference_implementation(w, x, padding_idx)
        expect(
            node,
            inputs=[w, x, padding_idx],
            outputs=[y],
            name="test_torch_embedding_padding_idx",
        )