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


##########
python/tvm/runtime/script_printer.py:
##########
@@ -99,14 +90,13 @@ def __init__(
             "obj_to_underline": obj_to_underline,
             "obj_to_annotate": obj_to_annotate,
             # Dialect-specific config via dotted keys in extra_config
-            "tirx.prefix": tir_prefix,
-            "tirx.buffer_dtype": buffer_dtype,
-            "relax.prefix": relax_prefix,
             "relax.show_all_struct_info": show_all_struct_info,
         }
 
         if name is not None:
             cfg["name"] = name
+        if extra_config is not None:
+            cfg["extra_config"] = extra_config

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   With the removal of `buffer_dtype` from the `PrinterConfig` constructor 
signature, dialect-specific configurations like `"tirx.buffer_dtype"` are now 
passed as strings within the `extra_config` dictionary.
   
   However, in `src/script/printer/script_printer.cc`, the conversion of 
`"tirx.buffer_dtype"` from a string to a `DataType` object is only performed if 
it is found at the top level of the `config_dict` (i.e., 
`config_dict.Get("tirx.buffer_dtype")`). If it is passed inside `extra_config`, 
it is copied directly as a raw string into `n->extra_config`.
   
   Later, when `GetExtraConfig<DataType>("tirx.buffer_dtype", ...)` is called 
in `src/tirx/script/printer/buffer.cc`, `Downcast<DataType>` is invoked on this 
raw string, which will cause a runtime type mismatch error or crash.
   
   To fix this, we can intercept `"tirx.buffer_dtype"` in the Python 
constructor of `PrinterConfig` and promote it to the top level of `cfg` so that 
the C++ side can correctly parse it into a `DataType` object.
   
   ```suggestion
           if extra_config is not None:
               if "tirx.buffer_dtype" in extra_config:
                   cfg["tirx.buffer_dtype"] = extra_config["tirx.buffer_dtype"]
                   extra_config = {k: v for k, v in extra_config.items() if k 
!= "tirx.buffer_dtype"}
               if extra_config:
                   cfg["extra_config"] = extra_config
   ```



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