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


##########
python/tvm_ffi/cython/dtype.pxi:
##########
@@ -191,15 +188,22 @@ if torch is not None:
         torch.double: DLDataType(2, 64, 1),
         torch.bfloat16: DLDataType(4, 16, 1),
         torch.bool: DLDataType(6, 8, 1),
-        torch.float8_e4m3fn: DLDataType(10, 8, 1),
-        torch.float8_e4m3fnuz: DLDataType(11, 8, 1),
-        torch.float8_e5m2: DLDataType(12, 8, 1),
-        torch.float8_e5m2fnuz: DLDataType(13, 8, 1),
     }
-    if hasattr(torch, "float8_e8m0fnu"):
-        TORCH_DTYPE_TO_DL_DATA_TYPE[torch.float8_e8m0fnu] = DLDataType(14, 8, 
1)
-    if hasattr(torch, "float4_e2m1fn_x2"):
-        TORCH_DTYPE_TO_DL_DATA_TYPE[torch.float4_e2m1fn_x2] = DLDataType(17, 
4, 2)
+
+    extra_types = [
+        ("uint16", DLDataType(1, 16, 1)),
+        ("uint32", DLDataType(1, 32, 1)),
+        ("uint64", DLDataType(1, 64, 1)),
+        ("float8_e4m3fn", DLDataType(10, 8, 1)),
+        ("float8_e4m3fnuz", DLDataType(11, 8, 1)),
+        ("float8_e5m2", DLDataType(12, 8, 1)),
+        ("float8_e5m2fnuz", DLDataType(13, 8, 1)),
+        ("float8_e8m0fnu", DLDataType(14, 8, 1)),
+        ("float4_e2m1fn_x2", DLDataType(17, 4, 2)),
+    ]

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   For a constant data structure like `extra_types`, it is a common Python 
convention to use a tuple of tuples instead of a list of tuples. This makes the 
data structure immutable, which prevents accidental modifications at runtime 
and more clearly signals the intent that this data is constant. This can also 
offer a minor performance benefit.
   
   ```
       extra_types = (
           ("uint16", DLDataType(1, 16, 1)),
           ("uint32", DLDataType(1, 32, 1)),
           ("uint64", DLDataType(1, 64, 1)),
           ("float8_e4m3fn", DLDataType(10, 8, 1)),
           ("float8_e4m3fnuz", DLDataType(11, 8, 1)),
           ("float8_e5m2", DLDataType(12, 8, 1)),
           ("float8_e5m2fnuz", DLDataType(13, 8, 1)),
           ("float8_e8m0fnu", DLDataType(14, 8, 1)),
           ("float4_e2m1fn_x2", DLDataType(17, 4, 2)),
       )
   ```



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