Skip to content

[Bugfix] Fix fast tokenizer import error #8367

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

Merged
merged 2 commits into from
May 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions paddlenlp/transformers/auto/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,23 @@
if init_class in cls._name_mapping:
class_name = cls._name_mapping[init_class]
import_class = import_module(f"paddlenlp.transformers.{class_name}.tokenizer")
tokenizer_class = getattr(import_class, init_class)
if use_fast:
fast_tokenizer_class = cls._get_fast_tokenizer_class(init_class, class_name)
tokenizer_class = fast_tokenizer_class if fast_tokenizer_class else tokenizer_class
tokenizer_class = None
try:
if use_fast:
tokenizer_class = cls._get_fast_tokenizer_class(init_class, class_name)
except:

Check warning on line 200 in paddlenlp/transformers/auto/tokenizer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/auto/tokenizer.py#L200

Added line #L200 was not covered by tests
# use the non fast tokenizer as default
logger.warning(

Check warning on line 202 in paddlenlp/transformers/auto/tokenizer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/auto/tokenizer.py#L202

Added line #L202 was not covered by tests
"`use_fast` is set to `True` but the tokenizer class does not have a fast version. "
" Falling back to the slow version."
)
try:
if tokenizer_class is None:
tokenizer_class = getattr(import_class, init_class)
except:
raise ValueError(

Check warning on line 210 in paddlenlp/transformers/auto/tokenizer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/auto/tokenizer.py#L209-L210

Added lines #L209 - L210 were not covered by tests
f"Tokenizer class {init_class} is not currently imported, if you use fast tokenizer, please set use_fast to True."
)
return tokenizer_class
else:
import_class = import_module("paddlenlp.transformers")
Expand Down
Loading