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


##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -2161,6 +2162,19 @@ def _convert_stablehlo_sort(self, op):
             relax.op.sort(data, axis=int(opts.Dimension()), 
descending=descending)
         )
 
+    def _convert_stablehlo_while(self, op):
+        """Convert STABLEHLO_WHILE to a recursive Relax private function."""
+        from tflite.StablehloWhileOptions import StablehloWhileOptions
+
+        opts = self._get_stablehlo_options(op, StablehloWhileOptions)
+        return self._convert_while_like(
+            op,
+            "STABLEHLO_WHILE",
+            int(opts.CondSubgraphIndex()),
+            int(opts.BodySubgraphIndex()),
+            "tflite_stablehlo_while",
+        )

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   In `_convert_stablehlo_while`, if `opts` is `None` (e.g., due to a malformed 
model or parsing failure), calling `opts.CondSubgraphIndex()` will raise an 
`AttributeError`. Adding a check to ensure `opts` is not `None` before 
extracting the subgraph indices would make the parser more robust and provide a 
clearer error message.
   
   ```suggestion
       def _convert_stablehlo_while(self, op):
           """Convert STABLEHLO_WHILE to a recursive Relax private function."""
           from tflite.StablehloWhileOptions import StablehloWhileOptions
   
           opts = self._get_stablehlo_options(op, StablehloWhileOptions)
           if opts is None:
               raise tvm.error.OpNotImplemented("STABLEHLO_WHILE requires valid 
StablehloWhileOptions")
           return self._convert_while_like(
               op,
               "STABLEHLO_WHILE",
               int(opts.CondSubgraphIndex()),
               int(opts.BodySubgraphIndex()),
               "tflite_stablehlo_while",
           )
   ```



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