Skip to content

vllm.utils.torch_version

Torch version checks.

Kept free of other vLLM imports so that early importers such as vllm.env_override don't pull in vllm.utils.torch_utils, which resolves current_platform at import time.

Functions:

is_torch_equal(target)

Check if the installed torch version is == the target version (a string like "2.6.0").

Source code in vllm/utils/torch_version.py
def is_torch_equal(target: str) -> bool:
    """Check if the installed torch version is == the target version
    (a string like "2.6.0").
    """
    try:
        return _is_torch_equal(target)
    except Exception:
        return Version(importlib.metadata.version("torch")) == Version(target)

is_torch_equal_or_newer(target)

Check if the installed torch version is >= the target version (a string like "2.6.0").

Source code in vllm/utils/torch_version.py
def is_torch_equal_or_newer(target: str) -> bool:
    """Check if the installed torch version is >= the target version
    (a string like "2.6.0").
    """
    try:
        return _is_torch_equal_or_newer(str(torch.__version__), target)
    except Exception:
        # Fallback to PKG-INFO to load the package info, needed by the doc gen.
        return Version(importlib.metadata.version("torch")) >= Version(target)