Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / auto_parallel / hyper_offload / ir / trace.py: 100%
26 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"""Scheduler input model for activation residency planning."""
17from __future__ import annotations
19from dataclasses import dataclass, field
20from enum import Enum, auto
23class AccessKind(Enum):
24 """How an op accesses a storage."""
26 READ = auto()
27 WRITE = auto()
30@dataclass
31class StorageAccess:
32 """A storage access made by an op."""
34 op_id: int
35 storage_id: int
36 kind: AccessKind
39@dataclass
40class TraceOp:
41 """A scheduler-visible execution op."""
43 name: str
44 duration_ms: float = 0.0
45 accesses: list[StorageAccess] = field(default_factory=list)
48@dataclass
49class ActivationTrace:
50 """Scheduler input: ordered ops plus storage metadata.
52 ``preferred_eviction_gaps`` contains optional ``(storage_id, start, end)``
53 preferences. A planner may prioritize these intervals to preserve native
54 autograd replay, but must retain its ordinary memory-budget constraints.
55 ``framework_allocation_bytes`` records the largest fresh framework output
56 without adopting its storage, so native plans can leave allocator slack.
57 """
59 ops: list[TraceOp] = field(default_factory=list)
60 storage_sizes: dict[int, int] = field(default_factory=dict)
61 retained_sids: set[int] = field(default_factory=set)
62 memory_limit_bytes: int | None = None
63 d2h_bandwidth_gbps: float = 16.0
64 h2d_bandwidth_gbps: float = 16.0
65 preferred_eviction_gaps: list[tuple[int, int, int]] = field(default_factory=list)
66 framework_allocation_bytes: int = 0