-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[testing][rollout] feat: support integration of vllm>=0.7.0 (spmd-version) #209
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
Merged
Merged
Changes from 31 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
be4cd50
[test] test for vllm-spmd
ZSL98 d76c04d
[test] test for sync weight in OpenRLHF style
ZSL98 e20ba1b
[chore] Remove dependencies on vllm<=0.6.3
ZSL98 ac4c91d
[test] Add time profiling on vllm sync weight
ZSL98 6fb4999
[test] Some formatting changes
ZSL98 b64a473
Merge branch 'volcengine:main' into zsl/vllm-spmd
ZSL98 4fe511a
Merge branch 'volcengine:main' into zsl/vllm-spmd
ZSL98 c77bbec
Merge branch 'volcengine:main' into zsl/vllm-spmd
ZSL98 234a52d
Add a tiny version of run_qwen2-7b_seq_balance.sh
ZSL98 bc689b6
init some files
ZSL98 6f55342
Merge remote-tracking branch 'upstream/main' into zsl/vllm-spmd
ZSL98 5a2d526
update
ZSL98 c0a5099
update
ZSL98 4a6d686
update
ZSL98 6c78554
support fsdp
ZSL98 ef47177
support vllm>=0.7.0 and fsdp
ZSL98 e8a7487
Merge remote-tracking branch 'origin/main' into latest
ZSL98 d71b5a2
Merge branch 'volcengine:main' into latest
ZSL98 18ed87f
Merge branch 'volcengine:main' into latest
ZSL98 a27ee29
remove redundant files
ZSL98 e936114
update
ZSL98 ffa88ed
[test] update run_fsdp_vllm_spmd.py
ZSL98 0fd82c6
Merge branch 'volcengine:main' into latest
ZSL98 c34d67e
fix
ZSL98 a6237a6
license
ZSL98 71f8a84
update
ZSL98 f6d2ef9
update
ZSL98 6d956e3
Merge branch 'volcengine:main' into latest
ZSL98 7ba97d8
update
ZSL98 6efc130
update
ZSL98 bf33df3
doc
ZSL98 c99d258
update doc
ZSL98 de27933
update
ZSL98 eb8242d
Merge branch 'volcengine:main' into latest
ZSL98 a85d88f
quick fix
ZSL98 43979c7
Merge branch 'latest' of https://github.com/ZSL98/verl into latest
ZSL98 fcd1474
doc
ZSL98 fcc0451
Merge branch 'volcengine:main' into latest
ZSL98 fe1ad99
reformat
ZSL98 1bf9e5a
Merge branch 'latest' of https://github.com/ZSL98/verl into latest
ZSL98 8f2ffae
fix ci
ZSL98 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Readme for verl(vllm0.7) version | ||
|
|
||
| ## Installation | ||
|
|
||
| Note: This version of veRL supports **FSDP** for training and **vLLM** for rollout. (Megatron-LM is not supported yet.) | ||
|
|
||
| ``` | ||
| # Create the conda environment | ||
| conda create -n verl python==3.10 | ||
| conda activate verl | ||
|
|
||
| # Install verl | ||
| git clone https://github.com/volcengine/verl.git | ||
| cd verl | ||
| pip3 install -e . | ||
| # Install vLLM>=0.7 | ||
| pip3 install vllm==0.7.0 | ||
|
PeterSH6 marked this conversation as resolved.
Outdated
|
||
| # Install flash-attn | ||
| pip3 install flash-attn --no-build-isolation | ||
|
|
||
| ``` | ||
|
|
||
| For existing stable vllm versions (<=0.7.2), you also need to make some tiny patches manually on vllm (/path/to/site-packages/vllm after installation) after the above steps: | ||
|
|
||
| - vllm/distributed/parallel_state.py: Remove the assertion below: | ||
|
|
||
| ``` | ||
| if (world_size | ||
|
ZSL98 marked this conversation as resolved.
|
||
| != tensor_model_parallel_size * pipeline_model_parallel_size): | ||
| raise RuntimeError( | ||
| f"world_size ({world_size}) is not equal to " | ||
| f"tensor_model_parallel_size ({tensor_model_parallel_size}) x " | ||
| f"pipeline_model_parallel_size ({pipeline_model_parallel_size})") | ||
|
|
||
| ``` | ||
|
|
||
| - vllm/executor/uniproc_executor.py: change `local_rank = rank` to `local_rank = int(os.environ["LOCAL_RANK"])` | ||
| - vllm/model_executor/model_loader/weight_utils.py: remove the `torch.cuda.empty_cache()` in `pt_weights_iterator` | ||
|
|
||
| These modifications have already been merged into the main branch of vLLM. To avoid modifying these files manually, you can directly build vLLM from source. | ||
|
PeterSH6 marked this conversation as resolved.
|
||
|
|
||
| ## Features | ||
|
|
||
| ### Use cuda graph | ||
|
|
||
| After installation, examples using FSDP as training backends can be used. By default, the `enforce_eager` is set to True, which disables the cuda graph. To enjoy cuda graphs and the sleep mode of vLLM>=0.7, add the following lines to the bash script: | ||
|
|
||
| ``` | ||
| actor_rollout_ref.rollout.enforce_eager=False \ | ||
| actor_rollout_ref.rollout.free_cache_engine=False \ | ||
|
|
||
| ``` | ||
|
|
||
| For a typical job like examples/ppo_trainer/run_qwen2-7b_seq_balance.sh, the rollout generation time is 115 seconds with vLLM0.6.3, while it is 90 seconds with vLLM0.7.0. By enabling the cudagraph, the generation duration is further reduced to 65 seconds. | ||
|
|
||
| **Note:** Currently, if the `n` is greater than 1 in `SamplingParams` in vLLM>=0.7, there is a potential performance issue on the stability of rollout generation time (Some iterations would see generation time bursts). We are working with the vLLM team to check this issue. | ||
|
|
||
| ### Other features in vLLM | ||
|
|
||
| 1. **num_scheduler_step>1:** not supported yet (weight loading has not been aligned with `MultiStepModelRunner`) | ||
| 2. **Prefix caching:** not supported yet (vLLM sleep mode does not support prefix caching) | ||
| 3. **Chunked prefill:** supported | ||
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 |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ pybind11 | |
| ray>=2.38 | ||
| tensordict<0.6 | ||
| transformers<4.48 | ||
| vllm<=0.6.3 | ||
| vllm | ||
| wandb | ||
| liger-kernel | ||
| pylatexenc | ||
|
|
||
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,162 @@ | ||
| # 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 torch | ||
| import transformers | ||
|
|
||
| from vllm import LLM, SamplingParams | ||
| from verl.utils.model import update_model_config | ||
| from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM | ||
|
|
||
| from transformers import GenerationConfig | ||
|
|
||
| from verl.utils.torch_functional import pad_sequence_to_length | ||
|
|
||
|
|
||
| def levenshtein(s1, s2): | ||
| m, n = len(s1), len(s2) | ||
| # Initialize matrix of zeros | ||
| dp = [[0] * (n + 1) for _ in range(m + 1)] | ||
| # Initialize first column and first row of the matrix | ||
| for i in range(m + 1): | ||
| dp[i][0] = i # Deletion from s1 to empty string | ||
| for j in range(n + 1): | ||
| dp[0][j] = j # Insertion to s1 from empty string | ||
| # Compute the Levenshtein distance matrix | ||
| for i in range(1, m + 1): | ||
| for j in range(1, n + 1): | ||
| cost = 0 if s1[i - 1] == s2[j - 1] else 1 # No cost if characters match | ||
| dp[i][j] = min( | ||
| dp[i - 1][j] + 1, # Deletion | ||
| dp[i][j - 1] + 1, # Insertion | ||
| dp[i - 1][j - 1] + cost # Substitution | ||
| ) | ||
| return dp[m][n] | ||
|
|
||
|
|
||
| def are_lists_similar(a, b): | ||
| if len(a) != len(b): | ||
| print("The lists are of different lengths.") | ||
| return False | ||
|
|
||
| total_length = 0 | ||
| total_diff = 0 | ||
|
|
||
| for s1, s2 in zip(a, b): | ||
| max_len = max(len(s1), len(s2)) | ||
| total_length += max_len | ||
| diff = levenshtein(s1, s2) | ||
| total_diff += diff | ||
| print(f"Comparing strings:\n{s1}\n{s2}\nDifference: {diff} characters\n") | ||
|
|
||
| percentage_difference = (total_diff / total_length) * 100 | ||
| print(f"Total difference: {percentage_difference:.2f}%") | ||
|
|
||
| return percentage_difference <= 10 | ||
|
|
||
|
|
||
| def test_vllm_spmd(): | ||
| assert torch.cuda.device_count() >= 2, 'At least 2 GPUs is required to run tp+dp tests.' | ||
|
|
||
| # fill rollout config | ||
| max_prompt_length = 16 | ||
| max_response_length = 16 | ||
|
|
||
| # Initialize model and token | ||
| local_cache_path = '~/.cache/verl/rlhf' | ||
| local_cache_path = os.path.expanduser(local_cache_path) | ||
| hdfs_path = 'deepseek-ai/deepseek-llm-7b-chat' | ||
| from verl.utils.fs import copy_local_path_from_hdfs | ||
| local_model_path = copy_local_path_from_hdfs(src=hdfs_path, cache_dir=local_cache_path) | ||
| tokenizer = AutoTokenizer.from_pretrained(local_model_path) | ||
|
|
||
| preencode_prompts = [ | ||
| "Who won the Champions League in 2019?", | ||
| "The founder of Apple is", | ||
| "What's your name", | ||
| ] | ||
| tokenizer.pad_token = tokenizer.eos_token | ||
| prompts = tokenizer(preencode_prompts, return_tensors='pt', padding=True) | ||
| input_ids = prompts['input_ids'] | ||
| attention_mask = prompts['attention_mask'] | ||
|
|
||
| input_ids = pad_sequence_to_length(input_ids, max_prompt_length, tokenizer.pad_token_id, left_pad=True) | ||
| attention_mask = pad_sequence_to_length(attention_mask, max_prompt_length, 0, left_pad=True) | ||
|
|
||
| actor_model = AutoModelForCausalLM.from_pretrained(local_model_path) | ||
| actor_model.to(torch.bfloat16) | ||
|
|
||
| actor_model_config = AutoConfig.from_pretrained(local_model_path) | ||
|
|
||
| temperature = 0 | ||
| top_p = 1 | ||
|
|
||
| kwargs = dict(n=1, | ||
| temperature=temperature, | ||
| top_p=top_p, | ||
| max_tokens=max_response_length, | ||
| logprobs=1, | ||
| ignore_eos=True) | ||
|
|
||
| sampling_params = SamplingParams(**kwargs) | ||
| tensor_parallel_size = 8 | ||
|
|
||
| llm = LLM(model=local_model_path, | ||
| enable_sleep_mode=True, | ||
| tensor_parallel_size=tensor_parallel_size, | ||
| distributed_executor_backend="external_launcher", | ||
| dtype='bfloat16', | ||
| gpu_memory_utilization=0.1) | ||
|
|
||
| print('start generation') | ||
| input_ids = input_ids.cuda() | ||
| attention_mask = attention_mask.cuda() | ||
| batch_size = input_ids.size(0) | ||
|
|
||
| generation_config = GenerationConfig(do_sample=False) | ||
| actor_model.cuda() | ||
| output = actor_model.generate( | ||
| input_ids=input_ids, | ||
| attention_mask=attention_mask, | ||
| max_new_tokens=max_response_length, | ||
| # max_length=max_length, | ||
| eos_token_id=tokenizer.eos_token_id, | ||
| pad_token_id=tokenizer.pad_token_id, | ||
| generation_config=generation_config, | ||
| # renormalize_logits=True, | ||
| output_scores=False, # this is potentially very large | ||
| return_dict_in_generate=True, | ||
| use_cache=False) # may OOM when use_cache = True | ||
| seq = output.sequences | ||
| response = seq[:, max_prompt_length:] | ||
|
|
||
| hf_response_tokens = tokenizer.batch_decode(response) | ||
| print(f'hf response: {hf_response_tokens}') | ||
|
|
||
| outputs = llm.generate(preencode_prompts, sampling_params=sampling_params, use_tqdm=False) | ||
| vllm_response_tokens = [] | ||
| for output in outputs: | ||
| prompt = output.prompt | ||
| generated_text = output.outputs[0].text | ||
| vllm_response_tokens.append(generated_text) | ||
|
|
||
| print(f'vllm response: {vllm_response_tokens}') | ||
| assert are_lists_similar(hf_response_tokens, vllm_response_tokens), \ | ||
| f'Strings differ more than 10%:\n' | ||
| print('Check Pass') | ||
|
|
||
|
|
||
| # if __name__ == "__main__": | ||
| # test_vllm_spmd() |
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,13 @@ | ||
| # 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. |
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.