__init__.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. # Copyright 2023 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_torch_available
  16. _import_structure = {
  17. "aqlm": ["replace_with_aqlm_linear"],
  18. "awq": [
  19. "fuse_awq_modules",
  20. "post_init_awq_exllama_modules",
  21. "post_init_awq_ipex_modules",
  22. "replace_quantization_scales",
  23. "replace_with_awq_linear",
  24. ],
  25. "bitnet": [
  26. "BitLinear",
  27. "pack_weights",
  28. "replace_with_bitnet_linear",
  29. "unpack_weights",
  30. ],
  31. "bitsandbytes": [
  32. "dequantize_and_replace",
  33. "get_keys_to_not_convert",
  34. "replace_8bit_linear",
  35. "replace_with_bnb_linear",
  36. "set_module_8bit_tensor_to_device",
  37. "set_module_quantized_tensor_to_device",
  38. "validate_bnb_backend_availability",
  39. ],
  40. "deepspeed": [
  41. "HfDeepSpeedConfig",
  42. "HfTrainerDeepSpeedConfig",
  43. "deepspeed_config",
  44. "deepspeed_init",
  45. "deepspeed_load_checkpoint",
  46. "deepspeed_optim_sched",
  47. "is_deepspeed_available",
  48. "is_deepspeed_zero3_enabled",
  49. "set_hf_deepspeed_config",
  50. "unset_hf_deepspeed_config",
  51. ],
  52. "eetq": ["replace_with_eetq_linear"],
  53. "fbgemm_fp8": ["FbgemmFp8Linear", "replace_with_fbgemm_fp8_linear"],
  54. "fsdp": ["is_fsdp_managed_module"],
  55. "ggml": [
  56. "GGUF_CONFIG_MAPPING",
  57. "GGUF_TENSOR_MAPPING",
  58. "GGUF_TOKENIZER_MAPPING",
  59. "_gguf_parse_value",
  60. "load_dequant_gguf_tensor",
  61. "load_gguf",
  62. ],
  63. "hqq": ["prepare_for_hqq_linear"],
  64. "integration_utils": [
  65. "INTEGRATION_TO_CALLBACK",
  66. "AzureMLCallback",
  67. "ClearMLCallback",
  68. "CodeCarbonCallback",
  69. "CometCallback",
  70. "DagsHubCallback",
  71. "DVCLiveCallback",
  72. "FlyteCallback",
  73. "MLflowCallback",
  74. "NeptuneCallback",
  75. "NeptuneMissingConfiguration",
  76. "TensorBoardCallback",
  77. "WandbCallback",
  78. "get_available_reporting_integrations",
  79. "get_reporting_integration_callbacks",
  80. "hp_params",
  81. "is_azureml_available",
  82. "is_clearml_available",
  83. "is_codecarbon_available",
  84. "is_comet_available",
  85. "is_dagshub_available",
  86. "is_dvclive_available",
  87. "is_flyte_deck_standard_available",
  88. "is_flytekit_available",
  89. "is_mlflow_available",
  90. "is_neptune_available",
  91. "is_optuna_available",
  92. "is_ray_available",
  93. "is_ray_tune_available",
  94. "is_sigopt_available",
  95. "is_tensorboard_available",
  96. "is_wandb_available",
  97. "rewrite_logs",
  98. "run_hp_search_optuna",
  99. "run_hp_search_ray",
  100. "run_hp_search_sigopt",
  101. "run_hp_search_wandb",
  102. ],
  103. "peft": ["PeftAdapterMixin"],
  104. "quanto": ["replace_with_quanto_layers"],
  105. }
  106. try:
  107. if not is_torch_available():
  108. raise OptionalDependencyNotAvailable()
  109. except OptionalDependencyNotAvailable:
  110. pass
  111. else:
  112. _import_structure["executorch"] = [
  113. "TorchExportableModuleWithStaticCache",
  114. "convert_and_export_with_cache",
  115. ]
  116. if TYPE_CHECKING:
  117. from .aqlm import replace_with_aqlm_linear
  118. from .awq import (
  119. fuse_awq_modules,
  120. post_init_awq_exllama_modules,
  121. post_init_awq_ipex_modules,
  122. replace_quantization_scales,
  123. replace_with_awq_linear,
  124. )
  125. from .bitnet import (
  126. BitLinear,
  127. pack_weights,
  128. replace_with_bitnet_linear,
  129. unpack_weights,
  130. )
  131. from .bitsandbytes import (
  132. dequantize_and_replace,
  133. get_keys_to_not_convert,
  134. replace_8bit_linear,
  135. replace_with_bnb_linear,
  136. set_module_8bit_tensor_to_device,
  137. set_module_quantized_tensor_to_device,
  138. validate_bnb_backend_availability,
  139. )
  140. from .deepspeed import (
  141. HfDeepSpeedConfig,
  142. HfTrainerDeepSpeedConfig,
  143. deepspeed_config,
  144. deepspeed_init,
  145. deepspeed_load_checkpoint,
  146. deepspeed_optim_sched,
  147. is_deepspeed_available,
  148. is_deepspeed_zero3_enabled,
  149. set_hf_deepspeed_config,
  150. unset_hf_deepspeed_config,
  151. )
  152. from .eetq import replace_with_eetq_linear
  153. from .fbgemm_fp8 import FbgemmFp8Linear, replace_with_fbgemm_fp8_linear
  154. from .fsdp import is_fsdp_managed_module
  155. from .ggml import (
  156. GGUF_CONFIG_MAPPING,
  157. GGUF_TENSOR_MAPPING,
  158. GGUF_TOKENIZER_MAPPING,
  159. _gguf_parse_value,
  160. load_dequant_gguf_tensor,
  161. load_gguf,
  162. )
  163. from .hqq import prepare_for_hqq_linear
  164. from .integration_utils import (
  165. INTEGRATION_TO_CALLBACK,
  166. AzureMLCallback,
  167. ClearMLCallback,
  168. CodeCarbonCallback,
  169. CometCallback,
  170. DagsHubCallback,
  171. DVCLiveCallback,
  172. FlyteCallback,
  173. MLflowCallback,
  174. NeptuneCallback,
  175. NeptuneMissingConfiguration,
  176. TensorBoardCallback,
  177. WandbCallback,
  178. get_available_reporting_integrations,
  179. get_reporting_integration_callbacks,
  180. hp_params,
  181. is_azureml_available,
  182. is_clearml_available,
  183. is_codecarbon_available,
  184. is_comet_available,
  185. is_dagshub_available,
  186. is_dvclive_available,
  187. is_flyte_deck_standard_available,
  188. is_flytekit_available,
  189. is_mlflow_available,
  190. is_neptune_available,
  191. is_optuna_available,
  192. is_ray_available,
  193. is_ray_tune_available,
  194. is_sigopt_available,
  195. is_tensorboard_available,
  196. is_wandb_available,
  197. rewrite_logs,
  198. run_hp_search_optuna,
  199. run_hp_search_ray,
  200. run_hp_search_sigopt,
  201. run_hp_search_wandb,
  202. )
  203. from .peft import PeftAdapterMixin
  204. from .quanto import replace_with_quanto_layers
  205. try:
  206. if not is_torch_available():
  207. raise OptionalDependencyNotAvailable()
  208. except OptionalDependencyNotAvailable:
  209. pass
  210. else:
  211. from .executorch import TorchExportableModuleWithStaticCache, convert_and_export_with_cache
  212. else:
  213. import sys
  214. sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)