Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

summerspringwei
Copy link

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines.
  • Did you write any new necessary tests?

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.

@@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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()
Copy link
Member

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Member

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,
Copy link
Member

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
Copy link
Member

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# torch.cuda.memory._record_memory_history()

@qgallouedec
Copy link
Member

Thanks for the PR. It seems to be still a draft right?
Also, it seems like you're using an old version of the codebase. Can you merge main to your branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants