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


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -4231,7 +4231,7 @@ def _impl_v11(cls, bb, inputs, attr, params):
         k = inputs[1]
         if not isinstance(k, relax.Constant):
             raise ValueError("TopK k must be a constant")
-        k = int(k.data.numpy())
+        k = int(k.data.numpy().item())

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The use of `.item()` correctly fixes the crash when `k` is a 1-D tensor. 
However, to be consistent with other operators in this frontend (e.g., `Trilu` 
at line 1435 or `Reshape` at line 1322) and to correctly handle cases where `k` 
is a parameter (when `keep_params_in_input=True`), it should be resolved using 
`get_constant(inputs[1], params)` before the type check. Additionally, similar 
patterns of `int(k.data.numpy())` without `.item()` exist in `SequenceErase` 
(line 4604), `SequenceInsert` (line 4636), and `SequenceAt` (line 4742), which 
likely suffer from the same issue and should be addressed in a follow-up.



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