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"""Public routed-expert configuration, family factory, and low-precision members."""
16
17import importlib
18from typing import TYPE_CHECKING, Any
19
20if TYPE_CHECKING:
21 from hyper_parallel.components.modules.moe.grouped_experts.grouped_experts import (
22 GroupedExpertsConfig,
23 GroupedExpertsModule,
24 )
25 from hyper_parallel.components.modules.moe.grouped_experts.grouped_experts_family import GroupedExperts
26 from hyper_parallel.components.modules.moe.grouped_experts.low_precision_grouped_experts import (
27 EPLowPrecisionGroupedExperts,
28 LowPrecisionGroupedExperts,
29 MoonEPLowPrecisionGroupedExperts,
30 )
31
32_LOW_PRECISION_EXPORTS = frozenset({
33 "EPLowPrecisionGroupedExperts",
34 "LowPrecisionGroupedExperts",
35 "MoonEPLowPrecisionGroupedExperts",
36})
37
38_EXPORT_TO_MODULE = {
39 "GroupedExperts": "grouped_experts_family",
40 "GroupedExpertsConfig": "grouped_experts",
41 "GroupedExpertsModule": "grouped_experts",
42 **{name: "low_precision_grouped_experts" for name in _LOW_PRECISION_EXPORTS},
43}
44
45__all__ = [
46 "EPLowPrecisionGroupedExperts",
47 "GroupedExperts",
48 "GroupedExpertsConfig",
49 "GroupedExpertsModule",
50 "LowPrecisionGroupedExperts",
51 "MoonEPLowPrecisionGroupedExperts",
52]
53
54
55def __getattr__(name: str) -> Any: # pylint: disable=invalid-name
56 """Lazily resolve routed-expert and low-precision exports without eager backend imports."""
57 submodule = _EXPORT_TO_MODULE.get(name)
58 if submodule is None:
59 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
60 module = importlib.import_module(
61 f"hyper_parallel.components.modules.moe.grouped_experts.{submodule}"
62 )
63 value = getattr(module, name)
64 globals()[name] = value
65 return value