Skip to content

ZeRO-1/2: one CPU-offload accumulator per group; zero idle gradients - #8964

Closed
sfc-gh-truwase wants to merge 1 commit into
masterfrom
truwase/zero-request-boundary-grads
Closed

sfc-gh-truwase wants to merge 1 commit into
masterfrom
truwase/zero-request-boundary-grads

Conversation

@sfc-gh-truwase

@sfc-gh-truwase sfc-gh-truwase commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #8949 (merged as dc046b1). Fixes #8991.

This replaces the earlier content of this PR (accumulating every backward in the optimizer's FP32 partition gradient). That approach was dropped: its extra complexity was not worth its gains. This version keeps #8949's design and makes two narrow changes: preallocate the CPU-offload accumulator per partition group instead of lazily per parameter, and fix the stale-gradient leak.

Problem

  • Lazy accumulator complexity. ZeRO-1/2: preserve gradients across request boundaries until step #8949 stores CPU-offload gradient sums in accumulated_grads_in_cpu, a dict keyed by parameter id and filled on first use. FP32 masters get owned buffers sized to the whole parameter; low-precision masters get aliased views of the partition gradient, created in two places. Accumulate, copy-back, and restore each branch on which kind they hold (about ten branches across four functions). The pinned buffers are never unpinned, and the low-precision restore leaves stale data in a shared scratch tensor that the overflow scan reads.
  • Stale-gradient leak ([BUG] ZeRO-1/2 CPU offload reapplies stale FP32 gradients for unused parameters #8991). reset_cpu_buffers did not zero the FP32 partition gradient. A trainable parameter that receives no gradient in the next window kept its previous slice, and Adam applied it again.

Fix

  • One host accumulator per partition group, sized to the partition, in the bit16 dtype, pinned when cpu_offload_pin_memory is set. Each parameter uses a fixed slice at its dest_offset, the same layout as the FP32 partition. The buffer is allocated on the first non-boundary accumulation, so boundary-only training (GAS=1) pins no extra host memory. Low-precision masters keep accumulating in the partition gradient.
  • _get_cpu_offload_accumulator_slice() is the only place that picks the buffer. The per-parameter dict, both alias sites, and the full-parameter versus fragment branching are removed.
  • Restore clears the scratch tensor before copying this rank's fragment.
  • The group buffers are unpinned with the other offload buffers.
  • reset_cpu_buffers zeros each FP32 partition gradient after the step, after overflow, and on reset.
  • set_norm_for_param_grad is removed; it has no callers.

No config or API changes.

Overflow detection

Restore now zeros the non-owned part of the restored gradient, where #8949 kept this rank's local pre-reduction values. Skip-step behavior does not change: each reduced fragment is checked by the rank that owns it, and has_overflow() MAX-reduces local_overflow across the data-parallel and model-parallel groups. A multi-rank test with an inf in a non-owned region was not run.

Not a duplicate

Validation

CPU unit tests

Hardware: 1x Intel Xeon Platinum 8488C (96 logical CPUs), no GPU. Python 3.12.12, PyTorch 2.9.1+cu130.

python -m pytest -q tests/unit/v1/zero/test_zero2_gradient_safety.py \
  tests/unit/v1/zero/test_zero_cpu_offload_grad_accum.py

57 passed, 2 skipped (the two CUDA stream tests).

After rebasing onto master b62afa8, test_zero2_gradient_safety.py, test_zero_cpu_offload_grad_accum.py, and test_zero2_offload_multi_backward.py (includes #8728's test) run with LOCAL_SIZE=2: 87 passed, 2 skipped.

#8728's regression test, TestZero2OffloadOverflowRecovery::test_finite_step_after_overflow (two CPU ranks via LOCAL_SIZE=2, BF16 and FP16, low-precision and FP32 masters), passes 4/4 on this branch. With the zero_() in _restore_cpu_offload_grad_to_gpu removed, all 4 cases fail with finite step did not update large. The new leak tests (test_idle_parameter_window_does_not_reuse_previous_gradient, test_idle_parameter_stays_zero_beside_active_neighbor, FP32 and BF16 masters) compare against torch.optim.Adam; all four fail with the reset_cpu_buffers zeroing removed. test_single_boundary_offload_avoids_auxiliary_storage_and_copy checks that a boundary-only step allocates no host accumulator.

python -m pytest -q tests/unit/runtime/zenflow \
  tests/unit/runtime/zero/test_zero1_optimizer_fastpath.py \
  tests/unit/runtime/half_precision/test_zero_grad_norm_overflow.py

97 passed, 42 skipped.

pre-commit run --files passed on the three changed files.

GPU memory and throughput

Hardware: 8x NVIDIA H200 (141 GiB), PyTorch 2.14.0+cu130, CUDA 13.0 (driver version not recorded). Qwen3-4B and Qwen3.5-4B, ZeRO-2, bf16, CPU optimizer offload with pinned memory, torch.optim.Adam, GAS 1 and 4, sequence length 512 and 2048, 1 warmup and the median of 2 measured iterations, at 1, 2, 4, and 8 GPUs. Baseline is #8949 plus the same reset_cpu_buffers zeroing, so these numbers isolate the accumulator change. The measured tree differs from this commit only in comments and tests.

All 16 runs passed (64 rows).

  • Forward, backward, boundary backward, and step time: median difference within ±1% at GAS=1 and ±0.5% at GAS=4. Per-pair differences stay inside the run-to-run noise.
  • Peak GPU allocated and reserved memory: identical in all 32 pairs.
  • Pinned host memory (peak GiB, baseline → this PR, sequence length 512):
Model GPUs GAS=1 GAS=4
Qwen3-4B 1 41.0 → 41.0 51.6 → 49.0
Qwen3-4B 2 21.0 → 21.0 26.3 → 25.0
Qwen3-4B 4 11.0 → 11.0 13.6 → 13.0
Qwen3-4B 8 6.0 → 6.0 7.3 → 7.0
Qwen3.5-4B 1 42.0 → 42.0 53.9 → 50.0
Qwen3.5-4B 2 22.0 → 22.0 28.1 → 26.0
Qwen3.5-4B 4 12.0 → 12.0 15.2 → 14.0
Qwen3.5-4B 8 7.0 → 7.0 9.0 → 8.0

Host RSS moves with pinned memory. No convergence run was performed.

Compatibility matrix

Validated: ZeRO-1 and ZeRO-2 with CPU optimizer offload, FP32 and BF16 (low-precision) masters, bf16 parameters, managed gradient accumulation (GAS 1 and 4), 1 to 8 GPUs data parallel (GPU sweep is ZeRO-2 only), and the ZenFlow and ZeRO-1 fast-path unit tests above.

Not validated: FP16 loss scaling, NVMe offload, ZeRO-3, pipeline, tensor, sequence, or expert parallelism, gradient clipping, checkpoint load in the middle of a window, and convergence. The GPU sweep never takes a non-boundary step at GAS=1, so the first-use allocation in unmanaged mode is covered only by CPU tests. The cost of zeroing the full FP32 partition each step was not measured on its own, because the baseline includes the same zeroing.

ZeRO-3 is unchanged: its reset_cpu_buffers only clears norms, and it was not checked for the same leak. ZenFlow inherits reset_cpu_buffers and so gets the new zeroing; its unit tests pass.

AI assistance was used to write, review, and measure this change. The submitting human needs to review every changed line before sign-off.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T13:39:16.390016Z 4c6e756 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4c6e7560ac

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread deepspeed/runtime/zero/stage_1_and_2.py Outdated
Comment on lines +1127 to +1131
if self.use_grad_accum_attribute:
self._current_backward_grads[group_idx] = self._clone_grad_snapshot(latest)
self.all_grad_tensors[group_idx] = self._sum_grad_snapshots(
self._clone_grad_snapshot(self._completed_request_grads[group_idx])
if group_idx in self._completed_request_grads else None, latest)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid duplicating every ZeRO-1 gradient snapshot

When use_grad_accum_attribute is enabled (notably ZeRO-1 with a higher-precision accumulation dtype), this branch clones latest into _current_backward_grads and then clones it again while constructing all_grad_tensors; with completed requests it additionally clones the full accumulated snapshot. Because param.grad_accum also remains live until the next forward, an ordinary backward can retain multiple full, unpartitioned gradient copies per rank, causing large-model jobs to OOM and defeating ZeRO's memory-saving purpose. Keep a single cumulative snapshot and avoid materializing duplicate per-request copies.

AGENTS.md reference: AGENTS.md:L34-L38

Useful? React with 👍 / 👎.

@sfc-gh-truwase
sfc-gh-truwase requested a review from stas00 October 31, 2026 14:00

@stas00 stas00 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for working on a much cleaner approach, Tunji.

the main concern is a change in memory requirements - should we profile that - original, mine and yours and correlate to the number of elements? should be easy to do via an agent.

@0z5a 0z5a 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.

Read at 4c6e7560. I checked the two #8949 failure modes the description names, using #8949's own request-boundary harness (DP=2, gloo, exact expected gradients) with two targeted windows:

  • miss_boundary: a request ["c0", "c1"] where the non-boundary c0 uses only projection 0 and the boundary c1 uses only projection 1.
  • unused_window: projection 0 is used in one window, unused for the whole next window, then used again.

With CPU offload, across ZeRO-1/2 and bf16/fp32 accumulation, this branch passes all 8 cases. Master and #8949 fail the same 6, all on the gradient comparison rather than with errors. For example, on miss_boundary under ZeRO-2 the projection-0 gradient is already wrong at step 0, and on unused_window under ZeRO-1 the projection that no backward used in that window has a nonzero gradient at its step. So both are real, and both predate #8949. Without offload, all three trees pass the same windows, so both are offload-only.

On stas00's memory question, one data point from CPU. After a single backward, at step() entry, I counted the bytes held in all_grad_tensors plus any still-live param.grad/grad_accum. ZeRO-1 with bf16 accumulation, a 131,072-parameter bf16 model at DP=2: 0 on master, 131,072 bytes on #8949 and on this branch. That is one extra copy of the rank's partition gradients, the same on both; no param.grad was live at that point on any of the three. This probe doesn't cover ZeRO-2, which keeps reduced gradients outside all_grad_tensors, or the grad_accum path Codex flagged, which needs fp16, and the CPU accelerator doesn't support it.

@sfc-gh-truwase

Copy link
Copy Markdown
Collaborator Author

@stas00 cleaner version is currently slower because of sync copies and cpu-based norm/overflow checks. In summary, it is not ready to replace #8949. I will keep tuning it but I think we can move forward to merging #8949.

@sfc-gh-truwase

Copy link
Copy Markdown
Collaborator Author

@0z5a thanks for the analysis.

@stas00

stas00 commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@sfc-gh-truwase, let's approve / merge it then

@sfc-gh-truwase
sfc-gh-truwase force-pushed the truwase/zero-request-boundary-grads branch from 4c6e756 to 3f7d7d2 Compare November 4, 2026 22:06
@sfc-gh-truwase sfc-gh-truwase changed the title ZeRO-1/2: keep every request's gradients until the optimizer step ZeRO-1/2: one CPU-offload accumulator per group; zero idle gradients Nov 4, 2026
@sfc-gh-truwase
sfc-gh-truwase force-pushed the truwase/zero-request-boundary-grads branch from 3f7d7d2 to 186a031 Compare November 5, 2026 11:44
…aseline runners

New self-contained BIRD harness under trl_gsm8k/, kept separate from the
uncommitted ZoRRo load_balancer edits (Arctic-Platform client.py + gsm8k script):

- bird_task.py: verl-parquet loader (flattens ground_truth/db_path columns) and
  sql_reward wrapping the txt2sql recipe's compute_score (SQLite exec-match);
  module-level + picklable for the native rollout child.
- test_bird_task.py: CPU reward test (exec-match 1.0 / wrong 0.1 / no-SQL 0.0).
- run_qwen3_1.7b_bird_grpo_trl.py: Arctic backend, disaggregated 4t/4s, R1
  thinking prompt, max_completion 1024 / max_seq_len 8192 / MAX_TOKEN_LEN_PER_GPU 8192.
- run_qwen3_1.7b_bird_grpo_baseline.py + run_bird_baseline.sh: native TRL baseline,
  accelerate-DDP 4 trainer + external vllm serve TP4 (disaggregated), kill only the
  vllm pid-subtree and run accelerate from trl_gsm8k/ to avoid the ./trl shadow.

Validated: 3-step smokes on-policy (ratio~1, kl~0.002) and a 30-step C1/C2/C3
comparison (native vs Arctic-noZoRRo vs Arctic-ZoRRo) with reward parity and ~2.5x
Arctic wall-clock speedup.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>
@sfc-gh-truwase

Copy link
Copy Markdown
Collaborator Author

Closed by an accidental force-push of an unrelated TRL commit onto truwase/zero-request-boundary-grads. GitHub will not reopen this PR after that rewrite. Replacement: #9018.

banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Nov 9, 2026
…eepspeedai#9018)

Replacement for deepspeedai#8964, which was closed after an accidental force-push
of an unrelated commit onto this branch. GitHub will not reopen deepspeedai#8964
after that rewrite. Follow-up to deepspeedai#8949 (merged as dc046b1). Fixes
deepspeedai#8991.

This replaces the earlier content of this PR (accumulating every
backward in the optimizer's FP32 partition gradient). That approach was
dropped: its extra complexity was not worth its gains. This version
keeps deepspeedai#8949's design and makes two narrow changes: preallocate the
CPU-offload accumulator per partition group instead of lazily per
parameter, and fix the stale-gradient leak.

## Problem

- **Lazy accumulator complexity.** deepspeedai#8949 stores CPU-offload gradient
sums in `accumulated_grads_in_cpu`, a dict keyed by parameter id and
filled on first use. FP32 masters get owned buffers sized to the whole
parameter; low-precision masters get aliased views of the partition
gradient, created in two places. Accumulate, copy-back, and restore each
branch on which kind they hold (about ten branches across four
functions). The pinned buffers are never unpinned, and the low-precision
restore leaves stale data in a shared scratch tensor that the overflow
scan reads.
- **Stale-gradient leak (deepspeedai#8991).** `reset_cpu_buffers` did not zero the
FP32 partition gradient. A trainable parameter that receives no gradient
in the next window kept its previous slice, and Adam applied it again.

## Fix

- One host accumulator per partition group, sized to the partition, in
the bit16 dtype, pinned when `cpu_offload_pin_memory` is set. Each
parameter uses a fixed slice at its `dest_offset`, the same layout as
the FP32 partition. The buffer is allocated on the first non-boundary
accumulation, so boundary-only training (GAS=1) pins no extra host
memory. Low-precision masters keep accumulating in the partition
gradient.
- `_get_cpu_offload_accumulator_slice()` is the only place that picks
the buffer. The per-parameter dict, both alias sites, and the
full-parameter versus fragment branching are removed.
- Restore clears the scratch tensor before copying this rank's fragment.
- The group buffers are unpinned with the other offload buffers.
- `reset_cpu_buffers` zeros each FP32 partition gradient after the step,
after overflow, and on reset.
- `set_norm_for_param_grad` is removed; it has no callers.

No config or API changes.

## Overflow detection

Restore now zeros the non-owned part of the restored gradient, where
deepspeedai#8949 kept this rank's local pre-reduction values. Skip-step behavior
does not change: each reduced fragment is checked by the rank that owns
it, and `has_overflow()` MAX-reduces `local_overflow` across the
data-parallel and model-parallel groups. A multi-rank test with an inf
in a non-owned region was not run.

## Not a duplicate

- deepspeedai#8949 (merged): this builds on it.
- deepspeedai#8991 (open issue): the leak this fixes.
- deepspeedai#8728 (merged as 0d0aa30): clears stale offload scratch before
restoring low-precision gradients. Its change is the same `zero_()` in
`_restore_cpu_offload_grad_to_gpu` that this PR includes. This PR is
rebased onto master (b62afa8) after deepspeedai#8728 landed. The one conflict was
in `_restore_cpu_offload_grad_to_gpu`; the resolution keeps this PR's
version (unconditional `zero_()` on the scratch, then the fragment copy
from `_get_cpu_offload_accumulator_slice`).
- deepspeedai#8920 (open): FP32 folded-gradient accumulation. Unrelated.
- deepspeedai#8957 (open issue): remaining test coverage. Not required for this
change.

## Validation

### CPU unit tests

Hardware: 1x Intel Xeon Platinum 8488C (96 logical CPUs), no GPU. Python
3.12.12, PyTorch 2.9.1+cu130.

```bash
python -m pytest -q tests/unit/v1/zero/test_zero2_gradient_safety.py \
  tests/unit/v1/zero/test_zero_cpu_offload_grad_accum.py
```

57 passed, 2 skipped (the two CUDA stream tests).

After rebasing onto master b62afa8, `test_zero2_gradient_safety.py`,
`test_zero_cpu_offload_grad_accum.py`, and
`test_zero2_offload_multi_backward.py` (includes deepspeedai#8728's test) run with
`LOCAL_SIZE=2`: 87 passed, 2 skipped.

deepspeedai#8728's regression test,
`TestZero2OffloadOverflowRecovery::test_finite_step_after_overflow` (two
CPU ranks via `LOCAL_SIZE=2`, BF16 and FP16, low-precision and FP32
masters), passes 4/4 on this branch. With the `zero_()` in
`_restore_cpu_offload_grad_to_gpu` removed, all 4 cases fail with
`finite step did not update large`. The new leak tests
(`test_idle_parameter_window_does_not_reuse_previous_gradient`,
`test_idle_parameter_stays_zero_beside_active_neighbor`, FP32 and BF16
masters) compare against `torch.optim.Adam`; all four fail with the
`reset_cpu_buffers` zeroing removed.
`test_single_boundary_offload_avoids_auxiliary_storage_and_copy` checks
that a boundary-only step allocates no host accumulator.

```bash
python -m pytest -q tests/unit/runtime/zenflow \
  tests/unit/runtime/zero/test_zero1_optimizer_fastpath.py \
  tests/unit/runtime/half_precision/test_zero_grad_norm_overflow.py
```

97 passed, 42 skipped.

`pre-commit run --files` passed on the three changed files.

### GPU memory and throughput

Hardware: 8x NVIDIA H200 (141 GiB), PyTorch 2.14.0+cu130, CUDA 13.0
(driver version not recorded). Qwen3-4B and Qwen3.5-4B, ZeRO-2, bf16,
CPU optimizer offload with pinned memory, `torch.optim.Adam`, GAS 1 and
4, sequence length 512 and 2048, 1 warmup and the median of 2 measured
iterations, at 1, 2, 4, and 8 GPUs. Baseline is deepspeedai#8949 plus the same
`reset_cpu_buffers` zeroing, so these numbers isolate the accumulator
change. The measured tree differs from this commit only in comments and
tests.

All 16 runs passed (64 rows). Change vs. baseline (deepspeedai#8949 plus the same
partition-gradient zeroing), in percent. Negative means faster. `bwd` is
total backward time per optimizer step; `iter` is forward + backward +
step.

Across all rows, iteration time moves between -4.0% and +2.0%. Backward
moves within ±2.5% in every row except Qwen3.5-4B at 8 GPUs with GAS=4,
which is 9.0% faster at sequence length 512 and 8.8% faster at 2048.
Both sequence lengths show it, but this sweep does not explain the
cause.

Sequence length 512:

| Model | GPUs | GAS | bwd | iter |
|---|---|---|---|---|
| Qwen3-4B | 1 | 1 | +4.4% | +0.2% |
| Qwen3-4B | 1 | 4 | +2.1% | +1.2% |
| Qwen3-4B | 2 | 1 | -0.4% | +2.0% |
| Qwen3-4B | 2 | 4 | -0.1% | +1.4% |
| Qwen3-4B | 4 | 1 | -0.7% | -0.3% |
| Qwen3-4B | 4 | 4 | -0.7% | -3.5% |
| Qwen3-4B | 8 | 1 | -1.2% | -1.6% |
| Qwen3-4B | 8 | 4 | -1.3% | -0.4% |
| Qwen3.5-4B | 1 | 1 | +0.6% | +0.7% |
| Qwen3.5-4B | 1 | 4 | -0.3% | -1.0% |
| Qwen3.5-4B | 2 | 1 | +2.5% | +0.4% |
| Qwen3.5-4B | 2 | 4 | +1.4% | +0.9% |
| Qwen3.5-4B | 4 | 1 | +1.0% | +0.1% |
| Qwen3.5-4B | 4 | 4 | -0.4% | -1.8% |
| Qwen3.5-4B | 8 | 1 | +1.3% | -0.0% |
| Qwen3.5-4B | 8 | 4 | -9.0% | +0.0% |

Sequence length 2048:

| Model | GPUs | GAS | bwd | iter |
|---|---|---|---|---|
| Qwen3-4B | 1 | 1 | +4.6% | +1.8% |
| Qwen3-4B | 1 | 4 | +2.4% | +1.3% |
| Qwen3-4B | 2 | 1 | +0.7% | +1.9% |
| Qwen3-4B | 2 | 4 | -0.4% | +0.1% |
| Qwen3-4B | 4 | 1 | -1.1% | +0.4% |
| Qwen3-4B | 4 | 4 | -0.7% | -2.1% |
| Qwen3-4B | 8 | 1 | -0.5% | -3.0% |
| Qwen3-4B | 8 | 4 | -0.8% | -4.0% |
| Qwen3.5-4B | 1 | 1 | -0.5% | -0.1% |
| Qwen3.5-4B | 1 | 4 | -0.6% | -1.3% |
| Qwen3.5-4B | 2 | 1 | +2.1% | -1.7% |
| Qwen3.5-4B | 2 | 4 | +0.5% | -0.9% |
| Qwen3.5-4B | 4 | 1 | +1.3% | +1.9% |
| Qwen3.5-4B | 4 | 4 | -0.3% | -0.9% |
| Qwen3.5-4B | 8 | 1 | +0.6% | -0.7% |
| Qwen3.5-4B | 8 | 4 | -8.8% | -0.6% |

- Peak GPU allocated and reserved memory: identical in all 32 pairs.
- Pinned host memory (peak GiB, baseline → this PR, sequence length
512):

| Model | GPUs | GAS=1 | GAS=4 |
|---|---|---|---|
| Qwen3-4B | 1 | 41.0 → 41.0 | 51.6 → 49.0 |
| Qwen3-4B | 2 | 21.0 → 21.0 | 26.3 → 25.0 |
| Qwen3-4B | 4 | 11.0 → 11.0 | 13.6 → 13.0 |
| Qwen3-4B | 8 | 6.0 → 6.0 | 7.3 → 7.0 |
| Qwen3.5-4B | 1 | 42.0 → 42.0 | 53.9 → 50.0 |
| Qwen3.5-4B | 2 | 22.0 → 22.0 | 28.1 → 26.0 |
| Qwen3.5-4B | 4 | 12.0 → 12.0 | 15.2 → 14.0 |
| Qwen3.5-4B | 8 | 7.0 → 7.0 | 9.0 → 8.0 |

Host RSS moves with pinned memory. No convergence run was performed.

### Compatibility matrix

Validated: ZeRO-1 and ZeRO-2 with CPU optimizer offload, FP32 and BF16
(low-precision) masters, bf16 parameters, managed gradient accumulation
(GAS 1 and 4), 1 to 8 GPUs data parallel (GPU sweep is ZeRO-2 only), and
the ZenFlow and ZeRO-1 fast-path unit tests above.

Not validated: FP16 loss scaling, NVMe offload, ZeRO-3, pipeline,
tensor, sequence, or expert parallelism, gradient clipping, checkpoint
load in the middle of a window, and convergence. The GPU sweep never
takes a non-boundary step at GAS=1, so the first-use allocation in
unmanaged mode is covered only by CPU tests. The cost of zeroing the
full FP32 partition each step was not measured on its own, because the
baseline includes the same zeroing.

ZeRO-3 is unchanged: its `reset_cpu_buffers` only clears norms, and it
was not checked for the same leak. ZenFlow inherits `reset_cpu_buffers`
and so gets the new zeroing; its unit tests pass.

AI assistance was used to write, review, and measure this change. The
submitting human needs to review every changed line before sign-off.

Signed-off-by: Olatunji Ruwase <tunji.ruwase@snowflake.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.

[BUG] ZeRO-1/2 CPU offload reapplies stale FP32 gradients for unused parameters

3 participants