Skip to content

Commit 2f4f4b1

Browse files
authored
[REFACTOR][IR][FFI] Bump tvm-ffi (+ SEqHashDef migration) and phase out tvm/ir/repr.h (#19627)
## Summary Two-commit PR: 1. Bump `3rdparty/tvm-ffi` from `3c35034` to `98d0029` and migrate all 21 in-tree `SEqHashDef()` call sites to `SEqHashDefRecursive()` (the conservative variant matching the prior default behavior). Six let-style sites carry `TODO(tqchen)` comments indicating they should flip to `SEqHashDefNonRecursive` after the new tvm-ffi ships on pypi. 2. Phase out `include/tvm/ir/repr.h`. The bumped tvm-ffi now provides ostream `operator<<` for `Any`/`ObjectRef`/`Variant`/`Optional` directly in `tvm/ffi/extra/dataclass.h`, making the in-tree thin wrapper redundant. Rewrite 8 includers, rename `src/ir/repr.cc` → `src/ir/access_path_repr.cc` (preserves `node.AsRepr` + AccessPath/AccessStep `__ffi_repr__` registrations; drops zero-caller `tvm::Dump()`), delete the header. Also fixes a Python-level import regression in `python/tvm/ir/attrs.py` caused by the bump: tvm_ffi 0.1.12.dev changes the field-registration guard from `not hasattr(cls, name)` to `name not in cls.__dict__`, which breaks `DictAttrs` because `DictAttrsNode` registers a reflection field named `"__dict__"` — Python forbids installing a class descriptor with that name via `setattr`. Fix: define `__dict__` as an explicit Python property on `DictAttrs` so the auto-installation is skipped. ## TODO follow-ups After the new tvm-ffi releases on pypi, flip the 6 `SEqHashDefRecursive()` sites that carry `TODO(tqchen)` comments to `SEqHashDefNonRecursive()`. Locations are enumerated in the commit body of commit 1. ## Test plan - [x] Full ninja build clean (638/638). - [x] 118/118 cpptest pass. - [x] `import tvm; tvm.cuda(0).exist` returns True. - [x] `tests/python/all-platform-minimal-test`: 37 passed, 105 skipped. - [x] `tests/python/relax/test_struct_info.py`: 9 passed. - [x] `git grep -nE 'SEqHashDef\(|"tvm/ir/repr\.h"'` is empty. - [x] `pre-commit run --all-files` clean.
1 parent ffea531 commit 2f4f4b1

22 files changed

Lines changed: 57 additions & 113 deletions

File tree

3rdparty/tvm-ffi

Submodule tvm-ffi updated 60 files

include/tvm/ir/expr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#ifndef TVM_IR_EXPR_H_
2525
#define TVM_IR_EXPR_H_
2626

27+
#include <tvm/ffi/extra/dataclass.h>
2728
#include <tvm/ffi/reflection/registry.h>
2829
#include <tvm/ffi/string.h>
2930
#include <tvm/ir/cast.h>
3031
#include <tvm/ir/cow.h>
31-
#include <tvm/ir/repr.h>
3232
#include <tvm/ir/source_map.h>
3333
#include <tvm/ir/type.h>
3434
#include <tvm/script/printer/config.h>

include/tvm/ir/repr.h

Lines changed: 0 additions & 72 deletions
This file was deleted.

include/tvm/relax/exec_builder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#ifndef TVM_RELAX_EXEC_BUILDER_H_
2424
#define TVM_RELAX_EXEC_BUILDER_H_
2525

26+
#include <tvm/ffi/extra/dataclass.h>
2627
#include <tvm/ffi/extra/structural_equal.h>
2728
#include <tvm/ffi/extra/structural_hash.h>
2829
#include <tvm/ffi/function.h>
2930
#include <tvm/ffi/reflection/registry.h>
3031
#include <tvm/ir/expr.h>
31-
#include <tvm/ir/repr.h>
3232
#include <tvm/runtime/vm/bytecode.h>
3333
#include <tvm/runtime/vm/executable.h>
3434

include/tvm/relax/expr.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ class BindingNode : public ffi::Object {
574574
namespace refl = tvm::ffi::reflection;
575575
refl::ObjectDef<BindingNode>()
576576
.def_ro("span", &BindingNode::span, refl::AttachFieldFlag::SEqHashIgnore())
577-
.def_ro("var", &BindingNode::var, refl::AttachFieldFlag::SEqHashDef());
577+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
578+
.def_ro("var", &BindingNode::var, refl::AttachFieldFlag::SEqHashDefRecursive());
578579
}
579580

580581
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
@@ -616,7 +617,9 @@ class MatchCastNode : public BindingNode {
616617
namespace refl = tvm::ffi::reflection;
617618
refl::ObjectDef<MatchCastNode>()
618619
.def_ro("value", &MatchCastNode::value)
619-
.def_ro("struct_info", &MatchCastNode::struct_info, refl::AttachFieldFlag::SEqHashDef());
620+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
621+
.def_ro("struct_info", &MatchCastNode::struct_info,
622+
refl::AttachFieldFlag::SEqHashDefRecursive());
620623
}
621624
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.expr.MatchCast", MatchCastNode, BindingNode);
622625
};
@@ -822,7 +825,7 @@ class FunctionNode : public BaseFuncNode {
822825
static void RegisterReflection() {
823826
namespace refl = tvm::ffi::reflection;
824827
refl::ObjectDef<FunctionNode>()
825-
.def_ro("params", &FunctionNode::params, refl::AttachFieldFlag::SEqHashDef())
828+
.def_ro("params", &FunctionNode::params, refl::AttachFieldFlag::SEqHashDefRecursive())
826829
.def_ro("body", &FunctionNode::body)
827830
.def_ro("ret_struct_info", &FunctionNode::ret_struct_info)
828831
.def_ro("is_pure", &FunctionNode::is_pure);

include/tvm/relax/struct_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class FuncStructInfoNode : public StructInfoNode {
294294
static void RegisterReflection() {
295295
namespace refl = tvm::ffi::reflection;
296296
refl::ObjectDef<FuncStructInfoNode>()
297-
.def_ro("params", &FuncStructInfoNode::params, refl::AttachFieldFlag::SEqHashDef())
297+
.def_ro("params", &FuncStructInfoNode::params, refl::AttachFieldFlag::SEqHashDefRecursive())
298298
.def_ro("ret", &FuncStructInfoNode::ret)
299299
.def_ro("derive_func", &FuncStructInfoNode::derive_func)
300300
.def_ro("purity", &FuncStructInfoNode::purity);

include/tvm/tirx/buffer.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,18 @@ class BufferNode : public ffi::Object {
126126
static void RegisterReflection() {
127127
namespace refl = tvm::ffi::reflection;
128128
refl::ObjectDef<BufferNode>()
129-
.def_ro("data", &BufferNode::data, refl::AttachFieldFlag::SEqHashDef())
129+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
130+
.def_ro("data", &BufferNode::data, refl::AttachFieldFlag::SEqHashDefRecursive())
130131
.def_ro("dtype", &BufferNode::dtype)
131-
.def_ro("shape", &BufferNode::shape, refl::AttachFieldFlag::SEqHashDef())
132-
.def_ro("strides", &BufferNode::strides, refl::AttachFieldFlag::SEqHashDef())
132+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
133+
.def_ro("shape", &BufferNode::shape, refl::AttachFieldFlag::SEqHashDefRecursive())
134+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
135+
.def_ro("strides", &BufferNode::strides, refl::AttachFieldFlag::SEqHashDefRecursive())
133136
.def_ro("axis_separators", &BufferNode::axis_separators,
134-
refl::AttachFieldFlag::SEqHashDef())
135-
.def_ro("elem_offset", &BufferNode::elem_offset, refl::AttachFieldFlag::SEqHashDef())
137+
refl::AttachFieldFlag::SEqHashDefRecursive())
138+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
139+
.def_ro("elem_offset", &BufferNode::elem_offset,
140+
refl::AttachFieldFlag::SEqHashDefRecursive())
136141
.def_ro("name", &BufferNode::name, refl::AttachFieldFlag::SEqHashIgnore())
137142
.def_ro("data_alignment", &BufferNode::data_alignment)
138143
.def_ro("offset_factor", &BufferNode::offset_factor)

include/tvm/tirx/exec_scope.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class ScopeIdDefNode : public ffi::Object {
126126
static void RegisterReflection() {
127127
namespace refl = tvm::ffi::reflection;
128128
refl::ObjectDef<ScopeIdDefNode>()
129-
.def_ro("def_ids", &ScopeIdDefNode::def_ids, refl::AttachFieldFlag::SEqHashDef())
129+
.def_ro("def_ids", &ScopeIdDefNode::def_ids, refl::AttachFieldFlag::SEqHashDefRecursive())
130130
.def_ro("extents", &ScopeIdDefNode::extents)
131131
.def_ro("scope", &ScopeIdDefNode::scope)
132132
.def_ro("preferred_extents", &ScopeIdDefNode::preferred_extents);

include/tvm/tirx/expr.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ class LetNode : public PrimExprNode {
698698
static void RegisterReflection() {
699699
namespace refl = tvm::ffi::reflection;
700700
refl::ObjectDef<LetNode>()
701-
.def_ro("var", &LetNode::var, refl::AttachFieldFlag::SEqHashDef())
701+
// TODO(tqchen): use SEqHashDefNonRecursive after the next pypi tvm-ffi release
702+
.def_ro("var", &LetNode::var, refl::AttachFieldFlag::SEqHashDefRecursive())
702703
.def_ro("value", &LetNode::value)
703704
.def_ro("body", &LetNode::body);
704705
}
@@ -823,8 +824,8 @@ class CommReducerNode : public ffi::Object {
823824
static void RegisterReflection() {
824825
namespace refl = tvm::ffi::reflection;
825826
refl::ObjectDef<CommReducerNode>()
826-
.def_ro("lhs", &CommReducerNode::lhs, refl::AttachFieldFlag::SEqHashDef())
827-
.def_ro("rhs", &CommReducerNode::rhs, refl::AttachFieldFlag::SEqHashDef())
827+
.def_ro("lhs", &CommReducerNode::lhs, refl::AttachFieldFlag::SEqHashDefRecursive())
828+
.def_ro("rhs", &CommReducerNode::rhs, refl::AttachFieldFlag::SEqHashDefRecursive())
828829
.def_ro("result", &CommReducerNode::result)
829830
.def_ro("identity_element", &CommReducerNode::identity_element)
830831
.def_ro("span", &CommReducerNode::span, refl::AttachFieldFlag::SEqHashIgnore());

include/tvm/tirx/function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class PrimFuncNode : public BaseFuncNode {
105105
static void RegisterReflection() {
106106
namespace refl = tvm::ffi::reflection;
107107
refl::ObjectDef<PrimFuncNode>()
108-
.def_ro("params", &PrimFuncNode::params, refl::AttachFieldFlag::SEqHashDef())
108+
.def_ro("params", &PrimFuncNode::params, refl::AttachFieldFlag::SEqHashDefRecursive())
109109
.def_ro("ret_type", &PrimFuncNode::ret_type)
110110
.def_ro("buffer_map", &PrimFuncNode::buffer_map)
111111
.def_ro("body", &PrimFuncNode::body);

0 commit comments

Comments
 (0)