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

Avoid import sentencepiece_model_pb2 in utils.__init__.py #24689

Merged
merged 1 commit into from
Jul 6, 2023
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
3 changes: 0 additions & 3 deletions src/transformers/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@
from . import sentencepiece_model_pb2
else:
from . import sentencepiece_model_pb2_new as sentencepiece_model_pb2
else:
# just to get the expected `No module named 'google.protobuf'` error
from . import sentencepiece_model_pb2
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added this as I would like to keep the following usage

from (transformers).utils import sentencepiece_model_pb2 as model_pb2

gives the same error

No module named 'google.protobuf'

as before 24599, when protobuf is not in the env.

It turns out that, if we just ignore this else block, the above import statement (when protobuf is missing) will find the corresponding file, and import it directly, and we wil get the expected error as before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

huh, interesting. Just to make sure I've understood, without this else statement, we still get the correct No module named 'google.protobuf' error still triggers if protobuf isn't in the env?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. The __init__ won't have the name sentencepiece_model_pb2, but the file utils/sentencepiece_model_pb2.py exist. So the import will look at that file and try to import.

(I was overthinking, partially I was thinking to have sentencepiece_model_pb2_old.py and sentencepiece_model_pb2_new.py (and need to keep the name sentencepiece_model_pb2 available in the __init__ for backward compatibility)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining 🤗



WEIGHTS_NAME = "pytorch_model.bin"
Expand Down