Archive of AI

Source Snapshot / 2025-02-24-deepseek-open-source-week-3

deepseek-ai/DeepEP

Linked event: 2025-02-24 · DeepSeek Launches "Open Source Week," Open-Sourcing Full-Stack Core Infrastructure Over Five Consecutive Days

Publisher
GitHub
Archived
2026-11-23
Capture Method
Direct page capture
HTTP / SHA-256
200 / a1583961c372a078
Original URL
Open source ↗
Wayback Backup
Not archived
This page preserves a plain-text static snapshot against link rot. When citing figures, tables, or full legal terms, verify against the original URL and Wayback Machine archive.

Skip to content

Navigation Menu

Appearance settings

You signed in with another tab or window. Reload to refresh your session.

You signed out in another tab or window. Reload to refresh your session.

You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Repository navigation

NotificationsYou must be signed in to change notification settings

Fork1.6k (1.6k)

Star10.5k (10.5k)You must be signed in to star a repository

DeepEP: an efficient expert-parallel communication library

Custom properties

110 watching

Report repository

BranchesTags

Open more actions menu

Latest commit

Folders and files

Last commit message

Last commit date

.editorconfig

CMakeLists.txt

View all files

Repository files navigation

DeepEP (DeepEveryParallel) is a high-performance communication library for machine learning training and inference. It provides high-throughput and low-latency expert-parallel (EP) all-to-all GPU kernels for MoE dispatch and combine, including FP8 dispatch, and NVLink weight and gradient exchange for redundant experts. It also offers experimental primitives for pipeline parallelism (PP), context parallelism (CP), data parallelism (DP), and remote memory access (Engram). Communication kernels are compiled at runtime via DeepJIT, with the supporting extension built during installation.

Ascend version release

Same API and full performance on HUAWEI Ascend 950 NPUs

Check DeepEP-Ascend for more details

V2.5 release:

Split ElasticBuffer into EPBuffer, EngramBuffer, PPBuffer, and BucketBuffer, sharing the BufferBase lifecycle

Add BufferAllocator for planning symmetric tensor allocations before buffer construction

Add batched all-gather, reduce-scatter, and all-reduce through BucketBuffer, with sessions for ordinary PyTorch tensors

Add EPBuffer.lb_prefetch_weights and EPBuffer.lb_reduce_grads for dynamic redundant experts: prefetch expert weights and quantization scales over NVLink before expert computation, then accumulate redundant experts' FP32 gradients into the original experts during backward. These primitives support the expert-replication approach explored by MoonEP and UltraEP; see Expert load balancing for the API and integration requirements

Support deferred EP epilogues, cached expanded layouts, and zero padding between experts

Support multi-layer Engram storage on GPU or CPU, with one wait hook per layer

Fully remove V1, including its APIs, NVSHMEM backend, and legacy documentation. NVSHMEM is no longer a dependency

V2 release: A complete refactoring of expert parallelism, with support for larger scale-up and scale-out domains and the lightweight NCCL Gin backend.

New features

JIT-compiled communication kernels via DeepJIT

NCCL Gin backend

Lightweight device-side communication APIs

Able to reuse existing NCCL communicators

High-throughput and low-latency APIs unified into a single EPBuffer interface, with an expanded layout for grouped expert GEMMs

Larger scale-up & scale-out domain support

Analytical SM & QP count calculation — no more auto-tuning needed

Both hybrid & direct modes remain supported

Engram (experimental, with RDMA)

PP (experimental, with RDMA)

Bucket collectives (experimental) for CP and DP (all-gather, reduce-scatter, and all-reduce)

EP dispatch and combine require GPU SMs; zero-SM RDMA EP is not supported

Bucket, Engram, and PP are experimental features

Engram requires a NCCL build providing ncclGinOptFlagsWarpGet

Requirements

Python 3.10 and above

NVIDIA Hopper or newer GPUs

CUDA Toolkit 13.1 and above for DeepJIT compilation, with support for the target GPU

A C++20 compiler and standard library with std::format support

PyTorch 2.10 and above, with CUDA support

NCCL 2.32.3 and above

NVLink for intranode communication

RDMA network for internode communication

Installation builds the host C++ extension against the CUDA and NCCL libraries. GPU kernels are compiled by DeepJIT for the current device at runtime, so installation does not require a visible GPU or TORCH_CUDA_ARCH_LIST. Keep the CUDA toolkit and host compiler available at runtime. Automatic bandwidth detection uses nvidia-smi and ibstat; BucketBuffer currently requires both NVLink and RDMA bandwidth to be detectable, even for a group using only one transport.

Install NCCL dependency

Install the NCCL package matching your CUDA environment so DeepEP can locate its headers and library:

python -m pip install "nvidia-nccl-cu13>=2.32.3" --no-deps

# For CUDA 12.x, use nvidia-nccl-cu12 instead

For a custom NCCL installation, set EP_NCCL_ROOT_DIR to a directory containing include/ and lib/. PyTorch and DeepEP must load the same NCCL shared library. Builds using NCCL headers older than 2.31 additionally require an exact compile-time/runtime NCCL version match.

Installation

# Initialize the DeepJIT submodule

git submodule update --init --recursive

# Build a wheel and install it into the current Python environment

bash install.sh

Then import deep_ep in your Python project.

Development and tests

# Build and link the extension into the source tree

bash develop.sh

# Run test cases

python tests/ep/test_ep.py

python tests/bucket/test_all_gather.py

python tests/bucket/test_reduce_scatter.py

python tests/bucket/test_all_reduce.py

python tests/buffer/test_allocation.py

python tests/ep/test_prefetch_weights.py

python tests/ep/test_reduce_grads.py

python tests/engram/test_engram.py

python tests/pp/test_pp.py

The test scripts require NumPy and spawn local GPU workers. For multi-node tests, launch the same script on each node with a shared MASTER_ADDR and MASTER_PORT, setting WORLD_SIZE to the number of nodes and RANK to the node index. These are the conventions of init_dist in deep_ep/utils/envs.py; adapt it to your cluster if needed. The tests default to NCCL_IB_SL=1 and EP_OVERRIDE_RDMA_SL=1 unless already set. Weight-prefetch and gradient-reduction tests use a single NVLink domain; PP tests require an RDMA-only group.

Interfaces and examples

Buffer initialization

High-throughput and low-latency EP operations share a single EPBuffer interface. Initialize the buffer with MoE settings directly; SM and QP counts are estimated analytically and can be overridden per call.

Create and reuse a buffer for each EP group. All ranks must agree on num_max_tokens_per_rank; choose a common capacity covering the intended training, prefill, and decoding batches. The example below manages one EP group. Finish outstanding operations before replacing its buffer.

import torch.distributed as dist

from typing import Optional

from deep_ep import EPBuffer

# Communication buffer (will allocate at runtime)

_buffer: Optional[EPBuffer] = None

# Number of SMs to use for communication kernels (will be set at buffer creation)

_num_comm_sms: int = 0

def get_buffer(group: dist.ProcessGroup,

num_max_tokens_per_rank: int,

hidden: int,

num_topk: int,

num_experts: int,

use_fp8_dispatch: bool = False) -> EPBuffer:

"""Initialize or retrieve the EPBuffer for EP communication."""

global _buffer, _num_comm_sms

# Check if we can reuse the existing buffer

required_bytes = EPBuffer.get_buffer_size_hint(

group, num_max_tokens_per_rank, hidden,

num_topk=num_topk, use_fp8_dispatch=use_fp8_dispatch,

if _buffer is not None and _buffer.group == group and _buffer.num_bytes >= required_bytes:

_num_comm_sms = _buffer.get_theoretical_num_sms(num_experts, num_topk)

return _buffer

# Allocate a new buffer with MoE settings

_buffer = EPBuffer(

num_max_tokens_per_rank=num_max_tokens_per_rank,

hidden=hidden,

num_topk=num_topk,

use_fp8_dispatch=use_fp8_dispatch,

# Estimate the SM count from the topology and communication volume

# You may also specify `num_sms` manually in dispatch/combine calls to override

Example use in model training and inference

[...内容已截断,完整版请查看原文或 Wayback 快照]