-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Reduce memory consumption when training with PPO #2571
base: main
Are you sure you want to change the base?
Conversation
@@ -176,7 +176,8 @@ def forward( | |||
**kwargs, | |||
) | |||
|
|||
last_hidden_state = base_model_output.hidden_states[-1] | |||
# last_hidden_state = base_model_output.hidden_states[-1] |
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.
# last_hidden_state = base_model_output.hidden_states[-1] |
@@ -485,6 +485,7 @@ def generate( | |||
if generate_ref_response: | |||
ref_model = self.model if self.is_peft_model else self.ref_model | |||
if isinstance(query_tensor, List): | |||
self.model.eval() |
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.
why do you need it in eval model here?
full_kl_penalty = self.config.kl_penalty == "full" | ||
|
||
# torch.cuda.memory._record_memory_history() |
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.
# torch.cuda.memory._record_memory_history() |
@@ -164,7 +164,7 @@ def forward( | |||
kwargs (`dict`, `optional`): | |||
Additional keyword arguments, that are passed to the wrapped model. | |||
""" | |||
kwargs["output_hidden_states"] = True # this had already been set in the LORA / PEFT examples | |||
kwargs["output_hidden_states"] = False # this had already been set in the LORA / PEFT examples |
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.
Isn't it the default value? maybe we can simply remove it
@@ -417,7 +417,7 @@ def prepare_dataloader(self, dataset: Union[torch.utils.data.Dataset, Dataset], | |||
dataset, | |||
batch_size=self.config.batch_size, | |||
collate_fn=data_collator, | |||
shuffle=True, | |||
shuffle=False, |
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.
Is it needed?
@@ -744,6 +745,7 @@ def step( | |||
model_inputs, | |||
response_masks=response_masks, | |||
return_logits=full_kl_penalty, | |||
use_cache=False |
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.
Why do you disable the cache?
) | ||
|
||
# torch.cuda.memory._dump_snapshot(f"ppo_batched_forward_pass-{time.time()}.pickle") |
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.
# torch.cuda.memory._dump_snapshot(f"ppo_batched_forward_pass-{time.time()}.pickle") |
@@ -813,13 +816,14 @@ def step( | |||
mini_batch_dict[k] = batch_dict[k][mini_batch_inds] | |||
with self.accelerator.accumulate(self.model): | |||
model_inputs = {k: mini_batch_dict[k] for k in model_inputs_names} | |||
|
|||
# torch.cuda.memory._record_memory_history() |
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.
# torch.cuda.memory._record_memory_history() |
Thanks for the PR. It seems to be still a draft right? |
What does this PR do?
Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.