Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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 foundry/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 recipe/sglang/README.md.

The adapted SGLang fork is published at foundry-org/sglang, branch foundry-dep: SGLang declares Foundry as an optional dependency (sglang[foundry]) and calls it through its in-tree adapter when --cuda-graph-persistence is set. See the SGLang recipe for the supported versions.

Performance

SGLang on 8×H100 (2 GPUs per run), all 256 decode graphs captured or restored, prefill graphs off on both sides, median TPOT of restored vs unmodified SGLang:

Config Model Capture Restore Init to /health: SGLang → foundry LOAD TPOT delta (bs 1 / 8 / 32 / 128)
TP=2 (symm-mem) Qwen3-32B 26.7 s 3.5 s 63 s → 41 s -0.4 / -0.3 / +0.0 / -0.7 %
EP=2 (DeepEP LL) Qwen3-30B-A3B 38.0 s 2.5 s 75 s → 45 s -0.0 / -0.0 / +0.1 / +0.6 %
EP=2 (DeepEP v2, NCCL) Qwen3-30B-A3B-FP8 56 s 2.1 s 93 s → 45 s +0.0 / +0.0 / +0.2 / +0.2 %

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.

Roadmap

See ROADMAP.md for the full development plan and progress.

Requirements

  • Linux x86_64, NVIDIA driver with CUDA 12.0+ (the driver's libcuda.so.1 is loaded at runtime)
  • PyTorch: foundry.ops is a torch C++ extension bound to the torch it was built with (major.minor and CUDA major), like sglang-kernel or flashinfer. Importing it under another torch raises a readable error.

Installation

Prebuilt wheels are published as foundry-core (the import name is foundry). A wheel works only with the torch major.minor and CUDA major it was built for, so, like torch itself, the pairs live in separate package indexes selected with --extra-index-url (whl/<cuda>/torch<A.B>/); PyPI carries the pair SGLang pins:

foundry-core torch pair index CPython Platform
0.1.x (0.1.0rc2 on) 2.14 (torch==2.14.1), cu130 PyPI, whl/cu130/torch2.14/ 3.10-3.13 manylinux_2_28 x86_64
0.1.x 2.13 (torch==2.13.0), cu130 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.0rc2,<0.2"
python -c "import foundry; print(foundry.__version__)"

# another pair: add its index (the wheel there carries a local version, +cu130.torch2.13)
pip install "torch==2.13.0" --index-url https://download.pytorch.org/whl/cu130
pip install "foundry-core>=0.1.0rc2,<0.2" --extra-index-url https://foundry-org.github.io/foundry/whl/cu130/torch2.13/

The wheel ships foundry/ops.*.so 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 any other torch, or for development. Requirements:

  • CMake 4.0+ and ninja (pip install "cmake>=4.0" ninja if the system ones are older)
  • the torch you will run with, already installed (Foundry compiles against it; rebuild after changing torch)
  • 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.

Debugging

Verbose C++ logging (allocator hook and graph replay) is gated behind a single compile-time flag, FOUNDRY_DEBUG. Uncomment the // #define FOUNDRY_DEBUG line at the top of csrc/hook.cpp or csrc/CUDAGraph.cpp (or build with -DFOUNDRY_DEBUG) and reinstall. With the flag on, every LOAD also logs a per-graph check that the restored edge records (PDL programmatic edges) survived insertion; see docs/pdl-edge-batching.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; 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/

Unit and single-GPU tiers run by default; engine launches and multi-GPU tiers 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.

Setting up clangd

conda install -c conda-forge libstdcxx-ng libgcc-ng
conda install -c conda-forge bear
bear -- python setup.py build_ext --inplace

Contributors

  • Xueshen Liu
  • Yongji Wu

Metadata

Release files for foundry-core 0.1.0rc5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for foundry-core 0.1.0rc5
File Size Uploaded Provenance Actions
foundry_core-0.1.0rc5.tar.gz 1.3 MB With provenance Details for foundry_core-0.1.0rc5.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for foundry-core 0.1.0rc5
File Actions
foundry_core-0.1.0rc5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for foundry_core-0.1.0rc5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
foundry_core-0.1.0rc5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for foundry_core-0.1.0rc5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
foundry_core-0.1.0rc5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for foundry_core-0.1.0rc5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
foundry_core-0.1.0rc5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for foundry_core-0.1.0rc5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Total release size: 44.4 MB

Release files / foundry_core-0.1.0rc5.tar.gz

Download URL foundry_core-0.1.0rc5.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
867234d95bdd19d19746d629f4a6fa5ee5873bf73f69dea4cbb8b6f02f5d36dc
BLAKE2b-256 checksum
How to use checksums
e205db82ef6f3339584e8b562d7f0b88f88785428a5912195dc60dae3139f534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / foundry_core-0.1.0rc5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL foundry_core-0.1.0rc5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.8 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ade47a0b0b597cc3bb2a48bfb8bcfa6fa3410bcd28e079eba32888a8919edfc7
BLAKE2b-256 checksum
How to use checksums
449c821b7703442c2b12a9164ffae15e60d73d23cb2731a023be600e5228006c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / foundry_core-0.1.0rc5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL foundry_core-0.1.0rc5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.8 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bcceeb82e46ddfa981f5d455fcae5f09527552fbbc7b27999a4440b044990511
BLAKE2b-256 checksum
How to use checksums
c3f317c589a3f6dd15908633308d3f1170bb3d916b65974bf76372412d9433df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / foundry_core-0.1.0rc5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL foundry_core-0.1.0rc5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.8 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2cf48a9661c6e4404195ce1eb7e4acef38baf96d958e4f5676038542e0af3529
BLAKE2b-256 checksum
How to use checksums
66ae6bc4257238b9ddbaf338f2c0b500c1f49f011241b94517e6afcd98f2c895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / foundry_core-0.1.0rc5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL foundry_core-0.1.0rc5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.8 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a01de71fb98266b7d79999bb247552cb9913f4d761c781094a7b7894fafa4f50
BLAKE2b-256 checksum
How to use checksums
133a7b39bb1fee13ea114f5d38dab3ebf16770635229d2d1bf3ad8d9379e692a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for foundry-core 0.1.0rc5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for foundry_core-0.1.0rc5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page