__init__.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_mbart": ["MBartConfig", "MBartOnnxConfig"]}
  25. try:
  26. if not is_sentencepiece_available():
  27. raise OptionalDependencyNotAvailable()
  28. except OptionalDependencyNotAvailable:
  29. pass
  30. else:
  31. _import_structure["tokenization_mbart"] = ["MBartTokenizer"]
  32. try:
  33. if not is_tokenizers_available():
  34. raise OptionalDependencyNotAvailable()
  35. except OptionalDependencyNotAvailable:
  36. pass
  37. else:
  38. _import_structure["tokenization_mbart_fast"] = ["MBartTokenizerFast"]
  39. try:
  40. if not is_torch_available():
  41. raise OptionalDependencyNotAvailable()
  42. except OptionalDependencyNotAvailable:
  43. pass
  44. else:
  45. _import_structure["modeling_mbart"] = [
  46. "MBartForCausalLM",
  47. "MBartForConditionalGeneration",
  48. "MBartForQuestionAnswering",
  49. "MBartForSequenceClassification",
  50. "MBartModel",
  51. "MBartPreTrainedModel",
  52. ]
  53. try:
  54. if not is_tf_available():
  55. raise OptionalDependencyNotAvailable()
  56. except OptionalDependencyNotAvailable:
  57. pass
  58. else:
  59. _import_structure["modeling_tf_mbart"] = [
  60. "TFMBartForConditionalGeneration",
  61. "TFMBartModel",
  62. "TFMBartPreTrainedModel",
  63. ]
  64. try:
  65. if not is_flax_available():
  66. raise OptionalDependencyNotAvailable()
  67. except OptionalDependencyNotAvailable:
  68. pass
  69. else:
  70. _import_structure["modeling_flax_mbart"] = [
  71. "FlaxMBartForConditionalGeneration",
  72. "FlaxMBartForQuestionAnswering",
  73. "FlaxMBartForSequenceClassification",
  74. "FlaxMBartModel",
  75. "FlaxMBartPreTrainedModel",
  76. ]
  77. if TYPE_CHECKING:
  78. from .configuration_mbart import MBartConfig, MBartOnnxConfig
  79. try:
  80. if not is_sentencepiece_available():
  81. raise OptionalDependencyNotAvailable()
  82. except OptionalDependencyNotAvailable:
  83. pass
  84. else:
  85. from .tokenization_mbart import MBartTokenizer
  86. try:
  87. if not is_tokenizers_available():
  88. raise OptionalDependencyNotAvailable()
  89. except OptionalDependencyNotAvailable:
  90. pass
  91. else:
  92. from .tokenization_mbart_fast import MBartTokenizerFast
  93. try:
  94. if not is_torch_available():
  95. raise OptionalDependencyNotAvailable()
  96. except OptionalDependencyNotAvailable:
  97. pass
  98. else:
  99. from .modeling_mbart import (
  100. MBartForCausalLM,
  101. MBartForConditionalGeneration,
  102. MBartForQuestionAnswering,
  103. MBartForSequenceClassification,
  104. MBartModel,
  105. MBartPreTrainedModel,
  106. )
  107. try:
  108. if not is_tf_available():
  109. raise OptionalDependencyNotAvailable()
  110. except OptionalDependencyNotAvailable:
  111. pass
  112. else:
  113. from .modeling_tf_mbart import TFMBartForConditionalGeneration, TFMBartModel, TFMBartPreTrainedModel
  114. try:
  115. if not is_flax_available():
  116. raise OptionalDependencyNotAvailable()
  117. except OptionalDependencyNotAvailable:
  118. pass
  119. else:
  120. from .modeling_flax_mbart import (
  121. FlaxMBartForConditionalGeneration,
  122. FlaxMBartForQuestionAnswering,
  123. FlaxMBartForSequenceClassification,
  124. FlaxMBartModel,
  125. FlaxMBartPreTrainedModel,
  126. )
  127. else:
  128. import sys
  129. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)