Skip to content

[core] Consolidate compiled-kernel caches under SGLANG_CACHE_DIR - #32434

Merged
Fridge003 merged 1 commit into
sgl-project:mainfrom
shuwang21:sglang-home
Aug 5, 2026
Merged

Fridge003 merged 1 commit into
sgl-project:mainfrom
shuwang21:sglang-home

Conversation

@shuwang21

@shuwang21 shuwang21 commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Motivation (Idea from @ch-wan)

Triton, Inductor, FlashInfer and the CUDA driver each write their compiled
kernels to their own directory:

~/.triton/                    
~/.cache/flashinfer/
/tmp/torchinductor_$USER/     
~/.nv/

Scattered across four places, they cannot be cleaned, warmed, copied between
hosts or volume-mounted as a unit, and nothing tells an operator where they
all are.

Modifications

  • environ.py — added third_party_cache_defaults() (env var → cache dir
    mapping) and redirect_third_party_caches(), which setdefaults those four
    vars. SGLANG_DG_CACHE_DIR now defaults to {SGLANG_CACHE_DIR}/deep_gemm.
  • sglang/__init__.py — calls the redirect above the imports that reach
    torch and FlashInfer, which otherwise fix these paths first.
  • compile_utils.py — reads SGLANG_DG_CACHE_DIR through envs instead
    of duplicating the default.
  • CI scripts — warmup_deep_gemm.py's MARKER_DIR derives from
    SGLANG_CACHE_DIR; ci_install_dependency.sh clears the inductor cache in
    every location it can be in.
  • Diffusion — _configure_persistent_torch_compile_cache compares against
    third_party_cache_defaults(), so an sglang default is not mistaken for an
    operator override and its caches still land under
    SGLANG_DIFFUSION_CACHE_ROOT.
  • Startup / docs — logs ~/.triton, ~/.cache/flashinfer and
    ~/.cache/deep_gemm if present, without touching them; environment-variable
    doc updated.

Important

Every cache moves, so the first launch after upgrading recompiles once.
Copy or symlink the old directory to the new one if you pre-warm or
volume-mount it — deep_gemm and flashinfer are the expensive ones.

was now
~/.triton {SGLANG_CACHE_DIR}/triton
~/.cache/flashinfer {SGLANG_CACHE_DIR}/.cache/flashinfer
~/.cache/deep_gemm {SGLANG_CACHE_DIR}/deep_gemm
/tmp/torchinductor_$USER {SGLANG_CACHE_DIR}/inductor
~/.nv/ComputeCache {SGLANG_CACHE_DIR}/nv

Setting any of TRITON_CACHE_DIR, FLASHINFER_WORKSPACE_BASE,
SGLANG_DG_CACHE_DIR, TORCHINDUCTOR_CACHE_DIR or CUDA_CACHE_PATH
keeps that one where it is.

Verification

E2E on a clean L4 studio, Qwen2.5-1.5B:

  • all four env vars resolve under ~/.cache/sglang
  • after a full launch + request, every cache landed there
    (triton 464K, .cache/flashinfer 5.9M, inductor, nv) and nothing
    appeared outside it
  • the legacy-dir notice fires only when those directories exist

Accuracy Tests

No forward or weight-loading logic changed — only where derived artifacts are
written.

Speed Tests and Profiling

No inference-path impact. One-time recompile on upgrade, see the note above.


CI States

Latest PR Test (Base): ⏳ Run #30972987487
Latest PR Test (Extra): ✅ Run #30972987297

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88a6597320

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@shuwang21

Copy link
Copy Markdown
Contributor Author

one open question: should presharded checkpoints really live under the same root as the kernel caches?

Comment thread python/sglang/srt/environ.py Resolved
Comment thread python/sglang/srt/environ.py Resolved
Comment thread scripts/ci/cuda/warmup_deep_gemm.py Resolved
Comment thread python/sglang/__init__.py Resolved
Comment thread python/sglang/__init__.py Resolved
Comment thread python/sglang/__init__.py Resolved
@github-actions github-actions Bot added documentation Improvements or additions to documentation diffusion SGLang Diffusion labels Aug 2, 2026
@shuwang21
shuwang21 requested a review from Fridge003 August 2, 2026 14:22
@Fridge003 Fridge003 added run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci) release-highlight Candidate PR for release note highlight labels Aug 3, 2026
@shuwang21

Copy link
Copy Markdown
Contributor Author

Rebased to resolve conflicts.

@Fridge003
Fridge003 merged commit 55b1c09 into sgl-project:main Aug 5, 2026
191 of 207 checks passed
chromecast56 added a commit to chromecast56/sglang-fork that referenced this pull request Aug 28, 2026
SGLANG_CUTE_AOT_CACHE_DIR is now registered in environ.py and defaults
to {SGLANG_CACHE_DIR}/cute_aot, matching the convention from sgl-project#32434;
setting it to an empty string keeps compilation process-local.
JITPersistentCache resolves its directory on first storage access so
import-time construction never probes the GPU or hashes sources, which
is what makes default-on safe. The flash_attn cache_config adapter and
the FLASH_ATTENTION_CUTE_DSL_CACHE_* variables are removed; interface.py
consumes the shared factory directly.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diffusion SGLang Diffusion documentation Improvements or additions to documentation release-highlight Candidate PR for release note highlight run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants