-
Notifications
You must be signed in to change notification settings - Fork 299
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
[PPO] feat: Add LoRA support for PPO #205
Draft
StephenXie
wants to merge
8
commits into
volcengine:main
Choose a base branch
from
StephenXie:lora
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.
+112
−30
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac31baa
Add initial LoRA to ppo fsdp actor
StephenXie 76b1875
Add LoRA in critic and adjust the config format
TonyLianLong b2a2824
Update peft implementation
TonyLianLong 50be77d
Update get_fsdp_wrap_policy for the critic
TonyLianLong 25fd586
actor ref lora 2in1 wip
Jiayi-Pan e01412a
minor fix
Jiayi-Pan a0be6d9
clean up fsdp lora logic
Jiayi-Pan cbc9e5d
actor ref lora 2in1
Jiayi-Pan 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 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 |
---|---|---|
|
@@ -111,3 +111,5 @@ tests/e2e/toy_examples/deepspeed/synchronous/output.txt | |
|
||
# vim | ||
*.swp | ||
|
||
.venv/ |
This file contains 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 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 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 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 |
---|---|---|
|
@@ -15,9 +15,11 @@ | |
import os | ||
import logging | ||
import torch | ||
from peft import PeftModel | ||
from torch.distributed.fsdp.fully_sharded_data_parallel import FullyShardedDataParallel as FSDP | ||
from torch.distributed.fsdp.api import ShardingStrategy, ShardedStateDictConfig, StateDictType, FullStateDictConfig | ||
from torch.distributed.device_mesh import DeviceMesh | ||
from collections import OrderedDict | ||
|
||
from verl.third_party.vllm import LLM | ||
from verl.third_party.vllm import parallel_state as vllm_ps | ||
|
@@ -68,13 +70,26 @@ def __init__(self, | |
|
||
def __enter__(self): | ||
log_gpu_memory_usage('Before state_dict() in sharding manager memory', logger=logger) | ||
params = self.module.state_dict() | ||
|
||
if isinstance(self.module._fsdp_wrapped_module, PeftModel): | ||
# the model to sync weights to is a vLLM model (not a peft model), so we need to merge the adapters | ||
with FSDP.summon_full_params(self.module): | ||
self.module.merge_adapter() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The merge_adapter is not releasing the same original model structure as before. Is there any other way to merge and get the original base model structure? |
||
params = self.module._fsdp_wrapped_module.base_model.model.state_dict() | ||
# FIXME: use more rigorous way to filter out the adapter weights | ||
params = OrderedDict((k.replace(".base_layer.", "."), v) for k, v in params.items() if not ".lora_" in k) | ||
else: | ||
params = self.module.state_dict() | ||
|
||
log_gpu_memory_usage('After state_dict() in sharding manager memory', logger=logger) | ||
# Copy, not share memory | ||
load_format = 'hf' if self.full_params else 'dtensor' | ||
self.inference_engine.sync_model_weights(params, load_format=load_format) | ||
log_gpu_memory_usage('After sync model weights in sharding manager', logger=logger) | ||
|
||
if isinstance(self.module._fsdp_wrapped_module, PeftModel): | ||
with FSDP.summon_full_params(self.module): | ||
self.module.unmerge_adapter() | ||
del params | ||
torch.cuda.empty_cache() | ||
log_gpu_memory_usage('After del state_dict and empty_cache in sharding manager', logger=logger) | ||
|
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.
Summon full params may cause OOM. @PeterSH6 Is there a better approach, that can merge lora weights in sharded form, or at least, one parameter after another to support large models?