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


##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -5009,7 +5009,22 @@ def convert_reverse_sequence(self, op):
         batch_axis = options.BatchDim()
         seq_axis = options.SeqDim()
 
-        return relax.op.reverse_sequence(in_expr, length_expr, seq_axis, 
batch_axis)
+        if batch_axis != 0:
+            raise tvm.error.OpNotImplemented(
+                "TFLite REVERSE_SEQUENCE with non-zero batch_dim is not 
supported yet."
+            )
+
+        output_tensors = self.get_output_tensors(op)
+        assert len(output_tensors) == 1, "output tensors length should be 1"
+        output_tensor = output_tensors[0]
+        output_shape = to_int_list(self.get_tensor_shape(output_tensor))
+        output_dtype = self.get_tensor_type_str(output_tensor.tensor.Type())
+
+        return relax.op.call_dps_packed(
+            "topi.reverse_sequence",
+            (in_expr, length_expr, seq_axis),
+            out_sinfo=relax.TensorStructInfo(output_shape, output_dtype),
+        )

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   The `topi.reverse_sequence` operator expects 4 arguments: `(data, 
seq_lengths, seq_axis, batch_axis)`. Omitting `batch_axis` can lead to runtime 
errors (such as arity mismatch) when calling the packed function, especially in 
non-Python runtimes or environments where default arguments are not 
automatically resolved. Since `batch_axis` is validated to be `0`, we should 
explicitly pass it as the fourth argument.
   
   ```suggestion
           return relax.op.call_dps_packed(
               "topi.reverse_sequence",
               (in_expr, length_expr, seq_axis, batch_axis),
               out_sinfo=relax.TensorStructInfo(output_shape, output_dtype),
           )
   ```



##########
tests/python/relax/test_frontend_tflite.py:
##########
@@ -1456,6 +1456,29 @@ def main(x: R.Tensor((2, 3), dtype="float32")) -> 
R.Tensor((2, 3), dtype="float3
     verify(ReverseV2, Expected)
 
 
+def test_reverse_sequence():
+    mod = _load_model_from_buffer(_build_tflite_reverse_sequence_model())
+
+    @I.ir_module
+    class Expected:
+        @R.function
+        def main(
+            tvmgen_tensor_0: R.Tensor((2, 4, 3), dtype="float32"),
+            tvmgen_tensor_1: R.Tensor((2,), dtype="int32"),
+        ) -> R.Tensor((2, 4, 3), dtype="float32"):
+            R.func_attr({"num_input": 2})
+            with R.dataflow():
+                gv: R.Tensor((2, 4, 3), dtype="float32") = R.call_dps_packed(
+                    "topi.reverse_sequence",
+                    (tvmgen_tensor_0, tvmgen_tensor_1, 1),
+                    out_sinfo=R.Tensor((2, 4, 3), dtype="float32"),
+                )

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   Update the expected IR module to match the explicit passing of `batch_axis` 
(which is `0`) to `topi.reverse_sequence`.
   
   ```suggestion
                   gv: R.Tensor((2, 4, 3), dtype="float32") = R.call_dps_packed(
                       "topi.reverse_sequence",
                       (tvmgen_tensor_0, tvmgen_tensor_1, 1, 0),
                       out_sinfo=R.Tensor((2, 4, 3), dtype="float32"),
                   )
   ```



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