vllm.model_executor.model_loader.reload.bake
¶
The load plan's bake: run load_weights once over TraceTensors, on
the model's real tensors as begin_direct_reload left them, and record each
copy_ from a trace and every reason a name cannot be written directly.
A trace has no data, so nothing it feeds reaches memory: its copy_ is
recorded, and any other op on it runs on meta copies of its arguments. Ops on
real tensors alone run for real: _TargetGuard makes a loader that reads a
checkpoint tensor a fallback, and constant writes into one (fill_,
zero_) happen, mid-update, and stay out of the plan (post-load processing
owns padding).
Classes:
-
Copy–One
dest.copy_(src)from a trace. -
Target–A checkpoint tensor, as a write destination.
-
Targets–Every checkpoint tensor in the layout
begin_direct_reloadapplied,
Functions:
-
trace_loads–Bake all names (see
_bake). A name that stopped the loader falls
Copy
dataclass
¶
One dest.copy_(src) from a trace.
Source code in vllm/model_executor/model_loader/reload/bake.py
Target
dataclass
¶
A checkpoint tensor, as a write destination.
Source code in vllm/model_executor/model_loader/reload/bake.py
Targets
¶
Every checkpoint tensor in the layout begin_direct_reload applied,
by storage and by name. Writes name their tensor, for readable plans and
tests; by_name looks it up.
Source code in vllm/model_executor/model_loader/reload/bake.py
_BakeStopped
¶
Bases: Exception
A loader needs a traced tensor's values, or an op on it fails on meta:
the loader cannot continue. name is the trace's name.
Source code in vllm/model_executor/model_loader/reload/bake.py
_PlanSink
dataclass
¶
One bake's record. Traces call accept_copy for a copy_ from
them, unsupported for any other op outside VIEW_OPS and
value_read for .item() and the like; it turns these into copies,
fallbacks and bake stops.
Methods:
-
unsupported–Mark the names fallbacks and run
funcon meta copies of its
Source code in vllm/model_executor/model_loader/reload/bake.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
unsupported(func, args, kwargs, traces)
¶
Mark the names fallbacks and run func on meta copies of its
arguments, so it writes no real tensor; tensor results become traces
of the first name, with no geometry.
Source code in vllm/model_executor/model_loader/reload/bake.py
_SinkClosed
¶
Bases: RuntimeError
A trace was used after its bake ended.
_TargetGuard
¶
Bases: TorchDispatchMode
Ops on real tensors alone run for real. One that reads a checkpoint
tensor (not a view, not only its metadata) makes the last name written
into that storage (or the name being loaded) a fallback: the direct path
would skip it. For example composed_weight_loader's
param.copy_(fn(param)), a check such as torch.equal(param, x), or
a mirror copied from param. Reads that bypass the dispatcher
(tolist() or numpy() of a CPU tensor, a raw kernel launch) go
unseen.
Source code in vllm/model_executor/model_loader/reload/bake.py
_bake(model, metas, targets)
¶
Trace load_weights over every name, in one pass. A name that stops
the loader (a value read, an op that fails on meta) unwinds the model's
load_weights; it falls back, and load_weights is called again
with the names after it, on the same sink. Loaders handle each name as it
arrives, so nothing is replayed.
Module state a loader sets stays: it is what that loader would leave on
the load_weights path.
Source code in vllm/model_executor/model_loader/reload/bake.py
_writes_a_real_tensor(func, args, kwargs)
¶
Whether func writes an argument that is not a trace (in place or
through out=).
Source code in vllm/model_executor/model_loader/reload/bake.py
trace_loads(model, metas, targets)
¶
Bake all names (see _bake). A name that stopped the loader falls
back; what it recorded before stopping is dropped.