Skip to content

Latest commit

 

History

History
129 lines (103 loc) · 6.68 KB

runtime-dependencies.md

File metadata and controls

129 lines (103 loc) · 6.68 KB

Runtime dependency contract

BatchGen validates the complete native runtime before it starts the HTTP server, creates worker processes, allocates model shared memory, or opens the serving port. This turns a first-request import failure into an actionable startup error.

Install a production environment

Use a dedicated Python/conda environment for each incompatible Torch/CUDA ABI. Install BatchGen non-editably from the worktree that owns the server:

./scripts/install_deps.sh --all

The installer verifies the existing Torch contract (2.9.0 with the selected CUDA channel) and fails instead of replacing a mismatched installation. Use --repair only when replacing that Torch installation is intentional:

./scripts/install_deps.sh --all --repair

The installation builds or installs AOT (ahead-of-time) native extensions for batchgen_kernels and batchgen.core_engine, then imports representative extensions outside the checkout. A missing NUMA development header, an incomplete kernel wheel, or a JIT-built extension is an installation failure. The installer does not warm a JIT cache and the server never compiles these extensions on its first request. Since batchgen_kernels 0.6.0 this includes the GLM-5 DSA indexer and FP8 WGMMA MoE kernels, which earlier releases compiled at run time; an environment built for an earlier release must rebuild batchgen_kernels. Triton kernels are the exception: Triton compiles them and caches the binaries in its own cache directory.

Never use an editable install (pip install -e) in a serving environment.

Run from a source worktree

For development, run a worktree directly instead of installing it. Build it once (and after every C++/CUDA change) and point a PYTHONPATH root at it:

./scripts/build_source_runtime.sh \
    --pyroot /path/to/pyroot_mylane \
    --model openai/gpt-oss-120b
PYTHONPATH=/path/to/pyroot_mylane python -m batchgen.launch_http_server ...

The script verifies Torch, builds batchgen.core_engine and batchgen_kernels in place, links pyroot/batchgen and pyroot/batchgen_kernels to the worktree, and runs the preflight. It refuses to repoint a pyroot that already links to a different worktree. Several worktrees can share one environment if they use the same Torch/CUDA ABI and third-party wheels.

Changed Rebuild
Python only nothing
core/** --skip-kernels (a stale core_engine fails the preflight)
batchgen_kernels/src/** --skip-core (the preflight detects an old version or a missing extension, but not stale code in a present extension; always rebuild)
Torch, CUDA, or a third-party native package a new environment

Provenance rule

batchgen, batchgen_kernels, batchgen.core_engine → the same root
                                                   (one site-packages or one worktree)
flash_attn / flash_attn_interface, flash_mla     → site-packages

Mixing roots (for example batchgen from one worktree and kernels from another, or from site-packages) is rejected.

Run the same check without starting a server:

cd / && PYTHONPATH=<pyroot> python -m batchgen.runtime_preflight --model MODEL

It prints the resolved path of every checked module.

Startup checks

python -m batchgen.launch_http_server --model MODEL performs a model-specific preflight before importing the HTTP server. It checks:

  • Torch version and CUDA ABI;
  • the selected tokenizer, EOS IDs, and its chat-template rendering (or the model's explicit non-Jinja formatter);
  • the FlashAttention module the model declares (FA3 or FA2) and FlashMLA where required;
  • the libucx runtime loader and DeepGEMM API where required;
  • a batchgen_kernels version of at least 0.6.0;
  • AOT batchgen_kernels extensions, plus the WGMMA decode kernel on H20; for the GLM-5 family (GLM-5, GLM-5.1, GLM-5.2, GLM-5.3) this includes the DSA indexer extensions (_C_fast_hadamard_transform, _C_fused_rope_hadamard, _C_dsa_fast_topk, _C_indexer_kv_proj_wgmma) and the FP8 WGMMA MoE extensions (_C_fp8_wgmma_grouped_gemm, _C_fp8_wgmma_quant_ops, _C_dispatch_scatter_3d); every model's contract lists each AOT extension its model code can load (MoE GEMMs such as _C_fp8_blockwise_gemm and _C_expert_mxfp4_wgmma included), so a partial kernel build is refused at startup. Extensions built only for sm_90a are required on a Hopper (sm_90) GPU; on other GPUs the model uses its non-WGMMA kernels;
  • a native (AOT) batchgen.core_engine module, not older than core/ when running from a worktree;
  • the provenance rule above.

An unknown model type has no implicit dependency contract and is rejected. Workers run in the same environment the preflight checked, so they resolve the same modules. If a declared module cannot be imported, startup fails; on H20 a WGMMA decode kernel that fails to load is an error, not a switch to FA3.

Interpreting common failures

Message Meaning Correct action
Torch ... unsupported or CUDA ABI mismatch The environment contains a different Torch build Create the matching environment, or explicitly use --repair
batchgen requires batchgen_kernels >= 0.6.0, found ... The kernel package was built for an earlier release Rebuild batchgen_kernels non-editably from this checkout: re-run install_deps.sh --all, or build_source_runtime.sh for a worktree
required runtime module 'batchgen_kernels...' failed to import The kernel build lacks an extension this model requires (for example a GLM-5 DSA or FP8 WGMMA MoE extension) Rebuild batchgen_kernels from this checkout; do not enable a JIT fallback
... same install or worktree batchgen, kernels, and core_engine come from different roots Rebuild one pyroot from one worktree, or reinstall
... outside site-packages A third-party native package is shadowed by a checkout Run from a neutral directory; remove the shadowing path
core_engine ... is older than core/ changed after the last build build_source_runtime.sh --skip-kernels
required runtime module ... failed to import A native dependency or its ABI is incomplete Fix the install; do not add a request-time fallback
core_engine is not an AOT native module The core engine was never built Re-run the installer, or build_source_runtime.sh for a worktree
unknown model type ... no declared runtime contract No exact dependency matrix exists for that model Add and review a model contract before serving it

The preflight is intentionally fail-closed. A healthy HTTP endpoint is not reported until these checks pass, so a later request should not be the first place that discovers FA3/FA2, UCX, Torch ABI, tokenizer, or AOT problems.