Skip to content

Add cuda_extension_utils JIT loader for CUDA/C++ extensions - #700

Merged
AkshitaB merged 3 commits into
akshitab/moe-v2-corefrom
akshitab/moe-cuda-extension-loader
Jun 5, 2026
Merged

AkshitaB merged 3 commits into
akshitab/moe-v2-corefrom
akshitab/moe-cuda-extension-loader

Conversation

@AkshitaB

@AkshitaB AkshitaB commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

olmo_core.kernels.cuda_extension_utils — a generic just-in-time loader (load_cuda_extension) for CUDA/C++ extensions built via torch.utils.cpp_extension, with:

  • arch/ABI-tagged build directories, so a cached build isn't reused across an incompatible torch/CUDA/arch toolchain;
  • cross-process build-lock handling, so concurrent ranks don't clobber each other's builds.

Import-safety / testing

Pure-Python and import-safe on CPU — the cpp_extension import is lazy, so importing the module needs neither a GPU nor a compiler. Includes cuda_extension_utils_test.py, a CPU unit test for the pure-Python helpers (env parsing, arch/ABI tag construction, lock handling). The actual extension build is exercised by GPU tests on hardware.

🤖 Generated with Claude Code

Generic just-in-time loader (`load_cuda_extension`) that builds and caches CUDA/C++
extensions via torch.utils.cpp_extension, with arch/ABI-tagged build directories and
cross-process build-lock handling so concurrent ranks don't clobber each other's
builds. Pure-Python and import-safe on CPU (the cpp_extension import is lazy).
Includes a CPU test for the pure-Python helpers.

Co-Authored-By: Akshita Bhagia <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@AkshitaB
AkshitaB force-pushed the akshitab/moe-cuda-extension-loader branch from 73d44d9 to d424e5f Compare June 3, 2026 23:27
@allenai allenai deleted a comment from chatgpt-codex-connector Bot Jun 3, 2026
… API

load_cuda_extension is the only function called outside this module, so:
- rename the internal helpers cuda_arch_tag -> _cuda_arch_tag,
  torch_extension_abi_tag -> _torch_extension_abi_tag, and
  maybe_remove_stale_build_lock -> _maybe_remove_stale_build_lock (and update
  the unit-test imports), so they don't read as public API or get auto-documented;
- add __all__ = ["load_cuda_extension"] to declare the real public surface;
- add a return annotation to load_cuda_extension and an _env_int helper (replacing
  int(_env_float(...)) for the retry count).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…t wording

- _force_rebuild_build_directory: gate the wipe on get_fs_local_rank() == 0 instead
  of global rank 0. The JIT build cache is typically node-local, so global-rank-0-only
  wiping left every other node's cache stale on multi-node jobs. get_fs_local_rank()
  resolves to global rank 0 on a shared FS (OLMO_SHARED_FS=1), per-node local rank 0 on
  node-local FS, and 0 when not distributed -- so each distinct cache is wiped once.
- Correct the docstring: torch.utils.cpp_extension (not torch) is the lazily-imported
  part; import torch stays top-level.
- Add a CPU test for the non-distributed force-rebuild path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@AkshitaB
AkshitaB requested a review from undfined June 5, 2026 17:59
@AkshitaB
AkshitaB merged commit b82d977 into akshitab/moe-v2-core Jun 5, 2026
40 of 45 checks passed
@AkshitaB
AkshitaB deleted the akshitab/moe-cuda-extension-loader branch June 5, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants