perf: keep scalar optimizer step counters on CPU in state offload - #3258
Draft
samsja wants to merge 1 commit into
Draft
perf: keep scalar optimizer step counters on CPU in state offload#3258samsja wants to merge 1 commit into
samsja wants to merge 1 commit into
Conversation
_move_states shipped the 0-dim step counters to CUDA with the rest of the optimizer state, so the GPU optimizer's per-parameter _get_value read (.item()) became a device synchronization — one per parameter per step, serializing the update against the state streaming. Scalar step counters now stay on CPU, their canonical torch.optim location. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
Author
|
Heads-up: #3234 has since removed the state-offload mode entirely (offload is now full-offload-only and disabled by default), which deletes the 🤖 Generated with Claude Code |
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.
Summary
optim_cpu_offload(on by default) moves optimizer state between CPU and GPU around each step._move_statesalso shipped the 0-dimstepcounters to CUDA — and torch's AdamW reads each one back with.item()per parameter per step, turning every read into a device sync (587 syncs/step on Qwen3-30B-A3B, visible asaten::item≈ 1.6 s in profiler traces at seq 8K on 8×H200).This keeps scalar step counters on CPU — their canonical
torch.optimlocation — so the optimizer reads them without touching the device.Measured effect is modest (8K step median 3.18 → 3.13 s) because the syncs were mostly waiting on the state transfers rather than adding to them — the dominant cost of state offload remains the ~2×30 GiB/rank PCIe streaming itself. The change removes the per-parameter serialization points and keeps step counters in the standard representation for checkpoints.
Losses unchanged (verified on paired 5-step runs).
🤖 Generated with Claude Code