Commit 1424286
authored
[FFI] Make StructuralEqual functor compare tensor content (#646)
Fixes #645.
The `StructuralEqual` functor calls `Equal(lhs, rhs, false,
/*skip_tensor_content=*/true)`, while the `StructuralHash` functor
hashes content (`skip_tensor_content = false`). The two are used
together as the hash and key-equal of the constant de-duplication map in
Relax VM codegen (`const_dedup_map_` in apache/tvm
`src/relax/backend/vm/exec_builder.cc`). When hash and equal disagree,
the map invariant `equal(a, b) => hash(a) == hash(b)` does not hold, so
two distinct constants of equal shape and dtype get merged on a bucket
collision and a later op reads the wrong constant.
Which pair collides depends on the STL bucket count, so the same model
produces wrong output under MSVC and correct output under libstdc++. The
defect is latent on every platform.
This change makes the functor compare content, so it agrees with the
hash. Constants that are genuinely equal are still de-duplicated.
Verified on a Windows build (MSVC 19.44, LLVM 18.1.8): after the change,
YOLO11n det, YOLO11s cls, PP-OCRv5 det and PP-OCRv5 rec all match
onnxruntime to within floating point; before, det and the PP-OCR models
were off by 6 to 61 percent relative error.
Full analysis in #645.1 parent 88e066e commit 1424286
2 files changed
Lines changed: 44 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
39 | 58 | | |
40 | 59 | | |
41 | 60 | | |
| |||
333 | 352 | | |
334 | 353 | | |
335 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
336 | 379 | | |
0 commit comments