Use the current CUDA stream for non-paged optimizer updates - #2050
Open
heiheiha798 wants to merge 4 commits into
Open
Use the current CUDA stream for non-paged optimizer updates#2050heiheiha798 wants to merge 4 commits into
heiheiha798 wants to merge 4 commits into
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.
Summary
max_unormreset and precondition kernels;The baseline launches registered optimizer updates on stream 0. With a pending event on a nondefault caller stream, a non-paged optimizer can read the stale gradient before the caller-stream producer runs. It also calls
torch.cuda.synchronize()once per active parameter. This patch orders ordinary non-paged NVIDIA CUDA work on the caller's current stream and relies on the caller's normal synchronization boundary.Paged managed state is deliberately excluded from that routing. Its existing
cprefetchABI submits migration on stream 0, so an actual state tensor carryingis_paged=Truepasses a null/default stream to the additive optimizer wrapper and preserves prefetch-before-update FIFO ordering plus the existing post-update synchronizations.Fork issue: heiheiha798#25
Fork engineering record: heiheiha798#26
Scope
The patch does not change optimizer arithmetic, state formats, kernel geometry, public schemas, UVM prefetch behavior, or the legacy direct C ABI. The tracked benchmark loads the legacy symbols from a separately built exact-baseline library and the stream-aware symbols from the exact-head candidate library in one process.
B300 validation
Environment: one NVIDIA B300 SXM6 AC, CC 10.3, 148 SMs; driver 580.126.09; CUDA/nvcc 13.0.88; PyTorch 2.13.0+cu130. Baseline was
95f9af309d4d5793847169c39288dcd3fcbdf564; final exact head wasb6530a80713f7ab6da29f7587b6398234bcce515. Isolated builds used CUDA targets75;80;86;89;90;100;120and resolved to75-real;80-real;86-real;89-real;90-real;100-real;120.0.0009999722. A four-parameter AdamW32bit step made four device-wide synchronizations.63d3785f81a1ea59c7505fc2f854e71feec2a65f. Candidate/baseline provenance and legacy/new symbols were asserted. Focused tests: 5 passed. Relevant optimizer matrix: 192 passed, 12 supported skips, 48 deselected. Racecheck: 0 hazards/errors/warnings. Synccheck: 0 errors. Every benchmarked final parameter, state tensor, and gradient was bitwise equal. Its Nsight Systems trace supplies the native launch/synchronization mechanism evidence because the review fix changes only Python routing for actual paged state and tests.PagedAdamW32bitfrom a nondefault caller, observed both state prefetch submissions before the update, and verified the update received stream 0; the event-gatedmax_unorm > 0case matched its serialized reference. The unchanged full benchmark matrix remained bitwise equal and passed every performance gate.pre-commit run --all-files: passed at the final head.Final exact-head completed wall-time ratios, baseline/current-stream (greater than 1 is faster):
The resident 32-layer, 64-trainable-parameter AdamW8 PEFT-style workload improved from 4.3408 ms to 3.9394 ms, or 1.102x. All four final-head single-large controls improved; the smallest ratio was BF16 AdamW8 at 1.013x.
Job 5225 Nsight Systems timed ranges showed the expected unchanged non-paged mechanism with identical optimizer launch counts:
cudaDeviceSynchronizecalls, candidate 0;The official-compatible candidate library grew by 23,080 bytes.
Reproduction
After building the baseline and candidate in separate source trees with the target list above, run the tracked CLI against their exact libraries:
The fork engineering record linked above retains the complete job and raw-evidence inventory.
Limits
Performance and runtime ordering were measured on one B300 and this CUDA/PyTorch stack. The other listed CUDA targets were compile-only. ROCm/hipcc was unavailable on both login and Slurm environments, so shared-source HIP compilation and runtime behavior were not validated here and must be covered by downstream CI. No CUDA graph-capture support is claimed. Fork CI currently provides no substitute for upstream multi-platform CI.