Simplify CPU bucket cache locking#14
Open
TianyeGGBond wants to merge 2 commits into
Open
Conversation
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.
Context
The F4 CPU bucket cache path currently has two layers of locking around the same state:
CPUBucketCacheowns an internalthreading.Lockfor_bucketsand_cache_ready_step.MegatronTrainRayActoralso creates_cache_lockand wraps bothbuild_cpu_bucket_cacheandrun_sync_sessionwith it.In the current deployment model, train actors are created as default synchronous Ray actors without
max_concurrency, and these methods are notasync. That meansbuild_cpu_bucket_cacheandrun_sync_sessionare already serialized by Ray on the same actor. The actor-level lock is therefore redundant, and its comments make the implementation look more concurrent than it is.What changed
MegatronTrainRayActor._cache_lockinitialization.build_cpu_bucket_cache.run_sync_session.CPUBucketCache's internal lock so the cache object remains self-contained and protects its own state.Why
This keeps the locking model to one layer while preserving behavior. The cache still publishes and reads
_cache_ready_stepthrough its own methods, but the train actor no longer adds a redundant critical section around synchronous Ray actor methods. This is closer to the style in miles main: rely on the actor execution model where it applies, and keep local state protection inside the small helper object.Validation
python -m py_compile miles/backends/megatron_utils/actor.py miles/backends/megatron_utils/update_weight/cpu_bucket_cache.pygit diff --checkgit grep -n _cache_lock -- miles/backends/megatron_utils/actor.py miles/backends/megatron_utils/update_weight/cpu_bucket_cache.pyreturns no matches