Skip to content

Conversation

@gante
Copy link
Contributor

@gante gante commented May 13, 2024

What does this PR do?

Restores a previous behavior -- forces the assistant in assisted decoding to do greedy decoding.

While providing this answer, I noticed that we dropped a property in the refactor that was present in the original implementation: the assistant should be greedy.

Why? We want the assistant to maximize the number of matches with the original model, to result in the maximum speedup. Remember: the main model always calls the shots, the output text is never changed regardless of the flags we set for the assistant. By forcing the assistant to be greedy, we pick its most likely tokens. If the assistant model has a distribution aligned with the main model, these tokens will also be the main model's most likely tokens, increasing the number of matches.

When running my original benchmarks (https://github.com/gante/huggingface-demos/tree/main/experiments/faster_generation), this resulted in a ~20% speedup @ temperature=0.5 over the current version of the code.

@gante gante requested review from amyeroberts and zucchini-nlp May 13, 2024 13:55
greedy_wrong_parameter_msg.format(flag_name="top_p", flag_value=self.top_p),
UserWarning,
)
if self.min_p is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This check was missing 👼

Copy link
Contributor

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for fixing!

Will this result in different outputs for the users? If so, we might want to make sure to run any slow tests.

Question for the future: would we ever want to enable a samplng strategy for the assistant?

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@gante
Copy link
Contributor Author

gante commented May 13, 2024

@amyeroberts

Will this result in different outputs for the users?

Nope :) The only difference is execution time. (The output is entirely defined by the main model and its generation config, both untouched in this PR)

Question for the future: would we ever want to enable a sampling strategy for the assistant?

Perhaps. A potential strategy for improvement is to sample several continuations and try them all as candidates. But that would require significant changes over the current code 👀

@gante gante merged commit 2e27291 into huggingface:main May 13, 2024
@gante gante deleted the assistant_should_use_greedy branch May 13, 2024 15:08
@gante
Copy link
Contributor Author

gante commented Sep 17, 2024

Will this result in different outputs for the users?

Nope

@amyeroberts my answer did not age well (#32867 -- some randomness was lost as a result of this change)

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.

3 participants