Skip to content

vllm.model_executor.model_loader.tensorizer

Classes:

TensorizerArgs dataclass

Methods:

add_cli_args(parser) staticmethod

Tensorizer CLI arguments.

TensorizerConfig dataclass

Bases: MutableMapping

_keys class-attribute

Configuration class for Tensorizer settings.

These settings configure the behavior of model serialization and deserialization using Tensorizer.

Attributes:

  • tensorizer_uri –

    Path to serialized model tensors. Can be a local file path or a S3 URI. Unless a tensorizer_dir is passed to this object's initializer, this is a required argument.

  • 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 tensorizer_uri where the model.tensors file will be assumed to be in this directory.

  • 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.

  • verify_hash –

    If True, the hashes of each tensor will be verified against the hashes stored in the metadata. A HashMismatchError will be raised if any of the hashes do not match.

  • num_readers –

    Controls how many threads are allowed to read concurrently from the source file. Default is None, which will dynamically set the number of readers based on the number of available resources and model size. This greatly increases performance.

  • encryption_keyfile –

    File path to a binary file containing a
    binary key to use for decryption. None (the default) means no decryption. See the example script in examples/features/tensorize_vllm_model.py.

  • s3_access_key_id –

    The access key for the S3 bucket. Can also be set via the S3_ACCESS_KEY_ID environment variable.

  • s3_secret_access_key –

    The secret access key for the S3 bucket. Can also be set via the S3_SECRET_ACCESS_KEY environment variable.

  • s3_endpoint –

    The endpoint for the S3 bucket. Can also be set via the S3_ENDPOINT_URL environment variable.

is_vllm_tensorized(tensorizer_config)

Infer if the model is a vLLM model by checking the weights for a vLLM tensorized marker.

Parameters:

  • tensorizer_config

    (TensorizerConfig) –

    The TensorizerConfig object containing the tensorizer_uri to the serialized model.

Returns:

  • bool ( bool ) –

    True if the model is a vLLM model, False otherwise.

tensorize_vllm_model(engine_args, tensorizer_config, generate_keyfile=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.