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

Fix Llama 3 TikToken conversion #33538

Merged
merged 2 commits into from
Sep 19, 2024
Merged

Fix Llama 3 TikToken conversion #33538

merged 2 commits into from
Sep 19, 2024

Conversation

pcuenca
Copy link
Member

@pcuenca pcuenca commented Sep 17, 2024

What does this PR do?

Fixes a tokenizer conversion problem for Llama 3, possibly introduced in #31656

How to reproduce:

The following fails in main and works with this PR:

python src/transformers/models/llama/convert_llama_weights_to_hf.py \
--input_dir path_to_original_checkpoint \
--model_size tokenizer_only \
--output_dir converted_tokenizer \
--llama_version 3.1

The same issue may happen with Gemma models as well. I didn't test yet, but can verify once we agree on a suitable approach.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@itazap @ArthurZucker

@@ -332,7 +332,7 @@ def permute(w, n_heads, dim1=dim, dim2=dim):

class Llama3Converter(TikTokenConverter):
def __init__(self, vocab_file, special_tokens=None, instruct=False, model_max_length=None, **kwargs):
super().__init__(vocab_file, **kwargs)
super().__init__(vocab_file, additional_special_tokens=special_tokens, **kwargs)
Copy link
Member Author

Choose a reason for hiding this comment

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

Line 348 below could possibly be removed, as the superclass will handle it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes agreed it can be removed! Thanks

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

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

Good catch and indeed since now it is natively supported let's use super's functionalities!

@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.

@pcuenca pcuenca merged commit 0c718f1 into main Sep 19, 2024
9 checks passed
@pcuenca pcuenca deleted the fix-llama-tokenizer-conversion branch September 19, 2024 23:28
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
* Fix Llama 3 TikToken conversion

* No need to add tokens again
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.

4 participants