Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / __init__.py: 97%
30 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-08-21 04:29 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-08-21 04:29 +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# pylint: disable=undefined-all-variable
16"""hyper parallel interface"""
18__all__ = ["get_platform", "DFunction", "fully_shard", "hsdp_sync_stream", "HSDPModule", "DTensor",
19 "Layout", "DeviceMesh", "init_device_mesh", "get_current_mesh", "distribute_module",
20 "distribute_tensor", "ones", "zeros", "empty", "full", "rand", "randn",
21 "Shard", "RaggedShard", "Replicate", "Partial", "Placement",
22 "init_parameters", "init_empty_weights", "init_on_device",
23 "shard_module", "custom_shard", "parallelize_value_and_grad", "SkipDTensorDispatch",
24 "MetaStep", "MetaStepType", "BatchDimSpec", "PipelineStage", "ScheduleInterleaved1F1B",
25 "ScheduleMPipeTranspose",
26 "init_process_group", "destroy_process_group", "get_process_group_ranks", "get_backend", "split_group",
27 "get_group_local_rank", "mark_created_groups",
28 "ContextParallel", "AsyncContextParallel",
29 "AsyncDSAIndexerContextParallel", "AsyncDSAIndexerLossContextParallel",
30 "AsyncDSASparseAttentionContextParallel",
31 "DSAIndexerContextParallel", "DSAIndexerLossContextParallel", "DSASparseAttentionContextParallel",
32 "ColwiseParallel", "MC2ColwiseParallel", "MC2RowwiseParallel", "MC2Linear",
33 "NoParallel", "RowwiseParallel", "SequenceParallel",
34 "PrepareModuleInput", "PrepareModuleInputOutput", "PrepareModuleOutput",
35 "ParallelStyle", "parallelize_module", "manual_seed"]
37from importlib import import_module as _import_module # pylint: disable=invalid-name
39from hyper_parallel.platform import get_platform
40from hyper_parallel.core.shard.dfunction import DFunction
41from hyper_parallel.core.dtensor.layout import Layout
42from hyper_parallel.core.dtensor.device_mesh import DeviceMesh, _mesh_resources, init_device_mesh
43from hyper_parallel.core.dtensor.dtensor import (
44 DTensor,
45 SkipDTensorDispatch,
46 distribute_module,
47 distribute_tensor,
48 ones,
49 zeros,
50 empty,
51 full,
52 rand,
53 randn,
54)
55from hyper_parallel.core.dtensor.placement_types import (
56 Placement,
57 RaggedShard,
58 Replicate,
59 Partial,
60 Shard,
61)
62from hyper_parallel.core.dtensor.parameter_init import init_parameters
63from hyper_parallel.core.dtensor.init_weights import init_empty_weights, init_on_device
64from hyper_parallel.core.shard.api import shard_module
65from hyper_parallel.core.shard.api import parallelize_value_and_grad
66from hyper_parallel.core.shard.custom_shard import custom_shard
67from hyper_parallel.core.pipeline_parallel import (PipelineStage, ScheduleInterleaved1F1B, ScheduleMPipeTranspose,
68 MetaStep, MetaStepType, BatchDimSpec)
69from hyper_parallel.collectives.cc import (init_process_group, destroy_process_group, get_process_group_ranks,
70 get_backend, split_group, get_group_local_rank, mark_created_groups)
71from hyper_parallel.core.context_parallel import (
72 AsyncDSAIndexerContextParallel,
73 AsyncDSAIndexerLossContextParallel,
74 AsyncDSASparseAttentionContextParallel,
75 ContextParallel,
76 AsyncContextParallel,
77 DSAIndexerContextParallel,
78 DSAIndexerLossContextParallel,
79 DSASparseAttentionContextParallel,
80)
81from hyper_parallel.core.tensor_parallel import (
82 ColwiseParallel,
83 NoParallel,
84 ParallelStyle,
85 PrepareModuleInput,
86 PrepareModuleInputOutput,
87 PrepareModuleOutput,
88 RowwiseParallel,
89 SequenceParallel,
90 parallelize_module,
91)
92from hyper_parallel.core.dtensor.random import manual_seed
93from hyper_parallel.core.fully_shard.api import fully_shard, hsdp_sync_stream, HSDPModule
95get_current_mesh = _mesh_resources.get_current_mesh
97# MC2 APIs import torch at module load. Resolve them through tensor_parallel's
98# lazy __getattr__ so `import hyper_parallel` does not require torch.
99_LAZY_EXPORTS = {
100 "MC2Linear": "hyper_parallel.core.tensor_parallel",
101 "MC2ColwiseParallel": "hyper_parallel.core.tensor_parallel",
102 "MC2RowwiseParallel": "hyper_parallel.core.tensor_parallel",
103}
106def __getattr__(name): # pylint: disable=invalid-name
107 """Lazily import MC2 symbols that require torch."""
108 if name not in _LAZY_EXPORTS:
109 raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
111 module = _import_module(_LAZY_EXPORTS[name])
112 value = getattr(module, name)
113 globals()[name] = value
114 return value
117def __dir__(): # pylint: disable=invalid-name
118 """Include lazy MC2 exports in ``dir()``."""
119 return sorted(set(globals()) | set(_LAZY_EXPORTS))