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

16 statements  

« 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"""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.common.attention_residual import ( 

29 AttentionResidual, AttentionResidualModule, 

30 ) 

31 from hyper_parallel.components.modules.common.gated_residual import ( 

32 GatedResidual, GatedResidualModule, 

33 ) 

34 from hyper_parallel.components.modules.attention.multi_latent_attention import ( 

35 MultiLatentAttention, MultiLatentAttentionModule, 

36 ) 

37 from hyper_parallel.components.modules.attention.gated_multi_latent_attention import ( 

38 GatedMultiLatentAttention, GatedMultiLatentAttentionModule, 

39 ) 

40 from hyper_parallel.components.modules.common.mtp import ( 

41 MTPLayer, MultiTokenPrediction, MTPOutput, build_mtp, 

42 ) 

43 from hyper_parallel.components.modules.attention.deepseek_sparse_attention import ( 

44 CPDeepseekSparseAttentionModule, DeepseekSparseAttention, DeepseekSparseAttentionModule, 

45 ) 

46 from hyper_parallel.components.modules.attention.grouped_query_attention import ( 

47 GroupedQueryAttention, 

48 ) 

49 from hyper_parallel.components.modules.attention.gated_grouped_query_attention import ( 

50 GatedGroupedQueryAttention, 

51 ) 

52 from hyper_parallel.components.modules.moe.grouped_experts.grouped_experts_family import GroupedExperts 

53 from hyper_parallel.components.modules.linear import Linear 

54 from hyper_parallel.components.modules.engram import Engram 

55 from hyper_parallel.components.modules.mhc import MhcPostModule, MhcPreModule, PipelinedMhc 

56 from hyper_parallel.components.modules.common.rms_norm import OffsetRMSNorm, RMSNorm 

57 from hyper_parallel.components.modules.moe.shared_expert import SharedExpert 

58 from hyper_parallel.components.modules.common.causal_lm_head import CausalLMHead, CausalLMHeadModule 

59 from hyper_parallel.components.modules.common.situ_mlp import SiTUMLP, SiTUMLPModule 

60 from hyper_parallel.components.modules.mlp import SwiGLUMLP, SwiGLUMLPModule 

61 

62_EXPORT_TO_MODULE = { 

63 "AttentionResidual": "common.attention_residual", 

64 "AttentionResidualModule": "common.attention_residual", 

65 "GatedResidual": "common.gated_residual", 

66 "GatedResidualModule": "common.gated_residual", 

67 "CausalLMHead": "common.causal_lm_head", 

68 "CausalLMHeadModule": "common.causal_lm_head", 

69 "SiTUMLP": "common.situ_mlp", 

70 "SiTUMLPModule": "common.situ_mlp", 

71 "CompressedSparseAttention2": "attention.compressed_sparse_attention2", 

72 "Gate": "moe.router", 

73 "GateModule": "moe.router", 

74 "MegaMhc": "mhc.mhc_family", 

75 "MegaMhcModule": "mhc.mega_mhc", 

76 "SpatialMergeProjector": "common.spatial_merge_projector", 

77 "SpatialMergeProjectorModule": "common.spatial_merge_projector", 

78 "RotaryEmbedding": "common.rotary_embedding", 

79 "RotaryEmbeddingModule": "common.rotary_embedding", 

80 "HostEngramModule": "engram.host_engram", 

81 "HostEngramTable": "engram.host_engram_table", 

82 "Engram": "engram", 

83 "MHCPre": "mhc", 

84 "MHCPost": "mhc", 

85 "PipelinedMhc": "mhc", 

86 "SwiGLUMLPModule": "mlp", 

87 "SwiGLUMLP": "mlp", 

88 "SharedExpertModule": "moe.shared_expert", 

89 "SharedExpert": "moe.shared_expert", 

90 "RMSNormModule": "common.rms_norm", 

91 "NativeRMSNormModule": "common.rms_norm", 

92 "NativeOffsetRMSNormModule": "common.rms_norm", 

93 "RMSNorm": "common.rms_norm", 

94 "OffsetRMSNormModule": "common.rms_norm", 

95 "OffsetRMSNorm": "common.rms_norm", 

96 "build_mtp": "common.mtp", 

97 "MTPLayer": "common.mtp", 

98 "MultiTokenPrediction": "common.mtp", 

99 "MTPOutput": "common.mtp", 

100 "DeepseekSparseAttention": "attention.deepseek_sparse_attention", 

101 "DeepseekSparseAttentionModule": "attention.deepseek_sparse_attention", 

102 "CPDeepseekSparseAttentionModule": "attention.deepseek_sparse_attention", 

103 "GroupedQueryAttention": "attention.grouped_query_attention.grouped_query_attention_family", 

104 "GatedGroupedQueryAttention": "attention.gated_grouped_query_attention.gated_grouped_query_attention_family", 

105 "EngramModule": "engram", 

106 "GroupedExperts": "moe.grouped_experts.grouped_experts_family", 

107 "Linear": "linear", 

108 "KimiDeltaAttention": "attention.kimi_delta_attention", 

109 "KimiDeltaAttentionModule": "attention.kimi_delta_attention", 

110 "GatedDeltaNet": "attention.gated_delta_net", 

111 "GatedDeltaNetModule": "attention.gated_delta_net", 

112 "KimiRMSNormGated": "attention.kimi_delta_attention.kimi_delta_attention", 

113 "MhcPostModule": "mhc", 

114 "MhcPreModule": "mhc", 

115 "NgramHashMapping": "engram", 

116 "PipelinedMhcModule": "mhc", 

117 "MultiLatentAttention": "attention.multi_latent_attention", 

118 "MultiLatentAttentionModule": "attention.multi_latent_attention", 

119 "GatedMultiLatentAttention": "attention.gated_multi_latent_attention", 

120 "GatedMultiLatentAttentionModule": "attention.gated_multi_latent_attention", 

121 "SharedCompressedAttentionState": "attention.compressed_sparse_attention2.compressed_sparse_attention2", 

122 "SharedCompressedPackedSequence": "attention.compressed_sparse_attention2.document_layout", 

123 "CSA2Indexer": "attention.compressed_sparse_attention2.indexer", 

124} 

125_EXPORT_TO_MODULE.update({name: "module_family" for name in ( 

126 "ModuleFamily", "SelectorSpec", "VariantRule", "FamilyRequest", "ResolvedFamily", 

127 "build_family", "register_module_family", "get_family_build_info", "collect_family_modules", 

128 "FamilyShardingContext", 

129)}) 

130__all__.extend(_EXPORT_TO_MODULE) 

131 

132 

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

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

135 submodule = _EXPORT_TO_MODULE.get(name) 

136 if submodule is None: 

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

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

139 value = getattr(module, name) 

140 globals()[name] = value 

141 return value 

142 

143 

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

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

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