-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Delta weight sync for AsyncGRPO (sparse patches over HF Bucket) #5937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AmineDiro
wants to merge
13
commits into
main
Choose a base branch
from
delta-weight-sync-v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
081a21a
Add delta weight sync (sparse bucket patches) for AsyncGRPO
AmineDiro 36d54db
Add AsyncGRPO delta weight sync example
AmineDiro e3166c0
Merge branch 'main' into delta-weight-sync-v3
AmineDiro ceae48b
Use placeholder HF bucket in delta sync example
AmineDiro cb4154e
Halve change-detector peak memory: free each pre-step snapshot as it'…
AmineDiro cd83506
weight diff bucketed
AmineDiro 4a4bf3b
Default AsyncGRPO weight sync to sparse delta (AdamW-inversion) with …
AmineDiro fec7c55
Chunk sparse extraction to bound the nonzero buffer on large models
AmineDiro 1562e53
Support FSDP2 in sparse weight sync via per-shard mask reconstruction
AmineDiro a8b5ebf
Stream sparse extraction in chunks to bound rank-0 memory under FSDP
AmineDiro f2a20d1
Add disaggregated async-GRPO bucket example + weight-sync docs
AmineDiro 9d68f7d
simplify docs
AmineDiro 606abb1
Guard delta_engine import behind vLLM availability
AmineDiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright 2020-2026 The HuggingFace Team. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """ | ||
| AsyncGRPO with delta weight sync (Transport B: HF Storage Bucket + in-place sparse apply). | ||
|
|
||
| Only changed bf16 weights are encoded as a sparse safetensors patch, uploaded to a bucket, and | ||
| applied in place on vLLM via PR #40096 — no full-model broadcast, no vLLM-side snapshot. | ||
|
|
||
| Start the vLLM server with the `delta` backend + worker extension (registers the engine) and the | ||
| `transformers` model impl (so vLLM's runtime param names match the trainer's HF names — every | ||
| param is then addressable by the in-place sparse apply, no fuse/unfuse remap needed): | ||
|
|
||
| # VLLM_USE_V2_MODEL_RUNNER=0 is required: the in-place sparse apply (apply_sparse_weight_patches, | ||
| # vLLM #40096) exists only on the V1 model runner. Without it the server picks V2 and every sparse | ||
| # delta update fails (the dense anchors still work, so it silently degrades to anchor-only sync). | ||
| CUDA_VISIBLE_DEVICES=1 VLLM_SERVER_DEV_MODE=1 VLLM_USE_V2_MODEL_RUNNER=0 vllm serve Qwen/Qwen3-1.7B \ | ||
| --model-impl transformers \ | ||
| --worker-extension-cls trl.experimental.async_grpo.delta_engine.DeltaWorkerExtension \ | ||
| --weight-transfer-config '{"backend":"delta"}' \ | ||
| --max-model-len 2560 | ||
|
|
||
| CUDA_VISIBLE_DEVICES=0 accelerate launch examples/scripts/async_grpo_delta.py | ||
| """ | ||
|
|
||
| import logging | ||
| import os | ||
|
|
||
| from datasets import load_dataset | ||
|
|
||
| from trl.experimental.async_grpo import AsyncGRPOConfig, AsyncGRPOTrainer | ||
| from trl.rewards import accuracy_reward | ||
|
|
||
|
|
||
| logging.basicConfig( | ||
| level=getattr(logging, os.environ.get("LOG_LEVEL", "INFO").upper(), logging.INFO), | ||
| format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | ||
| ) | ||
| logging.getLogger("trl").setLevel(logging.INFO) | ||
|
|
||
|
|
||
| def format_sample(sample): | ||
| return { | ||
| "prompt": [{"role": "user", "content": sample["question"]}], | ||
| "solution": sample["answer"].split("####")[-1].strip(), | ||
| } | ||
|
|
||
|
|
||
| def main() -> None: | ||
| dataset = load_dataset("openai/gsm8k", "main", split="train") | ||
| dataset = dataset.map(format_sample, remove_columns=dataset.column_names) | ||
|
|
||
| config = AsyncGRPOConfig( | ||
| output_dir="./results/async_grpo_delta", | ||
| per_device_train_batch_size=1, | ||
| num_generations=8, | ||
| max_completion_length=512, | ||
| max_steps=60, | ||
| learning_rate=1e-5, | ||
| logging_steps=1, | ||
| bf16=True, | ||
| report_to="none", | ||
| project="async_grpo_delta", | ||
| log_completions=True, | ||
| # Qwen3 thinking traces blow past the completion cap on GSM8K (truncated -> no answer -> | ||
| # zero reward); disable thinking so completions are short and accuracy_reward gets signal. | ||
| chat_template_kwargs={"enable_thinking": False}, | ||
| # --- delta weight sync (Transport B) --- | ||
| delta_sync_enabled=True, | ||
| delta_sync_repo_id="aminediroHF/async-grpo-delta-demo", | ||
| delta_sync_anchor_interval=20, # full anchor every N syncs; sparse deltas in between | ||
| delta_sync_encoding="gap_delta", # raw | gap_delta | nvcomp_cascaded | ||
| ) | ||
| trainer = AsyncGRPOTrainer( | ||
| model="Qwen/Qwen3-1.7B", | ||
| args=config, | ||
| train_dataset=dataset, | ||
| reward_funcs=accuracy_reward, | ||
| ) | ||
| trainer.train() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.