Skip to main content

Contributor Guide

Build Files​

This image has no Dockerfile of its own. CICI: Continuous IntegrationThe practice of building and testing code automatically on every change, usually on a hosted service such as GitHub Actions, so problems show up before the change is merged.WikipediaGlossary builds the upstream vLLMvLLM: virtual Large Language ModelAn open-source inference and serving engine for LLMs, started at UC Berkeley in 2023. Its PagedAttention technique manages the key-value cache in fixed-size blocks, as an OS pages virtual memory, and it batches concurrent requests continuously, so one server can answer many requests at once. It runs on GPUs and CPUs and serves models through an OpenAI-compatible HTTP API.vLLM docsvLLM on GitHubOrigin of the nameGlossary CPUCPU: Central Processing UnitThe general-purpose processor of a computer, which runs the operating system and programs. A CPU has one or more physical cores, and with SMT each core runs two or more hardware threads.WikipediaGlossary Dockerfile⁠ (opens in a new tab) from a vLLM source tree that the prepare.sh⁠ (opens in a new tab) hook clones and patches. The metadata files of the image folder set the following:

FileValueEffect
CONTEXTvllm-common/.vllm-srcBuild context: the cloned vLLM source tree
DOCKERFILEvllm-common/.vllm-src/docker/Dockerfile.cpuThe patched upstream CPU Dockerfile
TARGETvllm-openaiThe upstream serving stage
PLATFORMSamd64Only AMD64AMD64The 64-bit version of the x86 instruction set architecture, introduced by AMD in 2003 and also implemented by Intel, which runs most cloud servers. Linux distributions and Docker name it amd64 or x86_64.WikipediaGlossary is built
BUILD_ARGSVLLM_CPU_AVX2=truePassed as a build argument; the upstream Dockerfile of vLLM 0.27.1 declares no such argument, so it has no effect
ZRAMtrueCompressed swap on the build runner; see CI Builds
SCCACHEtrueCompiler cache in S3; see Compiler Cache
CATEGORYbaseImage category label

The folder has no DEPENDS_ON file. CI finds the folder by its prepare.sh, because it has no Dockerfile. Git ignores the cloned source tree and the .cache/ folder that the hook writes.

The build framework of the sc-images repository⁠ (opens in a new tab) describes the metadata files that all images share.

Pre-Build Hook​

When an image folder has a prepare.sh, CICI: Continuous IntegrationThe practice of building and testing code automatically on every change, usually on a hosted service such as GitHub Actions, so problems show up before the change is merged.WikipediaGlossary runs it before the build. The hook does the following, in order:

  1. Reads the vLLM version from vllm-common/VLLM_VERSION⁠ (opens in a new tab), currently 0.27.1.
  2. Sizes the compile parallelism (see Compile Parallelism), and writes the runtime values of MAX_JOBS, NVCC_THREADS, and CARGO_BUILD_JOBS to .cache/vllm-parallelism.env, which the build mounts as the BuildKitBuildKitThe build engine of Docker, which builds container images from a Dockerfile. It runs independent build stages in parallel, caches each layer under a key computed from its instruction and inputs, and can export this cache to a registry and import it in a later build. It can also pass secrets to a build step as files that are not stored in the image or its cache.Docker docsGlossary secret vllm_parallelism.
  3. Clones the vLLM tag v<VLLM_VERSION> with depth 1 into vllm-common/.vllm-src, or fetches and checks out the tag when the tree exists.
  4. Patches docker/Dockerfile.cpu in that tree with tune-vllm-cpu-dockerfile.sh⁠ (opens in a new tab); see Dockerfile Patches.
  5. Prints dockerfile_sha256=<hash> of the patched file.
  6. Changes the owner of the source tree to 0:0 with sudo -n chown, so that the BuildKit context hash is the same on GitHub-hosted and self-hosted runners. The CONTEXT_CANONICAL_OWNER environment variable (a uid:gid pair) overrides the owner.
  7. Prints the sccachesccacheA compiler cache that wraps C, C++, and Rust compilers and reuses the output of an earlier compilation when the same source is compiled again with the same options. It keeps its cache on a local disk or in remote storage, such as an S3 bucket, so that several build machines can share it.GitHubGlossary lines, the install lines, and the FROM lines of the patched file, in collapsed log groups.
  8. Appends max_jobs=32 and, when the compiler cache is on, its build arguments to .cache/extra-build-args.

Without passwordless sudo, step 6 prints normalize-context-ownership: WARNING could not chown ... layer cache will not be shared across runner types and the hook continues.

Dockerfile Patches​

The tune-vllm-cpu-dockerfile.sh script makes the following changes to the upstream Dockerfile, and fails the build when one of them cannot be applied:

  • Adds .git to the .dockerignore file of the build context.
  • Sets SETUPTOOLS_SCM_PRETEND_VERSION to the vLLM version, and prints the resulting ENV line.
  • Sets ARG max_jobs and ENV CARGO_BUILD_JOBS to 32, the values the formula gives a builder with 64 GiB of RAMRAM: Random-Access MemoryThe main memory of a computer, which holds the running programs and their data. It is much faster than disk storage, and its content is lost when the power is off.WikipediaGlossary. Upstream, CARGO_BUILD_JOBS is 4. Fixed values keep the Dockerfile text and its layer cachelayer cacheThe layers of earlier container image builds that BuildKit stores and reuses. Each Dockerfile instruction adds one layer to the image, stored under a key computed from the instruction and its inputs; when a later build reaches an instruction with the same key, it reuses the stored layer instead of running the step again. A build with --no-cache ignores the cache and runs every step.Docker docsGlossary keys the same on every runner.
  • Makes the RUN steps of setup.py bdist_wheel, build_rust.sh, and triton-cpu read the runtime parallelism from the vllm_parallelism secret, whose content is not part of the layer cache key.
  • Adds git submodule update --init --recursive after the triton-cpu checkout, because an empty third_party/sleef folder breaks the vLLM build.
  • Pins both ubuntu:22.04 stages, base-common and rust-build, to the digest sha256:79676deb51ebb02885b0b9d33788e78a37cf1045ad79d1bb04c6a222c3556b3d (resolved on 2026-08-21), and fails when an unpinned ubuntu:22.04 FROM line remains.
  • Adds the compiler cache to the vllm-build and rust-build stages; see Compiler Cache.

Compile Parallelism​

The hook runs compute-build-parallelism.sh⁠ (opens in a new tab) with the vllm-cpu profile. VLLM_CPU_COMPILE_GIB_PER_SLOT is the memory of one compile job in GiB (default: 6). MemTotal is the physical RAM, and effective_GiB is MemTotal + (swap × 0.5), rounded to the nearest GiB. The script sizes the build as follows:

  • MAX_JOBS = min((32 × effective_GiB) / 64, nproc, MemTotal / VLLM_CPU_COMPILE_GIB_PER_SLOT, 32)
  • CARGO_BUILD_JOBS = min((32 × effective_GiB) / 64, MAX_JOBS, 32)
  • BuildKitBuildKitThe build engine of Docker, which builds container images from a Dockerfile. It runs independent build stages in parallel, caches each layer under a key computed from its instruction and inputs, and can export this cache to a registry and import it in a later build. It can also pass secrets to a build step as files that are not stored in the image or its cache.Docker docsGlossary max-parallelism = min(MAX_JOBS, 16)
  • NVCC_THREADS = 1

CICI: Continuous IntegrationThe practice of building and testing code automatically on every change, usually on a hosted service such as GitHub Actions, so problems show up before the change is merged.WikipediaGlossary sets the BuildKit max-parallelism in the builder configuration. The local build command in Local Build does not.

The memory slots (the third term) count physical RAM only, so the compressed swap raises the first term but adds no slots. All divisions are integer divisions, and the effective_GiB terms and the memory slots are at least 1.

A VLLM_CPU_COMPILE_GIB_PER_SLOT of 0 or a value that is not an integer makes the script fail, and the hook with it. A negative value sets MAX_JOBS to 1.

The script prints the following three lines to stderrstderrThe standard error stream of a process, one of the three standard streams with stdin and stdout. Programs write logs, progress, and error messages to it, so that they stay separate from the output on stdout when the output is redirected to a file or another program.WikipediaGlossary:

  • the memory and CPU inputs, after Parallelism (vllm-cpu):
  • the runtime values, after runtime:
  • the values written to the Dockerfile, after docker (cache-stable):

On GitHub-hosted runners, the script caps MAX_JOBS, CARGO_BUILD_JOBS, and the BuildKit parallelism at 2, but CI never builds this image there.

CI Builds​

CICI: Continuous IntegrationThe practice of building and testing code automatically on every change, usually on a hosted service such as GitHub Actions, so problems show up before the change is merged.WikipediaGlossary builds this image on every push to main (push.yml⁠ (opens in a new tab)), in the first level of the build plan that resolve-build-plan.sh⁠ (opens in a new tab) resolves, and then builds benchmark-vllm-cpu-avx2 on top of it. The build runs as follows:

  • Runner: Always the self-hosted [self-hosted, Linux, X64, workhorse] runner. The workflow⁠ (opens in a new tab) notes that the build is too heavy for GitHub-hosted runners, citing out-of-memory errors, disk pressure, and an unreliable compiler cache.
  • Compressed swap: CI runs setup-zram.sh⁠ (opens in a new tab) before the build, with the default ZRAM_PERCENT=125: a zramzramA Linux kernel module that creates compressed block devices in memory. It is most often used as swap, so swapped-out pages are compressed in RAM instead of written to disk, trading CPU time for memory.Linux kernel docsGlossary swap of 125% of the RAM, compressed with zstd. When the runner has no apt-get or the kernel has no zram module, the script skips zram, keeps the existing swap, and exits with code 0. It exits with code 1 when zram fails to start or swapon shows no zram device.
  • Build command: CI prints the full docker buildx build command after build-push-image:, and runs it under run-with-resource-tracker.sh⁠ (opens in a new tab).

Tags​

The build pushes ghcr.io/sparecores/vllm-cpu-base-avx2:main-amd64, and a merge job then creates the main tag from it. The merge job runs even when the build fails. When main-amd64 is missing, it skips the main tag and prints Skipping <tag>: missing <ref>. The package is public.

The image labels give the title, the description from DESCRIPTION⁠ (opens in a new tab), the documentation URLURL: Uniform Resource LocatorThe address of a resource on the web or a network, such as https://sparecores.com/, made of a scheme, a host, and a path.Glossary, and the category base. The layers are pushed compressed with zstd, at level 7.

Layer Cache​

The build imports its layer cache from the following sources:

  • ghcr.io/sparecores/vllm-cpu-base-avx2:buildcache-amd64
  • ghcr.io/sparecores/vllm-cpu-base-avx2:main-amd64
  • the GitHub Actions cache scope vllm-cpu-base-avx2-amd64-v0.27.1

It exports all layers (mode=max) to the buildcache-amd64 tag and to the same GitHub Actions cache scope. A new vLLM version starts a new scope.

The first successful build fills both caches. When the buildcache-amd64 tag does not exist yet, the build skips its import and still runs; see Docker's registry cache⁠ (opens in a new tab) docs.

A force rebuild of the resource-trackerresource-trackerAn open-source Spare Cores tool that runs a command and samples resource usage while it runs, such as CPU, memory, disk, network, GPU, and GPU memory use. It can optionally stream the samples to the Spare Cores Sentinel platform, so that a run can be checked to see its aggregated and detailed resource utilization, e.g., whether it used all CPU or GPU cores as intended while running a Navigator benchmark workload.resource-tracker on GitHubGlossary consumers, the default in a manual run, keeps this image's layer cache, because this image does not depend on resource-tracker. It rebuilds benchmark-vllm-cpu-avx2 without cache, because that image does.

Compiler Cache​

With SCCACHE set to true, CICI: Continuous IntegrationThe practice of building and testing code automatically on every change, usually on a hosted service such as GitHub Actions, so problems show up before the change is merged.WikipediaGlossary runs the hook with SCCACHE_ENABLED=true, and the build runs its compilers through sccachesccacheA compiler cache that wraps C, C++, and Rust compilers and reuses the output of an earlier compilation when the same source is compiled again with the same options. It keeps its cache on a local disk or in remote storage, such as an S3 bucket, so that several build machines can share it.GitHubGlossary 0.15.0, with an S3 bucket as its storage. The hook reads the following environment variables:

VariableMeaningDefault
SCCACHE_ENABLEDtrue turns the compiler cache onUnset; true in CI
SCCACHE_BUCKETName of the S3 bucket; the hook stops with SCCACHE_BUCKET required when SCCACHE is enabled when it is unsetRepository variable in CI
SCCACHE_REGIONRegion of the bucketus-west-2
SCCACHE_PREFIXKey prefix of this image in the bucketvllm-cpu-base-avx2/amd64
SCCACHE_VERBOSE1 turns on the trace logsUnset

From these, the hook writes the following build arguments:

Build argumentValue
USE_SCCACHE1
RUSTC_WRAPPER/usr/local/bin/sc-rust-wrap
SCCACHE_BUCKET_NAMEThe value of SCCACHE_BUCKET
SCCACHE_REGION_NAMEThe value of SCCACHE_REGION
SCCACHE_S3_NO_CREDENTIALS0
SCCACHE_S3_KEY_PREFIXThe value of SCCACHE_PREFIX
SCCACHE_VERBOSE1, only when SCCACHE_VERBOSE is 1

Without USE_SCCACHE=1, the build skips the sccache install and its wrappers.

CI writes the AWS credentials of an assumed role to .cache/aws-credentials and mounts them as an optional BuildKitBuildKitThe build engine of Docker, which builds container images from a Dockerfile. It runs independent build stages in parallel, caches each layer under a key computed from its instruction and inputs, and can export this cache to a registry and import it in a later build. It can also pass secrets to a build step as files that are not stored in the image or its cache.Docker docsGlossary secret. The patched Dockerfile does the following with the cache:

  • It downloads the x86_64-unknown-linux-musl build of sccache 0.15.0 from its GitHub releases, before the RustRustAn open-source programming language that compiles to native code, for fast and reliable software. It checks memory safety when a program is compiled, so its programs need no extra checks for it while they run.Rust websiteGlossary and vLLM builds.
  • In the rust-build stage, cargo runs each rustc call through the /usr/local/bin/sc-rust-wrap script (RUSTC_WRAPPER⁠ (opens in a new tab)), which runs sccache. The script has its own name because a wrapper whose file name stem is sccache breaks the openssl-sys build. The stage also sets CARGO_INCREMENTAL=0, CC=/usr/bin/gcc, and CXX=/usr/bin/g++.
  • The vLLM build compiles through /usr/local/bin/sccache-wrapper, which reruns a compile without sccache when sccache fails with one of the infrastructure errors that the wrapper lists, and prints [sccache-wrapper] infrastructure failure rc=..., falling back.

Outside the verbose mode, the build sets SCCACHE_IGNORE_SERVER_IO_ERROR=1, so errors of the S3 storage do not fail the build, and the log shows only the output of sccache --show-stats after each compile.

With SCCACHE_VERBOSE=1, the build sets SCCACHE_IGNORE_SERVER_IO_ERROR=0, and the log also shows [sccache-trace] and [sccache-debug] lines and the S3 errors. In this mode, the vLLM build still falls back to a plain compile on the errors that sccache-wrapper lists, but the Rust build has no fallback.

Local Build​

The hook runs only on a host with /proc/meminfo, nproc, and sha256sum, such as Linux; it stops on macOS. It also needs git to clone vLLM, and the build needs Docker Buildx.

The hook writes vllm-common/.vllm-src and .cache/ relative to the current folder, so run it from the root of the sc-images repository. To clone and patch the vLLM source:

bash images/vllm-cpu-base-avx2/prepare.sh

The hook leaves the source tree owned by root when passwordless sudo is available. Outside CICI: Continuous IntegrationThe practice of building and testing code automatically on every change, usually on a hosted service such as GitHub Actions, so problems show up before the change is merged.WikipediaGlossary, the build gets only the build arguments given with --build-arg. A local build needs none of the build arguments that CI passes:

  • VLLM_CPU_AVX2=true has no effect.
  • max_jobs=32 is already the default of the patched Dockerfile.
  • The hook writes compiler cache arguments only with SCCACHE_ENABLED=true.

The local command below builds without the compiler cache.

To build the image from the patched source, with the parallelism that the hook computed for this machine:

docker buildx build \
--file vllm-common/.vllm-src/docker/Dockerfile.cpu \
--target vllm-openai \
--platform linux/amd64 \
--secret id=vllm_parallelism,src=.cache/vllm-parallelism.env \
--load \
-t vllm-cpu-base-avx2 \
vllm-common/.vllm-src

To start a vLLM server from the local tag:

docker run --rm vllm-cpu-base-avx2 <owner>/<model>

Version Changes​

This image takes its vLLM version from vllm-common/VLLM_VERSION, like the other vLLM images; see the Version Changes of the vLLM benchmarks. The hook clones the tag v<VLLM_VERSION> from the vLLM repository⁠ (opens in a new tab), and the build fails when a patch no longer applies to the new Dockerfile.