fix(cann): prevent race condition on .om cache file during multi-card compilation#28533
Open
0AnshuAditya0 wants to merge 2 commits into
Open
fix(cann): prevent race condition on .om cache file during multi-card compilation#285330AnshuAditya0 wants to merge 2 commits into
0AnshuAditya0 wants to merge 2 commits into
Conversation
… file during multi-card compilation
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #26778
When running multi-card inference via
torchrun --nproc_per_node=8withdump_om_modelenabled, a TOCTOU (Time-Of-Check-Time-Of-Use) race conditioncauses
aclmdlLoadFromFile()to fail or produce accuracy errors.Fix:
BuildONNXModel(cann_graph.cc): write to a temporary file(
file_name + "_tmp") first, then callstd::filesystem::rename()oncethe write is complete. POSIX
rename(2)is atomic — readers will only everobserve the file as absent or complete, never partial.
MatchFile(cann_utils.cc): explicitly skip_tmp.omfiles as adefensive guard against any future naming overlap.
Motivation and Context
reproducible
CANN error executing aclmdlLoadFromFile()under8-card concurrent compilation with
torchrun.The fix is validated via a standalone C++ mock harness simulating 8 concurrent
processes racing on the same file path (no Ascend hardware required — the race
is purely filesystem-level). The buggy path produces consistent read corruptions;
the atomic-rename path produces zero corruptions across 10,000+ iterations.
Changes
onnxruntime/core/providers/cann/cann_graph.ccBuildONNXModelonnxruntime/core/providers/cann/cann_utils.cc_tmp_files inMatchFile