gemini-code-assist[bot] commented on code in PR #19869:
URL: https://github.com/apache/tvm/pull/19869#discussion_r3456954109
##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -3014,6 +3015,17 @@ def _convert_stablehlo_broadcast_in_dim(self, op):
reshaped = self.bb.normalize(relax.op.reshape(in_expr,
intermediate_shape))
return self.bb.normalize(relax.op.broadcast_to(reshaped, output_shape))
+ def _convert_stablehlo_reshape(self, op):
+ """Convert STABLEHLO_RESHAPE to Relax."""
+ input_tensors = self.get_input_tensors(op)
+ assert len(input_tensors) == 1
+ output_tensors = self.get_output_tensors(op)
+ assert len(output_tensors) == 1
Review Comment:

Using `assert` statements for input validation is discouraged because they
can be optimized away when Python is run with the `-O` (optimize) flag. This
would bypass the validation checks entirely and could lead to cryptic errors
(like `IndexError`) later in the execution. It is safer and more robust to
explicitly check the conditions and raise a `ValueError` with a descriptive
error message.
```suggestion
input_tensors = self.get_input_tensors(op)
if len(input_tensors) != 1:
raise ValueError(f"STABLEHLO_RESHAPE expects exactly 1 input
tensor, but got {len(input_tensors)}")
output_tensors = self.get_output_tensors(op)
if len(output_tensors) != 1:
raise ValueError(f"STABLEHLO_RESHAPE expects exactly 1 output
tensor, but got {len(output_tensors)}")
```
--
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]