__init__.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. _import_structure = {"configuration_t5": ["T5Config", "T5OnnxConfig"]}
  25. try:
  26. if not is_sentencepiece_available():
  27. raise OptionalDependencyNotAvailable()
  28. except OptionalDependencyNotAvailable:
  29. pass
  30. else:
  31. _import_structure["tokenization_t5"] = ["T5Tokenizer"]
  32. try:
  33. if not is_tokenizers_available():
  34. raise OptionalDependencyNotAvailable()
  35. except OptionalDependencyNotAvailable:
  36. pass
  37. else:
  38. _import_structure["tokenization_t5_fast"] = ["T5TokenizerFast"]
  39. try:
  40. if not is_torch_available():
  41. raise OptionalDependencyNotAvailable()
  42. except OptionalDependencyNotAvailable:
  43. pass
  44. else:
  45. _import_structure["modeling_t5"] = [
  46. "T5EncoderModel",
  47. "T5ForConditionalGeneration",
  48. "T5Model",
  49. "T5PreTrainedModel",
  50. "load_tf_weights_in_t5",
  51. "T5ForQuestionAnswering",
  52. "T5ForSequenceClassification",
  53. "T5ForTokenClassification",
  54. ]
  55. try:
  56. if not is_tf_available():
  57. raise OptionalDependencyNotAvailable()
  58. except OptionalDependencyNotAvailable:
  59. pass
  60. else:
  61. _import_structure["modeling_tf_t5"] = [
  62. "TFT5EncoderModel",
  63. "TFT5ForConditionalGeneration",
  64. "TFT5Model",
  65. "TFT5PreTrainedModel",
  66. ]
  67. try:
  68. if not is_flax_available():
  69. raise OptionalDependencyNotAvailable()
  70. except OptionalDependencyNotAvailable:
  71. pass
  72. else:
  73. _import_structure["modeling_flax_t5"] = [
  74. "FlaxT5EncoderModel",
  75. "FlaxT5ForConditionalGeneration",
  76. "FlaxT5Model",
  77. "FlaxT5PreTrainedModel",
  78. ]
  79. if TYPE_CHECKING:
  80. from .configuration_t5 import T5Config, T5OnnxConfig
  81. try:
  82. if not is_sentencepiece_available():
  83. raise OptionalDependencyNotAvailable()
  84. except OptionalDependencyNotAvailable:
  85. pass
  86. else:
  87. from .tokenization_t5 import T5Tokenizer
  88. try:
  89. if not is_tokenizers_available():
  90. raise OptionalDependencyNotAvailable()
  91. except OptionalDependencyNotAvailable:
  92. pass
  93. else:
  94. from .tokenization_t5_fast import T5TokenizerFast
  95. try:
  96. if not is_torch_available():
  97. raise OptionalDependencyNotAvailable()
  98. except OptionalDependencyNotAvailable:
  99. pass
  100. else:
  101. from .modeling_t5 import (
  102. T5EncoderModel,
  103. T5ForConditionalGeneration,
  104. T5ForQuestionAnswering,
  105. T5ForSequenceClassification,
  106. T5ForTokenClassification,
  107. T5Model,
  108. T5PreTrainedModel,
  109. load_tf_weights_in_t5,
  110. )
  111. try:
  112. if not is_tf_available():
  113. raise OptionalDependencyNotAvailable()
  114. except OptionalDependencyNotAvailable:
  115. pass
  116. else:
  117. from .modeling_tf_t5 import (
  118. TFT5EncoderModel,
  119. TFT5ForConditionalGeneration,
  120. TFT5Model,
  121. TFT5PreTrainedModel,
  122. )
  123. try:
  124. if not is_flax_available():
  125. raise OptionalDependencyNotAvailable()
  126. except OptionalDependencyNotAvailable:
  127. pass
  128. else:
  129. from .modeling_flax_t5 import (
  130. FlaxT5EncoderModel,
  131. FlaxT5ForConditionalGeneration,
  132. FlaxT5Model,
  133. FlaxT5PreTrainedModel,
  134. )
  135. else:
  136. import sys
  137. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)