Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_multicore / scheduler / builder.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-15 05:03 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-11-15 05:03 +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"""
16Standalone RuntimeConfig builder.
18build_runtime_config() is the generic framework entry point for converting a
19ComputeGraph + TaskSplitValue into a binary RuntimeConfigC. It omits
20graph-specific post-processing (add_terminate, revise_task_queue, etc.) — call
21build_config_for_rank() from a model's gen_runtime_data.py for full generation.
22"""
23from hyper_multicore._core_spec import DEFAULT_CORE_SPEC
24from hyper_multicore.scheduler.config import (
25 RuntimeConfigC,
26 TaskSplitValue,
27 init_task_split_value,
28 mega_moe_event_capacity,
29)
30from hyper_multicore.scheduler.graph import ComputeGraph
31from hyper_multicore.scheduler.runtime import allocate_runtime_config
34def allocate_graph_config(graph: ComputeGraph, tsv: TaskSplitValue,
35 num_cube_cores: int = DEFAULT_CORE_SPEC.num_cube_cores) -> RuntimeConfigC:
36 """Allocate graph tasks plus the terminal before any fill operation.
38 Args:
39 graph: Graph after split propagation.
40 tsv: Topology whose experts determine event storage.
41 num_cube_cores: Available Cube workers whose group lists need scratch.
43 Returns:
44 Zero-initialized runtime with sufficient task, queue and event slots.
45 """
46 required = 1 + sum(op.task_num for op in graph.topological_sort())
47 return allocate_runtime_config(
48 required, mega_moe_event_capacity(tsv.all_expert_num, tsv.ep), tsv.single_rank_expert_num,
49 num_workers=2 * num_cube_cores,
50 )
53def build_runtime_config(graph: ComputeGraph, tsv: TaskSplitValue,
54 rank_id: int = 0,
55 num_cube_cores: int = DEFAULT_CORE_SPEC.num_cube_cores) -> RuntimeConfigC:
56 """
57 Build RuntimeConfigC for a single rank from a ComputeGraph.
59 Args:
60 graph: A fully-built ComputeGraph after propagate_splits() has been called.
61 tsv: TaskSplitValue with TP/EP/seq topology.
62 rank_id: Target rank (written to tsv.rank_id before filling).
63 num_cube_cores: Number of Cube workers.
65 Returns:
66 RuntimeConfigC ready to be serialized with serialize_runtime_config(cfg).
67 """
68 cfg = allocate_graph_config(graph, tsv, num_cube_cores)
69 cfg.num_workers = 2 * num_cube_cores
71 init_task_split_value(tsv)
72 tsv.rank_id = rank_id
74 for op in graph.topological_sort():
75 op.fill_config.fill(cfg, op, tsv)
77 cfg.task_num = sum(op.task_num for op in graph.topological_sort())
78 cfg.atomic_add_values[0] = 1
79 return cfg