diff --git a/src/transformers/__init__.py b/src/transformers/__init__.py index 96937344cd8099..39cb0eabe67860 100644 --- a/src/transformers/__init__.py +++ b/src/transformers/__init__.py @@ -773,7 +773,6 @@ "SiglipConfig", "SiglipProcessor", "SiglipTextConfig", - "SiglipTokenizer", "SiglipVisionConfig", ], "models.speech_encoder_decoder": ["SpeechEncoderDecoderConfig"], @@ -1125,6 +1124,7 @@ _import_structure["models.reformer"].append("ReformerTokenizer") _import_structure["models.rembert"].append("RemBertTokenizer") _import_structure["models.seamless_m4t"].append("SeamlessM4TTokenizer") + _import_structure["models.siglip"].append("SiglipTokenizer") _import_structure["models.speech_to_text"].append("Speech2TextTokenizer") _import_structure["models.speecht5"].append("SpeechT5Tokenizer") _import_structure["models.t5"].append("T5Tokenizer") @@ -5503,7 +5503,6 @@ SiglipConfig, SiglipProcessor, SiglipTextConfig, - SiglipTokenizer, SiglipVisionConfig, ) from .models.speech_encoder_decoder import SpeechEncoderDecoderConfig @@ -5852,6 +5851,7 @@ from .models.reformer import ReformerTokenizer from .models.rembert import RemBertTokenizer from .models.seamless_m4t import SeamlessM4TTokenizer + from .models.siglip import SiglipTokenizer from .models.speech_to_text import Speech2TextTokenizer from .models.speecht5 import SpeechT5Tokenizer from .models.t5 import T5Tokenizer diff --git a/src/transformers/models/siglip/__init__.py b/src/transformers/models/siglip/__init__.py index d47b7c5f5d02f6..f802f630af7867 100644 --- a/src/transformers/models/siglip/__init__.py +++ b/src/transformers/models/siglip/__init__.py @@ -16,6 +16,7 @@ from ...utils import ( OptionalDependencyNotAvailable, _LazyModule, + is_sentencepiece_available, is_torch_available, is_vision_available, ) @@ -29,9 +30,17 @@ "SiglipVisionConfig", ], "processing_siglip": ["SiglipProcessor"], - "tokenization_siglip": ["SiglipTokenizer"], } +try: + if not is_sentencepiece_available(): + raise OptionalDependencyNotAvailable() +except OptionalDependencyNotAvailable: + pass +else: + _import_structure["tokenization_siglip"] = ["SiglipTokenizer"] + + try: if not is_vision_available(): raise OptionalDependencyNotAvailable() @@ -63,7 +72,14 @@ SiglipVisionConfig, ) from .processing_siglip import SiglipProcessor - from .tokenization_siglip import SiglipTokenizer + + try: + if not is_sentencepiece_available(): + raise OptionalDependencyNotAvailable() + except OptionalDependencyNotAvailable: + pass + else: + from .tokenization_siglip import SiglipTokenizer try: if not is_vision_available(): diff --git a/src/transformers/utils/dummy_sentencepiece_objects.py b/src/transformers/utils/dummy_sentencepiece_objects.py index 658645746329c6..6064ef7e8cac3c 100644 --- a/src/transformers/utils/dummy_sentencepiece_objects.py +++ b/src/transformers/utils/dummy_sentencepiece_objects.py @@ -184,6 +184,13 @@ def __init__(self, *args, **kwargs): requires_backends(self, ["sentencepiece"]) +class SiglipTokenizer(metaclass=DummyObject): + _backends = ["sentencepiece"] + + def __init__(self, *args, **kwargs): + requires_backends(self, ["sentencepiece"]) + + class Speech2TextTokenizer(metaclass=DummyObject): _backends = ["sentencepiece"]