fix(training): align DSv4 packed FLOPs with MCore - #5542
Conversation
Signed-off-by: Chen Cui <chcui@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
/claude review |
|
LGTM - light review, one observation. Verified the DSv4 packed-FLOPs split analytically:
Observation (not blocking): legacy BSHD equivalence holds only when seq_length is a multiple of 128 (and 4). The old code used integer floor // 128; the new quadratic term uses true division, so for a seq_length not divisible by 128 the fixed-length result now differs slightly from the pre-PR value. This is the intended MCore-parity direction, just worth noting for anyone comparing against older numbers. Note: I could not execute the unit tests in the review sandbox (pytest was blocked); the assessment above is by inspection. The PR reports 10 passed locally. Suggested test cases:
|
What does this PR do?
Align DeepSeek-V4 packed-sequence FLOPs accounting with Megatron-LM's token-linear and quadratic split.
Changelog
seqlen_squared_sum.Root cause and impact
The Bridge formula predated Megatron-LM's packed-sequence correction in NVIDIA/Megatron-LM#5358. It collapsed all DSv4 sparse-attention work into a token-linear expression using one effective sequence length. That is equivalent for the supported fixed-length cases covered by the existing test, but diverges for packed variable-length sequences.
This change preserves supported fixed-length results while making packed DSv4 accounting match Megatron-LM:
F = total_tokens * token_linear_term + seqlen_squared_sum * quadratic_termNo router, mHC, MTP, or backend-specific accounting is changed because those are shared calculator omissions rather than Bridge/Megatron-LM parity mismatches.
GitHub Actions CI
No GPU or cluster jobs were run for this CPU-only FLOPs change.
Validation
uv run python -m pytest tests/unit_tests/training/utils/test_flop_utils.py::TestDeepSeekV4HybridFlops -q— 10 passed in a dependency-isolated CPU environment.uv run pre-commit run --all-files— passed.32,548,061,184) and THD (32,538,230,784) fixtures.Before your PR is "Ready for review"
Additional Information