__init__.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available
  16. _import_structure = {
  17. "configuration_rag": ["RagConfig"],
  18. "retrieval_rag": ["RagRetriever"],
  19. "tokenization_rag": ["RagTokenizer"],
  20. }
  21. try:
  22. if not is_torch_available():
  23. raise OptionalDependencyNotAvailable()
  24. except OptionalDependencyNotAvailable:
  25. pass
  26. else:
  27. _import_structure["modeling_rag"] = [
  28. "RagModel",
  29. "RagPreTrainedModel",
  30. "RagSequenceForGeneration",
  31. "RagTokenForGeneration",
  32. ]
  33. try:
  34. if not is_tf_available():
  35. raise OptionalDependencyNotAvailable()
  36. except OptionalDependencyNotAvailable:
  37. pass
  38. else:
  39. _import_structure["modeling_tf_rag"] = [
  40. "TFRagModel",
  41. "TFRagPreTrainedModel",
  42. "TFRagSequenceForGeneration",
  43. "TFRagTokenForGeneration",
  44. ]
  45. if TYPE_CHECKING:
  46. from .configuration_rag import RagConfig
  47. from .retrieval_rag import RagRetriever
  48. from .tokenization_rag import RagTokenizer
  49. try:
  50. if not is_torch_available():
  51. raise OptionalDependencyNotAvailable()
  52. except OptionalDependencyNotAvailable:
  53. pass
  54. else:
  55. from .modeling_rag import RagModel, RagPreTrainedModel, RagSequenceForGeneration, RagTokenForGeneration
  56. try:
  57. if not is_tf_available():
  58. raise OptionalDependencyNotAvailable()
  59. except OptionalDependencyNotAvailable:
  60. pass
  61. else:
  62. from .modeling_tf_rag import (
  63. TFRagModel,
  64. TFRagPreTrainedModel,
  65. TFRagSequenceForGeneration,
  66. TFRagTokenForGeneration,
  67. )
  68. else:
  69. import sys
  70. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)