Print TVM IR into TVMScript text format with Python function support. This method extends the standard IRModule script() method to handle Python functions stored in the IRModule's pyfuncs attribute.
(
self,
*,
name: str | None = None,
show_meta: bool = False,
ir_prefix: str = "I",
module_alias: str = "cls",
int_dtype: str = "int32",
float_dtype: str = "void",
verbose_expr: bool = False,
indent_spaces: int = 4,
print_line_numbers: bool = False,
num_context_lines: int = -1,
syntax_sugar: bool = True,
show_object_address: bool = False,
show_all_struct_info: bool = True,
extra_config: dict | None = None,
)
| 496 | setattr(self, name, wrapper) |
| 497 | |
| 498 | def script( |
| 499 | self, |
| 500 | *, |
| 501 | name: str | None = None, |
| 502 | show_meta: bool = False, |
| 503 | ir_prefix: str = "I", |
| 504 | module_alias: str = "cls", |
| 505 | int_dtype: str = "int32", |
| 506 | float_dtype: str = "void", |
| 507 | verbose_expr: bool = False, |
| 508 | indent_spaces: int = 4, |
| 509 | print_line_numbers: bool = False, |
| 510 | num_context_lines: int = -1, |
| 511 | syntax_sugar: bool = True, |
| 512 | show_object_address: bool = False, |
| 513 | show_all_struct_info: bool = True, |
| 514 | extra_config: dict | None = None, |
| 515 | ) -> str: |
| 516 | """Print TVM IR into TVMScript text format with Python function support. |
| 517 | |
| 518 | This method extends the standard IRModule script() method to handle |
| 519 | Python functions stored in the IRModule's pyfuncs attribute. |
| 520 | """ |
| 521 | # First get the standard IRModule script |
| 522 | base_script = self.ir_mod.script( |
| 523 | name=name, |
| 524 | show_meta=show_meta, |
| 525 | ir_prefix=ir_prefix, |
| 526 | module_alias=module_alias, |
| 527 | int_dtype=int_dtype, |
| 528 | float_dtype=float_dtype, |
| 529 | verbose_expr=verbose_expr, |
| 530 | indent_spaces=indent_spaces, |
| 531 | print_line_numbers=print_line_numbers, |
| 532 | num_context_lines=num_context_lines, |
| 533 | syntax_sugar=syntax_sugar, |
| 534 | show_object_address=show_object_address, |
| 535 | show_all_struct_info=show_all_struct_info, |
| 536 | extra_config=extra_config, |
| 537 | ) |
| 538 | |
| 539 | # If there are no Python functions, return the base script |
| 540 | if not hasattr(self.ir_mod, "pyfuncs") or not self.ir_mod.pyfuncs: |
| 541 | return base_script |
| 542 | |
| 543 | # Insert Python functions into the script |
| 544 | return self._insert_python_functions(base_script, indent_spaces) |
| 545 | |
| 546 | def _insert_python_functions(self, base_script: str, indent_spaces: int) -> str: |
| 547 | """Insert Python functions into the TVMScript output.""" |