vllm.model_executor.model_loader.tensorizer
__all__ module-attribute
¶
__all__ = [
"EncryptionParams",
"DecryptionParams",
"TensorDeserializer",
"TensorSerializer",
"open_stream",
"convert_bytes",
"get_mem_usage",
"no_init_or_tensor",
"TensorizerConfig",
]
MetaTensorMode ¶
Bases: TorchDispatchMode
Source code in vllm/model_executor/model_loader/tensorizer.py
__torch_dispatch__ ¶
TensorizerArgs dataclass
¶
Source code in vllm/model_executor/model_loader/tensorizer.py
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 |
|
deserialization_kwargs instance-attribute
¶
deserialization_kwargs = {
"verify_hash": verify_hash,
"encryption": encryption_keyfile,
"num_readers": num_readers,
None: deserialization_kwargs or {},
}
s3_secret_access_key instance-attribute
¶
s3_secret_access_key = (
s3_secret_access_key or S3_SECRET_ACCESS_KEY
)
stream_kwargs instance-attribute
¶
stream_kwargs = {
"s3_access_key_id": s3_access_key_id,
"s3_secret_access_key": s3_secret_access_key,
"s3_endpoint": s3_endpoint,
None: stream_kwargs or {},
}
__init__ ¶
__init__(tensorizer_config: TensorizerConfig)
Source code in vllm/model_executor/model_loader/tensorizer.py
add_cli_args staticmethod
¶
add_cli_args(
parser: FlexibleArgumentParser,
) -> FlexibleArgumentParser
Tensorizer CLI arguments
Source code in vllm/model_executor/model_loader/tensorizer.py
from_cli_args classmethod
¶
from_cli_args(args: Namespace) -> TensorizerArgs
Source code in vllm/model_executor/model_loader/tensorizer.py
TensorizerConfig dataclass
¶
Bases: MutableMapping
Source code in vllm/model_executor/model_loader/tensorizer.py
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 |
|
_extra_serialization_attrs class-attribute
instance-attribute
¶
_is_sharded class-attribute
instance-attribute
¶
_keys class-attribute
¶
Args for the TensorizerConfig class. These are used to configure the behavior of model serialization and deserialization using Tensorizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensorizer_uri | Path to serialized model tensors. Can be a local file path or a S3 URI. This is a required field unless lora_dir is provided and the config is meant to be used for the | required | |
tensorizer_dir | Path to a directory containing serialized model tensors, and all other potential model artifacts to load the model, such as configs and tokenizer files. Can be passed instead of | required | |
vllm_tensorized | If True, indicates that the serialized model is a vLLM model. This is used to determine the behavior of the TensorDeserializer when loading tensors from a serialized model. It is far faster to deserialize a vLLM model as it utilizes tensorizer's optimized GPU loading. Note that this is now deprecated, as serialized vLLM models are now automatically inferred as vLLM models. | required | |
verify_hash | If True, the hashes of each tensor will be verified against the hashes stored in the metadata. A | required | |
num_readers | Controls how many threads are allowed to read concurrently from the source file. Default is | required | |
encryption_keyfile | File path to a binary file containing a | required | |
s3_access_key_id | The access key for the S3 bucket. Can also be set via the S3_ACCESS_KEY_ID environment variable. | required | |
s3_secret_access_key | The secret access key for the S3 bucket. Can also be set via the S3_SECRET_ACCESS_KEY environment variable. | required | |
s3_endpoint | The endpoint for the S3 bucket. Can also be set via the S3_ENDPOINT_URL environment variable. | required | |
lora_dir | Path to a directory containing LoRA adapter artifacts for serialization or deserialization. When serializing LoRA adapters this is the only necessary parameter to pass to this object's initializer. | required |
deserialization_kwargs class-attribute
instance-attribute
¶
dtype class-attribute
instance-attribute
¶
hf_config class-attribute
instance-attribute
¶
model_class class-attribute
instance-attribute
¶
s3_secret_access_key class-attribute
instance-attribute
¶
serialization_kwargs class-attribute
instance-attribute
¶
__delitem__ ¶
__getitem__ ¶
__init__ ¶
__init__(
tensorizer_uri: Optional[str] = None,
tensorizer_dir: Optional[str] = None,
vllm_tensorized: Optional[bool] = None,
verify_hash: Optional[bool] = None,
num_readers: Optional[int] = None,
encryption_keyfile: Optional[str] = None,
s3_access_key_id: Optional[str] = None,
s3_secret_access_key: Optional[str] = None,
s3_endpoint: Optional[str] = None,
lora_dir: Optional[str] = None,
stream_kwargs: Optional[dict[str, Any]] = None,
serialization_kwargs: Optional[dict[str, Any]] = None,
deserialization_kwargs: Optional[dict[str, Any]] = None,
) -> None
__iter__ ¶
__len__ ¶
__post_init__ ¶
Source code in vllm/model_executor/model_loader/tensorizer.py
__setitem__ ¶
_construct_tensorizer_args ¶
_construct_tensorizer_args() -> TensorizerArgs
keys ¶
open_stream ¶
open_stream(
tensorizer_args: Optional[TensorizerArgs] = None,
)
Source code in vllm/model_executor/model_loader/tensorizer.py
to_serializable ¶
Source code in vllm/model_executor/model_loader/tensorizer.py
verify_with_model_config ¶
verify_with_model_config(model_config: ModelConfig) -> None
Source code in vllm/model_executor/model_loader/tensorizer.py
verify_with_parallel_config ¶
verify_with_parallel_config(
parallel_config: ParallelConfig,
) -> None
Source code in vllm/model_executor/model_loader/tensorizer.py
_NoInitOrTensorImpl ¶
Source code in vllm/model_executor/model_loader/tensorizer.py
_MODULE_ORIGINALS class-attribute
instance-attribute
¶
is_active class-attribute
instance-attribute
¶
is_active = ContextVar(
"_NoInitOrTensorImpl.is_active", default=False
)
_disable staticmethod
¶
context_manager classmethod
¶
Source code in vllm/model_executor/model_loader/tensorizer.py
_check_tensors_on_meta_device ¶
_check_tensors_on_meta_device(model: Module) -> None
Source code in vllm/model_executor/model_loader/tensorizer.py
_resize_lora_embeddings ¶
_resize_lora_embeddings(model: Module)
Modify LoRA embedding layers to use bigger tensors to allow for adapter added tokens.
Source code in vllm/model_executor/model_loader/tensorizer.py
deserialize_tensorizer_model ¶
deserialize_tensorizer_model(
model: Module, tensorizer_config: TensorizerConfig
) -> None
Source code in vllm/model_executor/model_loader/tensorizer.py
init_tensorizer_model ¶
init_tensorizer_model(
tensorizer_config: TensorizerConfig,
vllm_config: VllmConfig,
) -> Module
Source code in vllm/model_executor/model_loader/tensorizer.py
is_valid_deserialization_uri ¶
is_vllm_tensorized ¶
is_vllm_tensorized(
tensorizer_config: TensorizerConfig,
) -> bool
Infer if the model is a vLLM model by checking the weights for a vLLM tensorized marker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tensorizer_config | TensorizerConfig | The TensorizerConfig object containing the tensorizer_uri to the serialized model. | required |
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if the model is a vLLM model, False otherwise. |
Source code in vllm/model_executor/model_loader/tensorizer.py
meta_tensor_mode ¶
Source code in vllm/model_executor/model_loader/tensorizer.py
serialize_extra_artifacts ¶
serialize_extra_artifacts(
tensorizer_args: TensorizerArgs,
served_model_name: Union[str, list[str], None],
) -> None
Source code in vllm/model_executor/model_loader/tensorizer.py
serialize_vllm_model ¶
serialize_vllm_model(
model: Module,
tensorizer_config: TensorizerConfig,
model_config: ModelConfig,
) -> Module
Source code in vllm/model_executor/model_loader/tensorizer.py
tensorize_lora_adapter ¶
tensorize_lora_adapter(
lora_path: str, tensorizer_config: TensorizerConfig
)
Uses tensorizer to serialize a LoRA adapter. Assumes that the files needed to load a LoRA adapter are a safetensors-format file called adapter_model.safetensors and a json config file called adapter_config.json.
Serializes the files in the tensorizer_config.tensorizer_dir
Source code in vllm/model_executor/model_loader/tensorizer.py
tensorize_vllm_model ¶
tensorize_vllm_model(
engine_args: EngineArgs,
tensorizer_config: TensorizerConfig,
generate_keyfile: bool = True,
)
Utility to load a model and then serialize it with Tensorizer
Intended to be used separately from running a vLLM server since it creates its own Engine instance.
Source code in vllm/model_executor/model_loader/tensorizer.py
tensorizer_kwargs_arg ¶
Source code in vllm/model_executor/model_loader/tensorizer.py
tensorizer_weights_iterator ¶
tensorizer_weights_iterator(
tensorizer_args: TensorizerArgs,
) -> Generator[tuple[str, Tensor], None, None]