Skip to content

[EP] Add JIT compilation support to Mooncake EP CUDA backend - #4581

Merged
UNIDY2002 merged 17 commits into
kvcache-ai:mainfrom
Bonjourz:bojunz/ep_jit_pr
Oct 27, 2026
Merged

UNIDY2002 merged 17 commits into
kvcache-ai:mainfrom
Bonjourz:bojunz/ep_jit_pr

Conversation

@Bonjourz

@Bonjourz Bonjourz commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

Port the JIT framework from NCCL-EP to Mooncake-EP, enabling on demand compiling CUDA kernels:

  • Add runtime source generation, nvcc compilation, CUDA module lading, and launch kernel support.
  • Cache compiled artifacts on disk and loaded kernels in memory, with a warm launch path that avoids source generation and file I/O.
  • Move standard dispatch and combine kernel implementations into reusable headers and route their CUDA launches through JIT.
  • Extend JIT coverage to ElasticBuffer kernels, including NCCL and IBGDA transport variants.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Test tracking items:

  • Unit tests pass
  • Integration tests pass: Have tested on H100 and GB300 platforms
  • Manual testing done (describe below)

Build

Build command:

cmake -S . -B build -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DWITH_EP=ON \
    -DUSE_CUDA=ON \
    -DCMAKE_CUDA_ARCHITECTURES=[90|100|103] \
    -DUSE_NCCL_DEVICE=ON \
    -DNCCL_ROOT=path/to/nccl" \
    -DWITH_STORE=OFF \
    -DWITH_STORE_RUST=OFF \
    -DBUILD_UNIT_TESTS=ON \
    -DBUILD_EXAMPLES=ON \

cmake --build build -j $(nproc)

Functionality Test

torch mooncake-ep/tests/test_elastic_buffer.py \
  --transport nccl --route alltoall --num-tokens 32 --max-tokens 128 \
  --hidden 4096 --num-experts 256 --num-topk 8 --num-sms 24 --warmup 20 --iters 200

Performance Test

Configuration: BF16, 32 tokens per rank, hidden size 4096, top-k 8, 256 experts, 24 communication SMs, 20 warm-up iterations, 200 measured iterations and 5 repetitions. The value is the mean of 5 runs.

GB300 platform, NCCL 2.31.2-1, CUDA 13.0, Python 3.12.3, torch 2.14.1

Topology JIT support Dispatch critical (mean, SD, ms) Combine critical (mean, SD, ms) E2E critical (mean, SD, ms) Wall/iter (mean, SD, ms)
1 node, 2 GPUs with JIT 0.176/0.008 0.124/0.003 0.300/0.011 0.769/0.015
1 node, 2 GPUs vanilla 0.170/0.003 0.123/0.001 0.292/0.004 0.762/0.007
2 nodes, 4 GPUs per node with JIT 0.241/0.006 0.149/0.002 0.384/0.009 0.837/0.009
2 nodes, 4 GPUs per node vanilla 0.242/0.005 0.151/0.002 0.386/0.007 0.838/0.007

Compilation Test

Without JIT support, a fixed set of instantiations combination of template parameter need to be compiled. That bloat the binary size. With JIT, the combination is determined based the user's need.

Without JIT support, the size of libmooncake_ep_device.so is 33M:

33M -rwxrwxr-x 1 ubuntu ubuntu 33M Oct 27 03:14 libmooncake_ep_device.so

with JIT support, the size is reduced to 6M:

6.0M -rwxrwxr-x 1 ubuntu ubuntu 6.0M Oct 27 02:45 ./build/mooncake-ep/src/libmooncake_ep_device.so

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
    The deployment guide for JIT support docs/source/deployment/mooncake-ep-jit.md is updated.
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

The code changes were made with the help of AI. The author reviewed the implementation and test results.

@Bonjourz
Bonjourz marked this pull request as ready for review October 16, 2026 14:41
Comment thread mooncake-ep/src/CMakeLists.txt Resolved
@UNIDY2002

Copy link
Copy Markdown
Collaborator

Hi @Bonjourz! Could you help merge Mooncake's latest main into this branch? Thanks!

@Bonjourz
Bonjourz force-pushed the bojunz/ep_jit_pr branch 8 times, most recently from b962126 to 92f43a8 Compare October 26, 2026 13:36
@github-actions github-actions Bot added the size/L 1001+ changed lines (additions + deletions) label Oct 26, 2026
The framework is ported from nccl_ep JIT module
(https://github.com/NVIDIA/nccl-extensions/tree/nccl-extensions-v0.1.0/nccl_ep/device/jit)

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Same approach as nccl-ep, with one change: jit_runtime.cpp includes
jit_config.h directly, instead of the compiler adding it to every file,
so readers can see where the path macros come from.

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
The CUDA EP JIT runs nvcc on the user's machine, so the kernel headers
staged under 'build/mooncake_ep_jit/' must be shipped with the wheel,
and the runtime must find them next to the installed library.

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
The 'sm_min' in mooncake-ep is sm 80. Make the 'sm_min' explicitly
configured by upper level.

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
All the kernels in mooncake-ep are launched with cooperative launch.

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
mooncake-ep only uses int64_t for top-k indices, but NVCC_EXTRA_FLAGS
can make 'topk_idx_t' a different type in the JIT compile. Add a static
assertion so that fails at compile time.

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
@Bonjourz

Bonjourz commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @Bonjourz! Could you help merge Mooncake's latest main into this branch? Thanks!

Hi @UNIDY2002 . I have updated update branch based on the latest main.

By the way, I also added docs for JIT deployment (docs/source/deployment/mooncake-ep-jit.md), and then updated the mooncake-ep docs (docs/source/design/mooncake-ep.md) to announce that JIT is supported on NVIDIA's backend.

@Bonjourz Bonjourz changed the title [EP] Add JIT compilation for dispatch and combine kernels [EP] Add JIT compilation support to Mooncake EP CUDA backend Oct 27, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 27, 2026
@UNIDY2002

Copy link
Copy Markdown
Collaborator

@UNIDY2002

UNIDY2002 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Signed-off-by: Bojun Zhu <bojunz@nvidia.com>
@UNIDY2002

Copy link
Copy Markdown
Collaborator

LGTM. Let's wait for the Mooncake CI results.

@UNIDY2002 UNIDY2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

@UNIDY2002
UNIDY2002 merged commit dfd1b71 into kvcache-ai:main Oct 27, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Integration Mooncake EP run-ci size/L 1001+ changed lines (additions + deletions)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants