AndrewZhaoLuo commented on code in PR #10949:
URL: https://github.com/apache/tvm/pull/10949#discussion_r846528009


##########
tests/python/frontend/onnx/test_forward.py:
##########
@@ -5433,6 +5433,218 @@ def verify_biasgelu(x, bias):
     verify_biasgelu(x, bias)
 
 
[email protected]_targets
+def test_embedlayernormalization(target, dev):
+    def verify_embedlayernormalization(
+        input_ids,
+        segment_ids,
+        word_embedding,
+        position_embedding,
+        segment_embedding,
+        gamma,
+        beta,
+    ):
+        node = onnx.helper.make_node(
+            "EmbedLayerNormalization",
+            inputs=[
+                "input_ids",
+                "segment_ids",
+                "word_embedding",
+                "position_embedding",
+                "segment_embedding",
+                "gamma",
+                "beta",
+            ],
+            outputs=["output", "mask_index", "embedding_sum"],
+            domain="com.microsoft",
+        )
+
+        node.attribute.append(onnx.helper.make_attribute("epsilon", 1e-4))
+
+        graph = helper.make_graph(
+            [node],
+            "embedlayernormalization_test",
+            inputs=[
+                helper.make_tensor_value_info(
+                    "input_ids", TensorProto.INT32, list(input_ids.shape)
+                ),
+                helper.make_tensor_value_info(
+                    "segment_ids", TensorProto.INT32, list(segment_ids.shape)
+                ),
+                helper.make_tensor_value_info(
+                    "word_embedding", TensorProto.FLOAT, 
list(word_embedding.shape)
+                ),
+                helper.make_tensor_value_info(
+                    "position_embedding", TensorProto.FLOAT, 
list(position_embedding.shape)
+                ),
+                helper.make_tensor_value_info(
+                    "segment_embedding", TensorProto.FLOAT, 
list(segment_embedding.shape)
+                ),
+                helper.make_tensor_value_info("gamma", TensorProto.FLOAT, 
list(gamma.shape)),
+                helper.make_tensor_value_info("beta", TensorProto.FLOAT, 
list(beta.shape)),
+            ],
+            outputs=[
+                helper.make_tensor_value_info(
+                    "output", TensorProto.FLOAT, list((batch_size, 
sequence_length, hidden_size))
+                ),
+                helper.make_tensor_value_info("mask_index", TensorProto.INT32, 
[batch_size]),
+                helper.make_tensor_value_info(
+                    "embedding_sum",
+                    TensorProto.FLOAT,
+                    list((batch_size, sequence_length, hidden_size)),
+                ),
+            ],
+        )
+
+        model = helper.make_model(graph, 
producer_name="embedlayernormalization_test")
+        verify_with_ort_with_inputs(
+            model,
+            [
+                input_ids,
+                segment_ids,
+                word_embedding,
+                position_embedding,
+                segment_embedding,
+                gamma,
+                beta,
+            ],
+            [
+                (batch_size, sequence_length, hidden_size),
+                batch_size,
+                (batch_size, sequence_length, hidden_size),
+            ],
+            target=target,
+            dev=dev,
+            rtol=1e-4,
+            atol=1e-4,
+        )
+
+    hidden_size = 384
+    batch_size = 4
+    sequence_length = 4
+    vocab_size = 5
+
+    input_ids = np.full((batch_size, sequence_length), 3).astype("int32")
+    segment_ids = np.zeros((batch_size, sequence_length)).astype("int32")
+    word_embedding = np.full((vocab_size, hidden_size), 1).astype("float32")
+    position_embedding = np.full((sequence_length, hidden_size), 
2).astype("float32")
+    segment_embedding = np.full((vocab_size, hidden_size), 3).astype("float32")
+
+    gamma = np.random.uniform(0.5, 0.7, hidden_size).astype("float32")

Review Comment:
   For coverage reasons, can you add cases for when optional arguments are 
optional? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to