Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / components / quantization / __init__.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-12-05 05:12 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-12-05 05:12 +0800
1# Copyright 2026 Huawei Technologies Co., Ltd
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# ============================================================================
15"""Low-precision quantization: config, tensors, quantizers, functions, modules."""
17import importlib
18from typing import TYPE_CHECKING, Any
20from hyper_parallel.components.quantization.config import (
21 LowPrecisionConfig,
22 LowPrecisionDtypeScheme,
23 MXBlockSizeValue,
24)
25from hyper_parallel.components.quantization.functional import (
26 GroupedLinear,
27 LinearStrategy,
28 W4A8GroupedLinear,
29 FakeW4A8GroupedLinear,
30 build_low_precision_strategy,
31)
32from hyper_parallel.components.quantization.ops import (
33 FakeW4A8CapabilityError,
34 FakeW4A8NpuOps,
35 HiFloat8NpuOps,
36 LowPrecisionCapabilityError,
37 MXFP8NpuOps,
38 W4A8CapabilityError,
39 W4A8NpuOps,
40 hifloat8_grouped_matmul,
41 hifloat8_matmul,
42 mxfp8_grouped_matmul,
43 mxfp8_matmul,
44 validate_fake_w4a8_gmm_runtime,
45 validate_w4a8_gmm_runtime,
46)
47from hyper_parallel.components.quantization.quantizers import (
48 HiFloat8Quantizer,
49 MXFP8Quantizer,
50 Quantizer,
51 W4A8Quantizer,
52 FakeW4A8Quantizer,
53)
54from hyper_parallel.components.quantization.tensor import (
55 HiFloat8Tensor,
56 HiFloat8TensorStorage,
57 MXFP8Tensor,
58 MXFP8TensorStorage,
59 QuantizedTensor,
60 QuantizedTensorStorage,
61 W4A8Tensor,
62 W4A8TensorStorage,
63)
65if TYPE_CHECKING:
66 from hyper_parallel.components.quantization.modules import LowPrecisionLinear
68__all__ = [
69 "HiFloat8NpuOps",
70 "HiFloat8Quantizer",
71 "HiFloat8Tensor",
72 "HiFloat8TensorStorage",
73 "LowPrecisionConfig",
74 "LowPrecisionDtypeScheme",
75 "MXBlockSizeValue",
76 "LowPrecisionCapabilityError",
77 "LinearStrategy",
78 "MXFP8NpuOps",
79 "MXFP8Quantizer",
80 "MXFP8Tensor",
81 "MXFP8TensorStorage",
82 "W4A8CapabilityError",
83 "W4A8GroupedLinear",
84 "W4A8NpuOps",
85 "W4A8Quantizer",
86 "W4A8Tensor",
87 "W4A8TensorStorage",
88 "FakeW4A8CapabilityError",
89 "FakeW4A8GroupedLinear",
90 "FakeW4A8NpuOps",
91 "FakeW4A8Quantizer",
92 "GroupedLinear",
93 "build_low_precision_strategy",
94 "LowPrecisionLinear",
95 "QuantizedTensor",
96 "QuantizedTensorStorage",
97 "Quantizer",
98 "hifloat8_grouped_matmul",
99 "hifloat8_matmul",
100 "mxfp8_grouped_matmul",
101 "mxfp8_matmul",
102 "validate_w4a8_gmm_runtime",
103 "validate_fake_w4a8_gmm_runtime",
104]
107def __getattr__(name: str) -> Any: # pylint: disable=invalid-name
108 """Defer the Linear compatibility export to avoid a cycle with its canonical package."""
109 if name != "LowPrecisionLinear":
110 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
111 modules_pkg = importlib.import_module("hyper_parallel.components.quantization.modules")
112 value = getattr(modules_pkg, name)
113 globals()[name] = value
114 return value