gemini-code-assist[bot] commented on code in PR #19841:
URL: https://github.com/apache/tvm/pull/19841#discussion_r3443151062


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -3084,6 +3084,15 @@ def _impl_v1(cls, bb, inputs, attr, params):
         return inputs[0]
 
 
+class Dropout(OnnxOpConverter):
+    """Converts an onnx Dropout node into an equivalent Relax expression."""
+
+    @classmethod
+    def _impl_v1(cls, bb, inputs, attr, params):
+        ratio = float(attr.get("ratio", 0.5))
+        return relax.op.nn.dropout(inputs[0], ratio)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   In ONNX Opset 12 and later, the `ratio` parameter for `Dropout` is passed as 
an optional second input tensor rather than an attribute. The current 
implementation only checks the `ratio` attribute, which means any custom 
dropout ratio specified as an input in newer ONNX models will be ignored and 
default to `0.5`.
   
   We should handle both cases by checking if the second input is provided and 
extracting its constant value if available.
   
   ```python
       def _impl_v1(cls, bb, inputs, attr, params):
           ratio = 0.5
           if len(inputs) > 1 and inputs[1] is not None:
               if isinstance(inputs[1], relax.Constant):
                   ratio = float(inputs[1].data.numpy().item())
               elif isinstance(inputs[1], relax.Var) and inputs[1].name_hint in 
params:
                   ratio = float(params[inputs[1].name_hint].numpy().item())
           else:
               ratio = float(attr.get("ratio", 0.5))
           return relax.op.nn.dropout(inputs[0], ratio)
   ```



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