Skip to content

Reduce GRPO trainer memory - #29

Merged
bingran-you merged 1 commit into
mainfrom
bry/reduce-grpo-memory
Jul 14, 2026
Merged

Reduce GRPO trainer memory#29
bingran-you merged 1 commit into
mainfrom
bry/reduce-grpo-memory

Conversation

@bingran-you

@bingran-you bingran-you commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Reduces the sampled-logprob model-bridge context cap from 24,576 to 16,384 tokens.
  • Leaves baseline, SFT, gate, and final evaluation at the full 49,152-token context.
  • Sets PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True at CLI startup unless the operator supplied another allocator configuration.

Why

The 24,576-token cap prevented the trainer's forward/logprob OOM, but a later variable-length batch still OOMed during backward due to fragmentation: PyTorch had 10.41 GiB reserved but unused and attempted an 11.66 GiB allocation.

A 16,384-token GRPO context reserves 4,096 tokens for generation and bounds the sampled prompt to 12,288 tokens. Expandable segments reduce fragmentation across the highly variable data-agent trajectories. Evaluation behavior remains unchanged.

The failed GRPO stage still had zero reward variance, loss=0, and grad_norm=0, so restarting from the saved SFT checkpoint loses no learned policy update.

Validation

  • 224 package contract tests pass.
  • 26 focused bridge/CLI tests pass.
  • Ruff check/format, Python compilation, and git diff --check pass.
  • Live replay of the known 59k-token follow-up with logprobs=true fitted to exactly 12,288 prompt tokens and returned a sidecar with the same exact prompt-ID count.

@bingran-you
bingran-you merged commit e7c09a9 into main Jul 14, 2026
1 check passed
@bingran-you
bingran-you deleted the bry/reduce-grpo-memory branch July 14, 2026 21:29
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.

1 participant