taomiao commented on code in PR #16390:
URL: https://github.com/apache/tvm/pull/16390#discussion_r1450136577


##########
tests/python/frontend/pytorch/test_nonzero_numpy.py:
##########
@@ -0,0 +1,49 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# pylint: disable=import-self, too-many-lines, len-as-condition, 
no-else-return, unused-variable, too-many-nested-blocks
+# pylint: disable=consider-iterating-dictionary, invalid-name, 
unused-argument, unused-variable, broad-except
+# pylint: disable=import-outside-toplevel, simplifiable-if-expression, 
cell-var-from-loop, unnecessary-lambda
+# pylint: disable=missing-function-docstring, redefined-builtin, 
use-implicit-booleaness-not-comparison
+"""Tests to ensure nonzero_numpy are correctly"""
+import torch
+from torch import nn
+
+import tvm
+
+
+class NonZeroModule(nn.Module):
+    """Module that performs nonzero"""
+
+    def __init__(self):
+        super().__init__()
+
+    def forward(self, x, mask):
+        mask_index = torch.nonzero(mask, as_tuple=True)
+        x[mask_index] = torch.ones_like(x[mask_index])
+        return x
+
+
+def test_pytorch_nonzero():
+    model = NonZeroModule()
+    x = torch.zeros((2, 10), dtype=torch.float32)
+    mask = torch.randint(0, 2, (2, 10)).bool()
+    with torch.no_grad():
+        traced_torch_model = torch.jit.trace(model, (x, mask))
+    import_input = [("input0", (2, 10)), ("input1", (2, 10))]
+    relay_model_ir, relay_model_params = tvm.relay.frontend.from_pytorch(
+        traced_torch_model, import_input
+    )

Review Comment:
   I see there is a test "test_forward_nonzero" (test_forward.py:4435). added a 
line there



-- 
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: commits-unsubscr...@tvm.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to