Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / auto_parallel / hyper_offload / api / config.py: 100%
18 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"""Configuration for hyper-offload."""
17from __future__ import annotations
19from dataclasses import dataclass
21from hyper_parallel.auto_parallel.hyper_offload.planning.base import ResidencyPlanner
24@dataclass
25class OffloadConfig:
26 """Configuration for the offload system.
28 Args:
29 max_resident_activation_mb: Maximum resident activation memory on device, in MiB.
30 max_offload_activation_mb: Maximum pinned host memory for offload buffers, in MiB.
31 Defaults to 65536 (64 GiB).
32 planner: Optional residency planner implementation. Defaults to peak planning
33 with communication masking.
35 """
37 max_resident_activation_mb: int = 1024
38 max_offload_activation_mb: int = 65536
39 planner: ResidencyPlanner | None = None
42# Python 3.10+ dataclass options are absent from the gate checker's older stdlib model.
43@dataclass(kw_only=True) # pylint: disable=unexpected-keyword-arg
44class HyperOffloadConfig(OffloadConfig):
45 """Add an opt-in Trainer switch while reusing the offload budgets."""
47 enable: bool = False
49 def __post_init__(self) -> None:
50 """Validate budgets before training allocates model memory."""
51 if not isinstance(self.enable, bool):
52 raise TypeError("hyper_offload.enable must be a bool")
53 for name in ("max_resident_activation_mb", "max_offload_activation_mb"):
54 value = getattr(self, name)
55 if isinstance(value, bool) or not isinstance(value, int) or value <= 0:
56 raise ValueError(f"hyper_offload.{name} must be a positive integer")