vllm.model_executor.model_loader.checkpoint_weight_patch ¶
Apply dense or sparse weight updates in checkpoint coordinates.
The model's load_weights method still handles checkpoint-name mapping, TP slicing, and packed parameters. Sparse patches use NaN to mark unchanged checkpoint elements. The supported sparse-loader contract permits only final same-shaped floating-point Tensor.copy_ writes. Composed, multi-stage, and custom-write loaders are unsupported.
Classes:
-
CheckpointWeightPatch–Describe one dense or sparse checkpoint-coordinate update.
Functions:
-
load_checkpoint_weight_patches–Load ordered patches through the model's checkpoint loader.
CheckpointWeightPatch ¶
Bases: NamedTuple
Describe one dense or sparse checkpoint-coordinate update.
Attributes:
-
name(str) –Checkpoint weight name passed to the model loader.
-
shape(tuple[int, ...]) –Full checkpoint tensor shape.
-
dtype(dtype) –Checkpoint tensor dtype.
-
values(Tensor) –The flattened full tensor for a dense patch, or the values at
indicesfor a sparse patch. -
indices(Tensor | None) –Flat indices into the full checkpoint tensor described by
shape.Nonemakesvaluesa dense replacement.
Source code in vllm/model_executor/model_loader/checkpoint_weight_patch.py
_load_nan_masked_weights(model, weights) ¶
Load NaN-masked checkpoint tensors while preserving runtime values at NaNs.
Source code in vllm/model_executor/model_loader/checkpoint_weight_patch.py
load_checkpoint_weight_patches(model, patches, *, max_chunk_bytes=_DEFAULT_PATCH_CHUNK_BYTES, validate_unique_indices=True) ¶
Load ordered patches through the model's checkpoint loader.
A call may contain either dense or sparse patches, but not both. A repeated name starts a new loader call, so patches for that weight are applied in input order. A later patch may update positions changed by an earlier patch. Each sparse patch creates a full checkpoint-shaped tensor whose NaNs mark unchanged elements. Each locally applied sparse patch must use one final same-shaped floating-point Tensor.copy_. Intermediate or unrelated copy_ calls, composed loaders, and custom write paths are unsupported. max_chunk_bytes is a batching target; one tensor may exceed it.
Online checkpoint-format dense updates require the caller to manage vLLM's layerwise reload lifecycle. Sparse online updates modify initialized model tensors in place and must not use that lifecycle. Patch shapes, dtypes, value lengths, and sparse indices are validated before loading begins.
This function does not roll back a partial update. If a loader fails after a write, some destinations may already be changed. Do not serve from the affected worker until a known baseline has been restored or the worker has been restarted.
Parameters:
-
(model¶Module) –Model whose native
load_weightsmethod applies the patches. -
(patches¶Iterable[CheckpointWeightPatch]) –Dense replacements or sparse updates in checkpoint coordinates.
-
(max_chunk_bytes¶int, default:_DEFAULT_PATCH_CHUNK_BYTES) –Target checkpoint tensor bytes per
model.load_weightscall. A single tensor may exceed this target. -
(validate_unique_indices¶bool, default:True) –Whether to reject duplicate sparse indices within each patch. Repeated patches may update the same positions. Disable only for a trusted producer that already guarantees unique positions within each patch.
Returns:
Source code in vllm/model_executor/model_loader/checkpoint_weight_patch.py
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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |