__init__.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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_tf_available,
  19. is_tokenizers_available,
  20. is_torch_available,
  21. )
  22. _import_structure = {
  23. "configuration_mobilebert": [
  24. "MobileBertConfig",
  25. "MobileBertOnnxConfig",
  26. ],
  27. "tokenization_mobilebert": ["MobileBertTokenizer"],
  28. }
  29. try:
  30. if not is_tokenizers_available():
  31. raise OptionalDependencyNotAvailable()
  32. except OptionalDependencyNotAvailable:
  33. pass
  34. else:
  35. _import_structure["tokenization_mobilebert_fast"] = ["MobileBertTokenizerFast"]
  36. try:
  37. if not is_torch_available():
  38. raise OptionalDependencyNotAvailable()
  39. except OptionalDependencyNotAvailable:
  40. pass
  41. else:
  42. _import_structure["modeling_mobilebert"] = [
  43. "MobileBertForMaskedLM",
  44. "MobileBertForMultipleChoice",
  45. "MobileBertForNextSentencePrediction",
  46. "MobileBertForPreTraining",
  47. "MobileBertForQuestionAnswering",
  48. "MobileBertForSequenceClassification",
  49. "MobileBertForTokenClassification",
  50. "MobileBertLayer",
  51. "MobileBertModel",
  52. "MobileBertPreTrainedModel",
  53. "load_tf_weights_in_mobilebert",
  54. ]
  55. try:
  56. if not is_tf_available():
  57. raise OptionalDependencyNotAvailable()
  58. except OptionalDependencyNotAvailable:
  59. pass
  60. else:
  61. _import_structure["modeling_tf_mobilebert"] = [
  62. "TFMobileBertForMaskedLM",
  63. "TFMobileBertForMultipleChoice",
  64. "TFMobileBertForNextSentencePrediction",
  65. "TFMobileBertForPreTraining",
  66. "TFMobileBertForQuestionAnswering",
  67. "TFMobileBertForSequenceClassification",
  68. "TFMobileBertForTokenClassification",
  69. "TFMobileBertMainLayer",
  70. "TFMobileBertModel",
  71. "TFMobileBertPreTrainedModel",
  72. ]
  73. if TYPE_CHECKING:
  74. from .configuration_mobilebert import (
  75. MobileBertConfig,
  76. MobileBertOnnxConfig,
  77. )
  78. from .tokenization_mobilebert import MobileBertTokenizer
  79. try:
  80. if not is_tokenizers_available():
  81. raise OptionalDependencyNotAvailable()
  82. except OptionalDependencyNotAvailable:
  83. pass
  84. else:
  85. from .tokenization_mobilebert_fast import MobileBertTokenizerFast
  86. try:
  87. if not is_torch_available():
  88. raise OptionalDependencyNotAvailable()
  89. except OptionalDependencyNotAvailable:
  90. pass
  91. else:
  92. from .modeling_mobilebert import (
  93. MobileBertForMaskedLM,
  94. MobileBertForMultipleChoice,
  95. MobileBertForNextSentencePrediction,
  96. MobileBertForPreTraining,
  97. MobileBertForQuestionAnswering,
  98. MobileBertForSequenceClassification,
  99. MobileBertForTokenClassification,
  100. MobileBertLayer,
  101. MobileBertModel,
  102. MobileBertPreTrainedModel,
  103. load_tf_weights_in_mobilebert,
  104. )
  105. try:
  106. if not is_tf_available():
  107. raise OptionalDependencyNotAvailable()
  108. except OptionalDependencyNotAvailable:
  109. pass
  110. else:
  111. from .modeling_tf_mobilebert import (
  112. TFMobileBertForMaskedLM,
  113. TFMobileBertForMultipleChoice,
  114. TFMobileBertForNextSentencePrediction,
  115. TFMobileBertForPreTraining,
  116. TFMobileBertForQuestionAnswering,
  117. TFMobileBertForSequenceClassification,
  118. TFMobileBertForTokenClassification,
  119. TFMobileBertMainLayer,
  120. TFMobileBertModel,
  121. TFMobileBertPreTrainedModel,
  122. )
  123. else:
  124. import sys
  125. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)