[CI/Build] use setuptools-scm to set __version__ (#4738)

Co-authored-by: youkaichao <youkaichao@126.com>
This commit is contained in:
Daniele 2024-09-23 18:44:26 +02:00 committed by GitHub
parent f2bd246c17
commit ee5f34b1c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 93 additions and 94 deletions

3
.gitignore vendored
View File

@ -196,5 +196,8 @@ _build/
*_hip* *_hip*
hip_compat.h hip_compat.h
# version file generated by setuptools-scm
/vllm/_version.py
# Benchmark dataset # Benchmark dataset
benchmarks/*.json benchmarks/*.json

View File

@ -79,15 +79,13 @@ ENV MAX_JOBS=${max_jobs}
ARG nvcc_threads=8 ARG nvcc_threads=8
ENV NVCC_THREADS=$nvcc_threads ENV NVCC_THREADS=$nvcc_threads
ARG buildkite_commit
ENV BUILDKITE_COMMIT=${buildkite_commit}
ARG USE_SCCACHE ARG USE_SCCACHE
ARG SCCACHE_BUCKET_NAME=vllm-build-sccache ARG SCCACHE_BUCKET_NAME=vllm-build-sccache
ARG SCCACHE_REGION_NAME=us-west-2 ARG SCCACHE_REGION_NAME=us-west-2
ARG SCCACHE_S3_NO_CREDENTIALS=0 ARG SCCACHE_S3_NO_CREDENTIALS=0
# if USE_SCCACHE is set, use sccache to speed up compilation # if USE_SCCACHE is set, use sccache to speed up compilation
RUN --mount=type=cache,target=/root/.cache/pip \ RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=.git,target=.git \
if [ "$USE_SCCACHE" = "1" ]; then \ if [ "$USE_SCCACHE" = "1" ]; then \
echo "Installing sccache..." \ echo "Installing sccache..." \
&& curl -L -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v0.8.1/sccache-v0.8.1-x86_64-unknown-linux-musl.tar.gz \ && curl -L -o sccache.tar.gz https://github.com/mozilla/sccache/releases/download/v0.8.1/sccache-v0.8.1-x86_64-unknown-linux-musl.tar.gz \
@ -107,6 +105,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \
ENV CCACHE_DIR=/root/.cache/ccache ENV CCACHE_DIR=/root/.cache/ccache
RUN --mount=type=cache,target=/root/.cache/ccache \ RUN --mount=type=cache,target=/root/.cache/ccache \
--mount=type=cache,target=/root/.cache/pip \ --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=.git,target=.git \
if [ "$USE_SCCACHE" != "1" ]; then \ if [ "$USE_SCCACHE" != "1" ]; then \
python3 setup.py bdist_wheel --dist-dir=dist --py-limited-api=cp38; \ python3 setup.py bdist_wheel --dist-dir=dist --py-limited-api=cp38; \
fi fi

View File

@ -62,8 +62,10 @@ ENV VLLM_CPU_DISABLE_AVX512=${VLLM_CPU_DISABLE_AVX512}
RUN --mount=type=cache,target=/root/.cache/pip \ RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=cache,target=/root/.cache/ccache \ --mount=type=cache,target=/root/.cache/ccache \
--mount=type=bind,source=.git,target=.git \
VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel && \ VLLM_TARGET_DEVICE=cpu python3 setup.py bdist_wheel && \
pip install dist/*.whl pip install dist/*.whl && \
rm -rf dist
WORKDIR /workspace/ WORKDIR /workspace/

View File

@ -6,9 +6,12 @@ FROM $BASE_IMAGE
RUN echo "Base image is $BASE_IMAGE" RUN echo "Base image is $BASE_IMAGE"
# Install some basic utilities # Install some basic utilities
RUN apt-get update \ RUN apt-get update && \
&& apt-get install python3 python3-pip -y \ apt-get install -y \
&& apt-get install -y ffmpeg libsm6 libxext6 libgl1 git \
python3 \
python3-pip \
ffmpeg libsm6 libxext6 libgl1
### Mount Point ### ### Mount Point ###
# When launching the container, mount the code directory to /app # When launching the container, mount the code directory to /app
@ -22,17 +25,17 @@ RUN python3 -m pip install sentencepiece transformers==4.36.2 -U
RUN python3 -m pip install transformers-neuronx --extra-index-url=https://pip.repos.neuron.amazonaws.com -U RUN python3 -m pip install transformers-neuronx --extra-index-url=https://pip.repos.neuron.amazonaws.com -U
RUN python3 -m pip install --pre neuronx-cc==2.15.* --extra-index-url=https://pip.repos.neuron.amazonaws.com -U RUN python3 -m pip install --pre neuronx-cc==2.15.* --extra-index-url=https://pip.repos.neuron.amazonaws.com -U
COPY ./vllm /app/vllm/vllm COPY . /app/vllm
COPY ./setup.py /app/vllm/setup.py
COPY ./requirements-common.txt /app/vllm/requirements-common.txt
COPY ./requirements-neuron.txt /app/vllm/requirements-neuron.txt
RUN cd /app/vllm \ RUN cd /app/vllm \
&& python3 -m pip install -U -r requirements-neuron.txt && python3 -m pip install -U \
cmake>=3.26 ninja packaging setuptools-scm>=8 wheel jinja2 \
-r requirements-neuron.txt
ENV VLLM_TARGET_DEVICE neuron ENV VLLM_TARGET_DEVICE neuron
RUN cd /app/vllm \ RUN --mount=type=bind,source=.git,target=.git \
&& pip install -e . \ cd /app/vllm \
&& pip install --no-build-isolation -v -e . \
&& cd .. && cd ..
CMD ["/bin/bash"] CMD ["/bin/bash"]

View File

@ -4,8 +4,9 @@
FROM ubuntu:22.04 AS dev FROM ubuntu:22.04 AS dev
RUN apt-get update -y && \ RUN apt-get update -y && \
apt-get install -y python3-pip git && \ apt-get install -y \
apt-get install -y ffmpeg libsm6 libxext6 libgl1 git python3-pip \
ffmpeg libsm6 libxext6 libgl1
WORKDIR /workspace WORKDIR /workspace
# copy requirements # copy requirements

View File

@ -16,9 +16,15 @@ COPY ./ /workspace/vllm
WORKDIR /workspace/vllm WORKDIR /workspace/vllm
# These packages will be in rocketce eventually # These packages will be in rocketce eventually
RUN pip install -v cmake xformers torch==2.3.1 uvloop==0.20.0 -r requirements-cpu.txt --prefer-binary --extra-index-url https://repo.fury.io/mgiessing RUN --mount=type=cache,target=/root/.cache/pip \
pip install -v --prefer-binary --extra-index-url https://repo.fury.io/mgiessing \
cmake>=3.26 ninja packaging setuptools-scm>=8 wheel jinja2 \
torch==2.3.1 \
-r requirements-cpu.txt \
xformers uvloop==0.20.0
RUN VLLM_TARGET_DEVICE=cpu python3 setup.py install RUN --mount=type=bind,source=.git,target=.git \
VLLM_TARGET_DEVICE=cpu python3 setup.py install
WORKDIR /workspace/ WORKDIR /workspace/

View File

@ -51,13 +51,15 @@ RUN python3 -m pip install --upgrade pip
# TODO: implement sccache support across components # TODO: implement sccache support across components
RUN apt-get purge -y sccache; python3 -m pip uninstall -y sccache; rm -f "$(which sccache)" RUN apt-get purge -y sccache; python3 -m pip uninstall -y sccache; rm -f "$(which sccache)"
# Install torch == 2.5.0 on ROCm # Install torch == 2.5.0 on ROCm
RUN case "$(ls /opt | grep -Po 'rocm-[0-9]\.[0-9]')" in \ RUN --mount=type=cache,target=/root/.cache/pip \
case "$(ls /opt | grep -Po 'rocm-[0-9]\.[0-9]')" in \
*"rocm-6.1"*) \ *"rocm-6.1"*) \
python3 -m pip uninstall -y torch torchvision \ python3 -m pip uninstall -y torch torchvision \
&& python3 -m pip install --no-cache-dir --pre \ && python3 -m pip install --pre \
torch==2.5.0.dev20240726 \ torch==2.5.0.dev20240726 \
cmake>=3.26 ninja packaging setuptools-scm>=8 wheel jinja2 \
torchvision==0.20.0.dev20240726 \ torchvision==0.20.0.dev20240726 \
--index-url https://download.pytorch.org/whl/nightly/rocm6.1;; \ --extra-index-url https://download.pytorch.org/whl/nightly/rocm6.1 ;; \
*) ;; esac *) ;; esac
ENV LLVM_SYMBOLIZER_PATH=/opt/rocm/llvm/bin/llvm-symbolizer ENV LLVM_SYMBOLIZER_PATH=/opt/rocm/llvm/bin/llvm-symbolizer
@ -138,6 +140,7 @@ ENV RAY_EXPERIMENTAL_NOSET_ROCR_VISIBLE_DEVICES=1
ENV TOKENIZERS_PARALLELISM=false ENV TOKENIZERS_PARALLELISM=false
RUN --mount=type=cache,target=${CCACHE_DIR} \ RUN --mount=type=cache,target=${CCACHE_DIR} \
--mount=type=bind,source=.git,target=.git \
--mount=type=cache,target=/root/.cache/pip \ --mount=type=cache,target=/root/.cache/pip \
python3 -m pip install -Ur requirements-rocm.txt \ python3 -m pip install -Ur requirements-rocm.txt \
&& case "$(ls /opt | grep -Po 'rocm-[0-9]\.[0-9]')" in \ && case "$(ls /opt | grep -Po 'rocm-[0-9]\.[0-9]')" in \

View File

@ -5,16 +5,25 @@ FROM $BASE_IMAGE
WORKDIR /workspace WORKDIR /workspace
# Install some basic utilities # Install some basic utilities
RUN apt-get update && apt-get install -y ffmpeg libsm6 libxext6 libgl1 RUN apt-get update && apt-get install -y \
git \
ffmpeg libsm6 libxext6 libgl1
# Install the TPU and Pallas dependencies. # Install the TPU and Pallas dependencies.
RUN python3 -m pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html RUN --mount=type=cache,target=/root/.cache/pip \
RUN python3 -m pip install torch_xla[pallas] -f https://storage.googleapis.com/jax-releases/jax_nightly_releases.html -f https://storage.googleapis.com/jax-releases/jaxlib_nightly_releases.html python3 -m pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html
RUN --mount=type=cache,target=/root/.cache/pip \
python3 -m pip install torch_xla[pallas] -f https://storage.googleapis.com/jax-releases/jax_nightly_releases.html -f https://storage.googleapis.com/jax-releases/jaxlib_nightly_releases.html
# Build vLLM. # Build vLLM.
COPY . /workspace/vllm COPY . /workspace/vllm
ENV VLLM_TARGET_DEVICE="tpu" ENV VLLM_TARGET_DEVICE="tpu"
RUN cd /workspace/vllm && python3 -m pip install -r requirements-tpu.txt RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=.git,target=.git \
cd /workspace/vllm && \
python3 -m pip install \
cmake>=3.26 ninja packaging setuptools-scm>=8 wheel jinja2 \
-r requirements-tpu.txt
RUN cd /workspace/vllm && python3 setup.py develop RUN cd /workspace/vllm && python3 setup.py develop
CMD ["/bin/bash"] CMD ["/bin/bash"]

View File

@ -7,15 +7,20 @@ RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRO
echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc" | tee /etc/apt/sources.list.d/intel.gpu.jammy.list && \ echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc" | tee /etc/apt/sources.list.d/intel.gpu.jammy.list && \
chmod 644 /usr/share/keyrings/intel-graphics.gpg chmod 644 /usr/share/keyrings/intel-graphics.gpg
RUN apt-get update -y \ RUN apt-get update -y && \
&& apt-get install -y curl libicu70 lsb-release git wget vim numactl python3 python3-pip ffmpeg libsm6 libxext6 libgl1 apt-get install -y curl libicu70 lsb-release git wget vim numactl python3 python3-pip ffmpeg libsm6 libxext6 libgl1
COPY ./ /workspace/vllm COPY ./ /workspace/vllm
WORKDIR /workspace/vllm WORKDIR /workspace/vllm
RUN pip install -v -r requirements-xpu.txt --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ RUN --mount=type=cache,target=/root/.cache/pip \
pip install -v --extra-index-url https://pytorch-extension.intel.com/release-whl/stable/xpu/us/ \
cmake>=3.26 ninja packaging setuptools-scm>=8 wheel jinja2 \
-r requirements-xpu.txt
RUN VLLM_TARGET_DEVICE=xpu python3 setup.py install RUN --mount=type=cache,target=/root/.cache/pip \
--mount=type=bind,source=.git,target=.git \
VLLM_TARGET_DEVICE=xpu python3 setup.py install
CMD ["/bin/bash"] CMD ["/bin/bash"]

View File

@ -56,7 +56,7 @@ Build from source
.. code-block:: console .. code-block:: console
$ pip install --upgrade pip $ pip install --upgrade pip
$ pip install wheel packaging ninja "setuptools>=49.4.0" numpy $ pip install cmake>=3.26 wheel packaging ninja "setuptools-scm>=8" numpy
$ pip install -v -r requirements-cpu.txt --extra-index-url https://download.pytorch.org/whl/cpu $ pip install -v -r requirements-cpu.txt --extra-index-url https://download.pytorch.org/whl/cpu
- Third, build and install oneDNN library from source: - Third, build and install oneDNN library from source:

View File

@ -4,7 +4,8 @@ requires = [
"cmake>=3.26", "cmake>=3.26",
"ninja", "ninja",
"packaging", "packaging",
"setuptools >= 49.4.0", "setuptools>=61",
"setuptools-scm>=8.0",
"torch == 2.4.0", "torch == 2.4.0",
"wheel", "wheel",
"jinja2", "jinja2",
@ -19,6 +20,10 @@ exclude = [
"examples/fp8/quantizer/quantize.py" "examples/fp8/quantizer/quantize.py"
] ]
[tool.ruff.lint.per-file-ignores]
"vllm/version.py" = ["F401"]
"vllm/_version.py" = ["ALL"]
[tool.ruff.lint] [tool.ruff.lint]
select = [ select = [
# pycodestyle # pycodestyle
@ -46,6 +51,9 @@ ignore = [
"UP032", "UP032",
] ]
[tool.setuptools_scm]
version_file = "vllm/_version.py"
[tool.mypy] [tool.mypy]
python_version = "3.8" python_version = "3.8"

View File

@ -2,7 +2,8 @@
cmake>=3.26 cmake>=3.26
ninja ninja
packaging packaging
setuptools>=49.4.0 setuptools>=61
setuptools-scm>=8
torch==2.4.0 torch==2.4.0
wheel wheel
jinja2 jinja2

View File

@ -5,7 +5,6 @@ import os
import re import re
import subprocess import subprocess
import sys import sys
import warnings
from pathlib import Path from pathlib import Path
from shutil import which from shutil import which
from typing import Dict, List from typing import Dict, List
@ -14,6 +13,7 @@ import torch
from packaging.version import Version, parse from packaging.version import Version, parse
from setuptools import Extension, find_packages, setup from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext from setuptools.command.build_ext import build_ext
from setuptools_scm import get_version
from torch.utils.cpp_extension import CUDA_HOME from torch.utils.cpp_extension import CUDA_HOME
@ -28,34 +28,6 @@ def load_module_from_path(module_name, path):
ROOT_DIR = os.path.dirname(__file__) ROOT_DIR = os.path.dirname(__file__)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
def embed_commit_hash():
try:
if "BUILDKITE_COMMIT" in os.environ:
# ci build
commit_id = os.environ["BUILDKITE_COMMIT"]
else:
commit_id = subprocess.check_output(["git", "rev-parse", "HEAD"],
encoding="utf-8").strip()
commit_contents = f'__commit__ = "{commit_id}"\n'
version_file = os.path.join(ROOT_DIR, "vllm", "commit_id.py")
with open(version_file, "w", encoding="utf-8") as f:
f.write(commit_contents)
except subprocess.CalledProcessError as e:
warnings.warn(f"Failed to get commit hash:\n{e}",
RuntimeWarning,
stacklevel=2)
except Exception as e:
warnings.warn(f"Failed to embed commit hash:\n{e}",
RuntimeWarning,
stacklevel=2)
embed_commit_hash()
# cannot import envs directly because it depends on vllm, # cannot import envs directly because it depends on vllm,
# which is not installed yet # which is not installed yet
envs = load_module_from_path('envs', os.path.join(ROOT_DIR, 'vllm', 'envs.py')) envs = load_module_from_path('envs', os.path.join(ROOT_DIR, 'vllm', 'envs.py'))
@ -381,21 +353,9 @@ def get_path(*filepath) -> str:
return os.path.join(ROOT_DIR, *filepath) return os.path.join(ROOT_DIR, *filepath)
def find_version(filepath: str) -> str:
"""Extract version information from the given filepath.
Adapted from https://github.com/ray-project/ray/blob/0b190ee1160eeca9796bc091e07eaebf4c85b511/python/setup.py
"""
with open(filepath) as fp:
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
fp.read(), re.M)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
def get_vllm_version() -> str: def get_vllm_version() -> str:
version = find_version(get_path("vllm", "version.py")) version = get_version()
sep = "+" if "+" not in version else "." # dev versions might contain +
if _no_device(): if _no_device():
if envs.VLLM_TARGET_DEVICE == "empty": if envs.VLLM_TARGET_DEVICE == "empty":
@ -406,27 +366,27 @@ def get_vllm_version() -> str:
cuda_version_str = cuda_version.replace(".", "")[:3] cuda_version_str = cuda_version.replace(".", "")[:3]
# skip this for source tarball, required for pypi # skip this for source tarball, required for pypi
if "sdist" not in sys.argv: if "sdist" not in sys.argv:
version += f"+cu{cuda_version_str}" version += f"{sep}cu{cuda_version_str}"
elif _is_hip(): elif _is_hip():
# Get the HIP version # Get the HIP version
hipcc_version = get_hipcc_rocm_version() hipcc_version = get_hipcc_rocm_version()
if hipcc_version != MAIN_CUDA_VERSION: if hipcc_version != MAIN_CUDA_VERSION:
rocm_version_str = hipcc_version.replace(".", "")[:3] rocm_version_str = hipcc_version.replace(".", "")[:3]
version += f"+rocm{rocm_version_str}" version += f"{sep}rocm{rocm_version_str}"
elif _is_neuron(): elif _is_neuron():
# Get the Neuron version # Get the Neuron version
neuron_version = str(get_neuronxcc_version()) neuron_version = str(get_neuronxcc_version())
if neuron_version != MAIN_CUDA_VERSION: if neuron_version != MAIN_CUDA_VERSION:
neuron_version_str = neuron_version.replace(".", "")[:3] neuron_version_str = neuron_version.replace(".", "")[:3]
version += f"+neuron{neuron_version_str}" version += f"{sep}neuron{neuron_version_str}"
elif _is_openvino(): elif _is_openvino():
version += "+openvino" version += f"{sep}openvino"
elif _is_tpu(): elif _is_tpu():
version += "+tpu" version += f"{sep}tpu"
elif _is_cpu(): elif _is_cpu():
version += "+cpu" version += f"{sep}cpu"
elif _is_xpu(): elif _is_xpu():
version += "+xpu" version += f"{sep}xpu"
else: else:
raise RuntimeError("Unknown runtime environment") raise RuntimeError("Unknown runtime environment")

View File

@ -2,6 +2,7 @@ import vllm
def test_embedded_commit_defined(): def test_embedded_commit_defined():
assert vllm.__commit__ != "COMMIT_HASH_PLACEHOLDER" assert hasattr(vllm, "__version__")
# 7 characters is the length of a short commit hash assert hasattr(vllm, "__version_tuple__")
assert len(vllm.__commit__) >= 7 assert vllm.__version__ != "dev"
assert vllm.__version_tuple__ != (0, 0, "dev")

View File

@ -12,11 +12,11 @@ from vllm.outputs import (CompletionOutput, EmbeddingOutput,
from vllm.pooling_params import PoolingParams from vllm.pooling_params import PoolingParams
from vllm.sampling_params import SamplingParams from vllm.sampling_params import SamplingParams
from .version import __commit__, __version__ from .version import __version__, __version_tuple__
__all__ = [ __all__ = [
"__commit__",
"__version__", "__version__",
"__version_tuple__",
"LLM", "LLM",
"ModelRegistry", "ModelRegistry",
"PromptType", "PromptType",

View File

@ -1,13 +1,11 @@
import warnings
try: try:
import vllm.commit_id from ._version import __version__, __version_tuple__
__commit__ = vllm.commit_id.__commit__
except Exception as e: except Exception as e:
import warnings
warnings.warn(f"Failed to read commit hash:\n{e}", warnings.warn(f"Failed to read commit hash:\n{e}",
RuntimeWarning, RuntimeWarning,
stacklevel=2) stacklevel=2)
__commit__ = "COMMIT_HASH_PLACEHOLDER"
__version__ = "0.6.1.post2" __version__ = "dev"
__version_tuple__ = (0, 0, __version__)