You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "guan404ming (via GitHub)" <gi...@apache.org> on 2026/06/19 14:39:47 UTC
[PR] [Relax] Legalize nn.dropout as inference no-op [tvm]
guan404ming opened a new pull request, #19841:
URL: https://github.com/apache/tvm/pull/19841
## Related Issue
Closed #19695
## Why
Building any module containing relax.nn.dropout crashed in VM codegen because the op had no real legalization, and the ONNX frontend could not import it
## How
- Legalize nn.dropout to pass the input through with an all-ones mask, matching its (output, mask) tuple result.
- Add and register a Dropout converter in the ONNX frontend.
- Add legalize structural and ONNX onnxruntime-parity tests.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Relax] Legalize nn.dropout as inference no-op [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #19841:
URL: https://github.com/apache/tvm/pull/19841
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Relax] Legalize nn.dropout as inference no-op [tvm]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on PR #19841:
URL: https://github.com/apache/tvm/pull/19841#issuecomment-4774430307
Thanks @tlopex!
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Relax] Legalize nn.dropout as inference no-op [tvm]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #19841:
URL: https://github.com/apache/tvm/pull/19841#discussion_r3443299012
##########
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:
Added _impl_v12 to read ratio from the optional input via get_constant
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Relax] Legalize nn.dropout as inference no-op [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
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:

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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org