Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / components / modules / __init__.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-25 05:45 +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"""Public high-performance module interfaces. 

16 

17Exports are resolved lazily so modules backed only by torch-npu do not import 

18unrelated optional Omni custom operators. Accessing an Omni-backed module still 

19loads and validates that dependency normally. 

20""" 

21 

22__all__: list[str] = [] 

23 

24import importlib 

25from typing import TYPE_CHECKING, Any 

26 

27if TYPE_CHECKING: 

28 from hyper_parallel.components.modules.dsa_attention import DSAAttention, DeepseekV32DSAAttention 

29 from hyper_parallel.components.modules.gqa_attention import GatedGQAAttention, GQAAttention 

30 from hyper_parallel.components.modules.grouped_experts import GroupedExperts 

31 from hyper_parallel.components.modules.mhc import MhcPostModule, MhcPreModule 

32 from hyper_parallel.components.modules.mla_attention import MLAAttention 

33 from hyper_parallel.components.modules.rms_norm import OffsetRMSNorm, RMSNorm 

34 from hyper_parallel.components.modules.shared_expert import SharedExpert 

35 from hyper_parallel.components.modules.swiglu_mlp import SwiGLUMLP 

36 

37_EXPORT_TO_MODULE = { 

38 "DeepseekV32DSAAttention": "dsa_attention", 

39 "DSAAttention": "dsa_attention", 

40 "GQAAttention": "gqa_attention", 

41 "GatedGQAAttention": "gqa_attention", 

42 "EngramModule": "engram", 

43 "GroupedExperts": "grouped_experts", 

44 "KimiDeltaAttention": "kimi_delta_attention", 

45 "KimiRMSNormGated": "kimi_delta_attention", 

46 "MhcPostModule": "mhc", 

47 "MhcPreModule": "mhc", 

48 "NgramHashMapping": "engram", 

49 "PipelinedMhcModule": "mhc", 

50 "MLAAttention": "mla_attention", 

51 "OffsetRMSNorm": "rms_norm", 

52 "RMSNorm": "rms_norm", 

53 "SharedExpert": "shared_expert", 

54 "SharedCompressedAttentionCPContext": "shared_compressed_dsa_attention", 

55 "SharedCompressedAttentionState": "shared_compressed_dsa_attention", 

56 "SharedCompressedPackedSequence": "shared_compressed_dsa_attention", 

57 "SharedCompressedAttentionTPContext": "shared_compressed_dsa_attention", 

58 "SharedCompressedDSAAttention": "shared_compressed_dsa_attention", 

59 "SharedCompressedDSAIndexer": "shared_compressed_dsa_attention", 

60 "SwiGLUMLP": "swiglu_mlp", 

61} 

62__all__.extend(_EXPORT_TO_MODULE) 

63 

64 

65def __getattr__(name: str) -> Any: # pylint: disable=invalid-name 

66 """Resolve a public class by importing only its owning submodule.""" 

67 submodule = _EXPORT_TO_MODULE.get(name) 

68 if submodule is None: 

69 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") 

70 module = importlib.import_module(f"hyper_parallel.components.modules.{submodule}") 

71 value = getattr(module, name) 

72 globals()[name] = value 

73 return value 

74 

75 

76def __dir__() -> list[str]: 

77 """Include lazy public exports in ``dir()``.""" 

78 return sorted(set(globals()) | set(__all__))