You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "pisarev (via GitHub)" <gi...@apache.org> on 2026/06/26 20:46:34 UTC
[PR] [FFI] Make StructuralEqual functor compare tensor content [tvm-ffi]
pisarev opened a new pull request, #646:
URL: https://github.com/apache/tvm-ffi/pull/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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FFI] Make StructuralEqual functor compare tensor content [tvm-ffi]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #646:
URL: https://github.com/apache/tvm-ffi/pull/646#discussion_r3484037108
##########
include/tvm/ffi/extra/structural_equal.h:
##########
@@ -69,7 +69,7 @@ class StructuralEqual {
* \return True if the two Any values are structurally equal, false otherwise.
*/
TVM_FFI_INLINE bool operator()(const Any& lhs, const Any& rhs) const {
- return Equal(lhs, rhs, false, true);
+ return Equal(lhs, rhs, false, false);
Review Comment:

Passing multiple consecutive boolean literals (often referred to as the "Boolean Trap") reduces code readability and increases the risk of parameter mismatch errors. Since both `map_free_vars` and `skip_tensor_content` default to `false` in the signature of `Equal`, we can simplify this call to `Equal(lhs, rhs)` to make the code cleaner and more maintainable.
```c
return Equal(lhs, rhs);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FFI] Make StructuralEqual functor compare tensor content [tvm-ffi]
Posted by "pisarev (via GitHub)" <gi...@apache.org>.
pisarev commented on PR #646:
URL: https://github.com/apache/tvm-ffi/pull/646#issuecomment-4820939443
Fixed the clang-tidy failure in 97bebe5. It was a "clang-analyzer-security.ArrayBound" false positive on the test's fill loop (the analyzer can't see the buffer size through the allocator). Suppressed it with a NOLINT plus a short explanatory comment, and verified locally with clang-tidy 21.1.1. Should be green on a re-run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FFI] Make StructuralEqual functor compare tensor content [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #646:
URL: https://github.com/apache/tvm-ffi/pull/646
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [FFI] Make StructuralEqual functor compare tensor content [tvm-ffi]
Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen commented on PR #646:
URL: https://github.com/apache/tvm-ffi/pull/646#issuecomment-4814666519
pls fix ci issue
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org