vllm.model_executor.model_loader
Modules:
Name | Description |
---|---|
base_loader |
|
bitsandbytes_loader |
|
default_loader |
|
dummy_loader |
|
gguf_loader |
|
neuron |
Utilities for selecting and loading Neuron models in transformers-neuronx |
neuronx_distributed |
Utilities for selecting and loading Neuron models in |
runai_streamer_loader |
|
sharded_state_loader |
|
tensorizer |
|
tensorizer_loader |
|
tpu |
|
utils |
Utilities for selecting and loading models. |
weight_utils |
Utilities for downloading and initializing model weights. |
__all__
module-attribute
¶
__all__ = [
"get_model",
"get_model_loader",
"get_architecture_class_name",
"get_model_architecture",
"get_model_cls",
"BaseModelLoader",
"BitsAndBytesModelLoader",
"GGUFModelLoader",
"DefaultModelLoader",
"DummyModelLoader",
"RunaiModelStreamerLoader",
"ShardedStateLoader",
"TensorizerLoader",
]
BaseModelLoader
¶
Bases: ABC
Base class for model loaders.
Source code in vllm/model_executor/model_loader/base_loader.py
__init__
¶
__init__(load_config: LoadConfig)
download_model
abstractmethod
¶
download_model(model_config: ModelConfig) -> None
load_model
¶
load_model(
vllm_config: VllmConfig, model_config: ModelConfig
) -> Module
Load a model with the given configurations.
Source code in vllm/model_executor/model_loader/base_loader.py
load_weights
abstractmethod
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
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
BitsAndBytesModelLoader
¶
Bases: BaseModelLoader
Model loader to load model weights with BitAndBytes quantization.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
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 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
|
maybe_fused_weights_modules
instance-attribute
¶
possible_config_file_names
class-attribute
instance-attribute
¶
__init__
¶
__init__(load_config: LoadConfig)
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_classify_module_sharding
¶
_classify_module_sharding(model: Module)
Categorize modules based on their weight sharding requirements for tensor parallelism.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_get_bnb_target_modules
¶
_get_bnb_target_modules(model: Module) -> None
Identify and collect all modules that support BitsAndBytes quantization.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_get_quantized_weights_iterator
¶
_get_quantized_weights_iterator(
model_name_or_path: str, revision: Optional[str]
) -> tuple[
Generator[tuple[str, Tensor], None, None],
dict[str, Any],
]
Get an iterator to the model weights with bitsandbytes quantization, as well as the quantization state dictionary.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_get_weight_files
¶
_get_weight_files(
model_name_or_path: str,
allowed_patterns: list[str],
revision: Optional[str] = None,
) -> tuple[str, list[str], str]
Retrieve weight files. Download the files if necessary.
Return the weight files and the file pattern.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_hf_weight_iter
¶
_hf_weight_iter(hf_weights_files, use_safetensors: bool)
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_initialize_loader_state
¶
_initialize_loader_state(
model: Module, model_config: ModelConfig
) -> None
Initialize the loader's internal state based on the model and configuration.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_is_4bit_weight_name
¶
_is_4bit_weight_name(weight_name: str)
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_prepare_weights
¶
Prepare weight files for the model.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_quantized_4bit_generator
¶
_quantized_4bit_generator(
hf_weights_files, use_safetensors, quant_state_dict
) -> Generator
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_quantized_8bit_generator
¶
_quantized_8bit_generator(
hf_weights_files, use_safetensors, quant_state_dict
) -> Generator
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
_unquantized_generator
¶
_unquantized_generator(
hf_weights_files, use_safetensors, quant_state_dict
) -> Generator
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
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 |
|
_verify_model_compatibility
¶
_verify_model_compatibility(
model: Module, model_config: ModelConfig
) -> None
Verify that the model is compatible with BitsAndBytes quantization.
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
download_model
¶
download_model(model_config: ModelConfig) -> None
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
Source code in vllm/model_executor/model_loader/bitsandbytes_loader.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
|
DefaultModelLoader
¶
Bases: BaseModelLoader
Model loader that can load different file types from disk.
Source code in vllm/model_executor/model_loader/default_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 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 |
|
counter_after_loading_weights
class-attribute
instance-attribute
¶
counter_after_loading_weights: float = 0.0
counter_before_loading_weights
class-attribute
instance-attribute
¶
counter_before_loading_weights: float = 0.0
Source
dataclass
¶
A source for weights.
Source code in vllm/model_executor/model_loader/default_loader.py
__init__
¶
__init__(load_config: LoadConfig)
Source code in vllm/model_executor/model_loader/default_loader.py
_get_weights_iterator
¶
Get an iterator for the model weights based on the load format.
Source code in vllm/model_executor/model_loader/default_loader.py
_maybe_download_from_modelscope
¶
Download model from ModelScope hub if VLLM_USE_MODELSCOPE is True.
Returns the path to the downloaded model, or None if the model is not downloaded from ModelScope.
Source code in vllm/model_executor/model_loader/default_loader.py
_prepare_weights
¶
_prepare_weights(
model_name_or_path: str,
revision: Optional[str],
fall_back_to_pt: bool,
allow_patterns_overrides: Optional[list[str]],
) -> tuple[str, list[str], bool]
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
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 |
|
download_model
¶
download_model(model_config: ModelConfig) -> None
get_all_weights
¶
get_all_weights(
model_config: ModelConfig, model: Module
) -> Generator[tuple[str, Tensor], None, None]
Source code in vllm/model_executor/model_loader/default_loader.py
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
Source code in vllm/model_executor/model_loader/default_loader.py
DummyModelLoader
¶
Bases: BaseModelLoader
Model loader that will set model weights to random values.
Source code in vllm/model_executor/model_loader/dummy_loader.py
__init__
¶
__init__(load_config: LoadConfig)
Source code in vllm/model_executor/model_loader/dummy_loader.py
download_model
¶
download_model(model_config: ModelConfig) -> None
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
GGUFModelLoader
¶
Bases: BaseModelLoader
Model loader that can load GGUF files. This is useful for loading models that are quantized with GGUF and saved in the GGUF format. This loader supports loading both full models and sharded models.
Source code in vllm/model_executor/model_loader/gguf_loader.py
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
__init__
¶
__init__(load_config: LoadConfig)
Source code in vllm/model_executor/model_loader/gguf_loader.py
_get_gguf_weights_map
¶
_get_gguf_weights_map(model_config: ModelConfig)
GGUF uses this naming convention for their tensors from HF checkpoint:
blk.N.BB.weight
and blk.N.BB.bias
where N signifies the block number of a layer, and BB signifies the
attention/mlp layer components.
See "Standardized tensor names" in
https://github.com/ggerganov/ggml/blob/master/docs/gguf.md for details.
Source code in vllm/model_executor/model_loader/gguf_loader.py
_get_weights_iterator
¶
_get_weights_iterator(
model_name_or_path: str,
gguf_to_hf_name_map: dict[str, str],
) -> Generator[tuple[str, Tensor], None, None]
Source code in vllm/model_executor/model_loader/gguf_loader.py
download_model
¶
download_model(model_config: ModelConfig) -> None
load_model
¶
load_model(
vllm_config: VllmConfig, model_config: ModelConfig
) -> Module
Source code in vllm/model_executor/model_loader/gguf_loader.py
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
Source code in vllm/model_executor/model_loader/gguf_loader.py
RunaiModelStreamerLoader
¶
Bases: BaseModelLoader
Model loader that can load safetensors files from local FS or S3 bucket.
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
__init__
¶
__init__(load_config: LoadConfig)
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
_get_weights_iterator
¶
_get_weights_iterator(
model_or_path: str, revision: str
) -> Generator[tuple[str, Tensor], None, None]
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
¶
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
¶
download_model(model_config: ModelConfig) -> None
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
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/offline_inference/save_sharded_state.py
for creating a sharded
checkpoint.
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
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 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 |
|
DEFAULT_PATTERN
class-attribute
instance-attribute
¶
__init__
¶
__init__(
load_config: LoadConfig,
runai_model_streamer: bool = False,
)
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
_filter_subtensors
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
_prepare_weights
¶
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
download_model
¶
download_model(model_config: ModelConfig) -> None
iterate_over_files
¶
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
save_model
staticmethod
¶
save_model(
model: Module,
path: str,
pattern: Optional[str] = None,
max_size: Optional[int] = None,
) -> None
Source code in vllm/model_executor/model_loader/sharded_state_loader.py
TensorizerLoader
¶
Bases: BaseModelLoader
Model loader using CoreWeave's tensorizer library.
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
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 |
|
__init__
¶
__init__(load_config: LoadConfig)
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
_get_weights_iterator
¶
_load_model_serialized_cpu
¶
_load_model_serialized_cpu(
vllm_config: VllmConfig,
) -> Module
Load a serialized model with tensorizer to the CPU.
This is only necessary when the model isn't vLLM-tensorized (see examples/others/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
_patch_tensorizer_config
¶
_patch_tensorizer_config(
model_config: ModelConfig,
) -> TensorizerConfig
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
_verify_config
¶
_verify_config(
model_config: ModelConfig,
parallel_config: ParallelConfig,
)
download_model
¶
download_model(model_config: ModelConfig) -> None
load_model
¶
load_model(
vllm_config: VllmConfig, model_config: ModelConfig
) -> Module
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
load_weights
¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
Load serialized model weights with tensorizer.
Expects a vLLM-tensorized model. See the examples/others/tensorize_vllm_model.py example script for serializing vLLM models.
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
save_model
staticmethod
¶
save_model(
model: Module,
tensorizer_config: Union[TensorizerConfig, dict],
) -> None
Source code in vllm/model_executor/model_loader/tensorizer_loader.py
get_architecture_class_name
¶
get_architecture_class_name(
model_config: ModelConfig,
) -> str
get_model
¶
get_model(
*,
vllm_config: VllmConfig,
model_config: Optional[ModelConfig] = None,
) -> Module
Source code in vllm/model_executor/model_loader/__init__.py
get_model_architecture
¶
get_model_architecture(
model_config: ModelConfig,
) -> tuple[type[Module], str]
Source code in vllm/model_executor/model_loader/utils.py
get_model_cls
¶
get_model_cls(model_config: ModelConfig) -> type[Module]
get_model_loader
¶
get_model_loader(
load_config: LoadConfig,
) -> BaseModelLoader
Get a model loader based on the load format.