-
Notifications
You must be signed in to change notification settings - Fork 448
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
Fix kv-cacheing and bsz > 1 in eval recipe #1622
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1622
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 3ff80a2 with merge base c5db813 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
recipes/eleuther_eval.py
Outdated
maybe_padded_context = torch.nn.functional.pad( | ||
context, | ||
(0, 0, 0, self._batch_size - curr_batch_size), | ||
value=self._tokenizer.eos_id, | ||
) |
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.
nit: add a comment explaining this cause otherwise it's not super obvious
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.
One small comment, otherwise looks good to me
Context
What is the purpose of this PR? Is it to
Please link to any issues this PR addresses.
closes #1600
Changelog
What are the changes made in this PR?
The eval harness will return
batch_size
specified prompts until the last batch, where it will return a smaller number of samples.This breaks our static KV-cacheing which is only setup for a single batch size.
To address this, we can manually pad out batches, and then remove the padded samples after generation.
This could be wasteful for large batch sizes, and where the last batch may be mostly empty. We can kind of mitigate this by padding out with
self._tokenizer.eos_id
so we correctly trigger early stopping in generation.Expected test values are changed because
limit
has changed.Since swapping between KV-cacheing-inference and regular inference isn't supported yet, I've guarded against using generation tasks with non-generation tasks. This will be addressed in a follow up.
I've also moved setup cache logic outside of
_model_generate
- it only needs to be called once if we're expecting a generation task.Thanks to @baberabb for the advice here.
Test plan
Please make sure to do each of the following if applicable to your PR. If you're unsure about any one of these just ask and we will happily help. We also have a contributing page for some guidance on contributing.
pre-commit install
)pytest tests
pytest tests -m integration_test
UX
If your function changed a public API, please add a dummy example of what the user experience will look like when calling it.
Here is a docstring example
and a tutorial example