-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ckpt] feat: implement large tensor slicing in vllm rollout and CheckpointEngine for weight updating #5378
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
jianjunzhong
wants to merge
19
commits into
verl-project:main
Choose a base branch
from
jianjunzhong:feat/chunked_weight_update
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
[ckpt] feat: implement large tensor slicing in vllm rollout and CheckpointEngine for weight updating #5378
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fe7e78e
[vllm] feat: implement chunked weight handling in vllm rollout for la…
jianjunzhong 46345a8
fix: handle large weight tensors in chunking logic to prevent ZeroDiv…
jianjunzhong fcf6ecd
[vllm] feat: implement chunked weight handling in vllm rollout for la…
jianjunzhong 9947884
fix: handle large weight tensors in chunking logic to prevent ZeroDiv…
jianjunzhong 9e1be9a
feat: implement chunked weight handling in checkpoint engines to supp…
jianjunzhong b13a546
refactor: move tensor yielding logic to CheckpointEngine for better c…
jianjunzhong 9d0a80e
feat: implement collective checkpoint engine for NCCL and HCCL with c…
jianjunzhong 418fbd0
refactor: implement chunk slicing in NIXLCheckpointEngine using base …
jianjunzhong ca5c4aa
fix: add properties for bucket size, rank, and buffers in HCCL and NC…
jianjunzhong 2a84ae4
fix: add update_weights_bucket_megabytes parameter to checkpoint engi…
jianjunzhong 4d617da
refactor: streamline HCCL and NCCL checkpoint engines
jianjunzhong 177c9f6
fix: update total_params calculation in NIXL and Collective checkpoin…
jianjunzhong d781221
[ckpt] feat: implement large tensor slicing in CheckpointEngine
jianjunzhong ec18f2b
refactor: utilize compute_weight_chunks utility for weight tensor sli…
jianjunzhong ec908ea
fix: add bucket_size property with getter and setter
jianjunzhong 5af5eed
Merge branch 'main' into feat/chunked_weight_update
jianjunzhong d31bb52
refactor: update CheckpointEngineManager initialization to use datacl…
jianjunzhong 80e3235
refactor: move logger initialization to the top of tensor_utils.py
jianjunzhong e7ed83a
test: temporarily skip test_naive_correctness.py
jianjunzhong 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| # Copyright 2024 Bytedance Ltd. and/or its affiliates | ||
| # | ||
| # 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. | ||
| import os | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
| import ray | ||
| from omegaconf import DictConfig | ||
|
|
||
| from verl.checkpoint_engine import CheckpointEngineManager | ||
| from verl.experimental.agent_loop.agent_loop import AgentLoopManager | ||
| from verl.protocol import DataProto | ||
| from verl.single_controller.ray import ( | ||
| RayClassWithInitArgs, | ||
| RayResourcePool, | ||
| RayWorkerGroup, | ||
| ) | ||
| from verl.single_controller.ray.base import create_colocated_worker_cls | ||
| from verl.utils.config import omega_conf_to_dataclass | ||
| from verl.utils.device import get_device_name | ||
| from verl.utils.tokenizer import hf_tokenizer | ||
| from verl.workers.config import CheckpointEngineConfig | ||
| from verl.workers.engine_workers import ActorRolloutRefWorker | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def init_config() -> DictConfig: | ||
| from hydra import compose, initialize_config_dir | ||
|
|
||
| with initialize_config_dir(config_dir=os.path.abspath("verl/trainer/config")): | ||
| config = compose(config_name="ppo_trainer") | ||
|
|
||
| config.trainer.n_gpus_per_node = 8 | ||
| config.trainer.nnodes = 1 | ||
| config.actor_rollout_ref.actor.use_dynamic_bsz = True | ||
| config.actor_rollout_ref.model.path = os.path.expanduser("~/models/Qwen/Qwen3-VL-2B-Instruct") | ||
| config.actor_rollout_ref.rollout.name = os.environ.get("ROLLOUT_NAME", "vllm") | ||
| config.actor_rollout_ref.rollout.skip_tokenizer_init = False | ||
| config.actor_rollout_ref.rollout.max_num_seqs = 256 | ||
| config.actor_rollout_ref.rollout.gpu_memory_utilization = 0.8 | ||
| config.actor_rollout_ref.rollout.agent.num_workers = 2 | ||
| config.actor_rollout_ref.rollout.checkpoint_engine.backend = "naive" | ||
| config.actor_rollout_ref.rollout.checkpoint_engine.update_weights_bucket_megabytes = 256 | ||
| config.actor_rollout_ref.rollout.enforce_eager = True | ||
|
|
||
| return config | ||
|
|
||
|
|
||
| @pytest.mark.skip(reason="temporary skip since our ci environment is not ready") | ||
| @pytest.mark.asyncio | ||
| def test_server_adapter_colocated_weight_update(init_config): | ||
| ray.init( | ||
| runtime_env={ | ||
| "env_vars": { | ||
| "TOKENIZERS_PARALLELISM": "true", | ||
| "NCCL_DEBUG": "WARN", | ||
| "VLLM_LOGGING_LEVEL": "INFO", | ||
| "VLLM_USE_V1": "1", | ||
| "VLLM_DISABLE_COMPILE_CACHE": "1", | ||
| "HCCL_HOST_SOCKET_PORT_RANGE": "60000-60050", | ||
| "HCCL_NPU_SOCKET_PORT_RANGE": "61000-61050", | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| # 0. init actor rollout worker group | ||
| resource_pool = RayResourcePool( | ||
| process_on_nodes=[init_config.trainer.n_gpus_per_node] * init_config.trainer.nnodes, max_colocate_count=3 | ||
| ) | ||
| actor_rollout_cls = ray.remote(ActorRolloutRefWorker) | ||
| cls_dict = { | ||
| "actor_rollout": RayClassWithInitArgs( | ||
| cls=actor_rollout_cls, config=init_config.actor_rollout_ref, role="actor_rollout" | ||
| ) | ||
| } | ||
| ray_cls_with_init = create_colocated_worker_cls(cls_dict) | ||
| wg_dict = RayWorkerGroup( | ||
| resource_pool=resource_pool, ray_cls_with_init=ray_cls_with_init, device_name=get_device_name() | ||
| ) | ||
| spawn_wg = wg_dict.spawn(prefix_set=cls_dict.keys()) | ||
| actor_rollout_wg = spawn_wg["actor_rollout"] | ||
| actor_rollout_wg.init_model() | ||
|
|
||
| # 1. create AgentLoopManager | ||
| agent_loop_manager = AgentLoopManager( | ||
| config=init_config, | ||
| worker_group=actor_rollout_wg, | ||
| rollout_resource_pool=resource_pool, | ||
| ) | ||
|
|
||
| # 2. create CheckpointEngineManager | ||
| checkpoint_engine_config: CheckpointEngineConfig = omega_conf_to_dataclass( | ||
| init_config.actor_rollout_ref.rollout.checkpoint_engine | ||
| ) | ||
| checkpoint_manager = CheckpointEngineManager( | ||
| config=checkpoint_engine_config, | ||
| trainer=actor_rollout_wg, | ||
| replicas=agent_loop_manager.rollout_replicas, | ||
| ) | ||
| checkpoint_manager.sleep_replicas() | ||
|
|
||
| # 3. generate prompts | ||
| raw_prompts = [ | ||
| [ | ||
| { | ||
| "role": "user", | ||
| "content": "This is a test for weight update. If the weight has been correctly " | ||
| 'updated and you understand my meaning, please respond with "Test Passed".', | ||
| } | ||
| ], | ||
| [ | ||
| { | ||
| "role": "user", | ||
| "content": "This is a test for weight update. If the weight has been correctly " | ||
| 'updated and you understand my meaning, please respond with "Test Passed".', | ||
| } | ||
| ], | ||
| ] | ||
| batch = DataProto( | ||
| non_tensor_batch={ | ||
| "raw_prompt": np.array(raw_prompts), | ||
| "agent_name": np.array(["single_turn_agent"] * len(raw_prompts)), | ||
| "data_source": np.array(["openai/gsm8k"] * len(raw_prompts)), | ||
| "reward_model": np.array([{"style": "rule", "ground_truth": "1.0"}] * len(raw_prompts)), | ||
| }, | ||
| ) | ||
|
|
||
| # 4. update weights and generate sequences, check if the responses are correct | ||
| for _ in range(3): | ||
| checkpoint_manager.update_weights() | ||
| result = agent_loop_manager.generate_sequences(batch) | ||
| checkpoint_manager.sleep_replicas() | ||
|
|
||
| # Check response | ||
| tokenizer = hf_tokenizer(init_config.actor_rollout_ref.model.path) | ||
| responses = result.batch["responses"] | ||
| response_mask = result.batch["response_mask"] | ||
|
|
||
| for i in range(len(responses)): | ||
| valid_tokens = responses[i][response_mask[i].bool()] | ||
| response = tokenizer.decode(valid_tokens) | ||
| assert "test passed" in response.lower(), f"Response does not contain 'test passed': {response}" | ||
|
|
||
| print("=========================") | ||
| print("[OUTPUT]:", response) | ||
| print("---") | ||
|
|
||
| ray.shutdown() | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The model path is hardcoded to a user-specific local directory. This makes the test non-portable and difficult for other developers to run. It's recommended to use a model from the Hugging Face Hub that can be downloaded automatically, or at least make this path configurable via an environment variable. Using a smaller model for this test would also make it faster and more efficient.