Skip to content

vllm.transformers_utils.utils

Functions:

convert_model_repo_to_path(model_repo)

When VLLM_USE_MODELSCOPE is True convert a model repository string to a Path str.

Source code in vllm/transformers_utils/utils.py
def convert_model_repo_to_path(model_repo: str) -> str:
    """When VLLM_USE_MODELSCOPE is True convert a model
    repository string to a Path str."""
    if not envs.VLLM_USE_MODELSCOPE or Path(model_repo).exists():
        return model_repo
    from modelscope.utils.file_utils import get_model_cache_root

    return os.path.join(get_model_cache_root(), model_repo)

maybe_model_redirect(model) cached

Use model_redirect to redirect the model name to a local folder.

Parameters:

  • model

    (str) –

    hf model name

Returns:

  • str

    maybe redirect to a local folder

Source code in vllm/transformers_utils/utils.py
@cache
def maybe_model_redirect(model: str) -> str:
    """
    Use model_redirect to redirect the model name to a local folder.

    Args:
        model: hf model name

    Returns:
        maybe redirect to a local folder
    """

    model_redirect_path = envs.VLLM_MODEL_REDIRECT_PATH

    if not model_redirect_path:
        return model

    if not Path(model_redirect_path).exists():
        return model

    redirect_dict = _maybe_json_dict(model_redirect_path) or _maybe_space_split_dict(
        model_redirect_path
    )
    if redirect_model := redirect_dict.get(model):
        logger.info("model redirect: [ %s ] -> [ %s ]", model, redirect_model)
        return redirect_model

    return model

modelscope_list_repo_files(repo_id, revision=None, token=None)

List files in a modelscope repo.

Source code in vllm/transformers_utils/utils.py
def modelscope_list_repo_files(
    repo_id: str,
    revision: str | None = None,
    token: str | bool | None = None,
) -> list[str]:
    """List files in a modelscope repo."""
    from modelscope.hub.api import HubApi

    api = HubApi()
    api.login(token)
    # same as huggingface_hub.list_repo_files
    files = [
        file["Path"]
        for file in api.get_model_files(
            model_id=repo_id, revision=revision, recursive=True
        )
        if file["Type"] == "blob"
    ]
    return files

without_trust_remote_code(kwargs)

Return kwargs without trust_remote_code without modifying original dict.

Source code in vllm/transformers_utils/utils.py
def without_trust_remote_code(kwargs: dict[str, Any]) -> dict[str, Any]:
    """Return kwargs without trust_remote_code without modifying original dict."""
    if "trust_remote_code" not in kwargs:
        return kwargs
    return {k: v for k, v in kwargs.items() if k != "trust_remote_code"}