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
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 |
|
s3_endpoint
class-attribute
instance-attribute
¶
Args for the TensorizerAgent class. These are used to configure the behavior of the TensorDeserializer when loading tensors from a serialized model.
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 | |
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 |
s3_secret_access_key
class-attribute
instance-attribute
¶
tensorizer_uri
instance-attribute
¶
__init__
¶
__init__(
tensorizer_uri: Union[
BufferedIOBase,
RawIOBase,
BinaryIO,
str,
bytes,
PathLike,
int,
],
vllm_tensorized: Optional[bool] = False,
verify_hash: Optional[bool] = False,
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,
) -> None
__post_init__
¶
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
¶
Source code in vllm/model_executor/model_loader/tensorizer.py
s3_secret_access_key
class-attribute
instance-attribute
¶
__init__
¶
__init__(
tensorizer_uri: Union[str, None] = None,
vllm_tensorized: Optional[bool] = False,
verify_hash: Optional[bool] = False,
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,
model_class: Optional[type[Module]] = None,
hf_config: Optional[PretrainedConfig] = None,
dtype: Optional[Union[str, dtype]] = None,
lora_dir: Optional[str] = None,
_is_sharded: bool = False,
) -> None
__post_init__
¶
Source code in vllm/model_executor/model_loader/tensorizer.py
_construct_tensorizer_args
¶
_construct_tensorizer_args() -> TensorizerArgs
Source code in vllm/model_executor/model_loader/tensorizer.py
as_dict
classmethod
¶
open_stream
¶
open_stream(
tensorizer_args: Optional[TensorizerArgs] = None,
)
Source code in vllm/model_executor/model_loader/tensorizer.py
to_dict
¶
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_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_vllm_model
¶
serialize_vllm_model(
model: Module, tensorizer_config: TensorizerConfig
) -> 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.lora_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_weights_iterator
¶
tensorizer_weights_iterator(
tensorizer_args: TensorizerArgs,
) -> Generator[tuple[str, Tensor], None, None]