Skip to content

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: replays don't redo them. begin zero-fills params flagged fill_on_reload (padded RoutedExperts params, MergedColumnParallelLinear output padding), so padding a loader fills in those stays 0 on replays, e.g. block scales under tp_shard_with_padding (1 at cold start). Padding a loader fills in unflagged params, such as vocab rows, keeps its bytes. Outputs are unaffected: the padded weights are 0.

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_reload applied,

Functions:

  • trace_loads –

    Bake all names (see _bake). A name that stopped the loader falls

Copy dataclass

One dest.copy_(src) from a trace.

Target dataclass

A checkpoint tensor, as a write destination.

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.

_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.

_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 func on meta copies of its

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.

_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.

_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.

_writes_a_real_tensor(func, args, kwargs)

Whether func writes an argument that is not a trace (in place or through out=).

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.