Skip to content

Implement delta model state dict transport - #6142

Closed
tushar00jain wants to merge 1 commit into
mainfrom
fs-head/delta-weight-sync/1
Closed

tushar00jain wants to merge 1 commit into
mainfrom
fs-head/delta-weight-sync/1

Conversation

@tushar00jain

@tushar00jain tushar00jain commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Why

Each pull reads the whole model, but an RL step changes only 1.6-2.2% of bf16 values, spread over every tensor. Delta sync sends only the changed 2-byte words, in NVIDIA NeMo RL's sparse refit format: the gap before each changed word and the word XOR its old value, compressed with zstd level 1. A 1-ulp change leaves the high bits of the XOR zero, so it compresses better than the new value. Gaps restart at each staged piece, so every change is addressed in the tensor that receives it, as other systems address changes per tensor; the generator applies them to the weights it loads, without translating them.

Trainer rank, per 64 MiB window of the staging buffer

 staging buffer (last push)            this push (GPU)
+------------+---------------+   +------------+---------------+
| k1: 7 3 9  | k2: 4 8 1     |   | k1: 7 5 9  | k2: 4 2 1     |
+------------+---------------+   +------------+---------------+
                  |  compare (GPU)
                  v
  k1: gaps [1]  XORs [3^5]     k2: gaps [1]  XORs [8^2]
                  |
                  v  zstd (CPU threads), one record per window
  delta buffer: [window 0 | window 1 | ...]
                  |
                  v
  Controller forwards per window (offset, size, gap width, changes per piece)
                  |
                  v
Generator
  prefetch: RDMA the windows covering its pieces -> unzstd (CPU threads)
            -> each FSDP group's changes packed into one pinned buffer
                  |
                  v
  load, per FSDP group:
    prefetch buffer (last push) -- copy to GPU, as for full sync --> weights
    group's changes -> GPU; positions = running sum of (gap + 1), per piece
    weights[positions] ^= XORs  -> k1: 7 5 9   k2: 4 2 1
                  |
                  v  after the load, in the background (CPU threads)
  prefetch buffer[positions] ^= XORs

A pull moves only the compressed changes plus the copy the load already does. The prefetch buffer catches up off the critical path, before the next read. The first pull is full. A push with more than 1/16 of a window's words changed, or a generator that missed a push, reads the push whole.

What changed

  • Trainer: stage compares each 64 MiB window of the staging buffer with the new push on the GPU and stages the changed words' gaps, XORs and per-piece counts in a pinned buffer, with no host synchronization. finish_stage compresses each changed window on CPU threads into a registered delta buffer.
  • Controller: forwards each trainer rank's window table and push index unchanged; finishes pull N before push N+1.
  • Generator: reads one range per run of adjacent changed windows into a registered receive buffer, decompresses on CPU threads, and packs each FSDP group's changes. The load applies them on the GPU (one copy and one running sum per group, one gather/XOR/scatter per key), then writes them into the prefetch buffers in the background.
  • zstandard is not a PyTorch library; a TODO names its standard-library replacement (compression.zstd, Python 3.14).

Alternatives considered

Approach Steady pull, same setup Why not
Dense zstd(old ^ new) per window, CPU (humans& #6176, vLLM vime) 2.80-2.92 s decodes and XORs all 54 GB per generator
(index, value) overwrite, GPU apply in prefetch 1.31-1.40 s 2.65-3.93 GB and ~400 reads per pull
Window-addressed gaps + XORs, GPU round trip in prefetch 1.39-1.55 s copies the whole prefetch buffer to the GPU and back
Window-addressed, translated to keys on the CPU 1.33-1.95 s the translation costs as much as the copies it saves
nvCOMP GPU decode (#6176) - non-PyTorch dependency; apply stays dense
Keep each window's updated copy on the GPU until the load - a second 54 GB copy of the model per generator

User-facing changes

Configuration Behavior
Default sync_mode="full" Existing full synchronization with one trainer staging buffer
sync_mode="delta" First pull is full; later pulls transfer only the changed words, compressed, and apply them during the load

Tradeoffs

  • Trainer: +2.35 GiB pinned changed-word buffer and +1.57 GiB delta buffer per rank. Generator: +6.26 GiB receive buffer.
  • Trainer staging is slower (0.38-4.57 s vs 0.11 s), overlapped with training; blocking stays at 0-8 ms.

Testing

.venv/bin/pytest -q \
  tests/rl/unit_tests/cpu/test_model_state_dict_transport.py \
  tests/rl/unit_tests/cpu/test_inter_generator_router.py \
  tests/rl/unit_tests/cpu/test_trainer_loop.py
  • test_delta_loads_changes: changes applied in place (row pieces) and to packed keys (column pieces), with pieces spanning windows.
  • test_delta_reads_only_changed_windows: unchanged windows are not read, adjacent windows share one read, consecutive pushes chain, a read that is not loaded is applied by the next one, and a missed push reads whole.
  • test_delta_reads_whole_past_capacity: a window over capacity makes the push read whole.
  • test_delta_windows_span_pieces: a window with several pieces and a piece spanning windows, mixed dtypes.

Loaded weights and prefetch buffers are bitwise equal to the trainer's after every delta in these tests and in a local 6.7 GB GPU check.

Qwen3.5 27B (53.8 GB bf16) on MAST, 2 GB300 hosts (4 NICs each), DAPO-Math recipe: trainer FSDP 2 x TP 2 on one host, 4 TP 1 vLLM generators on the other (each pulls the full model), 6 steps of 4 prompts x 16 samples, NIXL 1.5.0 (bundled UCX 1.23.0). The two columns run this PR's code; only sync_mode differs. Pull times are for the slowest generator.

Full sync (sync_mode="full") This PR (sync_mode="delta")
First pull 1.42 s 1.43 s
Steady pulls (pulls 2-7) 1.54-1.73 s (fastest generator 1.43-1.57 s) 0.93-1.49 s (fastest generator 0.67-1.00 s)
Effective rate, all 4 generators 125-140 GB/s 145-232 GB/s
Bytes read per generator per steady pull 53.79 GB (100%) 0.75-0.99 GB (1.4-1.8%)
RDMA reads per generator per steady pull 2538 4
Changed words per push - 1.56-2.23%
Compression ratio (staged / compressed) - 53-73x
Prefetch per generator (RDMA read + decompress) 0.95-1.02 s 0.19-0.74 s
Decompress (CPU zstd) - 0.18-0.32 s
Generator load (pause, includes the GPU XOR) 0.46-0.71 s 0.43-0.79 s
Blocking pull / step time (steps 2-6) 0-0.045 0-0.029
tok/s full step, mean of steps 2-6 10.2k 10.0k
Mean reward 0.250 0.310

Trainer staging, same runs (trainer rank 0).

Full sync (sync_mode="full") This PR (sync_mode="delta")
Trainer blocking per step 0-5 ms 0-8 ms
Full stage, overlapped 0.11 s 0.38-4.57 s
Compress (CPU, 32 threads, overlapped) - 0.08-0.11 s
forward_backward incl. overlapped staging (steps 2-6) 33.2-41.0 s 34.5-41.3 s
Init push 0.14 s 0.26 s

Memory, same runs (max over processes and steps).

Full sync (sync_mode="full") This PR (sync_mode="delta")
Trainer model GPU memory 30.79 GiB 30.79 GiB
Generator KV cache 196.77 GiB 196.77 GiB
Peak GPU reserved, trainer / generator 172.96 / 261.06 GiB 173.82 / 261.06 GiB
Peak RSS, trainer / generator 17.16 / 80.98 GiB 21.96 / 98.30 GiB
Trainer staging buffer 12.52 GiB 12.52 GiB
Trainer changed-word buffer - 2.35 GiB
Trainer delta buffer - 1.57 GiB
Generator prefetch buffer 50.10 GiB 50.10 GiB
Generator delta receive buffer - 6.26 GiB

Stack (top to bottom):


@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 16, 2026 23:16
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 16, 2026 23:59
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 16, 2026 23:59
@tushar00jain
tushar00jain added this pull request to stack #6148 November 16, 2026 23:59
@tushar00jain
tushar00jain removed this pull request from stack #6148 November 17, 2026 00:09
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 17, 2026 00:09
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 17, 2026 00:09
@tushar00jain
tushar00jain added this pull request to stack #6149 November 17, 2026 00:09
@tushar00jain
tushar00jain removed this pull request from stack #6149 November 17, 2026 17:07
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 17, 2026 17:07
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 17, 2026 17:07
@tushar00jain
tushar00jain added this pull request to stack #6160 November 17, 2026 17:07
@tushar00jain
tushar00jain removed this pull request from stack #6160 November 17, 2026 23:55
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 17, 2026 23:55
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from 8b10893 to b84ff0d Compare November 17, 2026 23:55
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 17, 2026 23:56
@tushar00jain
tushar00jain added this pull request to stack #6168 November 17, 2026 23:56
@tushar00jain
tushar00jain removed this pull request from stack #6168 November 18, 2026 00:19
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 18, 2026 00:19
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from b84ff0d to 750ac0e Compare November 18, 2026 00:19
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 18, 2026 00:19
@tushar00jain
tushar00jain added this pull request to stack #6170 November 18, 2026 00:19
@tushar00jain
tushar00jain marked this pull request as ready for review November 18, 2026 23:32
@tushar00jain
tushar00jain marked this pull request as draft November 19, 2026 22:00
@pytorch-bot pytorch-bot Bot removed the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Nov 19, 2026
@tushar00jain
tushar00jain removed this pull request from stack #6238 November 19, 2026 22:30
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 19, 2026 22:30
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from 750ac0e to 51f09a5 Compare November 19, 2026 22:31
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 19, 2026 22:31
@tushar00jain
tushar00jain added this pull request to stack #6255 November 19, 2026 22:31
stream.synchronize()


class ModelStateDictTransport(Configurable):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we make a "ModelStateDictDeltaTransport" impl? Wondering if it would be better to structure this separately. Would be nice to make a subfolder and split some of this logic up

@tushar00jain tushar00jain Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. Also still in the process of updating this PR from the previous version - refactoring, changing the custom format to XOR, wire compression, researching on optimizing the delta to the staging buffer bottleneck. Will mark it ready for review after updating.

@tushar00jain
tushar00jain removed this pull request from stack #6255 November 20, 2026 01:17
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 20, 2026 01:17
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from 51f09a5 to 51b484b Compare November 20, 2026 01:17
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 20, 2026 01:17
@tushar00jain
tushar00jain added this pull request to stack #6262 November 20, 2026 01:17
@tushar00jain
tushar00jain removed this pull request from stack #6262 November 20, 2026 02:54
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 20, 2026 02:54
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from 51b484b to bf2280a Compare November 20, 2026 02:54
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 20, 2026 02:54
@tushar00jain
tushar00jain added this pull request to stack #6265 November 20, 2026 02:54
@tushar00jain
tushar00jain removed this pull request from stack #6265 November 20, 2026 03:38
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 20, 2026 03:38
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from bf2280a to 0fad7e6 Compare November 20, 2026 03:38
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 20, 2026 03:38
@tushar00jain
tushar00jain added this pull request to stack #6267 November 20, 2026 03:38
@tushar00jain
tushar00jain removed this pull request from stack #6267 November 20, 2026 04:56
@tushar00jain
tushar00jain changed the base branch from main to fs-base/delta-weight-sync/1 November 20, 2026 04:56
@tushar00jain
tushar00jain force-pushed the fs-head/delta-weight-sync/1 branch from 0fad7e6 to bf2280a Compare November 20, 2026 04:56
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 20, 2026 04:56
@tushar00jain
tushar00jain added this pull request to stack #6272 November 20, 2026 04:56
Add optional delta synchronization to the direct model state dict transport, keeping full synchronization as the default.

At RL learning rates an optimizer step changes few bf16 values (about 2%), but they are spread over every tensor, so a range-level delta still sends nearly everything. Delta sync instead sends only the changed 2-byte words, in NeMo RL's sparse refit format: the gap before each changed word and the word XOR its old value, compressed with zstd level 1. A 1-ulp change leaves the high bits of the XOR zero, so it compresses better than the new value. Gaps restart at each staged piece, so every change is addressed in the tensor that receives it.

- The trainer keeps one dense staging buffer holding the latest push, as for full sync. After the first push, `stage` assembles each 64 MiB window of the staging buffer on the GPU, compares it with the window's previous contents (read back from the pinned buffer) before overwriting them, and copies the changed words' gaps, XORs and per-piece counts to a pinned buffer, with no host synchronization. `finish_stage` compresses each changed window's record on CPU threads into a registered delta buffer. A push with more than 1/16 of a window's words changed, or whose records exceed the delta buffer, is not sent as a delta.
- `finish_stage` returns each window's (offset, size, gap width, changes per piece) and the push index as ordinary Monarch endpoint metadata; the controller forwards them unchanged.
- Each generator rank reads the first push whole, then one range per run of adjacent changed windows covering its pieces into one registered receive buffer, decompresses the windows on CPU threads, and packs each FSDP group's changes into one pinned buffer. The load copies the prefetch buffers to the GPU as for full sync, and per FSDP group copies the changes there, computes their positions with one running sum and XORs them into the copies, so a pull moves only the compressed changes and the load's own copy. CPU threads then XOR the same words into the prefetch buffers in the background; the next read waits for them. A generator that missed a push, or a delta that was not sent, reads the push whole.

zstandard is not a PyTorch library; a TODO names its standard-library replacement (Python 3.14). The controller remains the sole coordinator, finishes pull N before push N+1, and keeps the restart-on-failure behavior.

Test Plan:

```
pytest -q tests/rl/unit_tests/cpu/test_model_state_dict_transport.py tests/rl/unit_tests/cpu/test_inter_generator_router.py tests/rl/unit_tests/cpu/test_trainer_loop.py
```

Authored with assistance from an AI coding assistant.

fs-branch: delta-weight-sync/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants