Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions models/deepseek/v4/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def mix_hc(self) -> int:


# Deployment constants
DECODE_BATCH = 4 # B: requests per decode step
DECODE_SEQ = 2 # S: 2 tokens per step (MTP)
DECODE_BATCH = 8 # B: requests per decode step
DECODE_SEQ = 1 # S: 1 token per step (single-token decode)
DECODE_TOKENS = DECODE_BATCH * DECODE_SEQ
PREFILL_BATCH = 1 # B: prefill batch for the current kernel programs
PREFILL_SEQ = 128 # S: prefill sequence for the current kernel programs
Expand Down Expand Up @@ -268,6 +268,7 @@ def mix_hc(self) -> int:
# bake different depths; default to decode, prefill overrides to PREFILL_RECV_MAX.
DECODE_RECV_MAX = max(16, DECODE_TOKENS * FLASH.num_experts_per_tok * RECV_SAFETY // (FLASH.n_routed_experts // EP_WORLD_SIZE))
PREFILL_RECV_MAX = max(16, PREFILL_TOKENS * FLASH.num_experts_per_tok * RECV_SAFETY // (FLASH.n_routed_experts // EP_WORLD_SIZE))
PREFILL_RECV_MAX = 1024 # real routing skews past the RECV_SAFETY=4 uniform bound; size for the observed peak
RECV_MAX = DECODE_RECV_MAX

# When True, gate.py's N_EXPERTS uses the full global expert space
Expand Down
33 changes: 17 additions & 16 deletions models/deepseek/v4/moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _parse_ep_argv():
assert N_EXPERTS_GLOBAL == N_RANKS * N_LOCAL


@pl.jit.inline
@pl.jit.inline(auto_scope=False)
def moe(
# model inputs
x_hc: pl.Tensor[[T, HC_MULT, D], pl.BF16],
Expand Down Expand Up @@ -168,23 +168,24 @@ def moe(
num_tokens, my_rank, moe_epoch,
)

recv_y = pl.create_tensor([N_LOCAL, RECV_MAX, D], dtype=pl.BF16)
expert_routed(
recv_x_out, recv_scale_out, recv_w_out, recv_count_out,
routed_w1, routed_w1_scale, routed_w3, routed_w3_scale,
routed_w2, routed_w2_scale,
recv_y,
)
with pl.scope():
recv_y = pl.create_tensor([N_LOCAL, RECV_MAX, D], dtype=pl.BF16)
expert_routed(
recv_x_out, recv_scale_out, recv_w_out, recv_count_out,
routed_w1, routed_w1_scale, routed_w3, routed_w3_scale,
routed_w2, routed_w2_scale,
recv_y,
)

ffn_out = pl.create_tensor([T, D], dtype=pl.BF16)
combine(
recv_y, recv_r_route_out, sh,
ffn_out,
pub_counts, routed_y_buf, combine_done,
num_tokens, my_rank, moe_epoch,
)
ffn_out = pl.create_tensor([T, D], dtype=pl.BF16)
combine(
recv_y, recv_r_route_out, sh,
ffn_out,
pub_counts, routed_y_buf, combine_done,
num_tokens, my_rank, moe_epoch,
)

hc_post(ffn_out, x_hc, post_ffn, comb_ffn, x_next)
hc_post(ffn_out, x_hc, post_ffn, comb_ffn, x_next)
return x_next


Expand Down
Loading