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

Add Tiktoken support for TRTLLM #10306

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Add Tiktoken support for TRTLLM #10306

wants to merge 13 commits into from

Conversation

meatybobby
Copy link
Collaborator

What does this PR do ?

Add Tiktoken support for TRTLLM

Collection: [Note which collection this PR will affect]

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

nemo/export/tiktoken_tokenizer.py Fixed Show fixed Hide fixed
nemo/export/tiktoken_tokenizer.py Fixed Show fixed Hide fixed
@github-actions github-actions bot removed the NLP label Aug 29, 2024
Copy link
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Sep 13, 2024
@github-actions github-actions bot removed the stale label Sep 18, 2024
Copy link
Contributor

github-actions bot commented Oct 2, 2024

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Oct 2, 2024
Copy link
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this Oct 10, 2024
Copy link
Collaborator

@oyilmaz-nvidia oyilmaz-nvidia left a comment

Choose a reason for hiding this comment

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

LGTM but let's get @janekl review as well

tmp_path = os.path.join(tmp_dir.name, "vocab.json")
vocab_file = os.path.join(nemo_checkpoint_path, tokenizer_cfg.vocab_file)
shutil.copy(vocab_file, tmp_path)
tokenizer = TiktokenTokenizer(vocab_file=tmp_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be just tokenizer = TiktokenTokenizer(vocab_file=vocab_file) i.e. w/o creating tmp_dir?

Copy link
Collaborator Author

@meatybobby meatybobby Nov 23, 2024

Choose a reason for hiding this comment

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

@janekl I've changed it

oyilmaz-nvidia
oyilmaz-nvidia previously approved these changes Nov 22, 2024
Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.export.tiktoken_tokenizer
nemo/export/tiktoken_tokenizer.py:24:0: C0301: Line too long (270/119) (line-too-long)
nemo/export/tiktoken_tokenizer.py:64:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/tiktoken_tokenizer.py:85:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:90:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:104:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:114:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:118:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:122:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.tensorrt_llm
nemo/export/tensorrt_llm.py:118:0: C0301: Line too long (148/119) (line-too-long)
nemo/export/tensorrt_llm.py:221:0: C0301: Line too long (123/119) (line-too-long)
nemo/export/tensorrt_llm.py:223:0: C0301: Line too long (135/119) (line-too-long)
nemo/export/tensorrt_llm.py:224:0: C0301: Line too long (141/119) (line-too-long)
nemo/export/tensorrt_llm.py:387:0: C0301: Line too long (186/119) (line-too-long)
nemo/export/tensorrt_llm.py:1001:0: C0301: Line too long (184/119) (line-too-long)
nemo/export/tensorrt_llm.py:1035:0: C0301: Line too long (131/119) (line-too-long)
nemo/export/tensorrt_llm.py:1039:0: C0301: Line too long (135/119) (line-too-long)
nemo/export/tensorrt_llm.py:1097:0: C0301: Line too long (121/119) (line-too-long)
nemo/export/tensorrt_llm.py:67:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:530:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:820:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:841:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:852:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:857:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:934:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:1143:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.trt_llm.nemo_ckpt_loader.nemo_file
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:44:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:73:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:80:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:96:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:104:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:114:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:120:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:125:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:136:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:167:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:174:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:188:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:192:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:201:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:226:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:237:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:258:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:313:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:359:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:443:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:447:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:458:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:470:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:510:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:547:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:560:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:27:0: W0611: Unused import tensorstore (unused-import)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:37:0: W0611: Unused SentencePieceTokenizer imported from nemo.export.sentencepiece_tokenizer (unused-import)
************* Module nemo.export.trt_llm.qnemo.tokenizer_utils
nemo/export/trt_llm/qnemo/tokenizer_utils.py:16:0: W0611: Unused import shutil (unused-import)
nemo/export/trt_llm/qnemo/tokenizer_utils.py:17:0: W0611: Unused import tempfile (unused-import)

-----------------------------------
Your code has been rated at 9.41/10

Thank you for improving NeMo's documentation!

1 similar comment
Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.export.tiktoken_tokenizer
nemo/export/tiktoken_tokenizer.py:24:0: C0301: Line too long (270/119) (line-too-long)
nemo/export/tiktoken_tokenizer.py:64:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/tiktoken_tokenizer.py:85:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:90:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:104:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:114:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:118:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tiktoken_tokenizer.py:122:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.tensorrt_llm
nemo/export/tensorrt_llm.py:118:0: C0301: Line too long (148/119) (line-too-long)
nemo/export/tensorrt_llm.py:221:0: C0301: Line too long (123/119) (line-too-long)
nemo/export/tensorrt_llm.py:223:0: C0301: Line too long (135/119) (line-too-long)
nemo/export/tensorrt_llm.py:224:0: C0301: Line too long (141/119) (line-too-long)
nemo/export/tensorrt_llm.py:387:0: C0301: Line too long (186/119) (line-too-long)
nemo/export/tensorrt_llm.py:1001:0: C0301: Line too long (184/119) (line-too-long)
nemo/export/tensorrt_llm.py:1035:0: C0301: Line too long (131/119) (line-too-long)
nemo/export/tensorrt_llm.py:1039:0: C0301: Line too long (135/119) (line-too-long)
nemo/export/tensorrt_llm.py:1097:0: C0301: Line too long (121/119) (line-too-long)
nemo/export/tensorrt_llm.py:67:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:530:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:820:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:841:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:852:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:857:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:934:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/tensorrt_llm.py:1143:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.export.trt_llm.nemo_ckpt_loader.nemo_file
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:44:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:73:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:80:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:96:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:104:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:114:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:120:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:125:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:136:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:167:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:174:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:188:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:192:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:201:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:226:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:237:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:258:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:313:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:359:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:443:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:447:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:458:0: C0115: Missing class docstring (missing-class-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:470:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:510:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:547:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:560:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:27:0: W0611: Unused import tensorstore (unused-import)
nemo/export/trt_llm/nemo_ckpt_loader/nemo_file.py:37:0: W0611: Unused SentencePieceTokenizer imported from nemo.export.sentencepiece_tokenizer (unused-import)
************* Module nemo.export.trt_llm.qnemo.tokenizer_utils
nemo/export/trt_llm/qnemo/tokenizer_utils.py:16:0: W0611: Unused import shutil (unused-import)
nemo/export/trt_llm/qnemo/tokenizer_utils.py:17:0: W0611: Unused import tempfile (unused-import)

-----------------------------------
Your code has been rated at 9.41/10

Thank you for improving NeMo's documentation!

@@ -13,11 +13,14 @@
# limitations under the License.

import os
import shutil
import tempfile

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'shutil' is not used.
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