Repository navigation
[dynamo] Make the frame cache safe for concurrent install and lookup - #193697
Closed
bobrenjc93 wants to merge 23 commits into
Closed
bobrenjc93 wants to merge 23 commits into
bobrenjc93 wants to merge 23 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/193697
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit b48d415 with merge base 1b4e490 ( NEW FAILURE - The following job has failed:
BROKEN TRUNK - The following job failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Aug 15, 2026
…reconstruction, and concurrent cache reset. [ghstack-poisoned]
[ghstack-poisoned]
…on, serialization, concurrency, and cache lifetime handling. [ghstack-poisoned]
bobrenjc93
marked this pull request as draft
August 17, 2026 21:49
This was referenced Aug 22, 2026
Closed
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
1 similar comment
Contributor
Author
|
@bobrenjc93 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Author
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.
Stack from ghstack (oldest at bottom):
Fourth of the six enablers. The precompile PR above installs and unloads compiled
artifacts onto live code objects at runtime -- both through its package loader
and through the transparent caching_precompile path -- and ExtraState's cache
had no lock at all.
That was survivable while every mutation happened under the GIL between frame
evaluations. It stops being survivable once artifacts are installed at runtime,
because
lookup()walks the cache while evaluating guards and guard evaluationruns Python -- so the GIL can drop mid-iteration and another thread can clear
the list being walked.
ExtraState gets a recursive mutex, and taking it is the part that needs care.
A thread that blocks on the mutex while holding the GIL wedges the owner, who
needs the GIL to finish its guards.
CacheLocktherefore try_locks first andreleases the GIL only when it actually has to wait. The matching hazard is
invalidate, which receives a raw CacheEntry pointer read before the lock: itnow re-establishes the entry under the lock by the identity of the guard manager
that owns it, since a recycled list node would pass an address check. For the
same reason the frame evaluator takes a strong reference to the code object a
lookup hands back before doing anything that can drop the GIL.
Most of the rest is compile-region plumbing. Cache entries and the exec strategy
already carried a region; this extends it to precompile entries and frame state,
so several artifacts can sit on one code object and each serves only its own.
Precompile entries match their region exactly and deliberately do not fall back
to the default bucket, because the identity guards that would tell two artifacts
apart are the ones precompile has to drop. That makes teardown a question of
ownership rather than of region: a library frame two loaded models both call
holds entries from both packages, so each entry carries a token identifying its
installer and uninstall removes only its own.
Two changes here are not about regions.
get_backendreturns a backend's_torchdynamo_cache_keywhen it has one, behind a process-global one-way gatethat only a precompile backend flips, so two artifacts on one frame get distinct
cache entries. And a
_torchdynamo_force_callback_on_cache_missmarker lets arun-only frame still reach the callback on a miss, which is what makes an
uncovered served call raise instead of quietly running eager.
Test Plan:
The deadlock does not fail when reintroduced, it hangs, so its test carries a
faulthandler timeout rather than an assertion. The use-after-free reproduces as
a SIGSEGV in under 7s with 8 caller threads against 2 installers, and survives
737k install/reset cycles after the fix.
Authored with an AI assistant.
Differential Revision: D116222526