Aluode/PerceptionLabPortable
0
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 at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# 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 and13# limitations under the License.14from typing import TYPE_CHECKING15 16from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_torch_greater_or_equal17 18 19_import_structure = {20 "aqlm": ["replace_with_aqlm_linear"],21 "awq": [22 "fuse_awq_modules",23 "post_init_awq_exllama_modules",24 "post_init_awq_ipex_modules",25 "replace_quantization_scales",26 "replace_with_awq_linear",27 ],28 "bitnet": [29 "BitLinear",30 "pack_weights",31 "replace_with_bitnet_linear",32 "unpack_weights",33 ],34 "bitsandbytes": [35 "dequantize_and_replace",36 "get_keys_to_not_convert",37 "replace_8bit_linear",38 "replace_with_bnb_linear",39 "set_module_8bit_tensor_to_device",40 "set_module_quantized_tensor_to_device",41 "validate_bnb_backend_availability",42 ],43 "deepspeed": [44 "HfDeepSpeedConfig",45 "HfTrainerDeepSpeedConfig",46 "deepspeed_config",47 "deepspeed_init",48 "deepspeed_load_checkpoint",49 "deepspeed_optim_sched",50 "is_deepspeed_available",51 "is_deepspeed_zero3_enabled",52 "set_hf_deepspeed_config",53 "unset_hf_deepspeed_config",54 ],55 "eetq": ["replace_with_eetq_linear"],56 "fbgemm_fp8": ["FbgemmFp8Linear", "FbgemmFp8Llama4TextExperts", "replace_with_fbgemm_fp8_linear"],57 "finegrained_fp8": ["FP8Linear", "replace_with_fp8_linear"],58 "fsdp": ["is_fsdp_enabled", "is_fsdp_managed_module"],59 "ggml": [60 "GGUF_CONFIG_MAPPING",61 "GGUF_TOKENIZER_MAPPING",62 "_gguf_parse_value",63 "load_dequant_gguf_tensor",64 "load_gguf",65 ],66 "higgs": [67 "HiggsLinear",68 "dequantize_higgs",69 "quantize_with_higgs",70 "replace_with_higgs_linear",71 ],72 "hqq": ["prepare_for_hqq_linear"],73 "hub_kernels": [74 "LayerRepository",75 "register_kernel_mapping",76 "replace_kernel_forward_from_hub",77 "use_kernel_forward_from_hub",78 ],79 "integration_utils": [80 "INTEGRATION_TO_CALLBACK",81 "AzureMLCallback",82 "ClearMLCallback",83 "CodeCarbonCallback",84 "CometCallback",85 "DagsHubCallback",86 "DVCLiveCallback",87 "FlyteCallback",88 "MLflowCallback",89 "NeptuneCallback",90 "NeptuneMissingConfiguration",91 "SwanLabCallback",92 "TensorBoardCallback",93 "TrackioCallback",94 "WandbCallback",95 "get_available_reporting_integrations",96 "get_reporting_integration_callbacks",97 "hp_params",98 "is_azureml_available",99 "is_clearml_available",100 "is_codecarbon_available",101 "is_comet_available",102 "is_dagshub_available",103 "is_dvclive_available",104 "is_flyte_deck_standard_available",105 "is_flytekit_available",106 "is_mlflow_available",107 "is_neptune_available",108 "is_optuna_available",109 "is_ray_available",110 "is_ray_tune_available",111 "is_sigopt_available",112 "is_swanlab_available",113 "is_tensorboard_available",114 "is_trackio_available",115 "is_wandb_available",116 "rewrite_logs",117 "run_hp_search_optuna",118 "run_hp_search_ray",119 "run_hp_search_sigopt",120 "run_hp_search_wandb",121 ],122 "mxfp4": [123 "Mxfp4GptOssExperts",124 "convert_moe_packed_tensors",125 "dequantize",126 "load_and_swizzle_mxfp4",127 "quantize_to_mxfp4",128 "replace_with_mxfp4_linear",129 "swizzle_mxfp4",130 ],131 "peft": ["PeftAdapterMixin"],132 "quanto": ["replace_with_quanto_layers"],133 "spqr": ["replace_with_spqr_linear"],134 "vptq": ["replace_with_vptq_linear"],135}136 137try:138 if not is_torch_available():139 raise OptionalDependencyNotAvailable()140except OptionalDependencyNotAvailable:141 pass142else:143 _import_structure["executorch"] = [144 "TorchExportableModuleWithStaticCache",145 "convert_and_export_with_cache",146 ]147 148try:149 if not is_torch_greater_or_equal("2.3"):150 raise OptionalDependencyNotAvailable()151except OptionalDependencyNotAvailable:152 pass153else:154 _import_structure["tensor_parallel"] = [155 "shard_and_distribute_module",156 "ALL_PARALLEL_STYLES",157 "translate_to_torch_parallel_style",158 ]159try:160 if not is_torch_greater_or_equal("2.5"):161 raise OptionalDependencyNotAvailable()162except OptionalDependencyNotAvailable:163 pass164else:165 _import_structure["flex_attention"] = [166 "make_flex_block_causal_mask",167 ]168 169if TYPE_CHECKING:170 from .aqlm import replace_with_aqlm_linear171 from .awq import (172 fuse_awq_modules,173 post_init_awq_exllama_modules,174 post_init_awq_ipex_modules,175 replace_quantization_scales,176 replace_with_awq_linear,177 )178 from .bitnet import (179 BitLinear,180 pack_weights,181 replace_with_bitnet_linear,182 unpack_weights,183 )184 from .bitsandbytes import (185 dequantize_and_replace,186 get_keys_to_not_convert,187 replace_8bit_linear,188 replace_with_bnb_linear,189 set_module_8bit_tensor_to_device,190 set_module_quantized_tensor_to_device,191 validate_bnb_backend_availability,192 )193 from .deepspeed import (194 HfDeepSpeedConfig,195 HfTrainerDeepSpeedConfig,196 deepspeed_config,197 deepspeed_init,198 deepspeed_load_checkpoint,199 deepspeed_optim_sched,200 is_deepspeed_available,201 is_deepspeed_zero3_enabled,202 set_hf_deepspeed_config,203 unset_hf_deepspeed_config,204 )205 from .eetq import replace_with_eetq_linear206 from .fbgemm_fp8 import FbgemmFp8Linear, FbgemmFp8Llama4TextExperts, replace_with_fbgemm_fp8_linear207 from .finegrained_fp8 import FP8Linear, replace_with_fp8_linear208 from .fsdp import is_fsdp_enabled, is_fsdp_managed_module209 from .ggml import (210 GGUF_CONFIG_MAPPING,211 GGUF_TOKENIZER_MAPPING,212 _gguf_parse_value,213 load_dequant_gguf_tensor,214 load_gguf,215 )216 from .higgs import HiggsLinear, dequantize_higgs, quantize_with_higgs, replace_with_higgs_linear217 from .hqq import prepare_for_hqq_linear218 from .hub_kernels import (219 LayerRepository,220 register_kernel_mapping,221 replace_kernel_forward_from_hub,222 use_kernel_forward_from_hub,223 )224 from .integration_utils import (225 INTEGRATION_TO_CALLBACK,226 AzureMLCallback,227 ClearMLCallback,228 CodeCarbonCallback,229 CometCallback,230 DagsHubCallback,231 DVCLiveCallback,232 FlyteCallback,233 MLflowCallback,234 NeptuneCallback,235 NeptuneMissingConfiguration,236 SwanLabCallback,237 TensorBoardCallback,238 TrackioCallback,239 WandbCallback,240 get_available_reporting_integrations,241 get_reporting_integration_callbacks,242 hp_params,243 is_azureml_available,244 is_clearml_available,245 is_codecarbon_available,246 is_comet_available,247 is_dagshub_available,248 is_dvclive_available,249 is_flyte_deck_standard_available,250 is_flytekit_available,251 is_mlflow_available,252 is_neptune_available,253 is_optuna_available,254 is_ray_available,255 is_ray_tune_available,256 is_sigopt_available,257 is_swanlab_available,258 is_tensorboard_available,259 is_trackio_available,260 is_wandb_available,261 rewrite_logs,262 run_hp_search_optuna,263 run_hp_search_ray,264 run_hp_search_sigopt,265 run_hp_search_wandb,266 )267 from .mxfp4 import (268 Mxfp4GptOssExperts,269 dequantize,270 load_and_swizzle_mxfp4,271 quantize_to_mxfp4,272 replace_with_mxfp4_linear,273 swizzle_mxfp4,274 )275 from .peft import PeftAdapterMixin276 from .quanto import replace_with_quanto_layers277 from .spqr import replace_with_spqr_linear278 from .vptq import replace_with_vptq_linear279 280 try:281 if not is_torch_available():282 raise OptionalDependencyNotAvailable()283 except OptionalDependencyNotAvailable:284 pass285 else:286 from .executorch import TorchExportableModuleWithStaticCache, convert_and_export_with_cache287 288 try:289 if not is_torch_greater_or_equal("2.3"):290 raise OptionalDependencyNotAvailable()291 except OptionalDependencyNotAvailable:292 pass293 else:294 from .tensor_parallel import (295 ALL_PARALLEL_STYLES,296 shard_and_distribute_module,297 translate_to_torch_parallel_style,298 )299 300 try:301 if not is_torch_greater_or_equal("2.5"):302 raise OptionalDependencyNotAvailable()303 except OptionalDependencyNotAvailable:304 pass305 else:306 from .flex_attention import make_flex_block_causal_mask307else:308 import sys309 310 sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)311 