Repository navigation
Conversation
…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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 "你是谁,你能做啥"
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