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

[BUG] Fix basic tokenizer no special tokens #1640

Merged
merged 9 commits into from
Sep 21, 2024

Conversation

joecummings
Copy link
Contributor

@joecummings joecummings commented Sep 20, 2024

Context

What is the purpose of this PR? Is it to

  • add a new feature
  • fix a bug
  • update tests and/or documentation
  • other (please add here)

Goal: Toggle add_bos and add_eos for Llama2 tokenizer.
Problem: This is not configurable from the Llama2 tokenizer tokenize_messages, which is now the default API.
Root cause: The underlying method used by the Llama2 tokenizer is tokenize_messages_no_special_tokens, which requires you to pass in bos_id and eos_id and always applies them.

Side quest: Turns out the masking for bos_id and eos_id using this function was INCORRECT (it would always apply the mask from the message instead of the proper mask for the special tokens. I fixed this.

Solution: I made the bos_id and eos_id optional for users to pass in. If they passed it in, I apply them. Otherwise, the method will not add the bos/eos tokens.

Changelog

What are the changes made in this PR?

  • Make bos_id and eos_id optional. If they are specified, then I do add them. Otherwise, I don't
  • Update all corresponding tests
  • Update docstring for tokenize_messages_no_special_tokens

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.

  • run pre-commit hooks and linters (make sure you've first installed via pre-commit install)
  • add unit tests for any new functionality
  • update docstrings for any new or updated methods or classes
  • run unit tests via pytest tests
  • run recipe tests via pytest tests -m integration_test
  • manually run any new or modified recipes with sufficient proof of correctness
  • include relevant commands and any other artifacts in this summary (pastes of loss curves, eval results, etc.)

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

  • I did not change any public API
  • I have added an example to docs or docstrings

Copy link

pytorch-bot bot commented Sep 20, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/torchtune/1640

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 846002d with merge base 9a863c8 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 20, 2024
@@ -239,6 +239,7 @@ def test_tokenize_messages(self, tokenizer):
4,
2,
]
expected_mask = [True] * 75 + [False] * 125
# Mask user, unmask assistant, add EOS token
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were WRONG

Copy link
Contributor

@ebsmothers ebsmothers left a comment

Choose a reason for hiding this comment

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

Great work

@codecov-commenter
Copy link

codecov-commenter commented Sep 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.09%. Comparing base (9a863c8) to head (846002d).
Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1640      +/-   ##
==========================================
- Coverage   70.96%   69.09%   -1.88%     
==========================================
  Files         295      296       +1     
  Lines       15080    15112      +32     
==========================================
- Hits        10701    10441     -260     
- Misses       4379     4671     +292     
Flag Coverage Δ
69.09% <100.00%> (-1.88%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joecummings joecummings merged commit bf93806 into pytorch:main Sep 21, 2024
17 checks passed
@joecummings joecummings deleted the update-basic-tokenizer branch September 21, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants