Repository navigation
[megatron] KDA context parallelism: opt-in all-gather exchange (SKYRL_KDA_CP_EXCHANGE=allgather) - #2437
Draft
avigyabb wants to merge 2 commits into
Draft
[megatron] KDA context parallelism: opt-in all-gather exchange (SKYRL_KDA_CP_EXCHANGE=allgather)#2437avigyabb wants to merge 2 commits into
avigyabb wants to merge 2 commits into
Conversation
…_KDA_CP_EXCHANGE=allgather) Under CP, KDA moves from sequence to head parallelism with megatron-core's GatedDeltaNet all-to-all of the projected q/k/v/f/g/beta, which are ~1.25x wider than the hidden state and run on TP-gathered rows. SKYRL_KDA_CP_EXCHANGE=allgather instead all-gathers the sequence-parallel hidden-state shards over CP (the only cross-node hop when CP spans nodes), then over TP, and projects only this rank's 1/cp slice of the local heads: ~5x fewer bytes across the CP group. Measured over TCP NCCL at 1M tokens, TP8 CP2: fwd+bwd 1482 -> 1251 s. Tests: test_kda_context_parallel.py covers both exchanges (CP=2 vs CP=1). Split out of #2418. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 of 2 tasks
Collaborator
Author
|
all gather was better in all tests - maybe we should fold into one path? maybe just wait until megatron PR gets pushed? |
…llgather-exchange Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K4BmK8yuJTMbprizvT4Rja
This branch was successfully deployed
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.
Stacked on #2418 (KDA context parallelism, all-to-all exchange). Review only the top commit.
Summary
Under context parallelism, KDA moves from sequence to head parallelism. #2418 does that with megatron-core's
GatedDeltaNetall-to-all of the projected q/k/v/f/g/beta, which are ~1.25x wider than the hidden state and run on TP-gathered rows.SKYRL_KDA_CP_EXCHANGE=allgather(opt-in) instead all-gathers the sequence-parallel hidden-state shards over CP (the only cross-node hop when CP spans nodes), then over TP, and projects only this rank's 1/cp slice of the local heads. One permutation of the narrow projected tensors puts tokens into natural order; backward reduce-scatters in reverse. About 5x fewer bytes cross the CP group.Performance
Over EFA the step is 8% faster at the same peak memory (144.6 vs 144.5 GiB); EFA rows are the mean warm step of the full step (fwd+bwd+optimizer) with the rest of the long-context recipe on. On a 4-layer GLM-5.3-Flash slice at 1M tokens, CP2 across 2 nodes over EFA: 34.9 -> 32.8 s/step (−6%), same memory.
Testing
gpu_ci/patches/megatron/mcore_ext/test_kda_context_parallel.py, parametrized over both exchanges: CP=2 outputs and input/param grads match CP=1. Passed on B200 on this exact code before the split (as part of [megatron] Context parallelism for GLM-5.3-Flash (head-wise KDA, all-gather DSA) #2418).Split out of #2418.
🤖 Generated with Claude Code