__init__.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright 2020 The HuggingFace Team. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import TYPE_CHECKING
  15. from ...utils import (
  16. OptionalDependencyNotAvailable,
  17. _LazyModule,
  18. is_flax_available,
  19. is_sentencepiece_available,
  20. is_tf_available,
  21. is_tokenizers_available,
  22. is_torch_available,
  23. )
  24. if is_sentencepiece_available():
  25. from ..t5.tokenization_t5 import T5Tokenizer
  26. else:
  27. from ...utils.dummy_sentencepiece_objects import T5Tokenizer
  28. MT5Tokenizer = T5Tokenizer
  29. if is_tokenizers_available():
  30. from ..t5.tokenization_t5_fast import T5TokenizerFast
  31. else:
  32. from ...utils.dummy_tokenizers_objects import T5TokenizerFast
  33. MT5TokenizerFast = T5TokenizerFast
  34. _import_structure = {"configuration_mt5": ["MT5Config", "MT5OnnxConfig"]}
  35. try:
  36. if not is_torch_available():
  37. raise OptionalDependencyNotAvailable()
  38. except OptionalDependencyNotAvailable:
  39. pass
  40. else:
  41. _import_structure["modeling_mt5"] = [
  42. "MT5EncoderModel",
  43. "MT5ForConditionalGeneration",
  44. "MT5ForQuestionAnswering",
  45. "MT5ForSequenceClassification",
  46. "MT5ForTokenClassification",
  47. "MT5Model",
  48. "MT5PreTrainedModel",
  49. "MT5Stack",
  50. ]
  51. try:
  52. if not is_tf_available():
  53. raise OptionalDependencyNotAvailable()
  54. except OptionalDependencyNotAvailable:
  55. pass
  56. else:
  57. _import_structure["modeling_tf_mt5"] = ["TFMT5EncoderModel", "TFMT5ForConditionalGeneration", "TFMT5Model"]
  58. try:
  59. if not is_flax_available():
  60. raise OptionalDependencyNotAvailable()
  61. except OptionalDependencyNotAvailable:
  62. pass
  63. else:
  64. _import_structure["modeling_flax_mt5"] = ["FlaxMT5EncoderModel", "FlaxMT5ForConditionalGeneration", "FlaxMT5Model"]
  65. if TYPE_CHECKING:
  66. from .configuration_mt5 import MT5Config, MT5OnnxConfig
  67. try:
  68. if not is_torch_available():
  69. raise OptionalDependencyNotAvailable()
  70. except OptionalDependencyNotAvailable:
  71. pass
  72. else:
  73. from .modeling_mt5 import (
  74. MT5EncoderModel,
  75. MT5ForConditionalGeneration,
  76. MT5ForQuestionAnswering,
  77. MT5ForSequenceClassification,
  78. MT5ForTokenClassification,
  79. MT5Model,
  80. MT5PreTrainedModel,
  81. MT5Stack,
  82. )
  83. try:
  84. if not is_tf_available():
  85. raise OptionalDependencyNotAvailable()
  86. except OptionalDependencyNotAvailable:
  87. pass
  88. else:
  89. from .modeling_tf_mt5 import TFMT5EncoderModel, TFMT5ForConditionalGeneration, TFMT5Model
  90. try:
  91. if not is_flax_available():
  92. raise OptionalDependencyNotAvailable()
  93. except OptionalDependencyNotAvailable:
  94. pass
  95. else:
  96. from .modeling_flax_mt5 import FlaxMT5EncoderModel, FlaxMT5ForConditionalGeneration, FlaxMT5Model
  97. else:
  98. import sys
  99. sys.modules[__name__] = _LazyModule(
  100. __name__,
  101. globals()["__file__"],
  102. _import_structure,
  103. extra_objects={"MT5Tokenizer": MT5Tokenizer, "MT5TokenizerFast": MT5TokenizerFast},
  104. module_spec=__spec__,
  105. )