gemini-code-assist[bot] commented on code in PR #19527:
URL: https://github.com/apache/tvm/pull/19527#discussion_r3213350996
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -1140,6 +1140,19 @@ def _impl_v11(cls, bb, inputs, attr, params):
raise ValueError("Scatter is deprecated in ONNX 11")
+def _get_onnx_reduction(attr, valid_reductions: list[str]):
+ reduction = attr.get("reduction", None)
+ reduction = reduction or b"update"
+ if isinstance(reduction, bytes):
+ reduction = reduction.decode("utf-8")
+ reduction = "update" if reduction == "none" else reduction
+ assert reduction in valid_reductions, (
+ f"Only {valid_reductions} reductions are supported, but {reduction} is
gotten"
+ )
Review Comment:

Using `assert` for validating model attributes is discouraged as it can be
optimized away in production environments (when running Python with `-O`). It
is better to raise a `ValueError` to ensure the validation logic always
executes. Additionally, the error message "is gotten" is non-idiomatic; "got"
or "received" is preferred.
```suggestion
if reduction not in valid_reductions:
raise ValueError(
f"Only {valid_reductions} reductions are supported, but got
{reduction}"
)
```
--
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]