__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_distilbert": [
  25. "DistilBertConfig",
  26. "DistilBertOnnxConfig",
  27. ],
  28. "tokenization_distilbert": ["DistilBertTokenizer"],
  29. }
  30. try:
  31. if not is_tokenizers_available():
  32. raise OptionalDependencyNotAvailable()
  33. except OptionalDependencyNotAvailable:
  34. pass
  35. else:
  36. _import_structure["tokenization_distilbert_fast"] = ["DistilBertTokenizerFast"]
  37. try:
  38. if not is_torch_available():
  39. raise OptionalDependencyNotAvailable()
  40. except OptionalDependencyNotAvailable:
  41. pass
  42. else:
  43. _import_structure["modeling_distilbert"] = [
  44. "DistilBertForMaskedLM",
  45. "DistilBertForMultipleChoice",
  46. "DistilBertForQuestionAnswering",
  47. "DistilBertForSequenceClassification",
  48. "DistilBertForTokenClassification",
  49. "DistilBertModel",
  50. "DistilBertPreTrainedModel",
  51. ]
  52. try:
  53. if not is_tf_available():
  54. raise OptionalDependencyNotAvailable()
  55. except OptionalDependencyNotAvailable:
  56. pass
  57. else:
  58. _import_structure["modeling_tf_distilbert"] = [
  59. "TFDistilBertForMaskedLM",
  60. "TFDistilBertForMultipleChoice",
  61. "TFDistilBertForQuestionAnswering",
  62. "TFDistilBertForSequenceClassification",
  63. "TFDistilBertForTokenClassification",
  64. "TFDistilBertMainLayer",
  65. "TFDistilBertModel",
  66. "TFDistilBertPreTrainedModel",
  67. ]
  68. try:
  69. if not is_flax_available():
  70. raise OptionalDependencyNotAvailable()
  71. except OptionalDependencyNotAvailable:
  72. pass
  73. else:
  74. _import_structure["modeling_flax_distilbert"] = [
  75. "FlaxDistilBertForMaskedLM",
  76. "FlaxDistilBertForMultipleChoice",
  77. "FlaxDistilBertForQuestionAnswering",
  78. "FlaxDistilBertForSequenceClassification",
  79. "FlaxDistilBertForTokenClassification",
  80. "FlaxDistilBertModel",
  81. "FlaxDistilBertPreTrainedModel",
  82. ]
  83. if TYPE_CHECKING:
  84. from .configuration_distilbert import (
  85. DistilBertConfig,
  86. DistilBertOnnxConfig,
  87. )
  88. from .tokenization_distilbert import DistilBertTokenizer
  89. try:
  90. if not is_tokenizers_available():
  91. raise OptionalDependencyNotAvailable()
  92. except OptionalDependencyNotAvailable:
  93. pass
  94. else:
  95. from .tokenization_distilbert_fast import DistilBertTokenizerFast
  96. try:
  97. if not is_torch_available():
  98. raise OptionalDependencyNotAvailable()
  99. except OptionalDependencyNotAvailable:
  100. pass
  101. else:
  102. from .modeling_distilbert import (
  103. DistilBertForMaskedLM,
  104. DistilBertForMultipleChoice,
  105. DistilBertForQuestionAnswering,
  106. DistilBertForSequenceClassification,
  107. DistilBertForTokenClassification,
  108. DistilBertModel,
  109. DistilBertPreTrainedModel,
  110. )
  111. try:
  112. if not is_tf_available():
  113. raise OptionalDependencyNotAvailable()
  114. except OptionalDependencyNotAvailable:
  115. pass
  116. else:
  117. from .modeling_tf_distilbert import (
  118. TFDistilBertForMaskedLM,
  119. TFDistilBertForMultipleChoice,
  120. TFDistilBertForQuestionAnswering,
  121. TFDistilBertForSequenceClassification,
  122. TFDistilBertForTokenClassification,
  123. TFDistilBertMainLayer,
  124. TFDistilBertModel,
  125. TFDistilBertPreTrainedModel,
  126. )
  127. try:
  128. if not is_flax_available():
  129. raise OptionalDependencyNotAvailable()
  130. except OptionalDependencyNotAvailable:
  131. pass
  132. else:
  133. from .modeling_flax_distilbert import (
  134. FlaxDistilBertForMaskedLM,
  135. FlaxDistilBertForMultipleChoice,
  136. FlaxDistilBertForQuestionAnswering,
  137. FlaxDistilBertForSequenceClassification,
  138. FlaxDistilBertForTokenClassification,
  139. FlaxDistilBertModel,
  140. FlaxDistilBertPreTrainedModel,
  141. )
  142. else:
  143. import sys
  144. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)