__init__.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_keras_nlp_available,
  20. is_tensorflow_text_available,
  21. is_tf_available,
  22. is_tokenizers_available,
  23. is_torch_available,
  24. )
  25. _import_structure = {
  26. "configuration_gpt2": ["GPT2Config", "GPT2OnnxConfig"],
  27. "tokenization_gpt2": ["GPT2Tokenizer"],
  28. }
  29. try:
  30. if not is_tokenizers_available():
  31. raise OptionalDependencyNotAvailable()
  32. except OptionalDependencyNotAvailable:
  33. pass
  34. else:
  35. _import_structure["tokenization_gpt2_fast"] = ["GPT2TokenizerFast"]
  36. try:
  37. if not is_torch_available():
  38. raise OptionalDependencyNotAvailable()
  39. except OptionalDependencyNotAvailable:
  40. pass
  41. else:
  42. _import_structure["modeling_gpt2"] = [
  43. "GPT2DoubleHeadsModel",
  44. "GPT2ForQuestionAnswering",
  45. "GPT2ForSequenceClassification",
  46. "GPT2ForTokenClassification",
  47. "GPT2LMHeadModel",
  48. "GPT2Model",
  49. "GPT2PreTrainedModel",
  50. "load_tf_weights_in_gpt2",
  51. ]
  52. try:
  53. if not is_tf_available():
  54. raise OptionalDependencyNotAvailable()
  55. except OptionalDependencyNotAvailable:
  56. pass
  57. else:
  58. _import_structure["modeling_tf_gpt2"] = [
  59. "TFGPT2DoubleHeadsModel",
  60. "TFGPT2ForSequenceClassification",
  61. "TFGPT2LMHeadModel",
  62. "TFGPT2MainLayer",
  63. "TFGPT2Model",
  64. "TFGPT2PreTrainedModel",
  65. ]
  66. try:
  67. if not is_keras_nlp_available():
  68. raise OptionalDependencyNotAvailable()
  69. except OptionalDependencyNotAvailable:
  70. pass
  71. else:
  72. _import_structure["tokenization_gpt2_tf"] = ["TFGPT2Tokenizer"]
  73. try:
  74. if not is_flax_available():
  75. raise OptionalDependencyNotAvailable()
  76. except OptionalDependencyNotAvailable:
  77. pass
  78. else:
  79. _import_structure["modeling_flax_gpt2"] = ["FlaxGPT2LMHeadModel", "FlaxGPT2Model", "FlaxGPT2PreTrainedModel"]
  80. if TYPE_CHECKING:
  81. from .configuration_gpt2 import GPT2Config, GPT2OnnxConfig
  82. from .tokenization_gpt2 import GPT2Tokenizer
  83. try:
  84. if not is_tokenizers_available():
  85. raise OptionalDependencyNotAvailable()
  86. except OptionalDependencyNotAvailable:
  87. pass
  88. else:
  89. from .tokenization_gpt2_fast import GPT2TokenizerFast
  90. try:
  91. if not is_torch_available():
  92. raise OptionalDependencyNotAvailable()
  93. except OptionalDependencyNotAvailable:
  94. pass
  95. else:
  96. from .modeling_gpt2 import (
  97. GPT2DoubleHeadsModel,
  98. GPT2ForQuestionAnswering,
  99. GPT2ForSequenceClassification,
  100. GPT2ForTokenClassification,
  101. GPT2LMHeadModel,
  102. GPT2Model,
  103. GPT2PreTrainedModel,
  104. load_tf_weights_in_gpt2,
  105. )
  106. try:
  107. if not is_tf_available():
  108. raise OptionalDependencyNotAvailable()
  109. except OptionalDependencyNotAvailable:
  110. pass
  111. else:
  112. from .modeling_tf_gpt2 import (
  113. TFGPT2DoubleHeadsModel,
  114. TFGPT2ForSequenceClassification,
  115. TFGPT2LMHeadModel,
  116. TFGPT2MainLayer,
  117. TFGPT2Model,
  118. TFGPT2PreTrainedModel,
  119. )
  120. try:
  121. if not is_keras_nlp_available():
  122. raise OptionalDependencyNotAvailable()
  123. except OptionalDependencyNotAvailable:
  124. pass
  125. else:
  126. from .tokenization_gpt2_tf import TFGPT2Tokenizer
  127. try:
  128. if not is_flax_available():
  129. raise OptionalDependencyNotAvailable()
  130. except OptionalDependencyNotAvailable:
  131. pass
  132. else:
  133. from .modeling_flax_gpt2 import FlaxGPT2LMHeadModel, FlaxGPT2Model, FlaxGPT2PreTrainedModel
  134. else:
  135. import sys
  136. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)