Skip to content

feat(metax): add scalar Mul and native DeepseekMoe for DeepSeek-style MoE - #1050

Open
rubik-hua wants to merge 1 commit into
InfiniTensor:masterfrom
rubik-hua:metax-021-ops
Open

rubik-hua wants to merge 1 commit into
InfiniTensor:masterfrom
rubik-hua:metax-021-ops

Conversation

@rubik-hua

Copy link
Copy Markdown
Contributor

Add the MetaX operators the 021 model (DeepseekV2-style MoE with
80 experts, top-7 routing) needs beyond the core inference set:

  • Scalar Mul: the shared CudaMul only prepares tensor x tensor multiplication; its scalar constructor is protected and its scalar operator() rejects scalar mode, so dispatching Mul(tensor, double, tensor) found no MetaX provider. Add a native scalar kernel with contiguous and strided paths over fp16/bf16/fp32/fp64; the strided metadata is allocated at prepare time so the buffer outlives the asynchronous kernel launch.

  • DeepseekMoe: replace the throw stub with a native expert-grouped implementation. Routing runs on device (expert counting, prefix scan, pack-by-expert), per-expert gate/up/down projections go through mcblasGemmStridedBatchedEx with batch=1 (the pattern moe_fused_dense already exercises on MetaX), SiLUuptopk_weight applies in place, and a final kernel sums the top-k contributions per token. Large prefills are chunked to bound the workspace.

Together these run the fused MoE path end to end on MetaX with no
engine-side fallback: on 021-32B TP2 (C550, MACA 3.5.3) prefill TTFT
drops from 2340 ms to 207 ms (54.7 to 618 tok/s) and decode improves
from 46.7 ms to 42.0 ms per token versus the CPU-routed per-expert
Gemm fallback.

021模型所需要的算子实现

验证
python3 examples/test_infer.py --device metax --model=/mnt/infini/infrahi/infinilm-models/021/021-32B-A4B-256k-20261024/021-32B-A4B-256k-20261024 --tp 2 --disable-prefix-caching --enable-paged-attn --attn flash-attn --use-mla --prompt "你是谁,你能做啥"

image

python examples/bench.py --device metax
--model=/mnt/infini/infrahi/infinilm-models/021/021-32B-A4B-256k-20261024/021-32B-A4B-256k-20261024
--tp 2 --enable-paged-attn --use-mla --attn flash-attn --disable-prefix-caching
--warmup --batch-size 1 --input-len 128 --output-len 64

image

…e MoE

  Add the MetaX operators the 021 model (DeepseekV2-style MoE with
  80 experts, top-7 routing) needs beyond the core inference set:

  - Scalar Mul: the shared CudaMul only prepares tensor x tensor
    multiplication; its scalar constructor is protected and its scalar
    operator() rejects scalar mode, so dispatching
    Mul(tensor, double, tensor) found no MetaX provider. Add a native
    scalar kernel with contiguous and strided paths over
    fp16/bf16/fp32/fp64; the strided metadata is allocated at prepare
    time so the buffer outlives the asynchronous kernel launch.

  - DeepseekMoe: replace the throw stub with a native expert-grouped
    implementation. Routing runs on device (expert counting, prefix
    scan, pack-by-expert), per-expert gate/up/down projections go
    through mcblasGemmStridedBatchedEx with batch=1 (the pattern
    moe_fused_dense already exercises on MetaX), SiLU*up*topk_weight
    applies in place, and a final kernel sums the top-k contributions
    per token. Large prefills are chunked to bound the workspace.

  Together these run the fused MoE path end to end on MetaX with no
  engine-side fallback: on 021-32B TP2 (C550, MACA 3.5.3) prefill TTFT
  drops from 2340 ms to 207 ms (54.7 to 618 tok/s) and decode improves
  from 46.7 ms to 42.0 ms per token versus the CPU-routed per-expert
  Gemm fallback.
@rubik-hua
rubik-hua requested a review from a team November 19, 2026 02:55

This branch has not been deployed

No deployments
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.

1 participant