vllm.model_executor.model_loader ¶
Modules:
| Name | Description |
|---|---|
base_loader | |
default_loader | |
dummy_loader | |
ep_weight_filter | Filter out non-local expert weights during loading to avoid redundant I/O. |
gguf_loader | |
modelexpress_loader | |
reload | Layerwise weight reloading utilities for vLLM. |
runai_streamer_loader | |
sharded_state_loader | |
tensorizer | |
tensorizer_loader | |
utils | Utilities for selecting and loading models. |
weight_utils | Utilities for downloading and initializing model weights. |
BaseModelLoader ¶
Bases: ABC
Base class for model loaders.
Source code in vllm/model_executor/model_loader/base_loader.py
download_model abstractmethod ¶
download_model(model_config: ModelConfig) -> None
load_model ¶
load_model(
vllm_config: VllmConfig,
model_config: ModelConfig,
prefix: str = "",
) -> 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
DefaultModelLoader ¶
Bases: BaseModelLoader
Model loader that can load different file types from disk.
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 | |
Source dataclass ¶
A source for weights.
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
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 | |
_init_ep_weight_filter ¶
_init_ep_weight_filter(model_config: ModelConfig) -> None
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 ¶
_prepare_weights(
model_name_or_path: str,
subfolder: str | None,
revision: str | None,
fall_back_to_pt: bool,
allow_patterns_overrides: list[str] | None,
) -> 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
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 | |
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 ¶
_process_online_quant_layer(
layer: Module, info: LayerReloadingInfo
) -> None
Materialize, apply dummy weights, and run quantization processing.
Source code in vllm/model_executor/model_loader/dummy_loader.py
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
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 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 | |
_get_all_gguf_files staticmethod ¶
Discover all GGUF shard files from a single shard path.
Supports variable-width shard indices by dynamically detecting the padding from the original filename. E.g. *-00001-of-00005.gguf → all 5 shards, *-01-of-15.gguf → all 15 shards.
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
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 | |
_get_weights_iterator ¶
_get_weights_iterator(
model_config: ModelConfig,
model_name_or_path: str,
gguf_to_hf_name_map: dict[str, str],
) -> Generator[tuple[str, Tensor], None, None]
Iterate over GGUF model weights, loading from both main model file and mmproj.gguf for multimodal Gemma3 models.
For Gemma3 multimodal GGUF models: - Main file (gemma-3-.gguf): Language model weights (model.) - mmproj file (mmproj.gguf): Vision tower + projector weights (v., mm.*)
Yields:
| Type | Description |
|---|---|
tuple[str, Tensor] | Tuples of (parameter_name, tensor) for all model weights |
Source code in vllm/model_executor/model_loader/gguf_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.
Source code in vllm/model_executor/model_loader/runai_streamer_loader.py
_get_weights_iterator ¶
_get_weights_iterator(
model_or_path: str, revision: str | None
) -> 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/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 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.
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 ¶
_load_model_serialized_cpu(
vllm_config: VllmConfig, prefix: str = ""
) -> Module
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 ¶
load_weights(
model: Module, model_config: ModelConfig
) -> None
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 ¶
get_model_loader(
load_config: LoadConfig,
) -> BaseModelLoader
Get a model loader based on the load format.
Source code in vllm/model_executor/model_loader/__init__.py
register_model_loader ¶
register_model_loader(load_format: str)
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:
| Name | Type | Description | Default |
|---|---|---|---|
load_format | str | The model loader format name. | required |
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'>