Repository navigation
perf(server): keep SGLang tvm_ffi kernels and reuse kept ninja builds in a new container - #993
Conversation
… in a new container The kernel-cache root now covers TVM_FFI_CACHE_DIR, where SGLang 0.5.10 builds its own kernels through tvm_ffi (default ~/.cache/tvm-ffi). Before the engine starts, the adapter gives every file of each kept ninja build the oldest output mtime its .ninja_log recorded, so ninja reuses a build whose files a shared volume returned with new mtimes. It then reads every kept file once, so the engine does not wait on each first read.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
SIE_SGLANG_KERNEL_CACHE_ROOTkeeps the compiler caches of an SGLang load, so a later load can reuse them. On the CUDA 12 bundles (SGLang 0.5.10.post1), three gaps make a new container with a kept root compile almost as much as an empty one:tvm_ffi, which caches underTVM_FFI_CACHE_DIR, by default~/.cache/tvm-ffi.SGLANG_JIT_CACHE_DIR, which only SGLang 0.5.20 uses.tvm_ffirunsninjain its build directory on every load..ninja_log.Change
In
adapters/sglang/_server.py:TVM_FFI_CACHE_DIRjoins the kept directories, as<namespace>/tvm-ffi. An explicit value still wins..ninja_logunder the namespace, each file of that build gets the oldest output mtime the log recorded.Caveat. Unlike Triton, DeepGEMM and SGLang 0.5.20's JIT cache,
tvm_ffiwrites its objects in place rather than publishing them by rename. Two processes that miss the same kernel at once on one shared root both build it in the same directory. ItsFileLock(fcntl.flockon<build>/lock) serializes that only whereflockreaches both processes.Evidence
Setup.
sie-server serve -b <bundle> --preload <model>from this branch.flashinfer-jit-cache0.6.7.post3+cu129, the package perf(server): ship FlashInfer's prebuilt JIT modules in the CUDA 12 SGLang bundles #992 adds) are onPYTHONPATHin every variant except "nothing kept".HOMEand nothing else carried over.loaded.tencent/Hy-MT2-1.8B(sglang)lightonai/LightOnOCR-2-1B(sglang-vision-extract)ninja -vno-op checks and oneptxas --versionprobe. The 4 (Hy-MT2) and 5 (LightOnOCR)tvm_ffikernels gained no new files.tvm_ffikernels in every new container until the files shared one mtime. The ninja test under Validation reproduces that check with a real build.NVIDIA A10, while its writer's card reportedNVIDIA A10G; both came from the same A10G request. The namespace keys on the product name, so that container found an empty namespace and compiled everything (97 s). Its next load reused what it had written (44 s). It is excluded from the new-container column.Validation
tests/adapters/test_sglang.py:TVM_FFI_CACHE_DIRis placed under the namespace.ninjabuild whose source and object come back with mtimes later than the logged ones is reused, with "no work to do". This test skips whereninjaorccis missing. It was run with ninja 1.13.0.-k sglangovertests/adapters/): 1032 passed, 4 skipped.ruff check,ruff format --checkandmise run typecheckare clean.Summary by CodeRabbit