"examples/pooling/embed/vision_embedding_online.py" did not exist on "2a6dc67eb520ddb9c4138d8b35ed6fe6226997fb"
utils.py 1.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Utilities for selecting and loading models."""
import contextlib
from typing import Tuple, Type

import torch
from torch import nn

from vllm.config import ModelConfig
from vllm.model_executor.models import ModelRegistry


@contextlib.contextmanager
def set_default_torch_dtype(dtype: torch.dtype):
    """Sets the default torch dtype to the given dtype."""
    old_dtype = torch.get_default_dtype()
    torch.set_default_dtype(dtype)
    yield
    torch.set_default_dtype(old_dtype)


def get_model_architecture(
        model_config: ModelConfig) -> Tuple[Type[nn.Module], str]:
    architectures = getattr(model_config.hf_config, "architectures", [])
    # Special handling for quantized Mixtral.
    # FIXME(woosuk): This is a temporary hack.
26
    mixtral_supported = ["fp8", "compressed-tensors"]
27
    if (model_config.quantization is not None
28
            and model_config.quantization not in mixtral_supported
29
30
            and "MixtralForCausalLM" in architectures):
        architectures = ["QuantMixtralForCausalLM"]
31
    return ModelRegistry.resolve_model_cls(architectures)
32
33
34
35


def get_architecture_class_name(model_config: ModelConfig) -> str:
    return get_model_architecture(model_config)[1]