Skip to content

[CI] Bump tvm-ffi with compatible Python wrappers - #20032

Merged
cyx-6 merged 7 commits into
apache:mainfrom
tqchen:fix-tvm-ffi-bump-relax-slots
Jul 20, 2026
Merged

[CI] Bump tvm-ffi with compatible Python wrappers#20032
cyx-6 merged 7 commits into
apache:mainfrom
tqchen:fix-tvm-ffi-bump-relax-slots

Conversation

@tqchen

@tqchen tqchen commented Jul 19, 2026

Copy link
Copy Markdown
Member

Summary

  • bump tvm-ffi and include the device definition where its DLDevice traits are instantiated
  • keep only the required Tensor wrapper layout fix and register ir.Type before reflected Expr fields can materialize a fallback wrapper
  • preserve BaseFunc.with_attr callers by moving only method-private results, never the canonical self wrapper

Rationale

The tvm-ffi lifetime update requires a replacement wrapper to fit the layout already registered for the same type index. runtime.Tensor replaces the core ffi.Tensor wrapper, so it must use empty slots. The ordinary TVM mixins are first-registered with their concrete descendants and may safely retain normal Python dictionaries; the additional mixin and explicit-dictionary slot changes are not required.

Object tying also means BaseFuncCopy(self) may return self. Passing that wrapper through _move() invalidates the caller. The first update now passes the alias as an lvalue, forcing native copy-on-write to create a private result. Only later dictionary updates move a result that is not self and has not escaped the method.

Validation

  • built an exact CPython 3.12 wheel from tvm-ffi 21e30c3b1d and rebuilt TVM against it
  • direct Type/function/detach regressions: 3 passed
  • complete IR plus focused Relax coverage: 111 passed
  • prior Relax failure set: 157 passed, 9 skipped
  • runtime probe for relax.Function, relax.ExternFunc, and tirx.PrimFunc: original wrappers preserved; single- and multi-attribute results distinct and valid
  • all touched-file pre-commit hooks passed

cyx-6 and others added 6 commits July 19, 2026 12:20
tvm-ffi object tying can make BaseFuncCopy return the canonical Python wrapper for self. Moving that wrapper invalidates the caller instead of creating the promised copy.

Pass the initial self alias as an lvalue so native copy-on-write creates a private result. For dictionary updates, only move a later result when it is not self; that result was created inside this method and has not escaped, so the exclusive-move precondition holds.

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

Copy link
Copy Markdown
Contributor

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 commit and introduces several FFI-related fixes, including header inclusions, import reordering to ensure correct registration order, and copy-on-write safety improvements in BaseFunc.with_attr. It also adds slots to the Tensor class to maintain instance layout compatibility. The feedback suggests asserting that func.attrs is None directly in the test file to prevent a potential TypeError when checking for membership.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tests/python/relax/test_expr.py
@cyx-6
cyx-6 merged commit 1a4e037 into apache:main Jul 20, 2026
8 checks passed
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.

2 participants