Skip to content

Decoupling generation and loss batch sizes #1

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
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sidnarayanan
Copy link
Collaborator

This introduces a per_device_loss_batch_size to define microbatches to be used when computing the loss. Ideally, I would have liked to compute the loss in chunks of per_device_loss_batch_size and accumulate gradients. However, to compute the advantage, we need all per_device_train_batch_size * num_generations samples.

So instead, we compute the three tensors needed for the loss (reward, logp, KL) in chunks of per_device_loss_batch_size, concatenate the chunks, and compute the full loss all at once. I think this should result in a similar memory reduction, but it remains to be tested.

I also think this code is pretty compilation-unfriendly, since I'm slicing tensors dynamically. Oh well.

Copy link

@jamesbraza jamesbraza left a comment

Choose a reason for hiding this comment

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

LGTM, bonus points for a simple unit test

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