__init__.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_electra": ["ElectraConfig", "ElectraOnnxConfig"],
  25. "tokenization_electra": ["ElectraTokenizer"],
  26. }
  27. try:
  28. if not is_tokenizers_available():
  29. raise OptionalDependencyNotAvailable()
  30. except OptionalDependencyNotAvailable:
  31. pass
  32. else:
  33. _import_structure["tokenization_electra_fast"] = ["ElectraTokenizerFast"]
  34. try:
  35. if not is_torch_available():
  36. raise OptionalDependencyNotAvailable()
  37. except OptionalDependencyNotAvailable:
  38. pass
  39. else:
  40. _import_structure["modeling_electra"] = [
  41. "ElectraForCausalLM",
  42. "ElectraForMaskedLM",
  43. "ElectraForMultipleChoice",
  44. "ElectraForPreTraining",
  45. "ElectraForQuestionAnswering",
  46. "ElectraForSequenceClassification",
  47. "ElectraForTokenClassification",
  48. "ElectraModel",
  49. "ElectraPreTrainedModel",
  50. "load_tf_weights_in_electra",
  51. ]
  52. try:
  53. if not is_tf_available():
  54. raise OptionalDependencyNotAvailable()
  55. except OptionalDependencyNotAvailable:
  56. pass
  57. else:
  58. _import_structure["modeling_tf_electra"] = [
  59. "TFElectraForMaskedLM",
  60. "TFElectraForMultipleChoice",
  61. "TFElectraForPreTraining",
  62. "TFElectraForQuestionAnswering",
  63. "TFElectraForSequenceClassification",
  64. "TFElectraForTokenClassification",
  65. "TFElectraModel",
  66. "TFElectraPreTrainedModel",
  67. ]
  68. try:
  69. if not is_flax_available():
  70. raise OptionalDependencyNotAvailable()
  71. except OptionalDependencyNotAvailable:
  72. pass
  73. else:
  74. _import_structure["modeling_flax_electra"] = [
  75. "FlaxElectraForCausalLM",
  76. "FlaxElectraForMaskedLM",
  77. "FlaxElectraForMultipleChoice",
  78. "FlaxElectraForPreTraining",
  79. "FlaxElectraForQuestionAnswering",
  80. "FlaxElectraForSequenceClassification",
  81. "FlaxElectraForTokenClassification",
  82. "FlaxElectraModel",
  83. "FlaxElectraPreTrainedModel",
  84. ]
  85. if TYPE_CHECKING:
  86. from .configuration_electra import ElectraConfig, ElectraOnnxConfig
  87. from .tokenization_electra import ElectraTokenizer
  88. try:
  89. if not is_tokenizers_available():
  90. raise OptionalDependencyNotAvailable()
  91. except OptionalDependencyNotAvailable:
  92. pass
  93. else:
  94. from .tokenization_electra_fast import ElectraTokenizerFast
  95. try:
  96. if not is_torch_available():
  97. raise OptionalDependencyNotAvailable()
  98. except OptionalDependencyNotAvailable:
  99. pass
  100. else:
  101. from .modeling_electra import (
  102. ElectraForCausalLM,
  103. ElectraForMaskedLM,
  104. ElectraForMultipleChoice,
  105. ElectraForPreTraining,
  106. ElectraForQuestionAnswering,
  107. ElectraForSequenceClassification,
  108. ElectraForTokenClassification,
  109. ElectraModel,
  110. ElectraPreTrainedModel,
  111. load_tf_weights_in_electra,
  112. )
  113. try:
  114. if not is_tf_available():
  115. raise OptionalDependencyNotAvailable()
  116. except OptionalDependencyNotAvailable:
  117. pass
  118. else:
  119. from .modeling_tf_electra import (
  120. TFElectraForMaskedLM,
  121. TFElectraForMultipleChoice,
  122. TFElectraForPreTraining,
  123. TFElectraForQuestionAnswering,
  124. TFElectraForSequenceClassification,
  125. TFElectraForTokenClassification,
  126. TFElectraModel,
  127. TFElectraPreTrainedModel,
  128. )
  129. try:
  130. if not is_flax_available():
  131. raise OptionalDependencyNotAvailable()
  132. except OptionalDependencyNotAvailable:
  133. pass
  134. else:
  135. from .modeling_flax_electra import (
  136. FlaxElectraForCausalLM,
  137. FlaxElectraForMaskedLM,
  138. FlaxElectraForMultipleChoice,
  139. FlaxElectraForPreTraining,
  140. FlaxElectraForQuestionAnswering,
  141. FlaxElectraForSequenceClassification,
  142. FlaxElectraForTokenClassification,
  143. FlaxElectraModel,
  144. FlaxElectraPreTrainedModel,
  145. )
  146. else:
  147. import sys
  148. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)