Skip to content

[FFI] Bump tvm-ffi to 63224e3 and fix regressions#18938

Open
tqchen wants to merge 5 commits intoapache:mainfrom
tqchen:tvm-ffi-update
Open

[FFI] Bump tvm-ffi to 63224e3 and fix regressions#18938
tqchen wants to merge 5 commits intoapache:mainfrom
tqchen:tvm-ffi-update

Conversation

@tqchen
Copy link
Member

@tqchen tqchen commented Mar 26, 2026

Summary

Bump tvm-ffi submodule from c85fd42 (#471) to 63224e3 (#512), spanning 41 commits with 7 breaking changes. Fix regressions introduced by the bump:

Fixes

  1. Duplicate field declarations in C++ types — New tvm-ffi auto-wires __init__ from C++ reflection by walking the parent type chain. Child types that re-declared parent fields (RXPlaceholderOpNode, FunctionFrameNode) caused duplicate parameter errors. Fixed by removing duplicate field registrations from child types.

  2. Repr format regression (7 tests) — New tvm-ffi CObject.__repr__ uses dataclass repr. Added Node.__repr__ in python/tvm/ir/base.py to use TVMScript printer for IR nodes.

  3. Host/device function split (3 tests) — str(target.kind) now returns full dataclass repr instead of kind name. Changed to target.kind.name in python/tvm/tirx/build.py.

  4. __slots__ enforcement — New tvm-ffi enforces __slots__=() on Object subclasses. Added __slots__ = ("__dict__",) to classes that need instance attributes: Pass, BlockBuilder, TVMDerivedObject.

Changes

  • 3rdparty/tvm-ffi — submodule bump c85fd42 → 63224e3
  • python/tvm/ir/base.pyNode.__repr__ using TVMScript printer
  • python/tvm/ir/transform.pyPass.__slots__ = ("__dict__",)
  • python/tvm/tirx/build.pytarget.kind.name instead of str(target.kind)
  • python/tvm/relax/block_builder.pyBlockBuilder.__slots__ = ("__dict__",)
  • python/tvm/runtime/support.pyTVMDerivedObject.__slots__ = ("__dict__", "__weakref__")
  • python/tvm/s_tir/meta_schedule/utils.pyTVMDerivedObject.__slots__ = ("__dict__",)
  • include/tvm/script/ir_builder/relax/frame.h — remove duplicate field registrations
  • src/relax/ir/emit_te.h — remove duplicate field registrations

Test plan

  • tirx-base: 251 passed, 23 skipped
  • relax import + build: verified
  • Full CI

Update tvm-ffi submodule from c85fd42 (apache#471) to 63224e3 (apache#512).

Fix two regressions from the bump:
- Add no-op __init__ to relax.TEPlaceholderOp to prevent duplicate
  parameter name error from auto-init wiring (apache#491)
- Use query_imports=True in Executable.__call__ to find main in
  imported sub-modules
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on updating the tvm-ffi submodule to its latest version, which introduced several breaking changes. The core objective is to integrate these upstream modifications while simultaneously resolving critical regressions that emerged, specifically addressing issues with object initialization, function lookup within executables, the representation printing of TVM objects, and the accurate identification of target kinds.

Highlights

  • tvm-ffi Submodule Update: The tvm-ffi submodule was bumped from commit c85fd42 to 63224e3, incorporating 41 commits and addressing 7 breaking changes.
  • TEPlaceholderOp Auto-init Fix: A duplicate parameter error in relax.TEPlaceholderOp was resolved by adding a no-op __init__ method, which became necessary due to the new tvm-ffi auto-wiring __init__ from C++ reflection.
  • Executable.call Function Resolution: The Executable.__call__ method was updated to explicitly query imported sub-modules for the main function by setting query_imports=True, fixing an issue where main was not being found.
  • Repr Printer Override: The ffi.ReprPrint behavior was overridden in C++ to utilize TVMScriptPrinter::Script for TVM objects, ensuring that str() and repr() on these objects produce TVMScript format instead of the default dataclass representation.
  • Host/Device Function Split Logic: Host target detection in tirx/build.py was corrected by changing str(target.kind) to target.kind.name, as str(target.kind) now returns a dataclass representation instead of the kind name.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the tvm-ffi subproject and modifies the ReprPrint functionality to use the TVMScript printer for ObjectRef values, both in Python and C++. It also includes minor refactorings in python/tvm/relax/expr.py, python/tvm/runtime/executable.py, and python/tvm/tirx/build.py. A review comment points out that the direct monkey-patching of tvm_ffi._ffi_api.ReprPrint in python/tvm/base.py is fragile and suggests a more robust public API in tvm-ffi for future improvements.

- Add Node.__repr__ to use TVMScript printer instead of dataclass repr
- Fix host/device split: use target.kind.name instead of str(target.kind)
- Override Module.__getattr__ to use query_imports=True
tqchen added 2 commits March 26, 2026 12:22
- Remove duplicate field declarations from C++ child types
  (RXPlaceholderOpNode, FunctionFrameNode) so auto-init works correctly
- Add __slots__ = ("__dict__",) to Pass, BlockBuilder, and
  TVMDerivedObject to support instance attributes under slots enforcement
- Revert unnecessary Module.__getattr__ override with query_imports=True
New tvm-ffi uses ffi.ReprPrint (dataclass repr) for CObject.__repr__
instead of TVM's ReprPrinter. This caused:
- Target: str(target) returned dataclass repr instead of JSON
- AccessPath: structural equality error messages showed verbose repr
- PassInfo: pass name format changed in instrument output
- ExprStmtDoc: __dict__ not available with __slots__ enforcement

Fix by registering __ffi_repr__ TypeAttr for Target (returns JSON via
TargetNode::str()), AccessPath and AccessStep (returns concise path
format). Update tests for new PassInfo format and __slots__.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants