Skip to content

fix(refit): reduce oversized IPC buffer memory - #4643

Merged
yuki-97 merged 7 commits into
NVIDIA-NeMo:r0.8.0from
sharonyu-115:shuangy/fix-r080-oversized-refit-buffer
Oct 17, 2026
Merged

yuki-97 merged 7 commits into
NVIDIA-NeMo:r0.8.0from
sharonyu-115:shuangy/fix-r080-oversized-refit-buffer

Conversation

@sharonyu-115

@sharonyu-115 sharonyu-115 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Oversized tensors in streaming CUDA-IPC refit can exhaust GPU memory if both regular ping-pong buffers remain allocated alongside the oversized transfer. Qwen3.5-397B includes an 8 GiB grouped-expert export. Allocating the regular pair before checking each tensor also needlessly recreates it between consecutive oversized exports.

Changes

  • Flush ordinary parameters, consume outstanding receiver acknowledgements, and release both regular buffers before an oversized transfer.
  • Export contiguous CUDA tensors directly from their source storage; retain aligned staging copies for CPU or noncontiguous tensors. Wait for the receiver ACK before releasing transfer storage and drop the caller-side tensor reference before advancing the generator.
  • Resolve the transfer device independently of allocation. Create the regular buffer pair only for an ordinary-sized parameter, so first or back-to-back oversized tensors do not allocate it.
  • Add regression coverage for consecutive oversized exports, mixed small/oversized streams, ACK ordering, buffer lifetime, alignment, payload values, direct CUDA storage, and CPU-to-CUDA fallback.
  • Cap the 397B recipe's refit buffer budget at 4 GiB total (two 2 GiB regular buffers).
  • Set both STEPS_PER_RUN and MAX_STEPS to 10 in tests/test_suites/llm/grpo-qwen3.5-397ba17b-32n8g-megatron.v2.sh to fit the run within 4 hours. Adjust its provisional reward gate from > -0.2 to > -0.7; retain the KL gate < 0.004.
  • Rebase onto r0.8.0 at 6a521ef5af1ab8e32ab9aaba4511ca52259603c3.

Validation of current head

Head: 795a472c95cc41380d4d820f116088ccfd7f0f24 (threshold-only update; refit code unchanged from 0547792dda3a23251141a4b6795698f52753957a).

  • Focused local regression run before the threshold-only update: 8 passed, 5 GPU-dependent tests skipped, 13 deselected.
  • All repository pre-commit hooks passed, including Ruff and Pyrefly; shell syntax and git diff --check passed.
  • Slurm job 20103285 completed all 10/10 training steps on 32 nodes / 256 GPUs in 3h33m, using refit-code commit 0547792dda3a23251141a4b6795698f52753957a. Fresh run, no checkpoint resume, no async-scheduling override.
  • The original job exited 1:0: KL passed, but the unchanged 20-step reward threshold (> -0.2) failed. It was not an originally passing test job.
  • Threshold-only commit 795a472c95cc41380d4d820f116088ccfd7f0f24 changes the provisional 10-step reward gate to > -0.7, retaining KL < 0.004. The earlier successful 20-step run also missed -0.2 at step 10 (best reward -0.5014) and first crossed it at step 15.
  • Post-run re-evaluation of the saved metrics passed: mean generation KL error 0.0013572548632510006 < 0.004; maximum reward -0.5575790405273438 > -0.7; 10 loss steps and finite loss/KL/reward metrics. Shell syntax, diff checks, and applicable pre-commit checks passed. No new training run was launched for this threshold-only change.
  • Used cached r0.8.0 image rl.r080-pipeline71876279-878d98f2-x86.sqsh, with NIXL 1.4.1 and cuDNN frontend 1.28.0 updates applied in the job containers to match the rebased lockfile.
  • W&B run.

Historical validation (before the latest regression fix/rebase)

  • Original focused GPU test: 7/7 passed (job 19882909).
  • The earlier recipe completed 20 steps across jobs 19922621 and 19933869, using checkpoint/resume and async_scheduling=false to work around fix(recipes): disable vLLM async scheduling for GLM-5.1 #4354. That override is not part of this PR.
  • Mean generation KL error: 0.001358; maximum reward: 0.617565; final validation accuracy: 0.621094; generation failures: 0.
  • Historical W&B continuation.

@copy-pr-bot

copy-pr-bot Bot commented Oct 10, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@sharonyu-115 sharonyu-115 added the CI:L1 Run doctests, unit tests, and functional tests label Oct 10, 2026
@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 3b71b9e

@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 482ab27

@sharonyu-115
sharonyu-115 force-pushed the shuangy/fix-r080-oversized-refit-buffer branch from 482ab27 to 0547792 Compare October 13, 2026 07:00
@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 0547792

@sharonyu-115

sharonyu-115 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

10-step test: reward gate adjusted; saved metrics rechecked

Pushed 795a472c95cc41380d4d820f116088ccfd7f0f24: change the provisional 10-step reward threshold to max(train/reward) > -0.7; keep mean(train/gen_kl_error) < 0.004 unchanged.

Job 20103285 ran all 10/10 steps on 32 nodes / 256 GPUs in 3h33m, with refit code at 0547792dda3a23251141a4b6795698f52753957a. No refit/OOM failures were found in the driver log, and no async-scheduling override was used.

The job originally exited 1:0 because its final reward check still used the 20-step threshold of -0.2. The earlier successful 20-step run also missed that gate at step 10 (maximum reward -0.5014), only crossing it at step 15.

Re-running the metric checker on the saved results with the revised gate passes:

  • Mean generation KL error: 0.0013572548632510006 < 0.004 — PASS.
  • Maximum reward: -0.5575790405273438 > -0.7 — PASS.
  • All 10 loss steps present; loss, KL error, and reward values finite.
  • Shell syntax, diff checks, and applicable pre-commit checks passed.
  • Refit cost from the driver log: transfer_and_update_weights averaged about 39 s/step (37-45 s), about 3.6% of a steady-state step (steps 2-9, ~1070 s); prepare_for_generation averaged about 48 s (~4.5%). No spikes or growth across steps and no OOM. There is no before/after comparison, because the unfixed code OOMs on the first refit. Steps 1 and 10 have longer totals (validation).

This is a post-run metric re-evaluation, not a newly executed or originally passing Slurm job. The refit code and training configuration are unchanged by this commit. The reward threshold remains provisional pending more 10-step runs.

W&B run

@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 795a472

@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 1dc360a

@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 618dfc4

@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 882c9cb

@sharonyu-115

Copy link
Copy Markdown
Contributor Author

/ok to test 441a0e4

@sharonyu-115
sharonyu-115 marked this pull request as ready for review October 15, 2026 23:30
@sharonyu-115
sharonyu-115 requested a review from yuki-97 October 15, 2026 23:31
@sharonyu-115 sharonyu-115 added the cherry-pick-to-main Opt in: cherry-pick this PR's commit from the release branch back into main label Oct 15, 2026

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling the 8 GiB grouped-expert refit OOM on Qwen3.5-397B. Exporting contiguous CUDA tensors directly and releasing the ping-pong pair before an oversized transfer is a clean way to recover the headroom.

Thanks also for posting the 32n8g end-to-end run in the description, which makes it easy to see the fix holds at the target scale.

Scope: stream_weights_via_ipc_zmq_impl in nemo_rl/models/policy/utils.py, its unit tests, and the Qwen3.5-397B recipe and release test.

Checked:

  • Peak GPU memory during an oversized transfer, derived from the code (not measured). S is the parameter size and B the two regular buffers combined (4 GiB with refit_buffer_size_gb: 4); the last column is for the 8 GiB grouped-expert on 397B:

    tensor before after 397B (before → after)
    contiguous CUDA B + 2S (source + copy) S (source only, exported directly) 20 → 8 GiB
    non-contiguous CUDA B + 3S (source + copy + reshape(-1) temporary) 3S (copy path unchanged) 28 → 24 GiB
    contiguous / non-contiguous CPU B + S (copy) S (copy) 12 → 8 GiB
  • Extra cost of the new path, which the before/after code does not pay on the ordinary path:

    1. After flushing the pending group, the sender now waits for its ACK before releasing the pair, so that wait is no longer overlapped with the oversized copy (only relevant for CPU / non-contiguous tensors, since the direct export has no copy).
    2. The pair is released with empty_cache and re-allocated by the next ordinary parameter. If an oversized tensor appears in every layer, this repeats per layer; consecutive oversized tensors skip the re-allocation.
  • Wire protocol — an oversized parameter is still one group (handle, [name], aligned_size) and the grouping rule for ordinary parameters is unchanged. The vLLM and TRT-LLM receivers slice buffer[offset : offset + size_in_bytes] from state_dict_info and only check offset == used_bytes, so the smaller exported buffer is fine.

  • ACK ordering and buffer lifetime — the pending group is flushed and the outstanding ACK consumed before the regular pair is released, and each oversized send is ACKed before its storage is dropped.

  • Direct IPC export — storage offset and views of a larger storage are carried by reduce_tensor.

  • Lazy re-allocation of the regular pair — small → oversized → small, oversized-first and consecutive oversized streams all behave as intended, including device resolution for CPU-yielded tensors.

  • Test expectations — the allocation lists in the new tests match a hand computation from the code.

  • refit_buffer_size_gb: 4 — read as the total (two 2 GiB buffers) on the colocated vLLM path this recipe uses.

LGTM.

@yuki-97
yuki-97 merged commit 03f5d7d into NVIDIA-NeMo:r0.8.0 Oct 17, 2026
117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-to-main Opt in: cherry-pick this PR's commit from the release branch back into main CI:L1 Run doctests, unit tests, and functional tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants