gemini-code-assist[bot] commented on code in PR #19879:
URL: https://github.com/apache/tvm/pull/19879#discussion_r3464360196
##########
python/tvm/relax/frontend/tflite/tflite_frontend.py:
##########
@@ -759,21 +798,102 @@ def convert_hashtable_import(self, op):
):
raise tvm.error.OpNotImplemented("HASHTABLE_IMPORT requires
constant keys and values")
+ if self._is_tflite_string_type(table_info["key_dtype"]):
+ keys = self._get_string_tensor_value(key_tensor,
"HASHTABLE_IMPORT")
+ else:
+ keys = self.get_tensor_value(key_tensor)
+ if self._is_tflite_string_type(table_info["value_dtype"]):
+ values = self._get_string_tensor_value(value_tensor,
"HASHTABLE_IMPORT")
+ else:
+ values = self.get_tensor_value(value_tensor)
+
+ if np.unique(keys).size != keys.size:
+ raise tvm.error.OpNotImplemented(
+ "HASHTABLE_IMPORT with duplicate keys is not supported"
+ )
Review Comment:

In `HASHTABLE_IMPORT`, there is no validation to ensure that the keys and
values tensors have matching shapes. If a model has mismatched key and value
shapes, `zip` in `convert_hashtable_find` will silently truncate the elements,
leading to unexpected behavior or incorrect constant folding. We should
explicitly validate that the shapes of `keys` and `values` match before
proceeding.
```python
if keys.shape != values.shape:
raise tvm.error.OpNotImplemented(
"HASHTABLE_IMPORT requires keys and values to have the same
shape"
)
if np.unique(keys).size != keys.size:
raise tvm.error.OpNotImplemented(
"HASHTABLE_IMPORT with duplicate keys is not supported"
)
```
--
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]