GH-3676: make sentencepiece a lazy import for BytePairEmbeddings#3696
Open
haoyu-haoyu wants to merge 1 commit intoflairNLP:masterfrom
Open
GH-3676: make sentencepiece a lazy import for BytePairEmbeddings#3696haoyu-haoyu wants to merge 1 commit intoflairNLP:masterfrom
haoyu-haoyu wants to merge 1 commit intoflairNLP:masterfrom
Conversation
sentencepiece is unmaintained (last release Feb 2024) and fails to build on Python 3.13 + macOS. Since the direct import is only used by BytePairEmbeddings, move it from module-level to the constructor using the existing lazy_import() helper. Keep transformers[sentencepiece] in requirements.txt because other HF tokenizers (T5, XLM-RoBERTa) import sentencepiece internally and would break without it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sentencepiece fails to build on Python 3.13 + macOS and the package seems unmaintained (last release Feb 2024). The direct
from sentencepiece import SentencePieceProcessorat the top oftoken.pymeans the entire embeddings module fails to import even if nobody usesBytePairEmbeddings.Moved the import into
BytePairEmbeddings.__init__()using the existinglazy_import()helper that the class already uses for bpemb.Kept
transformers[sentencepiece]in requirements.txt since other HF tokenizers (T5, XLM-RoBERTa etc.) import sentencepiece internally and would break without it. This only fixes the direct import that blocks the module load.Closes #3676