op_builder: make JIT compile robust to non-curated conda envs - #143
Draft
Andrewxu313 wants to merge 1 commit into
Draft
op_builder: make JIT compile robust to non-curated conda envs#143Andrewxu313 wants to merge 1 commit into
Andrewxu313 wants to merge 1 commit into
Conversation
The default torch.utils.cpp_extension.load() invocation in jit_load()
fails out-of-the-box on any conda env that wasn't pre-blessed for
BatchGen, because torch's bundled CUDA libs, the system numa.h, and
nvcc's host-compiler version checks are all left up to the user to wire
up. We hit six distinct failure modes installing on a fresh Gemini-class
H20 node (different conda env, gcc-14, no LD_LIBRARY_PATH for nvidia/*,
hardcoded -L<env>/lib/stubs without `targets/x86_64-linux/lib` for the
libnuma symlink).
This patch makes JIT mode resilient to those quirks without changing
behaviour on the curated H20 envs:
builder.py: new OpBuilder._augment_jit_env(), called from jit_load()
just before torch.utils.cpp_extension.load:
- Prepend <torch>/lib + every <site-packages>/nvidia/*/lib to
LD_LIBRARY_PATH, so downstream `import deep_gemm` etc. don't fail
with `libc10.so: cannot open shared object file` or
`__nvJitLinkCreate_12_8 undefined`.
- Prepend $CUDA_HOME/include and $CONDA_PREFIX/include to CPATH, so
.cpp files including <cuda.h> or <numa.h> compile against the conda
headers (the conda compiler's sysroot has neither).
- Prepend $CONDA_PREFIX/{targets/x86_64-linux/lib,lib} to LIBRARY_PATH
so ld can find conda-managed libs at link time.
- If the active host compiler's gcc major > the running nvcc's
supported max (CUDA 12.x caps at gcc 12), search for a peer conda
env with a compatible gcc and pass it via -ccbin, plus prepend
-allow-unsupported-compiler to NVCC_PREPEND_FLAGS.
core_engine.py: extra_ldflags() now adds $CONDA_PREFIX/targets/x86_64-linux/lib
and $CONDA_PREFIX/lib in addition to lib/stubs, fixing
`/usr/bin/ld: cannot find -lnuma` on Gemini conda envs (libnuma is a
symlink at targets/x86_64-linux/lib/libnuma.so but not at lib/stubs).
All path additions are prepends, idempotent, and skipped if the dir
doesn't exist - so this is a no-op on H20-Node1's curated env where the
right paths are already wired up by the existing scripts/install_deps.sh.
Validated end-to-end on Gemini node-1 (Tencent IDC, 8x H20):
- pip install --force-reinstall of v1.0.9.post5 wheels (batchgen-1.0.9.post5,
batchgen_kernels-0.3.1.post3, deep_gemm, flash_mla, flash_attn_3)
- conda env: gcc-14, peer ray env has gcc-11
- Without this patch: 6 rounds of env patching to fight libc10.so /
numa.h / cuda.h / unsupported GNU / _Float32 / -lnuma failures.
- With this patch: `from batchgen import launch_http_server` succeeds
in ~84 s of JIT compile and the resulting core_engine.so is cached.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The default
torch.utils.cpp_extension.load()invocation inOpBuilder.jit_load()fails out-of-the-box on any conda env that wasn't pre-blessed for BatchGen. We hit six distinct failure modes installing v1.0.9.post5 on a Gemini-cluster H20 node (Tencent IDC):libc10.so: cannot open shared object fileconda activatedoesn't add<torch>/libtoLD_LIBRARY_PATH__nvJitLinkCreate_12_8 undefined symbolcusparse.solinks against newernvJitLinkthan the system onecuda.h: No such file or directorynuma.h: No such file or directory$CONDA_PREFIX/include, just not on path)unsupported GNU version! gcc later than 12 are not supportedcannot find -lnuma-L<env>/lib/stubsdoesn't includetargets/x86_64-linux/libwhere the libnuma symlink lives in conda CUDA bundlesThis patch makes
jit_load()resilient to all six without changing behaviour on the curated H20 envs (every change is a prepend, idempotent, and skipped if the dir doesn't exist — so it's a no-op when the right paths are already wired up).What changed
op_builder/builder.py— newOpBuilder._augment_jit_env(), called fromjit_load()just beforetorch.utils.cpp_extension.load:<torch>/lib+ every<site-packages>/nvidia/*/libtoLD_LIBRARY_PATH(fixes 1, 2)$CUDA_HOME/includeand$CONDA_PREFIX/includetoCPATH(fixes 3, 4)$CONDA_PREFIX/{targets/x86_64-linux/lib,lib}toLIBRARY_PATH(helps 6)-ccbin+-allow-unsupported-compilerinNVCC_PREPEND_FLAGS(fixes 5)op_builder/core_engine.py—extra_ldflags()now adds$CONDA_PREFIX/targets/x86_64-linux/liband$CONDA_PREFIX/libin addition tolib/stubs(fixes 6 — the linker invocation itself).Validated on Gemini node-1 (8× H20, conda env
batchgenwith gcc-14, peerrayenv with gcc-11)Before this patch:
from batchgen import launch_http_serverfails through six rounds of env patching, each surfacing a new failure mode.After this patch: same import succeeds in ~84 s of JIT compile,
core_engine.sois cached, subsequent invocations are instant.Test plan
bash scripts/run_test.sh glm5 L1and verify same outcomepython -m batchgen.launch_http_server ...should succeed after justpip installof the v1.0.9.post5 wheels_augment_jit_envis still safe (no AttributeError on missing CUDA paths)tests/test_deepseek_v4_flash_reference.pyafter JIT compile to confirm we haven't regressed parityNotes
os.path.isdirbefore adding, so this is safe to run on machines with partial / non-conda envs._find_peer_compatible_cclookup walks$CONDA_PREFIX/../*/bin/x86_64-conda-linux-gnu-cc— this is the standard conda envs layout, so should hit on most setups. If no peer is found, we still set-allow-unsupported-compileras a fallback.🤖 Generated with Claude Code