Skip to content
项目

关于

Foundry materializes CUDA graphs along with its execution context to disk to support fast cold start of serving engines.

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
正在收集历史
15天
正在收集历史
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Foundry

Instantaneous CUDA graph restoration via execution context materialization.

Python arXiv License

Foundry is a system that persists CUDA graph states through template-based context materialization. It materializes both the structure and execution context of captured CUDA graphs, making graph restoration kernel-agnostic and eliminating the need for hand-crafted patching rules. By intercepting CUDA driver calls, Foundry enforces a deterministic memory layout and automatically detects and serializes the binaries of kernels used in the CUDA graphs.

With Foundry, LLM serving engines can directly reload CUDA states from disk and skip the warmup process to start in a few seconds.

Foundry in Action

Demonstration of serving Qwen/Qwen3-30B-A3B-FP8 with expert parallel size = 2.

Foundry vs. baseline vLLM cold start

Baseline vLLM (top) vs. vLLM + Foundry (bottom). Foundry reconstructs 256 graphs in 1 sec (plus ~2 sec sampler warmup + API server init), while original vLLM spends around 30 sec to warmup and capture graphs.

How it works

Foundry intercepts three classes of CUDA driver calls and routes each through its own piece of in-process state, so SAVE can serialize that state to disk and LOAD can rebuild an identical driver-side state from the archive.

flowchart LR
    subgraph APP["Application calls"]
        direction TB
        A1["cudaMemXXX"]
        A2["cudaModuleLoadXXX<br/>cudaLibraryLoadXXX"]
        A3["cudaGraph capture<br/>cudaGraphLaunch"]
    end

    subgraph FDR["Foundry: indirection &amp; interception"]
        direction TB
        F1["<b>VMM region</b><br/>monotonic cursor →<br/>byte-deterministic offset"]
        F2["<b>Module registry</b><br/>fatbin bytes,<br/>entry_name → CUfunction"]
        F3["<b>Captured graphs</b><br/>each topology group:<br/>1 template + N on-demand"]
    end

    subgraph DRV["CUDA driver / context"]
        direction TB
        D1["cuMemCreate / cuMemMap<br/>cuMemAddressReserve"]
        D2["cuLibraryLoadData<br/>cuLibraryGetKernel"]
        D3["CUgraph<br/>CUgraphExec"]
    end

    A1 --> F1 --> D1
    A2 --> F2 --> D2
    A3 --> F3 --> D3

    classDef app fill:#dfe8ff,stroke:#4060c0,color:#000
    classDef fdr fill:#ffe8d6,stroke:#c08040,color:#000
    classDef drv fill:#d8f0d8,stroke:#40a040,color:#000
    class APP app
    class FDR fdr
    class DRV drv
  • Memory. Every device allocation is funneled into a single VMM region [base_addr, base_addr + region_size). A monotonic cursor gives every tensor a byte-deterministic offset; the underlying physical mapping is done with cuMemCreate + cuMemMap.
  • Modules / libraries. As device code is loaded, the fatbin bytes and the entry_name → CUfunction table are recorded. A device-linked library passed to cuLibraryLoadData (NCCL's) is archived as passed and restored with the same call and options, never re-linked.
  • Captured graphs. Each captured CUgraph is serialized and then grouped with other graphs that share the same topology (same kernels, dependency DAG and cluster dimensions; they differ only in kernel parameters). One graph per group is kept as the template; the rest are stored as on-demand members that carry only their per-node kernel parameters.

SAVE writes all three pieces to an archive. LOAD pre-maps the same VMM range, re-loads the same modules from the packed fatbins, builds each template's CUgraph node by node once, and then produces every member by rewriting the template's node parameters, either into a dedicated CUgraphExec per member (default, eager or lazy) or into one shared exec per template switched with cuGraphExecUpdate. Either way restored graphs replay at native speed; kernel handles embedded in the captured graphs resolve to the same device addresses they had at SAVE time. See docs/graph-templates.md for the design and measurements.

Inference-Engine Integrations

Foundry ships engine integrations under python/foundry/integration/. Per-engine setup instructions live under recipe/.

Engine Integration code Documentation Setup Instructions
SGLang integration/sglang/ docs/sglang/overview.md recipe/sglang/README.md
vLLM integration/vllm/ docs/vllm/overview.md recipe/vllm/README.md
TensorRT-LLM integration/trtllm/ docs/trtllm/overview.md recipe/trtllm/README.md

Status

Engine Single GPU DP TP EP
SGLang ✅ ✅ ✅ ✅
vLLM ✅ ✅ 🚧 ✅
TensorRT-LLM 🚧 🚧 🚧 🚧

✅ validated end-to-end (SAVE → LOAD → query)  ·  🚧 not yet

SGLang TP uses torch symmetric-memory allreduce inside the decode graphs (TP=2/4); SGLang EP covers DeepEP low-latency (NVSHMEM) and DeepEP v2 (NCCL symmetric windows). Every SGLang configuration is validated with the full decode-graph set (batch sizes 1..256) for restore time, per-token latency and greedy-output equality against unmodified SGLang; see docs/sglang/validated-configs.md.

The SGLang adapter is part of upstream SGLang (sgl-project/sglang#42254): SGLang declares Foundry as an optional dependency (sglang[foundry]) and calls it through its in-tree adapter when --cuda-graph-persistence is set. No fork is needed. See the SGLang recipe for the supported versions.

Performance

SGLang with Qwen3.5-35B-A3B on 2×H100: seconds from launch to the first /health (dummy weights, without buffer-prep optimization).

Config SGLang Foundry LOAD Foundry LOAD + CRIU
TP=2, 256 decode graphs 60.8 s 21.1 s 10.2 s
EP=2 (DeepEP), 256 decode graphs 59.9 s 22.5 s 11.3 s
TP=2, unified memory 62.6 s 21.8 s 10.7 s
TP=2, breakable prefill, MTP draft 33.3 s 22.8 s 12.7 s
EP=2, breakable prefill, MTP draft 50.1 s 24.4 s 13.5 s

Restored graphs keep their programmatic-dependent-launch edges, so per-token latency matches the captured graphs within run-to-run noise (docs/pdl-edge-batching.md). Greedy completions are identical to unmodified SGLang for dense TP and within SGLang's own run-to-run nondeterminism for MoE.

Requirements

  • Linux x86_64, NVIDIA driver with CUDA 12.0+ (the driver's libcuda.so.1 is loaded at runtime)
  • PyTorch >= 2.14 with the wheel's CUDA major: foundry.ops uses only the LibTorch Stable ABI (target 2.14), so one build loads on torch 2.14 and every later release. Importing it under an older torch or another CUDA major raises a readable error.

Installation

Prebuilt wheels are published as foundry-core (the import name is foundry). From 0.1.0: one wheel per CUDA major for every CPython >= 3.10, requiring torch>=2.14. Install torch first (pip would otherwise resolve it from PyPI's default build):

foundry-core torch index CPython Platform
0.1.0 and later >= 2.14, cu13x PyPI, whl/cu130/ >= 3.10 manylinux_2_28 x86_64
0.1.0rc2-0.1.0rc5 ==2.14.1 (cu130) / ==2.13.0 (cu130) PyPI / whl/cu130/torch2.13/ 3.10-3.13 manylinux_2_28 x86_64
pip install "torch==2.14.1" --index-url https://download.pytorch.org/whl/cu130
pip install "foundry-core>=0.1.0,<0.2"
python -c "import foundry; print(foundry.__version__)"

The wheel ships foundry/libfoundry_ops.so (torch custom ops, no Python C API) and foundry/libcuda_hook.so (the hook SGLang/vLLM preload around their workers). No Boost or other C++ runtime dependency is needed. Every wheel is also attached to the GitHub Release.

From source

Needed for another CUDA major, or for development. Requirements:

  • CMake 4.0+ and ninja (pip install "cmake>=4.0" ninja)
  • torch >= 2.14, already installed (Foundry compiles against its stable-ABI headers; the build loads on any later torch with the same CUDA major)
  • CUDA Toolkit with nvcc (CUDA 12+; CUDA 13 with torch cu130)
  • Boost headers, header-only (nothing is linked): the vendored copy in third_party/boost (populated by tools/release/vendor_boost.sh), or a system Boost >= 1.83 (Ubuntu 24.04: apt-get install libboost-dev; conda: conda install -c conda-forge boost-cpp; or point FOUNDRY_BOOST_INCLUDE_DIR at the directory that contains boost/version.hpp)
pip install "cmake>=4.0" ninja
# Torch 2.14 with CUDA 13.0
pip install torch==2.14.1 --index-url https://download.pytorch.org/whl/cu130
pip install -e . --no-build-isolation

--no-build-isolation matters: an isolated build compiles against whatever torch pip resolves, not the one in your environment. From PyPI's sdist into an existing environment: pip install --no-build-isolation --no-binary foundry-core foundry-core.

Release process (vendoring Boost, tagging, trusted publishing): docs/release.md.

Usage

Foundry is used through an inference engine, not by calling its Python API directly. For SGLang, install sglang[foundry] and start the server with --cuda-graph-persistence save once, then --cuda-graph-persistence load; the archive goes under SGLANG_CACHE_DIR unless a Foundry TOML names one; ready-to-run scripts per model and topology are in the SGLang recipe. For vLLM, see the vLLM recipe.

Testing

Run the test suite:

pytest tests/

The unit, core (1 GPU), multi-GPU (2 GPUs) and SGLang tiers run by default and skip what the host lacks; engine launches are opt-in (pytest tests/unit on a host without a GPU, -m slow for the SGLang engine tests, -m "slow and multigpu" for the 2-GPU ones). See tests/README.md.

Contributors

  • Xueshen Liu
  • Yongji Wu

探索相关项目

加载中…