Commit 3f615dc
authored
[Bugfix][Relax] BlockBuilder may not assume unique input functions (#16805)
Prior to this commit, the implementation of
`relax::BlockBuilder::AddFunction` implicitly assumed that the input
`IRModule` does not contain duplicate copies of the same function.
This commit updates the implementation, removing the reliance on this
assumption. This commit resolves the error by tracking all
`GlobalVar` that map to the same function, rather than an just one.
A well-formed IRModule may contain duplicate function definitions.
This is rare, as most functions can be disambiguated by the the
function attribute `tvm::attr::kGlobalSymbol`. However, private
functions do not have this attribute, and a well-formed IRModule
may contain multiple copies of the same function.
The regression test added in this PR calls `BlockBuilder::UpdateFunc`
and `BlockBuilder::AddFunc` in a specific order to reproduce this
issue. In practice, this failure was sporadic, depending on the order
in which a transformation pass visited functions in a module. This
was first observed in `VMShapeLower`, with sporadic errors depending
on the order of iteration over `mod->functions`.1 parent b5fda2d commit 3f615dc
File tree
2 files changed
+95
-10
lines changed- src/relax/ir
- tests/python/relax
2 files changed
+95
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
113 | 121 | | |
114 | 122 | | |
115 | | - | |
| 123 | + | |
116 | 124 | | |
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | | - | |
122 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
123 | 141 | | |
124 | 142 | | |
125 | 143 | | |
126 | 144 | | |
127 | 145 | | |
128 | 146 | | |
129 | 147 | | |
130 | | - | |
| 148 | + | |
131 | 149 | | |
132 | 150 | | |
133 | 151 | | |
| |||
399 | 417 | | |
400 | 418 | | |
401 | 419 | | |
402 | | - | |
| 420 | + | |
| 421 | + | |
403 | 422 | | |
404 | 423 | | |
405 | 424 | | |
| |||
408 | 427 | | |
409 | 428 | | |
410 | 429 | | |
411 | | - | |
| 430 | + | |
| 431 | + | |
412 | 432 | | |
413 | 433 | | |
414 | 434 | | |
415 | | - | |
| 435 | + | |
416 | 436 | | |
417 | 437 | | |
418 | 438 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
925 | 925 | | |
926 | 926 | | |
927 | 927 | | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
928 | 993 | | |
929 | 994 | | |
0 commit comments