Coverage for / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / auto_parallel / hyper_offload / api / opaque.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-07-06 05:41 +0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-07-06 05:41 +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"""Public API: skip_offload decorator for opaque offload regions.
17Delegates all interval recording or fast-path switching to the active
18:class:`~offload.execution.base.BaseExecutor` via
19:meth:`execute_opaque_op`.
20"""
22from __future__ import annotations
24import functools
25from collections.abc import Callable
26from typing import Any, TypeVar
28from hyper_parallel.auto_parallel.hyper_offload.api.session import OffloadSession
30F = TypeVar("F", bound=Callable[..., Any])
33def skip_offload(fn: F) -> F:
34 """Decorate a callable as a virtual op offload region.
36 The decorator wraps the function execution into a single "virtual op"
37 in the execution trace, while suspending fine-grained tracing for
38 internal operations.
39 """
40 if not callable(fn):
41 raise TypeError("skip_offload only supports decorator usage")
43 @functools.wraps(fn)
44 def wrapper(*args: Any, **kwargs: Any) -> Any:
45 """Wrap the function to skip offloading."""
46 session: OffloadSession | None = OffloadSession.get_active()
47 if session is None:
48 return fn(*args, **kwargs)
50 return session.executor.execute_opaque_op(fn.__name__, fn, args, kwargs)
52 return wrapper