Skip to content

Decoupling generation and loss batch sizes#1

Open
sidnarayanan wants to merge 9 commits into
mainfrom
decouple-batch-sizes
Open

Decoupling generation and loss batch sizes#1
sidnarayanan wants to merge 9 commits into
mainfrom
decouple-batch-sizes

Conversation

@sidnarayanan

Copy link
Copy Markdown
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.

@jamesbraza jamesbraza left a comment

Copy link
Copy Markdown
Member

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