You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tqchen (via GitHub)" <gi...@apache.org> on 2026/04/29 20:30:03 UTC
[PR] [REFACTOR][SCRIPT] Move script_printer.h → script/printer/config.h; rename TVM_SCRIPT_REPR; replace dialect fields with extra_config [tvm]
tqchen opened a new pull request, #19478:
URL: https://github.com/apache/tvm/pull/19478
## Summary
`include/tvm/ir/script_printer.h` placed `PrinterConfig` and `TVMScriptPrinter` under `tvm/ir/` — these are printer-layer concepts, not IR-specific. Move to `include/tvm/script/printer/config.h` alongside the printer's other public headers (`doc.h`, `ir_docsifier.h`, `ir_docsifier_functor.h`).
- **Rename `TVM_SCRIPT_REPR` → `TVM_REGISTER_SCRIPT_AS_REPR`**: the macro registers Script as the `kRepr` callback for an object type and installs the per-type `TVMScriptPrinter::vtable()` dispatch entry. The new name is explicit about the registration semantic and aligns with the `TVM_REGISTER_*` family.
- **Drop dialect-specific `PrinterConfig` fields** (`tir_prefix`, `relax_prefix`, `show_all_struct_info`, `buffer_dtype`) in favor of a generic `ffi::Map<String, Any> extra_config` keyed by `"<dialect>.<knob>"` (e.g. `"tirx.prefix"`, `"relax.show_all_struct_info"`). Each dialect reads its own keys via `GetExtraConfig<T>(key, fallback)` with defaults at the call site; the shared core never names a specific dialect through hard-coded fields. `ir_prefix` and `module_alias` also flip from `std::string` to `ffi::String` for consistency. `RedirectedReprPrinterMethod` is de-inlined into `src/script/printer/config.cc` to keep `<tvm/runtime/logging.h>` out of the public header.
- ~6 header includers and ~80 macro use sites updated; Python config wrappers updated to write into `extra_config` with dotted keys.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][SCRIPT] Move script_printer.h → script/printer/config.h; rename TVM_SCRIPT_REPR; replace dialect fields with extra_config [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #19478:
URL: https://github.com/apache/tvm/pull/19478#issuecomment-4347474827
Folded into #19479 — single coherent TVMScript dialect-friendly refactor PR. Commits absorbed; this PR's branch can be deleted.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][SCRIPT] Move script_printer.h → script/printer/config.h; rename TVM_SCRIPT_REPR; replace dialect fields with extra_config [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19478:
URL: https://github.com/apache/tvm/pull/19478#discussion_r3163984207
##########
include/tvm/script/printer/config.h:
##########
@@ -121,16 +80,39 @@ class PrinterConfigNode : public ffi::Object {
/*! \brief Object to be annotated. */
ffi::Map<ObjectRef, ffi::String> obj_to_annotate = ffi::Map<ObjectRef, ffi::String>();
+ /*!
+ * \brief Generic extension map for dialect-specific config knobs.
+ *
+ * Keys are conventionally namespaced as "<dialect>.<knob>", e.g.:
+ * "tirx.prefix" — the TIR prefix (default "T")
+ * "tirx.buffer_dtype" — default buffer dtype (default float32)
+ * "relax.prefix" — the Relax prefix (default "R")
+ * "relax.show_all_struct_info" — whether to show all struct info (default true)
+ *
+ * Use GetExtraConfig<T>(key, fallback) to read values with a typed fallback.
+ */
+ ffi::Map<ffi::String, ffi::Any> extra_config;
+
+ /*!
+ * \brief Look up a value in extra_config with type cast and fallback.
+ *
+ * Keys are conventionally namespaced as "<dialect>.<knob>"
+ * (e.g. "tirx.prefix", "relax.show_all_struct_info").
+ */
+ template <typename T>
+ T GetExtraConfig(const ffi::String& key, T fallback) const {
+ auto it = extra_config.find(key);
+ if (it == extra_config.end()) return fallback;
+ return Downcast<T>((*it).second);
Review Comment:

The use of `Downcast<T>` here is incorrect for non-`ObjectRef` types. Since `extra_config` stores `ffi::Any` values, and this method is used with types like `bool` (in `binding.cc`) and `DataType` (in `buffer.cc`), `Downcast` will fail to compile or error at runtime for these POD-like types. Using `ffi::Any::cast<T>()` is the correct way to retrieve values from an `Any` container generically.
```c
return (*it).second.cast<T>();
```
##########
src/ir/script_printer.cc:
##########
@@ -123,22 +114,47 @@ PrinterConfig::PrinterConfig(ffi::Map<ffi::String, Any> config_dict) {
if (auto v = config_dict.Get("show_object_address")) {
n->show_object_address = v.value().cast<bool>();
}
- if (auto v = config_dict.Get("show_all_struct_info")) {
- n->show_all_struct_info = v.value().cast<bool>();
+ // Dialect-specific keys are stored in extra_config with dotted-name keys.
+ // String-typed dialect keys passed through directly.
+ for (const char* key : {"tirx.prefix", "relax.prefix"}) {
+ if (auto v = config_dict.Get(key)) {
+ n->extra_config.Set(ffi::String(key), v.value());
+ }
+ }
+ // "tirx.buffer_dtype" is passed as a DLDataType string from Python; convert to DataType.
+ if (auto v = config_dict.Get("tirx.buffer_dtype")) {
+ DataType dt(ffi::StringToDLDataType(Downcast<ffi::String>(v.value())));
+ n->extra_config.Set(ffi::String("tirx.buffer_dtype"), ffi::Any(dt));
+ }
+ // Boolean dialect keys.
+ if (auto v = config_dict.Get("relax.show_all_struct_info")) {
+ n->extra_config.Set(ffi::String("relax.show_all_struct_info"), v.value());
+ }
Review Comment:

The implementation here contradicts the architectural goal stated in the PR description: "shared core never names a specific dialect through hard-coded fields." This constructor still contains hardcoded logic for `tirx` and `relax` dialects, including specific key mapping and `DataType` conversion for `tirx.buffer_dtype`. To achieve true decoupling, this logic should be generalized (e.g., by iterating over all non-core keys in `config_dict`) or moved to a registration-based system where dialects can define their own configuration conversion and validation logic.
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [REFACTOR][SCRIPT] Move script_printer.h → script/printer/config.h; rename TVM_SCRIPT_REPR; replace dialect fields with extra_config [tvm]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed pull request #19478: [REFACTOR][SCRIPT] Move script_printer.h → script/printer/config.h; rename TVM_SCRIPT_REPR; replace dialect fields with extra_config
URL: https://github.com/apache/tvm/pull/19478
--
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: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org