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

refactor: avoid downloading tokenizer if truncate is False #1152

Merged
merged 2 commits into from
Oct 23, 2024

Conversation

anakin87
Copy link
Member

@anakin87 anakin87 commented Oct 22, 2024

Related Issues

Proposed Changes:

If truncate is False, do not initialize the PromptHandler (which internally downloads the tokenizer).
In the Generator, the PromptHandler is only used to truncate the text if needed.

How did you test it?

CI + a new unit test.

Notes for the reviewer

This change only applies to AmazonBedrockGenerator.

I would have liked to do the same for the corresponding Chat Generator.
Unfortunately, in the Chat Generator, the PromptHandler (and its internal tokenizer) have 2 different purposes:

  • transform messages into text with special tokens (via tokenizer.apply_chat_template)
  • truncate the text, like in the Generator

Therefore, we cannot easily get rid of the tokenizer.

(I hope we can prioritize #977 soon: this would greatly simplify the Chat Generator.)

Checklist

@github-actions github-actions bot added integration:amazon-bedrock type:documentation Improvements or additions to documentation labels Oct 22, 2024
@anakin87 anakin87 changed the title avoid downloading tokenizer if truncate is False refactor: avoid downloading tokenizer if truncate is False Oct 22, 2024
@anakin87 anakin87 marked this pull request as ready for review October 22, 2024 13:55
@anakin87 anakin87 requested a review from a team as a code owner October 22, 2024 13:55
@anakin87 anakin87 requested review from Amnah199 and removed request for a team October 22, 2024 13:55
Copy link
Contributor

@Amnah199 Amnah199 left a comment

Choose a reason for hiding this comment

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

LG!

@anakin87 anakin87 merged commit ae207f0 into main Oct 23, 2024
10 checks passed
@anakin87 anakin87 deleted the bedrock-avoid-tokenizer-if-no-truncate branch October 23, 2024 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:amazon-bedrock type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AmazonBedrockGenerator shouldn't load tokenizer if truncate is set to False.
2 participants