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


##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -1521,6 +1534,18 @@ def get_scalar_value(tensor):
 
         return out
 
+    def convert_rank(self, op):
+        """Convert TFLite RANK."""
+        input_tensors = self.get_input_tensors(op)
+        assert len(input_tensors) == 1, "input tensors length should be 1"
+
+        output_tensors = self.get_output_tensors(op)
+        assert len(output_tensors) == 1, "output tensors length should be 1"
+        output_dtype = 
self.get_tensor_type_str(output_tensors[0].tensor.Type())
+
+        rank = len(self.get_tensor_shape(input_tensors[0]))
+        return relax.const(np.array(rank, dtype=output_dtype), 
dtype=output_dtype)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   We can simplify this by passing the Python integer `rank` directly to 
`relax.const` instead of wrapping it in a `np.array`. `relax.const` natively 
supports Python scalars with a specified `dtype`.
   
   ```suggestion
           return relax.const(rank, dtype=output_dtype)
   ```



##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -1564,6 +1612,26 @@ def convert_relu(self, op):
 
         return out
 
+    def convert_relu_0_to_1(self, op):
+        """Convert TFLite RELU_0_TO_1."""
+        input_tensors = self.get_input_tensors(op)
+        assert len(input_tensors) == 1, "input tensors length should be 1"
+        input_tensor = input_tensors[0]
+        in_expr = self.get_expr(input_tensor.tensor_idx)
+
+        output_tensors = self.get_output_tensors(op)
+        assert len(output_tensors) == 1, "output tensors length should be 1"
+        output_tensor = output_tensors[0]
+
+        if input_tensor.qnn_params:
+            in_f32 = self.dequantize(in_expr, input_tensor)
+            out = relax.op.clip(in_f32, min=0, max=1)
+            out = self.quantize(out, output_tensor)
+        else:
+            out = relax.op.clip(in_expr, min=0, max=1)

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For consistency with other uses of `relax.op.clip` in this file (e.g., in 
`convert_fake_quant`), and to ensure compatibility with TVM's FFI wrappers, it 
is recommended to use positional arguments instead of keyword arguments (`min` 
and `max`).
   
   ```suggestion
           if input_tensor.qnn_params:
               in_f32 = self.dequantize(in_expr, input_tensor)
               out = relax.op.clip(in_f32, 0, 1)
               out = self.quantize(out, output_tensor)
           else:
               out = relax.op.clip(in_expr, 0, 1)
   ```



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