Skip to content

[CI] [AMD] install: Cache the AOT kernel wheel and stop wiping venv bytecode - #46703

Merged
bingxche merged 1 commit into
sgl-project:mainfrom
michaelzhang-ai:ci-fix/amd-aot-kernel-cache
Oct 28, 2026
Merged

bingxche merged 1 commit into
sgl-project:mainfrom
michaelzhang-ai:ci-fix/amd-aot-kernel-cache

Conversation

@michaelzhang-ai

@michaelzhang-ai michaelzhang-ai commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What

Two cuts to the setup that every AMD CI job runs in amd_ci_install_dependency.sh before its first test:

Change Per job Expected per week
Cache the AOT kernel (sglang-kernel) wheel on the runner's persistent /sgl-data volume ~30 s build → wheel install on a cache hit ~350 runner-h (~830 GPU-h)
Stop deleting every .pyc under /opt/venv ~6 s ~70 runner-h

"Per week" assumes the ~41,900 AMD GPU jobs measured in the week of Oct 19–26 and a high hit rate. The real hit rate depends on how often kernels/aot and the CI image change. It will be measured after merge.

Why

The install step takes ~2.3 of the ~2.5 min of per-job setup:

  • 30 s of it compiles python/sglang/kernels/aot from source with setup_rocm.py install, in every job, although that tree rarely changes.
  • Another ~6 s is find /opt/venv -name "*.pyc" -delete and the __pycache__ cleanup. The pip uninstall calls just before it already remove the old sglang files, so the walk only throws away torch's bytecode, which every job then recompiles on first import.

Notes for the reviewer

  • Cache key: the git tree hash of python/sglang/kernels/aot, the container's image ID, and the image's GPU arch. Those are the only inputs to the build: setup_rocm.py reads nothing outside that directory, and the image fixes torch, HIP and Python.
    • A dirty tree, as in local runs, or a missing key builds without caching.
    • A host without the /sgl-data mount gets a container-local cache, so it just misses every time, same as today.
  • Build method: the build switches from setup_rocm.py install (an egg plus easy-install.pth) to setup_rocm.py bdist_wheel and pip install --no-deps --force-reinstall, so a cached build and a fresh one install the same way. Nothing else in the AMD scripts reads the egg or kernels/aot/dist.
  • Concurrency and cleanup: jobs on one host can build the same key at once, so each builds into a temp dir and publishes with mv -T; the loser drops its copy. Entries not used for 7 days are pruned, and a hit refreshes the entry's mtime.
  • Bytecode: clearing __pycache__ in the checkout is kept.

Test plan


CI States

Latest PR Test (Base): ✅ Run #40430396805
Latest PR Test (Extra): ❌ Run #40430396795
Latest PR Test (AMD ROCm 10): ❌ Run #40430396869

…ytecode

Every AMD CI job rebuilt python/sglang/kernels/aot from source (~30 s) and
deleted every .pyc under /opt/venv (~6 s) before running a test.

- Build sglang-kernel as a wheel and keep it on the persistent /sgl-data
  volume, keyed by the aot source tree hash, the image ID and the image's GPU
  arch. Later jobs on the same host install the cached wheel instead of
  compiling. A dirty tree builds without caching, publishing is atomic, and
  entries unused for 7 days are pruned.
- Only clear bytecode in the checkout. pip already removed the old sglang
  files from /opt/venv, so walking site-packages only made every job
  recompile torch's bytecode.
@michaelzhang-ai michaelzhang-ai added the run-ci CI: run the baseline test suite on this PR label Oct 27, 2026
@github-actions github-actions Bot added the amd label Oct 27, 2026
@michaelzhang-ai
michaelzhang-ai marked this pull request as ready for review October 27, 2026 17:28
@bingxche
bingxche merged commit 286e018 into sgl-project:main Oct 28, 2026
198 of 227 checks passed
@michaelzhang-ai
michaelzhang-ai deleted the ci-fix/amd-aot-kernel-cache branch October 28, 2026 17:25
TwelveNights added a commit to TwelveNights/sglang that referenced this pull request Nov 5, 2026
…y source tree and image

Replace the stage-a artifact handoff with a cache on the persistent
/sgl-data volume, next to the AOT wheel cache from sgl-project#46703 and with the
same conventions. The artifact only reached pull_request runs of
pr-test-amd.yml; the install script runs in every AMD job, so MI35x,
extra, nightly and later runs now hit too.

amd_ci_install_dependency.sh computes one entry per Cargo package:
sglang-radix-tree (mem_cache, mem_cache_inspection) and sglang-mm
(_multimodal). The key hashes the git tree of the package's sources, the
loader, the toolchain file and .cargo, plus the installed torch version
and SOABI, followed by the image ID and GPU arch. A dirty tree, a missing
path or a container without a /sgl-data mount gets no key, with the
reason logged, and nothing is built eagerly; the tests build at runtime
as before.

amd_ci_rust_ext_cache.py sync copies a cached entry into the loader's
own cache, then loads every module of the package through the loader,
which finds it in its cache or builds it. The loader stays in auto mode,
so its fingerprint still gates every load. An entry counts as a hit only
if it supplied every module that loaded; otherwise (a toolchain or
RUSTFLAGS the key does not cover, files lost to a killed prune) it is
replaced, not refreshed. A miss publishes the modules that built
atomically (mkdtemp + rename, the loser drops its copy), then prunes
entries unused for 7 days, renaming each aside before removing it.
sglang-radix-tree is skipped up front when torch is outside the Rust
TreeCore range. Errors are warnings and never fail the job.

The workflow changes and amd_ci_rust_ext_cache.sh are dropped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants