Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / components / functional / __init__.py: 100%
12 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"""Public high-performance function interfaces.
17Exports are resolved lazily (PEP 562): most functions wrap NPU-only kernels
18whose modules import ``torch_npu`` at top level, so importing this package
19must not force every backend onto CPU-only consumers that only need a
20single submodule (e.g. ``functional.npu_grouped_swiglu``).
21"""
23# PEP 562 requires the special ``__getattr__`` name, and the public symbols
24# listed in ``__all__`` are materialized dynamically by that hook.
25# pylint: disable=invalid-name,undefined-all-variable
27import importlib
28from typing import Any, TYPE_CHECKING
30if TYPE_CHECKING:
31 from hyper_parallel.components.functional.swiglu import swiglu
33_EXPORT_TO_MODULE = {
34 "aggregate_hidden": "aggregate_hidden",
35 "apply_rotary_pos_emb": "rotary_embedding",
36 "apply_rotary_pos_emb_interleave": "rotary_embedding",
37 "apply_rotary_pos_emb_single": "rotary_embedding",
38 "apply_rotary_pos_emb_single_freqs": "rotary_embedding",
39 "attention_rescale": "attention_rescale",
40 "block_attention_residuals": "attention_residuals",
41 "dsa_indexer": "dsa_indexer",
42 "dsa_dense_indexer_kl_loss": "dsa_dense",
43 "dsa_dense_indexer_lse": "dsa_dense",
44 "dsa_kl_loss": "dsa_kl_loss",
45 "dsa_sparse_attention": "dsa_sparse_attention",
46 "dsa_sparse_attention_rescale": "dsa_sparse_attention_rescale",
47 "grouped_matmul": "grouped_matmul",
48 "gated_residual": "gated_residual",
49 "chunk_gated_delta_rule": "gated_delta_net",
50 "fused_chunk_kda": "kimi_delta_attention",
51 "make_gram_newton_schulz": "gram_newton_schulz",
52 "mhc_post": "mhc_post",
53 "mhc_pre": "mhc_pre",
54 "moe_token_permute": "moe_token_permute",
55 "moe_token_unpermute": "moe_token_unpermute",
56 "npu_fusion_attention_forward": "npu_fusion_attention",
57 "npu_grouped_swiglu": "npu_grouped_swiglu",
58 "rms_norm": "rms_norm",
59 "sink_attention": "sink_attention",
60 "sinkhorn": "sinkhorn",
61 "situ": "activation_situ",
62 "situ_packed": "activation_situ",
63 "swiglu": "swiglu",
64}
67def __getattr__(name: str) -> Any:
68 """Resolve a public function by importing its owning submodule lazily."""
69 submodule = _EXPORT_TO_MODULE.get(name)
70 if submodule is None:
71 raise AttributeError(
72 f"module {__name__!r} has no attribute {name!r}"
73 )
74 module = importlib.import_module(
75 f"hyper_parallel.components.functional.{submodule}"
76 )
77 value = getattr(module, name)
78 globals()[name] = value
79 return value
82__all__ = [
83 "aggregate_hidden",
84 "apply_rotary_pos_emb",
85 "apply_rotary_pos_emb_interleave",
86 "apply_rotary_pos_emb_single",
87 "apply_rotary_pos_emb_single_freqs",
88 "attention_rescale",
89 "block_attention_residuals",
90 "dsa_indexer",
91 "dsa_dense_indexer_kl_loss",
92 "dsa_dense_indexer_lse",
93 "dsa_kl_loss",
94 "dsa_sparse_attention",
95 "dsa_sparse_attention_rescale",
96 "grouped_matmul",
97 "gated_residual",
98 "chunk_gated_delta_rule",
99 "fused_chunk_kda",
100 "make_gram_newton_schulz",
101 "mhc_post",
102 "mhc_pre",
103 "moe_token_permute",
104 "moe_token_unpermute",
105 "npu_fusion_attention_forward",
106 "npu_grouped_swiglu",
107 "rms_norm",
108 "sink_attention",
109 "sinkhorn",
110 "situ",
111 "situ_packed",
112 "swiglu",
113]