vllm.model_executor.model_loader ¶
Modules:
-
base_loader– -
default_loader– -
dummy_loader– -
ep_weight_filter–Filter out non-local expert weights during loading to avoid redundant I/O.
-
modelexpress_loader– -
mtp_validation–Scoped controls for MTP checkpoint completeness validation.
-
reload–Layerwise weight reloading utilities for vLLM.
-
runai_streamer_loader– -
sharded_state_loader– -
tensorizer– -
tensorizer_loader– -
utils–Utilities for selecting and loading models.
-
weight_tying–Reconcile word embedding tying with what the checkpoint actually contains.
-
weight_utils–Utilities for downloading and initializing model weights.
Classes:
-
BaseModelLoader–Base class for model loaders.
-
DefaultModelLoader–Model loader that can load different file types from disk.
-
DummyModelLoader–Model loader that will set model weights to random values.
-
ModelExpressModelLoader–Thin vLLM loader wrapper for ModelExpress.
-
RunaiModelStreamerLoader–Model loader that can load safetensors
-
ShardedStateLoader–Model loader that directly loads each worker's model state dict, which
-
TensorizerLoader–Model loader using CoreWeave's tensorizer library.
Functions:
-
get_model_loader–Get a model loader based on the load format.
-
register_model_loader–Register a customized vllm model loader.
BaseModelLoader ¶
Bases: ABC
Base class for model loaders.
Methods:
-
download_model–Download a model so that it can be immediately loaded.
-
load_model–Load a model with the given configurations.
-
load_weights–Load weights into a model. This standalone API allows
Source code in vllm/model_executor/model_loader/base_loader.py
download_model(model_config) abstractmethod ¶
load_model(vllm_config, model_config, prefix='') ¶
Load a model with the given configurations.
Source code in vllm/model_executor/model_loader/base_loader.py
load_weights(model, model_config) abstractmethod ¶
Load weights into a model. This standalone API allows inplace weights loading for an already-initialized model
Source code in vllm/model_executor/model_loader/base_loader.py
DefaultModelLoader ¶
Bases: BaseModelLoader
Model loader that can load different file types from disk.
Classes:
-
Source–A source for weights.
Source code in vllm/model_executor/model_loader/default_loader.py
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 100 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 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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
Source dataclass ¶
A source for weights.
Attributes:
-
allow_patterns_overrides(list[str] | None) –If defined, weights will load exclusively using these patterns.
-
fall_back_to_pt(bool) –Whether .pt weights can be used.
-
model_or_path(str) –The model ID or path.
-
prefix(str) –A prefix to prepend to all weights.
-
revision(str | None) –The optional model revision.
-
subfolder(str | None) –The subfolder inside the model repo.
Source code in vllm/model_executor/model_loader/default_loader.py
allow_patterns_overrides = None class-attribute instance-attribute ¶
If defined, weights will load exclusively using these patterns.
fall_back_to_pt = True class-attribute instance-attribute ¶
Whether .pt weights can be used.
model_or_path instance-attribute ¶
The model ID or path.
prefix = '' class-attribute instance-attribute ¶
A prefix to prepend to all weights.
revision instance-attribute ¶
The optional model revision.
subfolder = None class-attribute instance-attribute ¶
The subfolder inside the model repo.
_get_weights_iterator(source) ¶
Get an iterator for the model weights based on the load format.
Source code in vllm/model_executor/model_loader/default_loader.py
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 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
_init_ep_weight_filter(model_config) ¶
Compute local expert ids for EP weight filtering.
When expert parallelism is active, each rank only needs a subset of expert weights. By computing the set upfront we can skip non-local expert tensors before reading them from disk.
Source code in vllm/model_executor/model_loader/default_loader.py
_prepare_weights(model_name_or_path, subfolder, revision, fall_back_to_pt, allow_patterns_overrides) ¶
Prepare weights for the model.
If the model is not local, it will be downloaded.
Source code in vllm/model_executor/model_loader/default_loader.py
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 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 | |
DummyModelLoader ¶
Bases: BaseModelLoader
Model loader that will set model weights to random values.
Source code in vllm/model_executor/model_loader/dummy_loader.py
_process_online_quant_layer(layer, info) ¶
Materialize, apply dummy weights, and run quantization processing.
Source code in vllm/model_executor/model_loader/dummy_loader.py
ModelExpressModelLoader ¶
Bases: BaseModelLoader
Thin vLLM loader wrapper for ModelExpress.
Source code in vllm/model_executor/model_loader/modelexpress_loader.py
RunaiModelStreamerLoader ¶
Bases: BaseModelLoader
Model loader that can load safetensors files from local FS, S3, GCS, or Azure Blob Storage.
Methods:
-
download_model–Download model if necessary
-
load_weights–Load weights into a model.
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
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 100 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 | |
_get_weights_iterator(model_or_path, revision) ¶
Get an iterator for the model weights based on the load format.
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
_prepare_weights(model_name_or_path, revision) ¶
Prepare weights for the model.
If the model is not local, it will be downloaded.
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
download_model(model_config) ¶
load_weights(model, model_config) ¶
Load weights into a model.
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
ShardedStateLoader ¶
Bases: BaseModelLoader
Model loader that directly loads each worker's model state dict, which enables a fast load path for large tensor-parallel models where each worker only needs to read its own shard rather than the entire checkpoint. See examples/features/sharded_state/save_sharded_state_offline.py for creating a sharded checkpoint.
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
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 100 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 203 204 205 206 207 208 209 210 211 212 213 214 | |
_filter_subtensors(tensors) staticmethod ¶
Filter out all tensors that share the same memory or a subset of the memory of another tensor.
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
TensorizerLoader ¶
Bases: BaseModelLoader
Model loader using CoreWeave's tensorizer library.
Methods:
-
load_weights–Load serialized model weights with tensorizer.
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
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 100 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 | |
_load_model_serialized_cpu(vllm_config, prefix='') ¶
Load a serialized model with tensorizer to the CPU.
This is only necessary when the model isn't vLLM-tensorized (see examples/features/tensorize_vllm_model.py) This should still be faster than default HuggingFace loading, but will be slower than loading a vLLM-tensorized model.
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
load_weights(model, model_config) ¶
Load serialized model weights with tensorizer.
Expects a vLLM-tensorized model. See the examples/features/tensorize_vllm_model.py example script for serializing vLLM models.
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
get_model_loader(load_config) ¶
Get a model loader based on the load format.
Source code in vllm/model_executor/model_loader/__init__.py
register_model_loader(load_format) ¶
Register a customized vllm model loader.
When a load format is not supported by vllm, you can register a customized model loader to support it.
Parameters:
Examples:
>>> from vllm.config.load import LoadConfig
>>> from vllm.model_executor.model_loader import (
... get_model_loader,
... register_model_loader,
... )
>>> from vllm.model_executor.model_loader.base_loader import BaseModelLoader
>>>
>>> @register_model_loader("my_loader")
... class MyModelLoader(BaseModelLoader):
... def download_model(self):
... pass
...
... def load_weights(self):
... pass
>>>
>>> load_config = LoadConfig(load_format="my_loader")
>>> type(get_model_loader(load_config))
<class 'MyModelLoader'>