Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / codegen / inline / specs.py: 75%
8 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-10-25 05:45 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-10-25 05:45 +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"""Resolve inline declarations for a YAML target.
17The declarations are *derived from structure* — the family's own runtime
18replacement factories and the framework archetype table — never read from a
19per-family render spec. This module is the single lookup site the inline
20passes share, so the resolution rule is stated once.
21"""
23from __future__ import annotations
25from hyper_parallel.codegen.inline.framework_spec import (
26 replacement_spec_for,
27 strategy_spec_for,
28)
29from hyper_parallel.codegen.inline.spec_bundle import ReplacementSpec, StrategySpec
32def replacement_spec(
33 target: str | None,
34 model_type: str | None = None,
35 *,
36 module_type: str | None = None,
37) -> ReplacementSpec | None:
38 """Resolve a YAML ``replace_module`` target to its component replacement.
40 ``module_type`` is the rule's matched source type from the YAML; it names
41 the source class the generated artifact must model, so it is passed rather
42 than reconstructed.
43 """
44 return replacement_spec_for(target, model_type, module_type=module_type)
47def strategy_spec(
48 target: str | None,
49 model_type: str | None = None,
50 *,
51 inner_wrapper: bool = False,
52) -> StrategySpec | None:
53 """Resolve a YAML strategy target to its parallel strategy.
55 ``inner_wrapper`` marks the target as a ``plan_overrides.inner_wrapper``
56 declaration: only that position makes a CP attention wrapper a strategy
57 (a ``local_compute_fn`` in the same slot is not one).
58 """
59 return strategy_spec_for(target, model_type, inner_wrapper=inner_wrapper)
62__all__ = ["replacement_spec", "strategy_spec"]