Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / components / modules / engram / engram_family.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"""Device-table Engram replacement entry point and family registration."""
16from __future__ import annotations
18from collections.abc import Mapping
19from typing import Any
21from torch import nn
23from hyper_parallel.components.modules.family import SelectorSpec, VariantRule
24from hyper_parallel.components.modules.module_family import ModuleFamily, build_family, register_module_family
25from hyper_parallel.models.replacement import module_replacement
27from .engram import engram_sharding
30@module_replacement
31def Engram( # pylint: disable=invalid-name
32 *, config: Any = None, module: nn.Module | None = None,
33 module_fqn: str = "", context: Mapping[str, Any] | None = None, mesh: Any = None,
34 engram_storage_backend: str = "device",
35) -> nn.Module:
36 """Select host/device table storage independently of operator choice and full-module placement."""
37 return build_family(Engram, config=config, module=module, module_fqn=module_fqn,
38 context=context, mesh=mesh, engram_storage_backend=engram_storage_backend)
41register_module_family(ModuleFamily(
42 name="engram", baseline=Engram,
43 variants={"local": "hyper_parallel.components.modules.engram.engram.EngramModule",
44 "host": "hyper_parallel.components.modules.engram.host_engram.HostEngramModule"},
45 selector_specs={"engram_storage_backend": SelectorSpec(str, "device")},
46 default_variant="local", sharding=engram_sharding,
47 variant_rules=(VariantRule({"engram_storage_backend": "host", "parallel": False}, "host"),),
48))