1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
"""Refit cycle ownership for the RL generator path.
:mod:`modelexpress.refit.timing` owns the record, the stage vocabulary and the
recording helpers. This module owns only the thing that was missing on this
path: a cycle. The recorder is populated while one is active, so with nothing
activating it the RL client produced no stages at all, and a framework asking
where a refit spent its time could only see the total.
That gap was measurable from outside. Instrumenting a refit at the framework
boundary attributed about 18% of it, because the boundary can only see
``stage``, ``apply`` and ``release`` -- three calls, one of which contains the
wire transfer, the reconstruction, post-load processing and the copy into kernel
storage, all charged together as "install".
A cycle here spans two client calls, ``stage_weight`` and ``apply_weight``, with
the caller's own work in between at a safe point of its choosing. So it cannot be
one ``with`` block; the recorder is created when staging starts, carried on the
staged handle, and re-activated for the apply. Its ``e2e_ms`` is therefore
staging through install, including the caller's pause, which is why the stage
durations are what to read for transport cost.
Layers contributing stages inside a cycle should reach for
:func:`modelexpress.refit.timing.refit_span` directly rather than anything here.
"""
=
"""Open a recorder for one generator refit, or ``None`` when disabled.
Returning ``None`` rather than a dummy keeps the disabled path free of the
recorder entirely, and every consumer here already has to handle the absence
of a cycle, since lower layers are also reachable from callers that never
started one.
"""
return None
# A caller driving its own cycle wins. Nesting a second recorder would
# split one refit across two records and leave both looking incomplete.
return None
return
"""Make ``recorder`` visible to the layers that contribute stages."""
yield
return
yield
"""Emit the cycle's record, once, if there is one.
Idempotent in the recorder, which is what lets the client call this from
both the apply and the release path: whichever ends the cycle reports it,
and a refit that failed before applying is still reported rather than
vanishing.
"""
return
return None
=