__init__.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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_roberta": ["RobertaConfig", "RobertaOnnxConfig"],
  25. "tokenization_roberta": ["RobertaTokenizer"],
  26. }
  27. try:
  28. if not is_tokenizers_available():
  29. raise OptionalDependencyNotAvailable()
  30. except OptionalDependencyNotAvailable:
  31. pass
  32. else:
  33. _import_structure["tokenization_roberta_fast"] = ["RobertaTokenizerFast"]
  34. try:
  35. if not is_torch_available():
  36. raise OptionalDependencyNotAvailable()
  37. except OptionalDependencyNotAvailable:
  38. pass
  39. else:
  40. _import_structure["modeling_roberta"] = [
  41. "RobertaForCausalLM",
  42. "RobertaForMaskedLM",
  43. "RobertaForMultipleChoice",
  44. "RobertaForQuestionAnswering",
  45. "RobertaForSequenceClassification",
  46. "RobertaForTokenClassification",
  47. "RobertaModel",
  48. "RobertaPreTrainedModel",
  49. ]
  50. try:
  51. if not is_tf_available():
  52. raise OptionalDependencyNotAvailable()
  53. except OptionalDependencyNotAvailable:
  54. pass
  55. else:
  56. _import_structure["modeling_tf_roberta"] = [
  57. "TFRobertaForCausalLM",
  58. "TFRobertaForMaskedLM",
  59. "TFRobertaForMultipleChoice",
  60. "TFRobertaForQuestionAnswering",
  61. "TFRobertaForSequenceClassification",
  62. "TFRobertaForTokenClassification",
  63. "TFRobertaMainLayer",
  64. "TFRobertaModel",
  65. "TFRobertaPreTrainedModel",
  66. ]
  67. try:
  68. if not is_flax_available():
  69. raise OptionalDependencyNotAvailable()
  70. except OptionalDependencyNotAvailable:
  71. pass
  72. else:
  73. _import_structure["modeling_flax_roberta"] = [
  74. "FlaxRobertaForCausalLM",
  75. "FlaxRobertaForMaskedLM",
  76. "FlaxRobertaForMultipleChoice",
  77. "FlaxRobertaForQuestionAnswering",
  78. "FlaxRobertaForSequenceClassification",
  79. "FlaxRobertaForTokenClassification",
  80. "FlaxRobertaModel",
  81. "FlaxRobertaPreTrainedModel",
  82. ]
  83. if TYPE_CHECKING:
  84. from .configuration_roberta import RobertaConfig, RobertaOnnxConfig
  85. from .tokenization_roberta import RobertaTokenizer
  86. try:
  87. if not is_tokenizers_available():
  88. raise OptionalDependencyNotAvailable()
  89. except OptionalDependencyNotAvailable:
  90. pass
  91. else:
  92. from .tokenization_roberta_fast import RobertaTokenizerFast
  93. try:
  94. if not is_torch_available():
  95. raise OptionalDependencyNotAvailable()
  96. except OptionalDependencyNotAvailable:
  97. pass
  98. else:
  99. from .modeling_roberta import (
  100. RobertaForCausalLM,
  101. RobertaForMaskedLM,
  102. RobertaForMultipleChoice,
  103. RobertaForQuestionAnswering,
  104. RobertaForSequenceClassification,
  105. RobertaForTokenClassification,
  106. RobertaModel,
  107. RobertaPreTrainedModel,
  108. )
  109. try:
  110. if not is_tf_available():
  111. raise OptionalDependencyNotAvailable()
  112. except OptionalDependencyNotAvailable:
  113. pass
  114. else:
  115. from .modeling_tf_roberta import (
  116. TFRobertaForCausalLM,
  117. TFRobertaForMaskedLM,
  118. TFRobertaForMultipleChoice,
  119. TFRobertaForQuestionAnswering,
  120. TFRobertaForSequenceClassification,
  121. TFRobertaForTokenClassification,
  122. TFRobertaMainLayer,
  123. TFRobertaModel,
  124. TFRobertaPreTrainedModel,
  125. )
  126. try:
  127. if not is_flax_available():
  128. raise OptionalDependencyNotAvailable()
  129. except OptionalDependencyNotAvailable:
  130. pass
  131. else:
  132. from .modeling_flax_roberta import (
  133. FlaxRobertaForCausalLM,
  134. FlaxRobertaForMaskedLM,
  135. FlaxRobertaForMultipleChoice,
  136. FlaxRobertaForQuestionAnswering,
  137. FlaxRobertaForSequenceClassification,
  138. FlaxRobertaForTokenClassification,
  139. FlaxRobertaModel,
  140. FlaxRobertaPreTrainedModel,
  141. )
  142. else:
  143. import sys
  144. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)