Aharrypotter commented on code in PR #19897:
URL: https://github.com/apache/tvm/pull/19897#discussion_r3487214436


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -546,7 +546,15 @@ def _impl_v7(cls, bb, inputs, attr, params):
         if isinstance(inputs[1], relax.Constant) and 
bool(_np.any(inputs[1].data.numpy() == 0)):
             raise ValueError("ONNX Div with integer inputs encountered divisor 
value 0.")
 
-        return cls.base_impl(bb, inputs, attr, params)
+        if isinstance(inputs[1], relax.Constant):
+            return cls.base_impl(bb, inputs, attr, params)
+
+        rhs_nonzero = bb.normalize(relax.op.not_equal(inputs[1], 
relax.op.zeros_like(inputs[1])))
+        safe_rhs = bb.normalize(
+            relax.op.where(rhs_nonzero, inputs[1], 
relax.op.ones_like(inputs[1]))
+        )
+        quotient = bb.normalize(relax.op.divide(inputs[0], safe_rhs))
+        return relax.op.where(rhs_nonzero, quotient, 
relax.op.zeros_like(quotient))

Review Comment:
   fixed



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to