| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | """Lazy facade for the optional ``humming`` package. |
| 4 | |
| 5 | vLLM code should import humming symbols from here so that ``import humming`` |
| 6 | (which has import-time side effects) is deferred until first use. Add new |
| 7 | symbols to both the ``TYPE_CHECKING`` imports and ``_EXPORTS``, using |
| 8 | ``"module.path:attr"`` or ``"module.path"`` for a whole-module re-export. |
| 9 | """ |
| 10 | |
| 11 | import importlib |
| 12 | from typing import TYPE_CHECKING, Any |
| 13 | |
| 14 | if TYPE_CHECKING: |
| 15 | from humming import dtypes as dtypes |
| 16 | from humming.config import GemmType as GemmType |
| 17 | from humming.config import InputQuantizationMode as InputQuantizationMode |
| 18 | from humming.config import LayerConfig as LayerConfig |
| 19 | from humming.config import MmaType as MmaType |
| 20 | from humming.config import WeightScale2Type as WeightScale2Type |
| 21 | from humming.config import WeightScaleType as WeightScaleType |
| 22 | from humming.dtypes import DataType as DataType |
| 23 | from humming.forward import humming_forward as humming_forward |
| 24 | from humming.forward import may_process_input as may_process_input |
| 25 | from humming.forward import may_quant_input as may_quant_input |
| 26 | from humming.ops import process_input as process_input |
| 27 | from humming.schema import AWQWeightSchema as AWQWeightSchema |
| 28 | from humming.schema import BaseInputSchema as BaseInputSchema |
| 29 | from humming.schema import BaseWeightSchema as BaseWeightSchema |
| 30 | from humming.schema import BitnetWeightSchema as BitnetWeightSchema |
| 31 | from humming.schema import ( |
| 32 | CompressedTensorsInputSchema as CompressedTensorsInputSchema, |
| 33 | ) |
| 34 | from humming.schema import ( |
| 35 | CompressedTensorsWeightSchema as CompressedTensorsWeightSchema, |
| 36 | ) |
| 37 | from humming.schema import Fp8InputSchema as Fp8InputSchema |
| 38 | from humming.schema import GptOssMxfp4WeightSchema as GptOssMxfp4WeightSchema |
| 39 | from humming.schema import GPTQWeightSchema as GPTQWeightSchema |
| 40 | from humming.schema import HummingInputSchema as HummingInputSchema |
| 41 | from humming.schema import HummingWeightSchema as HummingWeightSchema |
| 42 | from humming.schema import Mxfp4WeightSchema as Mxfp4WeightSchema |
| 43 | from humming.schema.fp8 import Fp8WeightSchema as Fp8WeightSchema |
| 44 | from humming.schema.modelopt import ( |
| 45 | ModeloptMxfp8WeightSchema as ModeloptMxfp8WeightSchema, |
| 46 | ) |
| 47 | from humming.schema.modelopt import ( |
| 48 | ModeloptNvfp4InputSchema as ModeloptNvfp4InputSchema, |
| 49 | ) |
| 50 | from humming.schema.modelopt import ( |
| 51 | ModeloptNvfp4WeightSchema as ModeloptNvfp4WeightSchema, |
| 52 | ) |
| 53 | from humming.transform import prepare_layer_config as prepare_layer_config |
| 54 | from humming.transform import transform_humming_tensors as transform_humming_tensors |
| 55 | from humming.tune import get_heuristics_config as get_heuristics_config |
| 56 | from humming.utils.weight import quantize_weight as quantize_weight |
| 57 | |
| 58 | _EXPORTS: dict[str, str] = { |
| 59 | "dtypes": "humming.dtypes", |
| 60 | "DataType": "humming.dtypes:DataType", |
| 61 | "GemmType": "humming.config:GemmType", |
| 62 | "LayerConfig": "humming.config:LayerConfig", |
| 63 | "WeightScaleType": "humming.config:WeightScaleType", |
| 64 | "WeightScale2Type": "humming.config:WeightScale2Type", |
| 65 | "InputQuantizationMode": "humming.config:InputQuantizationMode", |
| 66 | "MmaType": "humming.config:MmaType", |
| 67 | "humming_forward": "humming.forward:humming_forward", |
| 68 | "may_process_input": "humming.forward:may_process_input", |
| 69 | "process_input": "humming.ops:process_input", |
| 70 | "may_quant_input": "humming.forward:may_quant_input", |
| 71 | "prepare_layer_config": "humming.transform:prepare_layer_config", |
| 72 | "transform_humming_tensors": "humming.transform:transform_humming_tensors", |
| 73 | "get_heuristics_config": "humming.tune:get_heuristics_config", |
| 74 | "BaseInputSchema": "humming.schema:BaseInputSchema", |
| 75 | "BaseWeightSchema": "humming.schema:BaseWeightSchema", |
| 76 | "HummingInputSchema": "humming.schema:HummingInputSchema", |
| 77 | "HummingWeightSchema": "humming.schema:HummingWeightSchema", |
| 78 | "quantize_weight": "humming.utils.weight:quantize_weight", |
| 79 | "AWQWeightSchema": "humming.schema:AWQWeightSchema", |
| 80 | "BitnetWeightSchema": "humming.schema:BitnetWeightSchema", |
| 81 | "ModeloptMxfp8WeightSchema": "humming.schema.modelopt:ModeloptMxfp8WeightSchema", |
| 82 | "ModeloptNvfp4InputSchema": "humming.schema.modelopt:ModeloptNvfp4InputSchema", |
| 83 | "ModeloptNvfp4WeightSchema": "humming.schema.modelopt:ModeloptNvfp4WeightSchema", |
| 84 | "CompressedTensorsInputSchema": "humming.schema:CompressedTensorsInputSchema", |
| 85 | "CompressedTensorsWeightSchema": "humming.schema:CompressedTensorsWeightSchema", |
| 86 | "Fp8InputSchema": "humming.schema:Fp8InputSchema", |
| 87 | "Fp8WeightSchema": "humming.schema.fp8:Fp8WeightSchema", |
| 88 | "Mxfp4WeightSchema": "humming.schema:Mxfp4WeightSchema", |
| 89 | "GptOssMxfp4WeightSchema": "humming.schema:GptOssMxfp4WeightSchema", |
| 90 | "GPTQWeightSchema": "humming.schema:GPTQWeightSchema", |
| 91 | } |
| 92 | |
| 93 | |
| 94 | def __getattr__(name: str) -> Any: |
| 95 | spec = _EXPORTS.get(name) |
| 96 | if spec is None: |
| 97 | raise AttributeError(f"module 'vllm.utils.humming' has no attribute {name!r}") |
| 98 | if ":" in spec: |
| 99 | mod_path, attr = spec.split(":", 1) |
| 100 | obj = getattr(importlib.import_module(mod_path), attr) |
| 101 | else: |
| 102 | obj = importlib.import_module(spec) |
| 103 | globals()[name] = obj |
| 104 | return obj |
| 105 | |
| 106 | |
| 107 | def __dir__() -> list[str]: |
| 108 | return sorted({*globals(), *_EXPORTS}) |