Skip to content

[LLM] slime example: offload optimizer state to host RAM by default - #10269

Merged
ishankaul1 merged 1 commit into
skypilot-org:masterfrom
ishankaul1:slime-optimizer-offload
Jul 29, 2026
Merged

ishankaul1 merged 1 commit into
skypilot-org:masterfrom
ishankaul1:slime-optimizer-offload

Conversation

@ishankaul1

@ishankaul1 ishankaul1 commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Long multi-turn RL rollouts can spike the trainer's activation memory past what a 4-GPU (TP4) 14B trainer has left once optimizer state sits on-device. The trainer's per-GPU statics are ~16 bytes/param (bf16 weights + fp32 grads + fp32 master weights + Adam moments) ≈ 56 GB at 14B/TP4 on an 80 GB H100 — leaving only a few GB of headroom. Long trajectories can produce a single packed sample tens of thousands of tokens long, whose fp32 [T, vocab/TP] log-prob computation transiently needs several contiguous GiB; runs then fail with CUDA OOMs a few GiB short after several steps, depending on how long a batch's trajectories happen to be:

torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 3.84 GiB.
GPU 0 has a total capacity of 79.19 GiB of which 3.79 GiB is free.
  ...
  File "slime/utils/ppo_utils.py", line 219, in vocab_parallel_softmax
    normalized_logits = logits.sub_(logits_max) if inplace else logits - logits_max

Fix

Offload optimizer state (Adam moments + fp32 master weights, ~12 of the ~16 bytes/param) to pinned host RAM — the same flag trio slime's own large-model scripts use:

  • --optimizer-cpu-offload --overlap-cpu-optimizer-d2h-h2d --use-precision-aware-optimizer on by default in run-slime.sh (OPTIMIZER_OFFLOAD=0 opts out)
  • memory: 256+ on the trainer task (the offloaded states live on the host)

Measured effect at 14B/TP4: per-GPU statics drop ~56 GB → ~22 GB, so the transient spike lands in ~38 GB of slack instead of ~4. Optimizer-step overhead is hidden behind rollout time for this workload (the D2H/H2D transfers overlap with compute).

Tested

  • 3-step smoke at TP4 with offload: clean; flags verified in the launched command; 27.5 GB allocated after model load (vs ~56 GB without).
  • 50-step training run at TP4 with offload on the full SWE-smith dataset: SUCCEEDED, 50/50 steps, zero recoveries. GPU memory flat across the whole run (20.6–27.5 GB allocated at the per-step checkpoints — never approached the ceiling). Mean step time 859 s vs ~950 s for a matched 50-step no-offload TP8 baseline — offload overhead is not measurable above rollout variance for this workload.
  • Previous behavior for comparison: TP4 without offload failed with the OOM above at steps 2–7 across three separate runs.

🤖 Generated with Claude Code

Long multi-turn RL rollouts can spike the trainer's activation memory past
what a 4-GPU (TP4) 14B trainer has left once optimizer state (Adam moments +
fp32 master weights, ~12 of ~16 bytes/param) sits on-device — runs fail with
CUDA OOMs a few GiB short after several steps, depending on how long a batch's
trajectories happen to be. Moving optimizer state to pinned host RAM
(--optimizer-cpu-offload + overlap/precision-aware companions, the same trio
slime's own large-model scripts use) roughly halves per-GPU static memory
(measured: ~56 GB -> ~22 GB at 14B TP4) and keeps long runs comfortably
inside the memory ceiling on the same 4 GPUs.

Adds a matching memory: 256+ request on the trainer task (the offloaded
states live on the host) and an OPTIMIZER_OFFLOAD=0 escape hatch to keep
optimizer state on-GPU.

Validated with a 50-step training run on the full SWE-smith dataset (plus a
matched no-offload baseline at TP8).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@ishankaul1
ishankaul1 marked this pull request as ready for review July 29, 2026 20:16
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@ishankaul1
ishankaul1 merged commit 6219060 into skypilot-org:master Jul 29, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants