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
...@@ -18,21 +18,31 @@ ...@@ -18,21 +18,31 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_tokenizers_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available
_import_structure = { _import_structure = {
"tokenization_herbert": ["HerbertTokenizer"], "tokenization_herbert": ["HerbertTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_herbert_fast"] = ["HerbertTokenizerFast"] _import_structure["tokenization_herbert_fast"] = ["HerbertTokenizerFast"]
if TYPE_CHECKING: if TYPE_CHECKING:
from .tokenization_herbert import HerbertTokenizer from .tokenization_herbert import HerbertTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_herbert_fast import HerbertTokenizerFast from .tokenization_herbert_fast import HerbertTokenizerFast
else: else:
......
...@@ -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_tf_available, is_torch_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available
_import_structure = { _import_structure = {
...@@ -25,7 +25,12 @@ _import_structure = { ...@@ -25,7 +25,12 @@ _import_structure = {
"configuration_hubert": ["HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "HubertConfig"], "configuration_hubert": ["HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "HubertConfig"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_hubert"] = [ _import_structure["modeling_hubert"] = [
"HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"HubertForCTC", "HubertForCTC",
...@@ -35,7 +40,12 @@ if is_torch_available(): ...@@ -35,7 +40,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_hubert"] = [ _import_structure["modeling_tf_hubert"] = [
"TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFHubertForCTC", "TFHubertForCTC",
...@@ -47,7 +57,12 @@ if TYPE_CHECKING: ...@@ -47,7 +57,12 @@ if TYPE_CHECKING:
from ..wav2vec2.feature_extraction_wav2vec2 import Wav2Vec2FeatureExtractor from ..wav2vec2.feature_extraction_wav2vec2 import Wav2Vec2FeatureExtractor
from .configuration_hubert import HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, HubertConfig from .configuration_hubert import HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, HubertConfig
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_hubert import ( from .modeling_hubert import (
HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST, HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
HubertForCTC, HubertForCTC,
...@@ -56,7 +71,12 @@ if TYPE_CHECKING: ...@@ -56,7 +71,12 @@ if TYPE_CHECKING:
HubertPreTrainedModel, HubertPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_hubert import ( from .modeling_tf_hubert import (
TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFHubertForCTC, TFHubertForCTC,
......
...@@ -18,14 +18,19 @@ ...@@ -18,14 +18,19 @@
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 = {
"configuration_ibert": ["IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "IBertConfig", "IBertOnnxConfig"], "configuration_ibert": ["IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "IBertConfig", "IBertOnnxConfig"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_ibert"] = [ _import_structure["modeling_ibert"] = [
"IBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "IBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"IBertForMaskedLM", "IBertForMaskedLM",
...@@ -40,7 +45,12 @@ if is_torch_available(): ...@@ -40,7 +45,12 @@ if is_torch_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_ibert import ( from .modeling_ibert import (
IBERT_PRETRAINED_MODEL_ARCHIVE_LIST, IBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
IBertForMaskedLM, IBertForMaskedLM,
......
...@@ -18,17 +18,27 @@ ...@@ -18,17 +18,27 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_torch_available, is_vision_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
_import_structure = { _import_structure = {
"configuration_imagegpt": ["IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ImageGPTConfig"], "configuration_imagegpt": ["IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ImageGPTConfig"],
} }
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["feature_extraction_imagegpt"] = ["ImageGPTFeatureExtractor"] _import_structure["feature_extraction_imagegpt"] = ["ImageGPTFeatureExtractor"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_imagegpt"] = [ _import_structure["modeling_imagegpt"] = [
"IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST", "IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST",
"ImageGPTForCausalImageModeling", "ImageGPTForCausalImageModeling",
...@@ -42,10 +52,20 @@ if is_torch_available(): ...@@ -42,10 +52,20 @@ if is_torch_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_imagegpt import IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, ImageGPTConfig from .configuration_imagegpt import IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP, ImageGPTConfig
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .feature_extraction_imagegpt import ImageGPTFeatureExtractor from .feature_extraction_imagegpt import ImageGPTFeatureExtractor
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_imagegpt import ( from .modeling_imagegpt import (
IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST, IMAGEGPT_PRETRAINED_MODEL_ARCHIVE_LIST,
ImageGPTForCausalImageModeling, ImageGPTForCausalImageModeling,
......
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
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,
)
from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig
from .tokenization_layoutlm import LayoutLMTokenizer from .tokenization_layoutlm import LayoutLMTokenizer
...@@ -28,10 +34,20 @@ _import_structure = { ...@@ -28,10 +34,20 @@ _import_structure = {
"tokenization_layoutlm": ["LayoutLMTokenizer"], "tokenization_layoutlm": ["LayoutLMTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_layoutlm_fast"] = ["LayoutLMTokenizerFast"] _import_structure["tokenization_layoutlm_fast"] = ["LayoutLMTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_layoutlm"] = [ _import_structure["modeling_layoutlm"] = [
"LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST", "LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST",
"LayoutLMForMaskedLM", "LayoutLMForMaskedLM",
...@@ -41,7 +57,12 @@ if is_torch_available(): ...@@ -41,7 +57,12 @@ if is_torch_available():
"LayoutLMPreTrainedModel", "LayoutLMPreTrainedModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_layoutlm"] = [ _import_structure["modeling_tf_layoutlm"] = [
"TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFLayoutLMForMaskedLM", "TFLayoutLMForMaskedLM",
...@@ -57,10 +78,20 @@ if TYPE_CHECKING: ...@@ -57,10 +78,20 @@ if TYPE_CHECKING:
from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig, LayoutLMOnnxConfig from .configuration_layoutlm import LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMConfig, LayoutLMOnnxConfig
from .tokenization_layoutlm import LayoutLMTokenizer from .tokenization_layoutlm import LayoutLMTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_layoutlm_fast import LayoutLMTokenizerFast from .tokenization_layoutlm_fast import LayoutLMTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_layoutlm import ( from .modeling_layoutlm import (
LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST, LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
LayoutLMForMaskedLM, LayoutLMForMaskedLM,
...@@ -69,7 +100,12 @@ if TYPE_CHECKING: ...@@ -69,7 +100,12 @@ if TYPE_CHECKING:
LayoutLMModel, LayoutLMModel,
LayoutLMPreTrainedModel, LayoutLMPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_layoutlm import ( from .modeling_tf_layoutlm import (
TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST, TF_LAYOUTLM_PRETRAINED_MODEL_ARCHIVE_LIST,
TFLayoutLMForMaskedLM, TFLayoutLMForMaskedLM,
......
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from ...utils import _LazyModule, is_tokenizers_available, is_torch_available, is_vision_available from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_tokenizers_available,
is_torch_available,
is_vision_available,
)
_import_structure = { _import_structure = {
...@@ -26,14 +32,29 @@ _import_structure = { ...@@ -26,14 +32,29 @@ _import_structure = {
"tokenization_layoutlmv2": ["LayoutLMv2Tokenizer"], "tokenization_layoutlmv2": ["LayoutLMv2Tokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_layoutlmv2_fast"] = ["LayoutLMv2TokenizerFast"] _import_structure["tokenization_layoutlmv2_fast"] = ["LayoutLMv2TokenizerFast"]
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["feature_extraction_layoutlmv2"] = ["LayoutLMv2FeatureExtractor"] _import_structure["feature_extraction_layoutlmv2"] = ["LayoutLMv2FeatureExtractor"]
_import_structure["processing_layoutlmv2"] = ["LayoutLMv2Processor"] _import_structure["processing_layoutlmv2"] = ["LayoutLMv2Processor"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_layoutlmv2"] = [ _import_structure["modeling_layoutlmv2"] = [
"LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST", "LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST",
"LayoutLMv2ForQuestionAnswering", "LayoutLMv2ForQuestionAnswering",
...@@ -48,14 +69,29 @@ if TYPE_CHECKING: ...@@ -48,14 +69,29 @@ if TYPE_CHECKING:
from .configuration_layoutlmv2 import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMv2Config from .configuration_layoutlmv2 import LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP, LayoutLMv2Config
from .tokenization_layoutlmv2 import LayoutLMv2Tokenizer from .tokenization_layoutlmv2 import LayoutLMv2Tokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_layoutlmv2_fast import LayoutLMv2TokenizerFast from .tokenization_layoutlmv2_fast import LayoutLMv2TokenizerFast
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .feature_extraction_layoutlmv2 import LayoutLMv2FeatureExtractor from .feature_extraction_layoutlmv2 import LayoutLMv2FeatureExtractor
from .processing_layoutlmv2 import LayoutLMv2Processor from .processing_layoutlmv2 import LayoutLMv2Processor
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_layoutlmv2 import ( from .modeling_layoutlmv2 import (
LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST, LAYOUTLMV2_PRETRAINED_MODEL_ARCHIVE_LIST,
LayoutLMv2ForQuestionAnswering, LayoutLMv2ForQuestionAnswering,
......
...@@ -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_tokenizers_available, is_tokenizers_available,
...@@ -29,23 +30,53 @@ from ...utils import ( ...@@ -29,23 +30,53 @@ from ...utils import (
_import_structure = {} _import_structure = {}
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_layoutxlm"] = ["LayoutXLMTokenizer"] _import_structure["tokenization_layoutxlm"] = ["LayoutXLMTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_layoutxlm_fast"] = ["LayoutXLMTokenizerFast"] _import_structure["tokenization_layoutxlm_fast"] = ["LayoutXLMTokenizerFast"]
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["processing_layoutxlm"] = ["LayoutXLMProcessor"] _import_structure["processing_layoutxlm"] = ["LayoutXLMProcessor"]
if TYPE_CHECKING: if TYPE_CHECKING:
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_layoutxlm import LayoutXLMTokenizer from .tokenization_layoutxlm import LayoutXLMTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_layoutxlm_fast import LayoutXLMTokenizerFast from .tokenization_layoutxlm_fast import LayoutXLMTokenizerFast
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .processing_layoutlmv2 import LayoutXLMProcessor from .processing_layoutlmv2 import LayoutXLMProcessor
else: else:
......
...@@ -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_led": ["LEDTokenizer"], "tokenization_led": ["LEDTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_led_fast"] = ["LEDTokenizerFast"] _import_structure["tokenization_led_fast"] = ["LEDTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_led"] = [ _import_structure["modeling_led"] = [
"LED_PRETRAINED_MODEL_ARCHIVE_LIST", "LED_PRETRAINED_MODEL_ARCHIVE_LIST",
"LEDForConditionalGeneration", "LEDForConditionalGeneration",
...@@ -39,7 +55,12 @@ if is_torch_available(): ...@@ -39,7 +55,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_led"] = ["TFLEDForConditionalGeneration", "TFLEDModel", "TFLEDPreTrainedModel"] _import_structure["modeling_tf_led"] = ["TFLEDForConditionalGeneration", "TFLEDModel", "TFLEDPreTrainedModel"]
...@@ -47,10 +68,20 @@ if TYPE_CHECKING: ...@@ -47,10 +68,20 @@ if TYPE_CHECKING:
from .configuration_led import LED_PRETRAINED_CONFIG_ARCHIVE_MAP, LEDConfig from .configuration_led import LED_PRETRAINED_CONFIG_ARCHIVE_MAP, LEDConfig
from .tokenization_led import LEDTokenizer from .tokenization_led import LEDTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_led_fast import LEDTokenizerFast from .tokenization_led_fast import LEDTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_led import ( from .modeling_led import (
LED_PRETRAINED_MODEL_ARCHIVE_LIST, LED_PRETRAINED_MODEL_ARCHIVE_LIST,
LEDForConditionalGeneration, LEDForConditionalGeneration,
...@@ -60,7 +91,12 @@ if TYPE_CHECKING: ...@@ -60,7 +91,12 @@ if TYPE_CHECKING:
LEDPreTrainedModel, LEDPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_led import TFLEDForConditionalGeneration, TFLEDModel, TFLEDPreTrainedModel from .modeling_tf_led import TFLEDForConditionalGeneration, TFLEDModel, TFLEDPreTrainedModel
else: else:
......
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
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 = {
...@@ -30,10 +36,20 @@ _import_structure = { ...@@ -30,10 +36,20 @@ _import_structure = {
"tokenization_longformer": ["LongformerTokenizer"], "tokenization_longformer": ["LongformerTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_longformer_fast"] = ["LongformerTokenizerFast"] _import_structure["tokenization_longformer_fast"] = ["LongformerTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_longformer"] = [ _import_structure["modeling_longformer"] = [
"LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST", "LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
"LongformerForMaskedLM", "LongformerForMaskedLM",
...@@ -46,7 +62,12 @@ if is_torch_available(): ...@@ -46,7 +62,12 @@ if is_torch_available():
"LongformerSelfAttention", "LongformerSelfAttention",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_longformer"] = [ _import_structure["modeling_tf_longformer"] = [
"TF_LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFLongformerForMaskedLM", "TFLongformerForMaskedLM",
...@@ -68,10 +89,20 @@ if TYPE_CHECKING: ...@@ -68,10 +89,20 @@ if TYPE_CHECKING:
) )
from .tokenization_longformer import LongformerTokenizer from .tokenization_longformer import LongformerTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_longformer_fast import LongformerTokenizerFast from .tokenization_longformer_fast import LongformerTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_longformer import ( from .modeling_longformer import (
LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST, LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
LongformerForMaskedLM, LongformerForMaskedLM,
...@@ -84,7 +115,12 @@ if TYPE_CHECKING: ...@@ -84,7 +115,12 @@ if TYPE_CHECKING:
LongformerSelfAttention, LongformerSelfAttention,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_longformer import ( from .modeling_tf_longformer import (
TF_LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST, TF_LONGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
TFLongformerForMaskedLM, TFLongformerForMaskedLM,
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
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 = {
...@@ -26,7 +26,12 @@ _import_structure = { ...@@ -26,7 +26,12 @@ _import_structure = {
"tokenization_luke": ["LukeTokenizer"], "tokenization_luke": ["LukeTokenizer"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_luke"] = [ _import_structure["modeling_luke"] = [
"LUKE_PRETRAINED_MODEL_ARCHIVE_LIST", "LUKE_PRETRAINED_MODEL_ARCHIVE_LIST",
"LukeForEntityClassification", "LukeForEntityClassification",
...@@ -42,7 +47,12 @@ if TYPE_CHECKING: ...@@ -42,7 +47,12 @@ if TYPE_CHECKING:
from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig from .configuration_luke import LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP, LukeConfig
from .tokenization_luke import LukeTokenizer from .tokenization_luke import LukeTokenizer
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_luke import ( from .modeling_luke import (
LUKE_PRETRAINED_MODEL_ARCHIVE_LIST, LUKE_PRETRAINED_MODEL_ARCHIVE_LIST,
LukeForEntityClassification, LukeForEntityClassification,
......
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
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 = {
...@@ -26,10 +32,20 @@ _import_structure = { ...@@ -26,10 +32,20 @@ _import_structure = {
"tokenization_lxmert": ["LxmertTokenizer"], "tokenization_lxmert": ["LxmertTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_lxmert_fast"] = ["LxmertTokenizerFast"] _import_structure["tokenization_lxmert_fast"] = ["LxmertTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_lxmert"] = [ _import_structure["modeling_lxmert"] = [
"LxmertEncoder", "LxmertEncoder",
"LxmertForPreTraining", "LxmertForPreTraining",
...@@ -40,7 +56,12 @@ if is_torch_available(): ...@@ -40,7 +56,12 @@ if is_torch_available():
"LxmertXLayer", "LxmertXLayer",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_lxmert"] = [ _import_structure["modeling_tf_lxmert"] = [
"TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFLxmertForPreTraining", "TFLxmertForPreTraining",
...@@ -55,10 +76,20 @@ if TYPE_CHECKING: ...@@ -55,10 +76,20 @@ if TYPE_CHECKING:
from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
from .tokenization_lxmert import LxmertTokenizer from .tokenization_lxmert import LxmertTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_lxmert_fast import LxmertTokenizerFast from .tokenization_lxmert_fast import LxmertTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_lxmert import ( from .modeling_lxmert import (
LxmertEncoder, LxmertEncoder,
LxmertForPreTraining, LxmertForPreTraining,
...@@ -69,7 +100,12 @@ if TYPE_CHECKING: ...@@ -69,7 +100,12 @@ if TYPE_CHECKING:
LxmertXLayer, LxmertXLayer,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_lxmert import ( from .modeling_tf_lxmert import (
TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFLxmertForPreTraining, TFLxmertForPreTraining,
......
...@@ -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 = {
...@@ -26,7 +26,12 @@ _import_structure = { ...@@ -26,7 +26,12 @@ _import_structure = {
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_m2m_100"] = [ _import_structure["modeling_m2m_100"] = [
"M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST", "M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST",
"M2M100ForConditionalGeneration", "M2M100ForConditionalGeneration",
...@@ -39,7 +44,12 @@ if TYPE_CHECKING: ...@@ -39,7 +44,12 @@ if TYPE_CHECKING:
from .configuration_m2m_100 import M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP, M2M100Config, M2M100OnnxConfig from .configuration_m2m_100 import M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP, M2M100Config, M2M100OnnxConfig
from .tokenization_m2m_100 import M2M100Tokenizer from .tokenization_m2m_100 import M2M100Tokenizer
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_m2m_100 import ( from .modeling_m2m_100 import (
M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST, M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST,
M2M100ForConditionalGeneration, M2M100ForConditionalGeneration,
......
...@@ -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,10 +32,20 @@ _import_structure = { ...@@ -31,10 +32,20 @@ _import_structure = {
"configuration_marian": ["MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP", "MarianConfig", "MarianOnnxConfig"], "configuration_marian": ["MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP", "MarianConfig", "MarianOnnxConfig"],
} }
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_marian"] = ["MarianTokenizer"] _import_structure["tokenization_marian"] = ["MarianTokenizer"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_marian"] = [ _import_structure["modeling_marian"] = [
"MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST", "MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST",
"MarianForCausalLM", "MarianForCausalLM",
...@@ -43,19 +54,39 @@ if is_torch_available(): ...@@ -43,19 +54,39 @@ if is_torch_available():
"MarianPreTrainedModel", "MarianPreTrainedModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_marian"] = ["TFMarianModel", "TFMarianMTModel", "TFMarianPreTrainedModel"] _import_structure["modeling_tf_marian"] = ["TFMarianModel", "TFMarianMTModel", "TFMarianPreTrainedModel"]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_marian"] = ["FlaxMarianModel", "FlaxMarianMTModel", "FlaxMarianPreTrainedModel"] _import_structure["modeling_flax_marian"] = ["FlaxMarianModel", "FlaxMarianMTModel", "FlaxMarianPreTrainedModel"]
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_marian import MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP, MarianConfig, MarianOnnxConfig from .configuration_marian import MARIAN_PRETRAINED_CONFIG_ARCHIVE_MAP, MarianConfig, MarianOnnxConfig
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_marian import MarianTokenizer from .tokenization_marian import MarianTokenizer
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_marian import ( from .modeling_marian import (
MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST, MARIAN_PRETRAINED_MODEL_ARCHIVE_LIST,
MarianForCausalLM, MarianForCausalLM,
...@@ -64,10 +95,20 @@ if TYPE_CHECKING: ...@@ -64,10 +95,20 @@ if TYPE_CHECKING:
MarianPreTrainedModel, MarianPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_marian import TFMarianModel, TFMarianMTModel, TFMarianPreTrainedModel from .modeling_tf_marian import TFMarianModel, TFMarianMTModel, TFMarianPreTrainedModel
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, FlaxMarianPreTrainedModel from .modeling_flax_marian import FlaxMarianModel, FlaxMarianMTModel, FlaxMarianPreTrainedModel
else: else:
......
...@@ -17,18 +17,28 @@ ...@@ -17,18 +17,28 @@
# 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, is_vision_available from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available
_import_structure = { _import_structure = {
"configuration_maskformer": ["MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP", "MaskFormerConfig"], "configuration_maskformer": ["MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP", "MaskFormerConfig"],
} }
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["feature_extraction_maskformer"] = ["MaskFormerFeatureExtractor"] _import_structure["feature_extraction_maskformer"] = ["MaskFormerFeatureExtractor"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_maskformer"] = [ _import_structure["modeling_maskformer"] = [
"MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST", "MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST",
"MaskFormerForInstanceSegmentation", "MaskFormerForInstanceSegmentation",
...@@ -39,9 +49,19 @@ if is_torch_available(): ...@@ -39,9 +49,19 @@ if is_torch_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig from .configuration_maskformer import MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, MaskFormerConfig
if is_vision_available(): try:
if not is_vision_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .feature_extraction_maskformer import MaskFormerFeatureExtractor from .feature_extraction_maskformer import MaskFormerFeatureExtractor
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_maskformer import ( from .modeling_maskformer import (
MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST, MASKFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
MaskFormerForInstanceSegmentation, MaskFormerForInstanceSegmentation,
......
...@@ -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_mbart": ["MBART_PRETRAINED_CONFIG_ARCHIVE_MAP", "MBartConfig", "MBartOnnxConfig"], "configuration_mbart": ["MBART_PRETRAINED_CONFIG_ARCHIVE_MAP", "MBartConfig", "MBartOnnxConfig"],
} }
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_mbart"] = ["MBartTokenizer"] _import_structure["tokenization_mbart"] = ["MBartTokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_mbart_fast"] = ["MBartTokenizerFast"] _import_structure["tokenization_mbart_fast"] = ["MBartTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_mbart"] = [ _import_structure["modeling_mbart"] = [
"MBART_PRETRAINED_MODEL_ARCHIVE_LIST", "MBART_PRETRAINED_MODEL_ARCHIVE_LIST",
"MBartForCausalLM", "MBartForCausalLM",
...@@ -48,14 +64,24 @@ if is_torch_available(): ...@@ -48,14 +64,24 @@ if is_torch_available():
"MBartPreTrainedModel", "MBartPreTrainedModel",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_mbart"] = [ _import_structure["modeling_tf_mbart"] = [
"TFMBartForConditionalGeneration", "TFMBartForConditionalGeneration",
"TFMBartModel", "TFMBartModel",
"TFMBartPreTrainedModel", "TFMBartPreTrainedModel",
] ]
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_flax_mbart"] = [ _import_structure["modeling_flax_mbart"] = [
"FlaxMBartForConditionalGeneration", "FlaxMBartForConditionalGeneration",
"FlaxMBartForQuestionAnswering", "FlaxMBartForQuestionAnswering",
...@@ -68,13 +94,28 @@ if is_flax_available(): ...@@ -68,13 +94,28 @@ if is_flax_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_mbart import MBART_PRETRAINED_CONFIG_ARCHIVE_MAP, MBartConfig, MBartOnnxConfig from .configuration_mbart import MBART_PRETRAINED_CONFIG_ARCHIVE_MAP, MBartConfig, MBartOnnxConfig
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_mbart import MBartTokenizer from .tokenization_mbart import MBartTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_mbart_fast import MBartTokenizerFast from .tokenization_mbart_fast import MBartTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_mbart import ( from .modeling_mbart import (
MBART_PRETRAINED_MODEL_ARCHIVE_LIST, MBART_PRETRAINED_MODEL_ARCHIVE_LIST,
MBartForCausalLM, MBartForCausalLM,
...@@ -85,10 +126,20 @@ if TYPE_CHECKING: ...@@ -85,10 +126,20 @@ if TYPE_CHECKING:
MBartPreTrainedModel, MBartPreTrainedModel,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_mbart import TFMBartForConditionalGeneration, TFMBartModel, TFMBartPreTrainedModel from .modeling_tf_mbart import TFMBartForConditionalGeneration, TFMBartModel, TFMBartPreTrainedModel
if is_flax_available(): try:
if not is_flax_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_flax_mbart import ( from .modeling_flax_mbart import (
FlaxMBartForConditionalGeneration, FlaxMBartForConditionalGeneration,
FlaxMBartForQuestionAnswering, FlaxMBartForQuestionAnswering,
......
...@@ -17,23 +17,43 @@ ...@@ -17,23 +17,43 @@
# limitations under the License. # limitations under the License.
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_mbart50"] = ["MBart50Tokenizer"] _import_structure["tokenization_mbart50"] = ["MBart50Tokenizer"]
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_mbart50_fast"] = ["MBart50TokenizerFast"] _import_structure["tokenization_mbart50_fast"] = ["MBart50TokenizerFast"]
if TYPE_CHECKING: if TYPE_CHECKING:
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_mbart50 import MBart50Tokenizer from .tokenization_mbart50 import MBart50Tokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_mbart50_fast import MBart50TokenizerFast from .tokenization_mbart50_fast import MBart50TokenizerFast
else: else:
......
...@@ -17,14 +17,19 @@ ...@@ -17,14 +17,19 @@
# 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 = {
"configuration_megatron_bert": ["MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "MegatronBertConfig"], "configuration_megatron_bert": ["MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "MegatronBertConfig"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_megatron_bert"] = [ _import_structure["modeling_megatron_bert"] = [
"MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST", "MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"MegatronBertForCausalLM", "MegatronBertForCausalLM",
...@@ -42,7 +47,12 @@ if is_torch_available(): ...@@ -42,7 +47,12 @@ if is_torch_available():
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_megatron_bert import MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, MegatronBertConfig from .configuration_megatron_bert import MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, MegatronBertConfig
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_megatron_bert import ( from .modeling_megatron_bert import (
MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST, MEGATRON_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
MegatronBertForCausalLM, MegatronBertForCausalLM,
......
...@@ -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 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_mluke"] = ["MLukeTokenizer"] _import_structure["tokenization_mluke"] = ["MLukeTokenizer"]
if TYPE_CHECKING: if TYPE_CHECKING:
if is_sentencepiece_available(): try:
if not is_sentencepiece_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_mluke import MLukeTokenizer from .tokenization_mluke import MLukeTokenizer
......
...@@ -18,21 +18,31 @@ ...@@ -18,21 +18,31 @@
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 = {
"configuration_mmbt": ["MMBTConfig"], "configuration_mmbt": ["MMBTConfig"],
} }
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_mmbt"] = ["MMBTForClassification", "MMBTModel", "ModalEmbeddings"] _import_structure["modeling_mmbt"] = ["MMBTForClassification", "MMBTModel", "ModalEmbeddings"]
if TYPE_CHECKING: if TYPE_CHECKING:
from .configuration_mmbt import MMBTConfig from .configuration_mmbt import MMBTConfig
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings
else: else:
......
...@@ -18,7 +18,13 @@ ...@@ -18,7 +18,13 @@
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 = {
...@@ -30,10 +36,20 @@ _import_structure = { ...@@ -30,10 +36,20 @@ _import_structure = {
"tokenization_mobilebert": ["MobileBertTokenizer"], "tokenization_mobilebert": ["MobileBertTokenizer"],
} }
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["tokenization_mobilebert_fast"] = ["MobileBertTokenizerFast"] _import_structure["tokenization_mobilebert_fast"] = ["MobileBertTokenizerFast"]
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_mobilebert"] = [ _import_structure["modeling_mobilebert"] = [
"MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"MobileBertForMaskedLM", "MobileBertForMaskedLM",
...@@ -49,7 +65,12 @@ if is_torch_available(): ...@@ -49,7 +65,12 @@ if is_torch_available():
"load_tf_weights_in_mobilebert", "load_tf_weights_in_mobilebert",
] ]
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_tf_mobilebert"] = [ _import_structure["modeling_tf_mobilebert"] = [
"TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST", "TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
"TFMobileBertForMaskedLM", "TFMobileBertForMaskedLM",
...@@ -73,10 +94,20 @@ if TYPE_CHECKING: ...@@ -73,10 +94,20 @@ if TYPE_CHECKING:
) )
from .tokenization_mobilebert import MobileBertTokenizer from .tokenization_mobilebert import MobileBertTokenizer
if is_tokenizers_available(): try:
if not is_tokenizers_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .tokenization_mobilebert_fast import MobileBertTokenizerFast from .tokenization_mobilebert_fast import MobileBertTokenizerFast
if is_torch_available(): try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_mobilebert import ( from .modeling_mobilebert import (
MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST, MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
MobileBertForMaskedLM, MobileBertForMaskedLM,
...@@ -92,7 +123,12 @@ if TYPE_CHECKING: ...@@ -92,7 +123,12 @@ if TYPE_CHECKING:
load_tf_weights_in_mobilebert, load_tf_weights_in_mobilebert,
) )
if is_tf_available(): try:
if not is_tf_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_tf_mobilebert import ( from .modeling_tf_mobilebert import (
TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST, TF_MOBILEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
TFMobileBertForMaskedLM, TFMobileBertForMaskedLM,
......
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