Skip to content

Implement delta model state dict transport - #6311

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 21, 2026 •

Copy link
Copy Markdown
Contributor

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.


Stack (top to bottom):


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
@tushar00jain
tushar00jain changed the base branch from fs-base/delta-weight-sync/1 to main November 21, 2026 00:48
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 21, 2026
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.

1 participant