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


##########
python/tvm/relax/frontend/torch/base_fx_graph_translator.py:
##########
@@ -2357,6 +2357,12 @@ def _item(self, node: fx.Node) -> relax.Var:
         x = self.env[node.args[0]]
         return self.block_builder.emit(relax.op.take(x, relax.const(0, 
"int64"), axis=0))
 
+    def _sym_size_int(self, node: fx.Node) -> relax.Expr:
+        x = self.env[node.args[0]]
+        shape = self.shape_of(x)
+        idx = node.args[1]
+        return self.block_builder.emit(relax.const(shape[idx].value, "int32"))

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The direct access to `.value` on `shape[idx]` assumes that the `PrimExpr` is 
a `tir.IntImm`. While this is likely true for `torch.ops.aten.sym_size.int`, 
it's more robust and idiomatic to use `int()` for conversion. This will work 
for `IntImm` and correctly fail with a `TypeError` for a symbolic `tir.Var`, 
improving code robustness against future changes in `PrimExpr`'s internal API.
   
   ```suggestion
           return self.block_builder.emit(relax.const(int(shape[idx]), "int32"))
   ```



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