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

Use get_vocab method instead of vocab #9289

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

Conversation

butsugiri
Copy link

@butsugiri butsugiri commented May 23, 2024

What does this PR do ?

This PR fixes the issue of missing vocab property for NeMo AutoTokenizer.

Currently, NeMo's AutoTokenizer obtains a list of vocabulary from tokenizer.vocab.
However, it can be problematic for the following reasons:

  • the property is sometimes missing for certain type of HuggingFace tokenizers.
  • the property is not documented in Huggingface Transformers Library.

For example, non-fast version of T5Tokenizer does not seem to have vocab as follows:

In [8]: assert getattr(AutoTokenizer.from_pretrained('google-t5/t5-base'), "vocab") # This one is OK
In [9]: assert getattr(AutoTokenizer.from_pretrained('google-t5/t5-base', use_fast=False), "vocab") # Not OK
…
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[9], line 1
----> 1 assert getattr(AutoTokenizer.from_pretrained('google-t5/t5-base', use_fast=False), "vocab")

AttributeError: 'T5Tokenizer' object has no attribute 'vocab'

This can be a problem for GPTSFTChatDataset because it assumes that a given tokenizer has avocab property.

assert hasattr(self.tokenizer, "vocab"), "tokenizer should have vocab property, not supported"

This PR renames a reference to vocabproperty to get_vocab method.
I believe that this method also returns a list of vocabulary in a same manner as vocab property.
Thus, existing tokenizers would not be affected.

Collection: [Note which collection this PR will affect]

This PR may affect tokenizer component.

Changelog

renamed vocab to get_vocab

Usage

n/a

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

n/a

Signed-off-by: Shun Kiyono <shun.kiyono@sbintuitions.co.jp>
Signed-off-by: butsugiri <butsugiri@users.noreply.github.com>
@butsugiri
Copy link
Author

@ericharper @titu1994 @blisc @okuchaiev Would you please review my PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant