Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / tools / dryrun / __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 entry points for model-independent logical memory dry-run.
17Keep this package lazy-loaded: ``core/`` modules import
18``hyper_parallel.tools.dryrun.simulation`` at import time, so eager imports of
19runner/runtime modules here would introduce circular imports.
20"""
22from importlib import import_module
23from typing import Any
25__all__ = [
26 "DryRunBatchMocker",
27 "DryRunConfig",
28 "DryRunOpRegistry",
29 "DryRunRuntime",
30 "DryRunSnapshotConfig",
31 "HyperModelsDryRunRunner",
32 "LogicalMemoryTracker",
33 "get_dryrun_op_registry",
34 "install_dryrun_patches",
35 "install_moe_replay",
36 "install_trainer_patches",
37 "register_builtin_fake_ops",
38 "register_fake_op",
39 "register_model_patch",
40 "write_memory_snapshot",
41]
43_EXPORTS = {
44 "DryRunBatchMocker": ("data_adapter", "DryRunBatchMocker"),
45 "DryRunConfig": ("config", "DryRunConfig"),
46 "DryRunOpRegistry": ("ops.registry", "DryRunOpRegistry"),
47 "DryRunRuntime": ("runtime", "DryRunRuntime"),
48 "DryRunSnapshotConfig": ("config", "DryRunSnapshotConfig"),
49 "HyperModelsDryRunRunner": ("runner", "HyperModelsDryRunRunner"),
50 "LogicalMemoryTracker": ("memory_tracker", "LogicalMemoryTracker"),
51 "get_dryrun_op_registry": ("ops.registry", "get_dryrun_op_registry"),
52 "install_dryrun_patches": ("patches", "install_dryrun_patches"),
53 "install_moe_replay": ("patches.models.moe", "install_moe_replay"),
54 "install_trainer_patches": ("patches.trainer", "install_trainer_patches"),
55 "register_builtin_fake_ops": ("ops.fake_kernels", "register_builtin_fake_ops"),
56 "register_fake_op": ("ops.registry", "register_fake_op"),
57 "register_model_patch": ("patches.registry", "register_model_patch"),
58 "write_memory_snapshot": ("memory_tracker", "write_memory_snapshot"),
59}
62def __getattr__(name: str) -> Any:
63 """Load a public dry-run symbol without importing heavy submodules eagerly."""
64 try:
65 module_name, attribute = _EXPORTS[name]
66 except KeyError as error:
67 raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from error
68 value = getattr(import_module(f"{__name__}.{module_name}"), attribute)
69 globals()[name] = value
70 return value