__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_tf_available,
  20. is_tokenizers_available,
  21. is_torch_available,
  22. )
  23. _import_structure = {
  24. "configuration_bart": ["BartConfig", "BartOnnxConfig"],
  25. "tokenization_bart": ["BartTokenizer"],
  26. }
  27. try:
  28. if not is_tokenizers_available():
  29. raise OptionalDependencyNotAvailable()
  30. except OptionalDependencyNotAvailable:
  31. pass
  32. else:
  33. _import_structure["tokenization_bart_fast"] = ["BartTokenizerFast"]
  34. try:
  35. if not is_torch_available():
  36. raise OptionalDependencyNotAvailable()
  37. except OptionalDependencyNotAvailable:
  38. pass
  39. else:
  40. _import_structure["modeling_bart"] = [
  41. "BartForCausalLM",
  42. "BartForConditionalGeneration",
  43. "BartForQuestionAnswering",
  44. "BartForSequenceClassification",
  45. "BartModel",
  46. "BartPreTrainedModel",
  47. "BartPretrainedModel",
  48. "PretrainedBartModel",
  49. ]
  50. try:
  51. if not is_tf_available():
  52. raise OptionalDependencyNotAvailable()
  53. except OptionalDependencyNotAvailable:
  54. pass
  55. else:
  56. _import_structure["modeling_tf_bart"] = [
  57. "TFBartForConditionalGeneration",
  58. "TFBartForSequenceClassification",
  59. "TFBartModel",
  60. "TFBartPretrainedModel",
  61. ]
  62. try:
  63. if not is_flax_available():
  64. raise OptionalDependencyNotAvailable()
  65. except OptionalDependencyNotAvailable:
  66. pass
  67. else:
  68. _import_structure["modeling_flax_bart"] = [
  69. "FlaxBartDecoderPreTrainedModel",
  70. "FlaxBartForCausalLM",
  71. "FlaxBartForConditionalGeneration",
  72. "FlaxBartForQuestionAnswering",
  73. "FlaxBartForSequenceClassification",
  74. "FlaxBartModel",
  75. "FlaxBartPreTrainedModel",
  76. ]
  77. if TYPE_CHECKING:
  78. from .configuration_bart import BartConfig, BartOnnxConfig
  79. from .tokenization_bart import BartTokenizer
  80. try:
  81. if not is_tokenizers_available():
  82. raise OptionalDependencyNotAvailable()
  83. except OptionalDependencyNotAvailable:
  84. pass
  85. else:
  86. from .tokenization_bart_fast import BartTokenizerFast
  87. try:
  88. if not is_torch_available():
  89. raise OptionalDependencyNotAvailable()
  90. except OptionalDependencyNotAvailable:
  91. pass
  92. else:
  93. from .modeling_bart import (
  94. BartForCausalLM,
  95. BartForConditionalGeneration,
  96. BartForQuestionAnswering,
  97. BartForSequenceClassification,
  98. BartModel,
  99. BartPreTrainedModel,
  100. BartPretrainedModel,
  101. PretrainedBartModel,
  102. )
  103. try:
  104. if not is_tf_available():
  105. raise OptionalDependencyNotAvailable()
  106. except OptionalDependencyNotAvailable:
  107. pass
  108. else:
  109. from .modeling_tf_bart import (
  110. TFBartForConditionalGeneration,
  111. TFBartForSequenceClassification,
  112. TFBartModel,
  113. TFBartPretrainedModel,
  114. )
  115. try:
  116. if not is_flax_available():
  117. raise OptionalDependencyNotAvailable()
  118. except OptionalDependencyNotAvailable:
  119. pass
  120. else:
  121. from .modeling_flax_bart import (
  122. FlaxBartDecoderPreTrainedModel,
  123. FlaxBartForCausalLM,
  124. FlaxBartForConditionalGeneration,
  125. FlaxBartForQuestionAnswering,
  126. FlaxBartForSequenceClassification,
  127. FlaxBartModel,
  128. FlaxBartPreTrainedModel,
  129. )
  130. else:
  131. import sys
  132. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)