Wiring up offload_opt_states - #8186
Draft
pengdurice wants to merge 4 commits into
Draft
Conversation
Replace the Python closures the move_opt_states pass inserted as FX graph nodes with registered custom ops (torch.library, dc namespace), making the pass compatible with the inductor backend and its compile cache. Wire the pass to the user config (compile.offload_opt_states) using the capacity-first schedule: offload everything, profile on the emptied GPU, then keep resident only what the memory budget allows. Frees are completion-driven (record_stream), empty_cache runs once per compile phase, and unit plus 2-GPU end-to-end tests cover op registration, budget planning, schedule placement, and loss parity. Signed-off-by: pengdurice <pengduhit@gmail.com>
Signed-off-by: pengdurice <pengduhit@gmail.com>
Signed-off-by: pengdurice <pengduhit@gmail.com>
Signed-off-by: pengdurice <pengduhit@gmail.com>
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.
Make DeepCompile's optimizer-state offloading work under inductor and reachable from config
Summary of Changes
dcnamespace. The graphcarries a tensor anchor and an integer index; live tensors stay in module state.
Reload-before-sync is correctness-critical. A test fails without it.
[(0,[z3]), (1,[for_init, z3, move_opt_states])]:states are emptied to host before profiling, so the plan is made against the floor and a job
that only fits with offloading never runs a step with everything resident. (The pass author's
own ordering from their test harness; the budget formula is unchanged.)
record_streamprotects reload buffers from early reuse; and the copy stream waits for thecompute stream before writing a reload buffer — without it a mid-backward reload overwrites a
live activation, which showed up as NaN losses. All are stream dependencies, no host waits.
The wrong pool costs an allocator retry plus a device-wide sync per step.
empty_cacheonce per compilephase rather than per step (per-step measured +28%); mutual exclusion with
offload_parameters.Results
Qwen3-14B, 8×H200 (141 GB), ZeRO-3, micro-batch 4, fp32 states (22.2 GB/rank),
expandable_segments:True. Medians over each run's final phase, single campaign.Limitations
gradient_accumulation_steps=1: the graph runs per micro-batch, so accumulationrepeats the whole cycle. Documented in the config docstring.
offload_parameters.Tests
tests/unit/v1/compile/test_offload_opt_states.py— op and ORDERED-effect registration; amechanism test compiling side-effect ops through stock inductor and asserting program order;
budget planning and node placement; re-run and multi-graph gating; once-per-phase
empty_cache;and a 2-GPU end-to-end loss-parity test whose op counters prove the ops ran in the compiled graph
(reloads are skipped while profiling, so a nonzero reload count is the proof).