Unverified Commit df735d13 authored by Dom Miketa's avatar Dom Miketa Committed by GitHub
Browse files

[WIP] Fix Pyright static type checking by replacing if-else imports with try-except (#16578)



* rebase and isort

* modify cookiecutter init

* fix cookiecutter auto imports

* fix clean_frameworks_in_init

* fix add_model_to_main_init

* blackify

* replace unnecessary f-strings

* update yolos imports

* fix roberta import bug

* fix yolos missing dependency

* fix add_model_like and cookiecutter bug

* fix repository consistency error

* modify cookiecutter, fix add_new_model_like

* remove stale line
Co-authored-by: default avatarDom Miketa <dmiketa@exscientia.co.uk>
parent 7783fa6b
...@@ -29,6 +29,7 @@ from typing import TYPE_CHECKING ...@@ -29,6 +29,7 @@ from typing import TYPE_CHECKING
# Check the dependencies satisfy the minimal versions required. # Check the dependencies satisfy the minimal versions required.
from . import dependency_versions_check from . import dependency_versions_check
from .utils import ( from .utils import (
OptionalDependencyNotAvailable,
_LazyModule, _LazyModule,
is_flax_available, is_flax_available,
is_scatter_available, is_scatter_available,
...@@ -412,7 +413,16 @@ _import_structure = { ...@@ -412,7 +413,16 @@ _import_structure = {
} }
# sentencepiece-backed objects # sentencepiece-backed objects
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_sentencepiece_objects
_import_structure["utils.dummy_sentencepiece_objects"] = [
name for name in dir(dummy_sentencepiece_objects) if not name.startswith("_")
]
else:
_import_structure["models.albert"].append("AlbertTokenizer") _import_structure["models.albert"].append("AlbertTokenizer")
_import_structure["models.barthez"].append("BarthezTokenizer") _import_structure["models.barthez"].append("BarthezTokenizer")
_import_structure["models.bartpho"].append("BartphoTokenizer") _import_structure["models.bartpho"].append("BartphoTokenizer")
...@@ -439,16 +449,19 @@ if is_sentencepiece_available(): ...@@ -439,16 +449,19 @@ if is_sentencepiece_available():
_import_structure["models.xlm_prophetnet"].append("XLMProphetNetTokenizer") _import_structure["models.xlm_prophetnet"].append("XLMProphetNetTokenizer")
_import_structure["models.xlm_roberta"].append("XLMRobertaTokenizer") _import_structure["models.xlm_roberta"].append("XLMRobertaTokenizer")
_import_structure["models.xlnet"].append("XLNetTokenizer") _import_structure["models.xlnet"].append("XLNetTokenizer")
else:
from .utils import dummy_sentencepiece_objects
_import_structure["utils.dummy_sentencepiece_objects"] = [
name for name in dir(dummy_sentencepiece_objects) if not name.startswith("_")
]
# tokenizers-backed objects # tokenizers-backed objects
if is_tokenizers_available(): try:
# Fast tokenizers if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_tokenizers_objects
_import_structure["utils.dummy_tokenizers_objects"] = [
name for name in dir(dummy_tokenizers_objects) if not name.startswith("_")
]
else:
# Fast tokenizers structure
_import_structure["models.albert"].append("AlbertTokenizerFast") _import_structure["models.albert"].append("AlbertTokenizerFast")
_import_structure["models.bart"].append("BartTokenizerFast") _import_structure["models.bart"].append("BartTokenizerFast")
_import_structure["models.barthez"].append("BarthezTokenizerFast") _import_structure["models.barthez"].append("BarthezTokenizerFast")
...@@ -498,43 +511,55 @@ if is_tokenizers_available(): ...@@ -498,43 +511,55 @@ if is_tokenizers_available():
_import_structure["models.xlnet"].append("XLNetTokenizerFast") _import_structure["models.xlnet"].append("XLNetTokenizerFast")
_import_structure["tokenization_utils_fast"] = ["PreTrainedTokenizerFast"] _import_structure["tokenization_utils_fast"] = ["PreTrainedTokenizerFast"]
else:
from .utils import dummy_tokenizers_objects
_import_structure["utils.dummy_tokenizers_objects"] = [
name for name in dir(dummy_tokenizers_objects) if not name.startswith("_")
]
if is_sentencepiece_available() and is_tokenizers_available(): try:
_import_structure["convert_slow_tokenizer"] = ["SLOW_TO_FAST_CONVERTERS", "convert_slow_tokenizer"] if not (is_sentencepiece_available() and is_tokenizers_available()):
else: raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_sentencepiece_and_tokenizers_objects from .utils import dummy_sentencepiece_and_tokenizers_objects
_import_structure["utils.dummy_sentencepiece_and_tokenizers_objects"] = [ _import_structure["utils.dummy_sentencepiece_and_tokenizers_objects"] = [
name for name in dir(dummy_sentencepiece_and_tokenizers_objects) if not name.startswith("_") name for name in dir(dummy_sentencepiece_and_tokenizers_objects) if not name.startswith("_")
] ]
else:
_import_structure["convert_slow_tokenizer"] = ["SLOW_TO_FAST_CONVERTERS", "convert_slow_tokenizer"]
# Speech-specific objects # Speech-specific objects
if is_speech_available(): try:
_import_structure["models.speech_to_text"].append("Speech2TextFeatureExtractor") if not is_speech_available():
else: raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_speech_objects from .utils import dummy_speech_objects
_import_structure["utils.dummy_speech_objects"] = [ _import_structure["utils.dummy_speech_objects"] = [
name for name in dir(dummy_speech_objects) if not name.startswith("_") name for name in dir(dummy_speech_objects) if not name.startswith("_")
] ]
if is_sentencepiece_available() and is_speech_available():
_import_structure["models.speech_to_text"].append("Speech2TextProcessor")
else: else:
_import_structure["models.speech_to_text"].append("Speech2TextFeatureExtractor")
try:
if not (is_sentencepiece_available() and is_speech_available()):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_sentencepiece_and_speech_objects from .utils import dummy_sentencepiece_and_speech_objects
_import_structure["utils.dummy_sentencepiece_and_speech_objects"] = [ _import_structure["utils.dummy_sentencepiece_and_speech_objects"] = [
name for name in dir(dummy_sentencepiece_and_speech_objects) if not name.startswith("_") name for name in dir(dummy_sentencepiece_and_speech_objects) if not name.startswith("_")
] ]
else:
_import_structure["models.speech_to_text"].append("Speech2TextProcessor")
# Vision-specific objects # Vision-specific objects
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_vision_objects
_import_structure["utils.dummy_vision_objects"] = [
name for name in dir(dummy_vision_objects) if not name.startswith("_")
]
else:
_import_structure["image_utils"] = ["ImageFeatureExtractionMixin"] _import_structure["image_utils"] = ["ImageFeatureExtractionMixin"]
_import_structure["models.beit"].append("BeitFeatureExtractor") _import_structure["models.beit"].append("BeitFeatureExtractor")
_import_structure["models.clip"].append("CLIPFeatureExtractor") _import_structure["models.clip"].append("CLIPFeatureExtractor")
...@@ -556,15 +581,18 @@ if is_vision_available(): ...@@ -556,15 +581,18 @@ if is_vision_available():
_import_structure["models.vilt"].append("ViltProcessor") _import_structure["models.vilt"].append("ViltProcessor")
_import_structure["models.vit"].append("ViTFeatureExtractor") _import_structure["models.vit"].append("ViTFeatureExtractor")
_import_structure["models.yolos"].append("YolosFeatureExtractor") _import_structure["models.yolos"].append("YolosFeatureExtractor")
else:
from .utils import dummy_vision_objects
_import_structure["utils.dummy_vision_objects"] = [
name for name in dir(dummy_vision_objects) if not name.startswith("_")
]
# Timm-backed objects # Timm-backed objects
if is_timm_available() and is_vision_available(): try:
if not (is_timm_available() and is_vision_available()):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_timm_objects
_import_structure["utils.dummy_timm_objects"] = [
name for name in dir(dummy_timm_objects) if not name.startswith("_")
]
else:
_import_structure["models.detr"].extend( _import_structure["models.detr"].extend(
[ [
"DETR_PRETRAINED_MODEL_ARCHIVE_LIST", "DETR_PRETRAINED_MODEL_ARCHIVE_LIST",
...@@ -574,14 +602,17 @@ if is_timm_available() and is_vision_available(): ...@@ -574,14 +602,17 @@ if is_timm_available() and is_vision_available():
"DetrPreTrainedModel", "DetrPreTrainedModel",
] ]
) )
else:
from .utils import dummy_timm_objects
_import_structure["utils.dummy_timm_objects"] = [ try:
name for name in dir(dummy_timm_objects) if not name.startswith("_") if not is_scatter_available():
] raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_scatter_objects
if is_scatter_available(): _import_structure["utils.dummy_scatter_objects"] = [
name for name in dir(dummy_scatter_objects) if not name.startswith("_")
]
else:
_import_structure["models.tapas"].extend( _import_structure["models.tapas"].extend(
[ [
"TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST", "TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST",
...@@ -593,16 +624,17 @@ if is_scatter_available(): ...@@ -593,16 +624,17 @@ if is_scatter_available():
"load_tf_weights_in_tapas", "load_tf_weights_in_tapas",
] ]
) )
else:
from .utils import dummy_scatter_objects
_import_structure["utils.dummy_scatter_objects"] = [
name for name in dir(dummy_scatter_objects) if not name.startswith("_")
]
# PyTorch-backed objects # PyTorch-backed objects
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_pt_objects
_import_structure["utils.dummy_pt_objects"] = [name for name in dir(dummy_pt_objects) if not name.startswith("_")]
else:
_import_structure["activations"] = [] _import_structure["activations"] = []
_import_structure["benchmark.benchmark"] = ["PyTorchBenchmark"] _import_structure["benchmark.benchmark"] = ["PyTorchBenchmark"]
_import_structure["benchmark.benchmark_args"] = ["PyTorchBenchmarkArguments"] _import_structure["benchmark.benchmark_args"] = ["PyTorchBenchmarkArguments"]
...@@ -1723,13 +1755,16 @@ if is_torch_available(): ...@@ -1723,13 +1755,16 @@ if is_torch_available():
_import_structure["trainer"] = ["Trainer"] _import_structure["trainer"] = ["Trainer"]
_import_structure["trainer_pt_utils"] = ["torch_distributed_zero_first"] _import_structure["trainer_pt_utils"] = ["torch_distributed_zero_first"]
_import_structure["trainer_seq2seq"] = ["Seq2SeqTrainer"] _import_structure["trainer_seq2seq"] = ["Seq2SeqTrainer"]
else:
from .utils import dummy_pt_objects
_import_structure["utils.dummy_pt_objects"] = [name for name in dir(dummy_pt_objects) if not name.startswith("_")]
# TensorFlow-backed objects # TensorFlow-backed objects
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_tf_objects
_import_structure["utils.dummy_tf_objects"] = [name for name in dir(dummy_tf_objects) if not name.startswith("_")]
else:
_import_structure["activations_tf"] = [] _import_structure["activations_tf"] = []
_import_structure["benchmark.benchmark_args_tf"] = ["TensorFlowBenchmarkArguments"] _import_structure["benchmark.benchmark_args_tf"] = ["TensorFlowBenchmarkArguments"]
_import_structure["benchmark.benchmark_tf"] = ["TensorFlowBenchmark"] _import_structure["benchmark.benchmark_tf"] = ["TensorFlowBenchmark"]
...@@ -2236,13 +2271,18 @@ if is_tf_available(): ...@@ -2236,13 +2271,18 @@ if is_tf_available():
_import_structure["tf_utils"] = [] _import_structure["tf_utils"] = []
_import_structure["trainer_tf"] = ["TFTrainer"] _import_structure["trainer_tf"] = ["TFTrainer"]
else:
from .utils import dummy_tf_objects
_import_structure["utils.dummy_tf_objects"] = [name for name in dir(dummy_tf_objects) if not name.startswith("_")]
# FLAX-backed objects # FLAX-backed objects
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils import dummy_flax_objects
_import_structure["utils.dummy_flax_objects"] = [
name for name in dir(dummy_flax_objects) if not name.startswith("_")
]
else:
_import_structure["generation_flax_logits_process"] = [ _import_structure["generation_flax_logits_process"] = [
"FlaxForcedBOSTokenLogitsProcessor", "FlaxForcedBOSTokenLogitsProcessor",
"FlaxForcedEOSTokenLogitsProcessor", "FlaxForcedEOSTokenLogitsProcessor",
...@@ -2469,12 +2509,6 @@ if is_flax_available(): ...@@ -2469,12 +2509,6 @@ if is_flax_available():
"FlaxXLMRobertaModel", "FlaxXLMRobertaModel",
] ]
) )
else:
from .utils import dummy_flax_objects
_import_structure["utils.dummy_flax_objects"] = [
name for name in dir(dummy_flax_objects) if not name.startswith("_")
]
# Direct imports for type-checking # Direct imports for type-checking
...@@ -2816,7 +2850,12 @@ if TYPE_CHECKING: ...@@ -2816,7 +2850,12 @@ if TYPE_CHECKING:
logging, logging,
) )
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_sentencepiece_objects import *
else:
from .models.albert import AlbertTokenizer from .models.albert import AlbertTokenizer
from .models.barthez import BarthezTokenizer from .models.barthez import BarthezTokenizer
from .models.bartpho import BartphoTokenizer from .models.bartpho import BartphoTokenizer
...@@ -2842,10 +2881,14 @@ if TYPE_CHECKING: ...@@ -2842,10 +2881,14 @@ if TYPE_CHECKING:
from .models.xlm_prophetnet import XLMProphetNetTokenizer from .models.xlm_prophetnet import XLMProphetNetTokenizer
from .models.xlm_roberta import XLMRobertaTokenizer from .models.xlm_roberta import XLMRobertaTokenizer
from .models.xlnet import XLNetTokenizer from .models.xlnet import XLNetTokenizer
else:
from .utils.dummy_sentencepiece_objects import *
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_tokenizers_objects import *
else:
# Fast tokenizers imports
from .models.albert import AlbertTokenizerFast from .models.albert import AlbertTokenizerFast
from .models.bart import BartTokenizerFast from .models.bart import BartTokenizerFast
from .models.barthez import BarthezTokenizerFast from .models.barthez import BarthezTokenizerFast
...@@ -2893,25 +2936,36 @@ if TYPE_CHECKING: ...@@ -2893,25 +2936,36 @@ if TYPE_CHECKING:
from .models.xlnet import XLNetTokenizerFast from .models.xlnet import XLNetTokenizerFast
from .tokenization_utils_fast import PreTrainedTokenizerFast from .tokenization_utils_fast import PreTrainedTokenizerFast
try:
if not (is_sentencepiece_available() and is_tokenizers_available()):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummies_sentencepiece_and_tokenizers_objects import *
else: else:
from .utils.dummy_tokenizers_objects import *
if is_sentencepiece_available() and is_tokenizers_available():
from .convert_slow_tokenizer import SLOW_TO_FAST_CONVERTERS, convert_slow_tokenizer from .convert_slow_tokenizer import SLOW_TO_FAST_CONVERTERS, convert_slow_tokenizer
else:
from .utils.dummies_sentencepiece_and_tokenizers_objects import *
if is_speech_available(): try:
from .models.speech_to_text import Speech2TextFeatureExtractor if not is_speech_available():
else: raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_speech_objects import * from .utils.dummy_speech_objects import *
if is_speech_available() and is_sentencepiece_available():
from .models.speech_to_text import Speech2TextProcessor
else: else:
from .models.speech_to_text import Speech2TextFeatureExtractor
try:
if not (is_speech_available() and is_sentencepiece_available()):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_sentencepiece_and_speech_objects import * from .utils.dummy_sentencepiece_and_speech_objects import *
else:
from .models.speech_to_text import Speech2TextProcessor
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_vision_objects import *
else:
from .image_utils import ImageFeatureExtractionMixin from .image_utils import ImageFeatureExtractionMixin
from .models.beit import BeitFeatureExtractor from .models.beit import BeitFeatureExtractor
from .models.clip import CLIPFeatureExtractor, CLIPProcessor from .models.clip import CLIPFeatureExtractor, CLIPProcessor
...@@ -2930,11 +2984,14 @@ if TYPE_CHECKING: ...@@ -2930,11 +2984,14 @@ if TYPE_CHECKING:
from .models.vilt import ViltFeatureExtractor, ViltProcessor from .models.vilt import ViltFeatureExtractor, ViltProcessor
from .models.vit import ViTFeatureExtractor from .models.vit import ViTFeatureExtractor
from .models.yolos import YolosFeatureExtractor from .models.yolos import YolosFeatureExtractor
else:
from .utils.dummy_vision_objects import *
# Modeling # Modeling
if is_timm_available() and is_vision_available(): try:
if not (is_timm_available() and is_vision_available()):
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_timm_objects import *
else:
from .models.detr import ( from .models.detr import (
DETR_PRETRAINED_MODEL_ARCHIVE_LIST, DETR_PRETRAINED_MODEL_ARCHIVE_LIST,
DetrForObjectDetection, DetrForObjectDetection,
...@@ -2942,10 +2999,13 @@ if TYPE_CHECKING: ...@@ -2942,10 +2999,13 @@ if TYPE_CHECKING:
DetrModel, DetrModel,
DetrPreTrainedModel, DetrPreTrainedModel,
) )
else:
from .utils.dummy_timm_objects import *
if is_scatter_available(): try:
if not is_scatter_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_scatter_objects import *
else:
from .models.tapas import ( from .models.tapas import (
TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST, TAPAS_PRETRAINED_MODEL_ARCHIVE_LIST,
TapasForMaskedLM, TapasForMaskedLM,
...@@ -2955,10 +3015,13 @@ if TYPE_CHECKING: ...@@ -2955,10 +3015,13 @@ if TYPE_CHECKING:
TapasPreTrainedModel, TapasPreTrainedModel,
load_tf_weights_in_tapas, load_tf_weights_in_tapas,
) )
else:
from .utils.dummy_scatter_objects import *
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
from .utils.dummy_pt_objects import *
else:
# Benchmarks # Benchmarks
from .benchmark.benchmark import PyTorchBenchmark from .benchmark.benchmark import PyTorchBenchmark
from .benchmark.benchmark_args import PyTorchBenchmarkArguments from .benchmark.benchmark_args import PyTorchBenchmarkArguments
...@@ -3005,6 +3068,8 @@ if TYPE_CHECKING: ...@@ -3005,6 +3068,8 @@ if TYPE_CHECKING:
) )
from .generation_utils import top_k_top_p_filtering from .generation_utils import top_k_top_p_filtering
from .modeling_utils import PreTrainedModel from .modeling_utils import PreTrainedModel
# PyTorch model imports
from .models.albert import ( from .models.albert import (
ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST, ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
AlbertForMaskedLM, AlbertForMaskedLM,
...@@ -3896,12 +3961,16 @@ if TYPE_CHECKING: ...@@ -3896,12 +3961,16 @@ if TYPE_CHECKING:
from .trainer import Trainer from .trainer import Trainer
from .trainer_pt_utils import torch_distributed_zero_first from .trainer_pt_utils import torch_distributed_zero_first
from .trainer_seq2seq import Seq2SeqTrainer from .trainer_seq2seq import Seq2SeqTrainer
else:
from .utils.dummy_pt_objects import *
# TensorFlow # TensorFlow
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
# Import the same objects as dummies to get them in the namespace.
# They will raise an import error if the user tries to instantiate / use them.
from .utils.dummy_tf_objects import *
else:
from .benchmark.benchmark_args_tf import TensorFlowBenchmarkArguments from .benchmark.benchmark_args_tf import TensorFlowBenchmarkArguments
# Benchmarks # Benchmarks
...@@ -3932,6 +4001,8 @@ if TYPE_CHECKING: ...@@ -3932,6 +4001,8 @@ if TYPE_CHECKING:
TFLayoutLMPreTrainedModel, TFLayoutLMPreTrainedModel,
) )
from .modeling_tf_utils import TFPreTrainedModel, TFSequenceSummary, TFSharedEmbeddings, shape_list from .modeling_tf_utils import TFPreTrainedModel, TFSequenceSummary, TFSharedEmbeddings, shape_list
# TensorFlow model imports
from .models.albert import ( from .models.albert import (
TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFAlbertForMaskedLM, TFAlbertForMaskedLM,
...@@ -4310,13 +4381,14 @@ if TYPE_CHECKING: ...@@ -4310,13 +4381,14 @@ if TYPE_CHECKING:
# Trainer # Trainer
from .trainer_tf import TFTrainer from .trainer_tf import TFTrainer
else: try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
# Import the same objects as dummies to get them in the namespace. # Import the same objects as dummies to get them in the namespace.
# They will raise an import error if the user tries to instantiate / use them. # They will raise an import error if the user tries to instantiate / use them.
from .utils.dummy_tf_objects import * from .utils.dummy_flax_objects import *
else:
if is_flax_available():
from .generation_flax_logits_process import ( from .generation_flax_logits_process import (
FlaxForcedBOSTokenLogitsProcessor, FlaxForcedBOSTokenLogitsProcessor,
FlaxForcedEOSTokenLogitsProcessor, FlaxForcedEOSTokenLogitsProcessor,
...@@ -4329,6 +4401,8 @@ if TYPE_CHECKING: ...@@ -4329,6 +4401,8 @@ if TYPE_CHECKING:
FlaxTopPLogitsWarper, FlaxTopPLogitsWarper,
) )
from .modeling_flax_utils import FlaxPreTrainedModel from .modeling_flax_utils import FlaxPreTrainedModel
# Flax model imports
from .models.albert import ( from .models.albert import (
FlaxAlbertForMaskedLM, FlaxAlbertForMaskedLM,
FlaxAlbertForMultipleChoice, FlaxAlbertForMultipleChoice,
...@@ -4494,10 +4568,6 @@ if TYPE_CHECKING: ...@@ -4494,10 +4568,6 @@ if TYPE_CHECKING:
FlaxXLMRobertaForTokenClassification, FlaxXLMRobertaForTokenClassification,
FlaxXLMRobertaModel, FlaxXLMRobertaModel,
) )
else:
# Import the same objects as dummies to get them in the namespace.
# They will raise an import error if the user tries to instantiate / use them.
from .utils.dummy_flax_objects import *
else: else:
import sys import sys
......
...@@ -766,7 +766,9 @@ def clean_frameworks_in_init( ...@@ -766,7 +766,9 @@ def clean_frameworks_in_init(
return return
remove_pattern = "|".join(to_remove) remove_pattern = "|".join(to_remove)
re_conditional_imports = re.compile(rf"^\s*if is_({remove_pattern})_available\(\):\s*$") re_conditional_imports = re.compile(rf"^\s*if not is_({remove_pattern})_available\(\):\s*$")
re_try = re.compile(r"\s*try:")
re_else = re.compile(r"\s*else:")
re_is_xxx_available = re.compile(rf"is_({remove_pattern})_available") re_is_xxx_available = re.compile(rf"is_({remove_pattern})_available")
with open(init_file, "r", encoding="utf-8") as f: with open(init_file, "r", encoding="utf-8") as f:
...@@ -776,11 +778,15 @@ def clean_frameworks_in_init( ...@@ -776,11 +778,15 @@ def clean_frameworks_in_init(
new_lines = [] new_lines = []
idx = 0 idx = 0
while idx < len(lines): while idx < len(lines):
# Conditional imports # Conditional imports in try-except-else blocks
if re_conditional_imports.search(lines[idx]) is not None: if (re_conditional_imports.search(lines[idx]) is not None) and (re_try.search(lines[idx - 1]) is not None):
# Remove the preceding `try:`
new_lines.pop()
idx += 1 idx += 1
while is_empty_line(lines[idx]): # Iterate until `else:`
while is_empty_line(lines[idx]) or re_else.search(lines[idx]) is None:
idx += 1 idx += 1
idx += 1
indent = find_indent(lines[idx]) indent = find_indent(lines[idx])
while find_indent(lines[idx]) >= indent or is_empty_line(lines[idx]): while find_indent(lines[idx]) >= indent or is_empty_line(lines[idx]):
idx += 1 idx += 1
...@@ -790,6 +796,7 @@ def clean_frameworks_in_init( ...@@ -790,6 +796,7 @@ def clean_frameworks_in_init(
for framework in to_remove: for framework in to_remove:
line = line.replace(f", is_{framework}_available", "") line = line.replace(f", is_{framework}_available", "")
line = line.replace(f"is_{framework}_available, ", "") line = line.replace(f"is_{framework}_available, ", "")
line = line.replace(f"is_{framework}_available,", "")
line = line.replace(f"is_{framework}_available", "") line = line.replace(f"is_{framework}_available", "")
if len(line.strip()) > 0: if len(line.strip()) > 0:
...@@ -836,11 +843,11 @@ def add_model_to_main_init( ...@@ -836,11 +843,11 @@ def add_model_to_main_init(
while idx < len(lines): while idx < len(lines):
if not is_empty_line(lines[idx]) and find_indent(lines[idx]) == 0: if not is_empty_line(lines[idx]) and find_indent(lines[idx]) == 0:
framework = None framework = None
elif lines[idx].lstrip().startswith("if is_torch_available"): elif lines[idx].lstrip().startswith("if not is_torch_available"):
framework = "pt" framework = "pt"
elif lines[idx].lstrip().startswith("if is_tf_available"): elif lines[idx].lstrip().startswith("if not is_tf_available"):
framework = "tf" framework = "tf"
elif lines[idx].lstrip().startswith("if is_flax_available"): elif lines[idx].lstrip().startswith("if not is_flax_available"):
framework = "flax" framework = "flax"
# Skip if we are in a framework not wanted. # Skip if we are in a framework not wanted.
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import ( from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule, _LazyModule,
is_flax_available, is_flax_available,
is_sentencepiece_available, is_sentencepiece_available,
...@@ -32,13 +33,28 @@ _import_structure = { ...@@ -32,13 +33,28 @@ _import_structure = {
"configuration_albert": ["ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "AlbertConfig", "AlbertOnnxConfig"], "configuration_albert": ["ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "AlbertConfig", "AlbertOnnxConfig"],
} }
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_albert"] = ["AlbertTokenizer"] _import_structure["tokenization_albert"] = ["AlbertTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_albert_fast"] = ["AlbertTokenizerFast"] _import_structure["tokenization_albert_fast"] = ["AlbertTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_albert"] = [ _import_structure["modeling_albert"] = [
"ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"AlbertForMaskedLM", "AlbertForMaskedLM",
...@@ -52,7 +68,12 @@ if is_torch_available(): ...@@ -52,7 +68,12 @@ if is_torch_available():
"load_tf_weights_in_albert", "load_tf_weights_in_albert",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_albert"] = [ _import_structure["modeling_tf_albert"] = [
"TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFAlbertForMaskedLM", "TFAlbertForMaskedLM",
...@@ -66,7 +87,12 @@ if is_tf_available(): ...@@ -66,7 +87,12 @@ if is_tf_available():
"TFAlbertPreTrainedModel", "TFAlbertPreTrainedModel",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_albert"] = [ _import_structure["modeling_flax_albert"] = [
"FlaxAlbertForMaskedLM", "FlaxAlbertForMaskedLM",
"FlaxAlbertForMultipleChoice", "FlaxAlbertForMultipleChoice",
...@@ -81,13 +107,28 @@ if is_flax_available(): ...@@ -81,13 +107,28 @@ if is_flax_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_albert import ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, AlbertConfig, AlbertOnnxConfig from .configuration_albert import ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, AlbertConfig, AlbertOnnxConfig
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_albert import AlbertTokenizer from .tokenization_albert import AlbertTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_albert_fast import AlbertTokenizerFast from .tokenization_albert_fast import AlbertTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_albert import ( from .modeling_albert import (
ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST, ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
AlbertForMaskedLM, AlbertForMaskedLM,
...@@ -101,7 +142,12 @@ if TYPE_CHECKING: ...@@ -101,7 +142,12 @@ if TYPE_CHECKING:
load_tf_weights_in_albert, load_tf_weights_in_albert,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_albert import ( from .modeling_tf_albert import (
TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFAlbertForMaskedLM, TFAlbertForMaskedLM,
...@@ -115,7 +161,12 @@ if TYPE_CHECKING: ...@@ -115,7 +161,12 @@ if TYPE_CHECKING:
TFAlbertPreTrainedModel, TFAlbertPreTrainedModel,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_albert import ( from .modeling_flax_albert import (
FlaxAlbertForMaskedLM, FlaxAlbertForMaskedLM,
FlaxAlbertForMultipleChoice, FlaxAlbertForMultipleChoice,
......
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_flax_available, is_tf_available, is_torch_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_tf_available,
is_torch_available,
)
_import_structure = { _import_structure = {
...@@ -29,7 +35,12 @@ _import_structure = { ...@@ -29,7 +35,12 @@ _import_structure = {
"tokenization_auto": ["TOKENIZER_MAPPING", "AutoTokenizer"], "tokenization_auto": ["TOKENIZER_MAPPING", "AutoTokenizer"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_auto"] = [ _import_structure["modeling_auto"] = [
"MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING", "MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING",
"MODEL_FOR_AUDIO_XVECTOR_MAPPING", "MODEL_FOR_AUDIO_XVECTOR_MAPPING",
...@@ -81,7 +92,12 @@ if is_torch_available(): ...@@ -81,7 +92,12 @@ if is_torch_available():
"AutoModelWithLMHead", "AutoModelWithLMHead",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_auto"] = [ _import_structure["modeling_tf_auto"] = [
"TF_MODEL_FOR_CAUSAL_LM_MAPPING", "TF_MODEL_FOR_CAUSAL_LM_MAPPING",
"TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING", "TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING",
...@@ -115,7 +131,12 @@ if is_tf_available(): ...@@ -115,7 +131,12 @@ if is_tf_available():
"TFAutoModelWithLMHead", "TFAutoModelWithLMHead",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_auto"] = [ _import_structure["modeling_flax_auto"] = [
"FLAX_MODEL_FOR_CAUSAL_LM_MAPPING", "FLAX_MODEL_FOR_CAUSAL_LM_MAPPING",
"FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING", "FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING",
...@@ -151,7 +172,12 @@ if TYPE_CHECKING: ...@@ -151,7 +172,12 @@ if TYPE_CHECKING:
from .processing_auto import PROCESSOR_MAPPING, AutoProcessor from .processing_auto import PROCESSOR_MAPPING, AutoProcessor
from .tokenization_auto import TOKENIZER_MAPPING, AutoTokenizer from .tokenization_auto import TOKENIZER_MAPPING, AutoTokenizer
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_auto import ( from .modeling_auto import (
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING, MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING,
MODEL_FOR_AUDIO_XVECTOR_MAPPING, MODEL_FOR_AUDIO_XVECTOR_MAPPING,
...@@ -203,7 +229,12 @@ if TYPE_CHECKING: ...@@ -203,7 +229,12 @@ if TYPE_CHECKING:
AutoModelWithLMHead, AutoModelWithLMHead,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_auto import ( from .modeling_tf_auto import (
TF_MODEL_FOR_CAUSAL_LM_MAPPING, TF_MODEL_FOR_CAUSAL_LM_MAPPING,
TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING, TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
...@@ -237,7 +268,12 @@ if TYPE_CHECKING: ...@@ -237,7 +268,12 @@ if TYPE_CHECKING:
TFAutoModelWithLMHead, TFAutoModelWithLMHead,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_auto import ( from .modeling_flax_auto import (
FLAX_MODEL_FOR_CAUSAL_LM_MAPPING, FLAX_MODEL_FOR_CAUSAL_LM_MAPPING,
FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING, FLAX_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
......
...@@ -17,7 +17,14 @@ ...@@ -17,7 +17,14 @@
# limitations under the License. # limitations under the License.
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_flax_available, is_tf_available, is_tokenizers_available, is_torch_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_tf_available,
is_tokenizers_available,
is_torch_available,
)
_import_structure = { _import_structure = {
...@@ -25,10 +32,20 @@ _import_structure = { ...@@ -25,10 +32,20 @@ _import_structure = {
"tokenization_bart": ["BartTokenizer"], "tokenization_bart": ["BartTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_bart_fast"] = ["BartTokenizerFast"] _import_structure["tokenization_bart_fast"] = ["BartTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_bart"] = [ _import_structure["modeling_bart"] = [
"BART_PRETRAINED_MODEL_ARCHIVE_LIST", "BART_PRETRAINED_MODEL_ARCHIVE_LIST",
"BartForCausalLM", "BartForCausalLM",
...@@ -40,10 +57,20 @@ if is_torch_available(): ...@@ -40,10 +57,20 @@ if is_torch_available():
"PretrainedBartModel", "PretrainedBartModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_bart"] = ["TFBartForConditionalGeneration", "TFBartModel", "TFBartPretrainedModel"] _import_structure["modeling_tf_bart"] = ["TFBartForConditionalGeneration", "TFBartModel", "TFBartPretrainedModel"]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_bart"] = [ _import_structure["modeling_flax_bart"] = [
"FlaxBartDecoderPreTrainedModel", "FlaxBartDecoderPreTrainedModel",
"FlaxBartForCausalLM", "FlaxBartForCausalLM",
...@@ -58,10 +85,20 @@ if TYPE_CHECKING: ...@@ -58,10 +85,20 @@ if TYPE_CHECKING:
from .configuration_bart import BART_PRETRAINED_CONFIG_ARCHIVE_MAP, BartConfig, BartOnnxConfig from .configuration_bart import BART_PRETRAINED_CONFIG_ARCHIVE_MAP, BartConfig, BartOnnxConfig
from .tokenization_bart import BartTokenizer from .tokenization_bart import BartTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_bart_fast import BartTokenizerFast from .tokenization_bart_fast import BartTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_bart import ( from .modeling_bart import (
BART_PRETRAINED_MODEL_ARCHIVE_LIST, BART_PRETRAINED_MODEL_ARCHIVE_LIST,
BartForCausalLM, BartForCausalLM,
...@@ -73,10 +110,20 @@ if TYPE_CHECKING: ...@@ -73,10 +110,20 @@ if TYPE_CHECKING:
PretrainedBartModel, PretrainedBartModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_bart import TFBartForConditionalGeneration, TFBartModel, TFBartPretrainedModel from .modeling_tf_bart import TFBartForConditionalGeneration, TFBartModel, TFBartPretrainedModel
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_bart import ( from .modeling_flax_bart import (
FlaxBartDecoderPreTrainedModel, FlaxBartDecoderPreTrainedModel,
FlaxBartForCausalLM, FlaxBartForCausalLM,
......
...@@ -18,24 +18,44 @@ ...@@ -18,24 +18,44 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_sentencepiece_available, is_tokenizers_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_tokenizers_available
_import_structure = {} _import_structure = {}
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_barthez"] = ["BarthezTokenizer"] _import_structure["tokenization_barthez"] = ["BarthezTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_barthez_fast"] = ["BarthezTokenizerFast"] _import_structure["tokenization_barthez_fast"] = ["BarthezTokenizerFast"]
if TYPE_CHECKING: if TYPE_CHECKING:
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_barthez import BarthezTokenizer from .tokenization_barthez import BarthezTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_barthez_fast import BarthezTokenizerFast from .tokenization_barthez_fast import BarthezTokenizerFast
else: else:
......
...@@ -18,16 +18,26 @@ ...@@ -18,16 +18,26 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_sentencepiece_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available
_import_structure = {} _import_structure = {}
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_bartpho"] = ["BartphoTokenizer"] _import_structure["tokenization_bartpho"] = ["BartphoTokenizer"]
if TYPE_CHECKING: if TYPE_CHECKING:
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_bartpho import BartphoTokenizer from .tokenization_bartpho import BartphoTokenizer
else: else:
......
...@@ -18,17 +18,33 @@ ...@@ -18,17 +18,33 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_flax_available, is_torch_available, is_vision_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_torch_available,
is_vision_available,
)
_import_structure = { _import_structure = {
"configuration_beit": ["BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "BeitConfig", "BeitOnnxConfig"], "configuration_beit": ["BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "BeitConfig", "BeitOnnxConfig"],
} }
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["feature_extraction_beit"] = ["BeitFeatureExtractor"] _import_structure["feature_extraction_beit"] = ["BeitFeatureExtractor"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_beit"] = [ _import_structure["modeling_beit"] = [
"BEIT_PRETRAINED_MODEL_ARCHIVE_LIST", "BEIT_PRETRAINED_MODEL_ARCHIVE_LIST",
"BeitForImageClassification", "BeitForImageClassification",
...@@ -39,7 +55,12 @@ if is_torch_available(): ...@@ -39,7 +55,12 @@ if is_torch_available():
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_beit"] = [ _import_structure["modeling_flax_beit"] = [
"FlaxBeitForImageClassification", "FlaxBeitForImageClassification",
"FlaxBeitForMaskedImageModeling", "FlaxBeitForMaskedImageModeling",
...@@ -50,10 +71,20 @@ if is_flax_available(): ...@@ -50,10 +71,20 @@ if is_flax_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_beit import BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, BeitConfig, BeitOnnxConfig from .configuration_beit import BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP, BeitConfig, BeitOnnxConfig
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .feature_extraction_beit import BeitFeatureExtractor from .feature_extraction_beit import BeitFeatureExtractor
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_beit import ( from .modeling_beit import (
BEIT_PRETRAINED_MODEL_ARCHIVE_LIST, BEIT_PRETRAINED_MODEL_ARCHIVE_LIST,
BeitForImageClassification, BeitForImageClassification,
...@@ -63,7 +94,12 @@ if TYPE_CHECKING: ...@@ -63,7 +94,12 @@ if TYPE_CHECKING:
BeitPreTrainedModel, BeitPreTrainedModel,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_beit import ( from .modeling_flax_beit import (
FlaxBeitForImageClassification, FlaxBeitForImageClassification,
FlaxBeitForMaskedImageModeling, FlaxBeitForMaskedImageModeling,
......
...@@ -18,7 +18,14 @@ ...@@ -18,7 +18,14 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_flax_available, is_tf_available, is_tokenizers_available, is_torch_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_tf_available,
is_tokenizers_available,
is_torch_available,
)
_import_structure = { _import_structure = {
...@@ -26,10 +33,20 @@ _import_structure = { ...@@ -26,10 +33,20 @@ _import_structure = {
"tokenization_bert": ["BasicTokenizer", "BertTokenizer", "WordpieceTokenizer"], "tokenization_bert": ["BasicTokenizer", "BertTokenizer", "WordpieceTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_bert_fast"] = ["BertTokenizerFast"] _import_structure["tokenization_bert_fast"] = ["BertTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_bert"] = [ _import_structure["modeling_bert"] = [
"BERT_PRETRAINED_MODEL_ARCHIVE_LIST", "BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"BertForMaskedLM", "BertForMaskedLM",
...@@ -46,7 +63,12 @@ if is_torch_available(): ...@@ -46,7 +63,12 @@ if is_torch_available():
"load_tf_weights_in_bert", "load_tf_weights_in_bert",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_bert"] = [ _import_structure["modeling_tf_bert"] = [
"TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFBertEmbeddings", "TFBertEmbeddings",
...@@ -63,7 +85,12 @@ if is_tf_available(): ...@@ -63,7 +85,12 @@ if is_tf_available():
"TFBertPreTrainedModel", "TFBertPreTrainedModel",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_bert"] = [ _import_structure["modeling_flax_bert"] = [
"FlaxBertForCausalLM", "FlaxBertForCausalLM",
"FlaxBertForMaskedLM", "FlaxBertForMaskedLM",
...@@ -81,10 +108,20 @@ if TYPE_CHECKING: ...@@ -81,10 +108,20 @@ if TYPE_CHECKING:
from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig
from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_bert_fast import BertTokenizerFast from .tokenization_bert_fast import BertTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_bert import ( from .modeling_bert import (
BERT_PRETRAINED_MODEL_ARCHIVE_LIST, BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
BertForMaskedLM, BertForMaskedLM,
...@@ -101,7 +138,12 @@ if TYPE_CHECKING: ...@@ -101,7 +138,12 @@ if TYPE_CHECKING:
load_tf_weights_in_bert, load_tf_weights_in_bert,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_bert import ( from .modeling_tf_bert import (
TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFBertEmbeddings, TFBertEmbeddings,
...@@ -118,7 +160,12 @@ if TYPE_CHECKING: ...@@ -118,7 +160,12 @@ if TYPE_CHECKING:
TFBertPreTrainedModel, TFBertPreTrainedModel,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_bert import ( from .modeling_flax_bert import (
FlaxBertForCausalLM, FlaxBertForCausalLM,
FlaxBertForMaskedLM, FlaxBertForMaskedLM,
......
...@@ -18,17 +18,27 @@ ...@@ -18,17 +18,27 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_sentencepiece_available, is_torch_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_torch_available
_import_structure = { _import_structure = {
"configuration_bert_generation": ["BertGenerationConfig"], "configuration_bert_generation": ["BertGenerationConfig"],
} }
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_bert_generation"] = ["BertGenerationTokenizer"] _import_structure["tokenization_bert_generation"] = ["BertGenerationTokenizer"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_bert_generation"] = [ _import_structure["modeling_bert_generation"] = [
"BertGenerationDecoder", "BertGenerationDecoder",
"BertGenerationEncoder", "BertGenerationEncoder",
...@@ -40,10 +50,20 @@ if is_torch_available(): ...@@ -40,10 +50,20 @@ if is_torch_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_bert_generation import BertGenerationConfig from .configuration_bert_generation import BertGenerationConfig
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_bert_generation import BertGenerationTokenizer from .tokenization_bert_generation import BertGenerationTokenizer
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_bert_generation import ( from .modeling_bert_generation import (
BertGenerationDecoder, BertGenerationDecoder,
BertGenerationEncoder, BertGenerationEncoder,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import ( from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule, _LazyModule,
is_flax_available, is_flax_available,
is_sentencepiece_available, is_sentencepiece_available,
...@@ -31,13 +32,28 @@ _import_structure = { ...@@ -31,13 +32,28 @@ _import_structure = {
"configuration_big_bird": ["BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP", "BigBirdConfig", "BigBirdOnnxConfig"], "configuration_big_bird": ["BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP", "BigBirdConfig", "BigBirdOnnxConfig"],
} }
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_big_bird"] = ["BigBirdTokenizer"] _import_structure["tokenization_big_bird"] = ["BigBirdTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_big_bird_fast"] = ["BigBirdTokenizerFast"] _import_structure["tokenization_big_bird_fast"] = ["BigBirdTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_big_bird"] = [ _import_structure["modeling_big_bird"] = [
"BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST", "BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST",
"BigBirdForCausalLM", "BigBirdForCausalLM",
...@@ -53,7 +69,12 @@ if is_torch_available(): ...@@ -53,7 +69,12 @@ if is_torch_available():
"load_tf_weights_in_big_bird", "load_tf_weights_in_big_bird",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_big_bird"] = [ _import_structure["modeling_flax_big_bird"] = [
"FlaxBigBirdForCausalLM", "FlaxBigBirdForCausalLM",
"FlaxBigBirdForMaskedLM", "FlaxBigBirdForMaskedLM",
...@@ -69,13 +90,28 @@ if is_flax_available(): ...@@ -69,13 +90,28 @@ if is_flax_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_big_bird import BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP, BigBirdConfig, BigBirdOnnxConfig from .configuration_big_bird import BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP, BigBirdConfig, BigBirdOnnxConfig
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_big_bird import BigBirdTokenizer from .tokenization_big_bird import BigBirdTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_big_bird_fast import BigBirdTokenizerFast from .tokenization_big_bird_fast import BigBirdTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_big_bird import ( from .modeling_big_bird import (
BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST, BIG_BIRD_PRETRAINED_MODEL_ARCHIVE_LIST,
BigBirdForCausalLM, BigBirdForCausalLM,
...@@ -91,7 +127,12 @@ if TYPE_CHECKING: ...@@ -91,7 +127,12 @@ if TYPE_CHECKING:
load_tf_weights_in_big_bird, load_tf_weights_in_big_bird,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_big_bird import ( from .modeling_flax_big_bird import (
FlaxBigBirdForCausalLM, FlaxBigBirdForCausalLM,
FlaxBigBirdForMaskedLM, FlaxBigBirdForMaskedLM,
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# limitations under the License. # limitations under the License.
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_torch_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available
_import_structure = { _import_structure = {
...@@ -28,7 +28,12 @@ _import_structure = { ...@@ -28,7 +28,12 @@ _import_structure = {
], ],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_bigbird_pegasus"] = [ _import_structure["modeling_bigbird_pegasus"] = [
"BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST", "BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST",
"BigBirdPegasusForCausalLM", "BigBirdPegasusForCausalLM",
...@@ -47,7 +52,12 @@ if TYPE_CHECKING: ...@@ -47,7 +52,12 @@ if TYPE_CHECKING:
BigBirdPegasusOnnxConfig, BigBirdPegasusOnnxConfig,
) )
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_bigbird_pegasus import ( from .modeling_bigbird_pegasus import (
BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST, BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
BigBirdPegasusForCausalLM, BigBirdPegasusForCausalLM,
......
...@@ -18,7 +18,14 @@ ...@@ -18,7 +18,14 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_flax_available, is_tf_available, is_tokenizers_available, is_torch_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_tf_available,
is_tokenizers_available,
is_torch_available,
)
_import_structure = { _import_structure = {
...@@ -30,10 +37,20 @@ _import_structure = { ...@@ -30,10 +37,20 @@ _import_structure = {
"tokenization_blenderbot": ["BlenderbotTokenizer"], "tokenization_blenderbot": ["BlenderbotTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_blenderbot_fast"] = ["BlenderbotTokenizerFast"] _import_structure["tokenization_blenderbot_fast"] = ["BlenderbotTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_blenderbot"] = [ _import_structure["modeling_blenderbot"] = [
"BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST", "BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST",
"BlenderbotForCausalLM", "BlenderbotForCausalLM",
...@@ -43,7 +60,12 @@ if is_torch_available(): ...@@ -43,7 +60,12 @@ if is_torch_available():
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_blenderbot"] = [ _import_structure["modeling_tf_blenderbot"] = [
"TFBlenderbotForConditionalGeneration", "TFBlenderbotForConditionalGeneration",
"TFBlenderbotModel", "TFBlenderbotModel",
...@@ -51,7 +73,12 @@ if is_tf_available(): ...@@ -51,7 +73,12 @@ if is_tf_available():
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_blenderbot"] = [ _import_structure["modeling_flax_blenderbot"] = [
"FlaxBlenderbotForConditionalGeneration", "FlaxBlenderbotForConditionalGeneration",
"FlaxBlenderbotModel", "FlaxBlenderbotModel",
...@@ -67,10 +94,20 @@ if TYPE_CHECKING: ...@@ -67,10 +94,20 @@ if TYPE_CHECKING:
) )
from .tokenization_blenderbot import BlenderbotTokenizer from .tokenization_blenderbot import BlenderbotTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_blenderbot_fast import BlenderbotTokenizerFast from .tokenization_blenderbot_fast import BlenderbotTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_blenderbot import ( from .modeling_blenderbot import (
BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST, BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST,
BlenderbotForCausalLM, BlenderbotForCausalLM,
...@@ -79,14 +116,24 @@ if TYPE_CHECKING: ...@@ -79,14 +116,24 @@ if TYPE_CHECKING:
BlenderbotPreTrainedModel, BlenderbotPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_blenderbot import ( from .modeling_tf_blenderbot import (
TFBlenderbotForConditionalGeneration, TFBlenderbotForConditionalGeneration,
TFBlenderbotModel, TFBlenderbotModel,
TFBlenderbotPreTrainedModel, TFBlenderbotPreTrainedModel,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_blenderbot import ( from .modeling_flax_blenderbot import (
FlaxBlenderbotForConditionalGeneration, FlaxBlenderbotForConditionalGeneration,
FlaxBlenderbotModel, FlaxBlenderbotModel,
......
...@@ -17,7 +17,14 @@ ...@@ -17,7 +17,14 @@
# limitations under the License. # limitations under the License.
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_flax_available, is_tf_available, is_tokenizers_available, is_torch_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_flax_available,
is_tf_available,
is_tokenizers_available,
is_torch_available,
)
_import_structure = { _import_structure = {
...@@ -29,10 +36,20 @@ _import_structure = { ...@@ -29,10 +36,20 @@ _import_structure = {
"tokenization_blenderbot_small": ["BlenderbotSmallTokenizer"], "tokenization_blenderbot_small": ["BlenderbotSmallTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_blenderbot_small_fast"] = ["BlenderbotSmallTokenizerFast"] _import_structure["tokenization_blenderbot_small_fast"] = ["BlenderbotSmallTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_blenderbot_small"] = [ _import_structure["modeling_blenderbot_small"] = [
"BLENDERBOT_SMALL_PRETRAINED_MODEL_ARCHIVE_LIST", "BLENDERBOT_SMALL_PRETRAINED_MODEL_ARCHIVE_LIST",
"BlenderbotSmallForCausalLM", "BlenderbotSmallForCausalLM",
...@@ -41,14 +58,24 @@ if is_torch_available(): ...@@ -41,14 +58,24 @@ if is_torch_available():
"BlenderbotSmallPreTrainedModel", "BlenderbotSmallPreTrainedModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_blenderbot_small"] = [ _import_structure["modeling_tf_blenderbot_small"] = [
"TFBlenderbotSmallForConditionalGeneration", "TFBlenderbotSmallForConditionalGeneration",
"TFBlenderbotSmallModel", "TFBlenderbotSmallModel",
"TFBlenderbotSmallPreTrainedModel", "TFBlenderbotSmallPreTrainedModel",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_blenderbot_small"] = [ _import_structure["modeling_flax_blenderbot_small"] = [
"FlaxBlenderbotSmallForConditionalGeneration", "FlaxBlenderbotSmallForConditionalGeneration",
"FlaxBlenderbotSmallModel", "FlaxBlenderbotSmallModel",
...@@ -63,10 +90,20 @@ if TYPE_CHECKING: ...@@ -63,10 +90,20 @@ if TYPE_CHECKING:
) )
from .tokenization_blenderbot_small import BlenderbotSmallTokenizer from .tokenization_blenderbot_small import BlenderbotSmallTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_blenderbot_small_fast import BlenderbotSmallTokenizerFast from .tokenization_blenderbot_small_fast import BlenderbotSmallTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_blenderbot_small import ( from .modeling_blenderbot_small import (
BLENDERBOT_SMALL_PRETRAINED_MODEL_ARCHIVE_LIST, BLENDERBOT_SMALL_PRETRAINED_MODEL_ARCHIVE_LIST,
BlenderbotSmallForCausalLM, BlenderbotSmallForCausalLM,
...@@ -75,14 +112,24 @@ if TYPE_CHECKING: ...@@ -75,14 +112,24 @@ if TYPE_CHECKING:
BlenderbotSmallPreTrainedModel, BlenderbotSmallPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_blenderbot_small import ( from .modeling_tf_blenderbot_small import (
TFBlenderbotSmallForConditionalGeneration, TFBlenderbotSmallForConditionalGeneration,
TFBlenderbotSmallModel, TFBlenderbotSmallModel,
TFBlenderbotSmallPreTrainedModel, TFBlenderbotSmallPreTrainedModel,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_blenderbot_small import ( from .modeling_flax_blenderbot_small import (
FlaxBlenderbotSmallForConditionalGeneration, FlaxBlenderbotSmallForConditionalGeneration,
FlaxBlenderbotSmallModel, FlaxBlenderbotSmallModel,
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import ( from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule, _LazyModule,
is_sentencepiece_available, is_sentencepiece_available,
is_tf_available, is_tf_available,
...@@ -31,13 +32,28 @@ _import_structure = { ...@@ -31,13 +32,28 @@ _import_structure = {
"configuration_camembert": ["CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "CamembertConfig", "CamembertOnnxConfig"], "configuration_camembert": ["CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "CamembertConfig", "CamembertOnnxConfig"],
} }
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_camembert"] = ["CamembertTokenizer"] _import_structure["tokenization_camembert"] = ["CamembertTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_camembert_fast"] = ["CamembertTokenizerFast"] _import_structure["tokenization_camembert_fast"] = ["CamembertTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_camembert"] = [ _import_structure["modeling_camembert"] = [
"CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"CamembertForCausalLM", "CamembertForCausalLM",
...@@ -49,7 +65,12 @@ if is_torch_available(): ...@@ -49,7 +65,12 @@ if is_torch_available():
"CamembertModel", "CamembertModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_camembert"] = [ _import_structure["modeling_tf_camembert"] = [
"TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFCamembertForCausalLM", "TFCamembertForCausalLM",
...@@ -65,13 +86,28 @@ if is_tf_available(): ...@@ -65,13 +86,28 @@ if is_tf_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_camembert import CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, CamembertConfig, CamembertOnnxConfig from .configuration_camembert import CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, CamembertConfig, CamembertOnnxConfig
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_camembert import CamembertTokenizer from .tokenization_camembert import CamembertTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_camembert_fast import CamembertTokenizerFast from .tokenization_camembert_fast import CamembertTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_camembert import ( from .modeling_camembert import (
CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST, CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
CamembertForCausalLM, CamembertForCausalLM,
...@@ -83,7 +119,12 @@ if TYPE_CHECKING: ...@@ -83,7 +119,12 @@ if TYPE_CHECKING:
CamembertModel, CamembertModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_camembert import ( from .modeling_tf_camembert import (
TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_CAMEMBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFCamembertForCausalLM, TFCamembertForCausalLM,
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# limitations under the License. # limitations under the License.
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_tokenizers_available, is_torch_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available
_import_structure = { _import_structure = {
...@@ -25,7 +25,12 @@ _import_structure = { ...@@ -25,7 +25,12 @@ _import_structure = {
"tokenization_canine": ["CanineTokenizer"], "tokenization_canine": ["CanineTokenizer"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_canine"] = [ _import_structure["modeling_canine"] = [
"CANINE_PRETRAINED_MODEL_ARCHIVE_LIST", "CANINE_PRETRAINED_MODEL_ARCHIVE_LIST",
"CanineForMultipleChoice", "CanineForMultipleChoice",
...@@ -43,7 +48,12 @@ if TYPE_CHECKING: ...@@ -43,7 +48,12 @@ if TYPE_CHECKING:
from .configuration_canine import CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP, CanineConfig from .configuration_canine import CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP, CanineConfig
from .tokenization_canine import CanineTokenizer from .tokenization_canine import CanineTokenizer
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_canine import ( from .modeling_canine import (
CANINE_PRETRAINED_MODEL_ARCHIVE_LIST, CANINE_PRETRAINED_MODEL_ARCHIVE_LIST,
CanineForMultipleChoice, CanineForMultipleChoice,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import ( from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule, _LazyModule,
is_flax_available, is_flax_available,
is_tf_available, is_tf_available,
...@@ -32,14 +33,29 @@ _import_structure = { ...@@ -32,14 +33,29 @@ _import_structure = {
"tokenization_clip": ["CLIPTokenizer"], "tokenization_clip": ["CLIPTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_clip_fast"] = ["CLIPTokenizerFast"] _import_structure["tokenization_clip_fast"] = ["CLIPTokenizerFast"]
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["feature_extraction_clip"] = ["CLIPFeatureExtractor"] _import_structure["feature_extraction_clip"] = ["CLIPFeatureExtractor"]
_import_structure["processing_clip"] = ["CLIPProcessor"] _import_structure["processing_clip"] = ["CLIPProcessor"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_clip"] = [ _import_structure["modeling_clip"] = [
"CLIP_PRETRAINED_MODEL_ARCHIVE_LIST", "CLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
"CLIPModel", "CLIPModel",
...@@ -48,7 +64,12 @@ if is_torch_available(): ...@@ -48,7 +64,12 @@ if is_torch_available():
"CLIPVisionModel", "CLIPVisionModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_clip"] = [ _import_structure["modeling_tf_clip"] = [
"TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFCLIPModel", "TFCLIPModel",
...@@ -57,7 +78,12 @@ if is_tf_available(): ...@@ -57,7 +78,12 @@ if is_tf_available():
"TFCLIPVisionModel", "TFCLIPVisionModel",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_clip"] = [ _import_structure["modeling_flax_clip"] = [
"FlaxCLIPModel", "FlaxCLIPModel",
"FlaxCLIPPreTrainedModel", "FlaxCLIPPreTrainedModel",
...@@ -72,14 +98,29 @@ if TYPE_CHECKING: ...@@ -72,14 +98,29 @@ if TYPE_CHECKING:
from .configuration_clip import CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, CLIPConfig, CLIPTextConfig, CLIPVisionConfig from .configuration_clip import CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, CLIPConfig, CLIPTextConfig, CLIPVisionConfig
from .tokenization_clip import CLIPTokenizer from .tokenization_clip import CLIPTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_clip_fast import CLIPTokenizerFast from .tokenization_clip_fast import CLIPTokenizerFast
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .feature_extraction_clip import CLIPFeatureExtractor from .feature_extraction_clip import CLIPFeatureExtractor
from .processing_clip import CLIPProcessor from .processing_clip import CLIPProcessor
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_clip import ( from .modeling_clip import (
CLIP_PRETRAINED_MODEL_ARCHIVE_LIST, CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
CLIPModel, CLIPModel,
...@@ -88,7 +129,12 @@ if TYPE_CHECKING: ...@@ -88,7 +129,12 @@ if TYPE_CHECKING:
CLIPVisionModel, CLIPVisionModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_clip import ( from .modeling_tf_clip import (
TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST, TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
TFCLIPModel, TFCLIPModel,
...@@ -97,7 +143,12 @@ if TYPE_CHECKING: ...@@ -97,7 +143,12 @@ if TYPE_CHECKING:
TFCLIPVisionModel, TFCLIPVisionModel,
) )
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_clip import ( from .modeling_flax_clip import (
FlaxCLIPModel, FlaxCLIPModel,
FlaxCLIPPreTrainedModel, FlaxCLIPPreTrainedModel,
......
...@@ -17,7 +17,13 @@ ...@@ -17,7 +17,13 @@
# limitations under the License. # limitations under the License.
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_tf_available, is_tokenizers_available, is_torch_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_tf_available,
is_tokenizers_available,
is_torch_available,
)
_import_structure = { _import_structure = {
...@@ -25,10 +31,20 @@ _import_structure = { ...@@ -25,10 +31,20 @@ _import_structure = {
"tokenization_convbert": ["ConvBertTokenizer"], "tokenization_convbert": ["ConvBertTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_convbert_fast"] = ["ConvBertTokenizerFast"] _import_structure["tokenization_convbert_fast"] = ["ConvBertTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_convbert"] = [ _import_structure["modeling_convbert"] = [
"CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"ConvBertForMaskedLM", "ConvBertForMaskedLM",
...@@ -43,7 +59,12 @@ if is_torch_available(): ...@@ -43,7 +59,12 @@ if is_torch_available():
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_convbert"] = [ _import_structure["modeling_tf_convbert"] = [
"TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFConvBertForMaskedLM", "TFConvBertForMaskedLM",
...@@ -61,10 +82,20 @@ if TYPE_CHECKING: ...@@ -61,10 +82,20 @@ if TYPE_CHECKING:
from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig from .configuration_convbert import CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvBertConfig, ConvBertOnnxConfig
from .tokenization_convbert import ConvBertTokenizer from .tokenization_convbert import ConvBertTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_convbert_fast import ConvBertTokenizerFast from .tokenization_convbert_fast import ConvBertTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_convbert import ( from .modeling_convbert import (
CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST, CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
ConvBertForMaskedLM, ConvBertForMaskedLM,
...@@ -78,7 +109,12 @@ if TYPE_CHECKING: ...@@ -78,7 +109,12 @@ if TYPE_CHECKING:
load_tf_weights_in_convbert, load_tf_weights_in_convbert,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_convbert import ( from .modeling_tf_convbert import (
TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFConvBertForMaskedLM, TFConvBertForMaskedLM,
......
...@@ -18,17 +18,33 @@ ...@@ -18,17 +18,33 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
# rely on isort to merge the imports # rely on isort to merge the imports
from ...utils import _LazyModule, is_tf_available, is_torch_available, is_vision_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_tf_available,
is_torch_available,
is_vision_available,
)
_import_structure = { _import_structure = {
"configuration_convnext": ["CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ConvNextConfig"], "configuration_convnext": ["CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ConvNextConfig"],
} }
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["feature_extraction_convnext"] = ["ConvNextFeatureExtractor"] _import_structure["feature_extraction_convnext"] = ["ConvNextFeatureExtractor"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_convnext"] = [ _import_structure["modeling_convnext"] = [
"CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST", "CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
"ConvNextForImageClassification", "ConvNextForImageClassification",
...@@ -36,7 +52,12 @@ if is_torch_available(): ...@@ -36,7 +52,12 @@ if is_torch_available():
"ConvNextPreTrainedModel", "ConvNextPreTrainedModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_convnext"] = [ _import_structure["modeling_tf_convnext"] = [
"TFConvNextForImageClassification", "TFConvNextForImageClassification",
"TFConvNextModel", "TFConvNextModel",
...@@ -46,10 +67,20 @@ if is_tf_available(): ...@@ -46,10 +67,20 @@ if is_tf_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_convnext import CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvNextConfig from .configuration_convnext import CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, ConvNextConfig
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .feature_extraction_convnext import ConvNextFeatureExtractor from .feature_extraction_convnext import ConvNextFeatureExtractor
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_convnext import ( from .modeling_convnext import (
CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST, CONVNEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
ConvNextForImageClassification, ConvNextForImageClassification,
...@@ -57,7 +88,12 @@ if TYPE_CHECKING: ...@@ -57,7 +88,12 @@ if TYPE_CHECKING:
ConvNextPreTrainedModel, ConvNextPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_convnext import TFConvNextForImageClassification, TFConvNextModel, TFConvNextPreTrainedModel from .modeling_convnext import TFConvNextForImageClassification, TFConvNextModel, TFConvNextPreTrainedModel
......
...@@ -18,23 +18,43 @@ ...@@ -18,23 +18,43 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_sentencepiece_available, is_tokenizers_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_tokenizers_available
_import_structure = {} _import_structure = {}
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_cpm"] = ["CpmTokenizer"] _import_structure["tokenization_cpm"] = ["CpmTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_cpm_fast"] = ["CpmTokenizerFast"] _import_structure["tokenization_cpm_fast"] = ["CpmTokenizerFast"]
if TYPE_CHECKING: if TYPE_CHECKING:
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_cpm import CpmTokenizer from .tokenization_cpm import CpmTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_cpm_fast import CpmTokenizerFast from .tokenization_cpm_fast import CpmTokenizerFast
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment