TileLang DeepSeek-V4 porting#123
Draft
MirkoDeVita98 wants to merge 4 commits into
Draft
Conversation
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.
Adds PTO DSL ports of the six custom kernels used by DeepSeek-V4, plus
benchmarks and documentation. Each kernel follows the standard examples-tree
layout (
compile.sh+run_*.py) and is exercised byexamples/validate_all_examples.py.What's new —
examples/aot/deepseek_v4/act_quant/fp4_act_quant/fp8_gemm/fp4_gemm/hc_split_sinkhorn/sparse_attn/Each folder ships a
<name>_builder.py,<name>_util.py,caller.cpp,compile.sh,run_<name>.py,README.md, and.gitignore.Notable design choices
fp8_gemm/fp4_gemmkeep the matmul pure (cube fp32 → fp16) andfold the per-channel
Sarescale into a host-side pre-scale ofA,leaving only
Sbon the vector pipe. Avoids two extra cube fragmentsper tile; matches reference within 5 × 10⁻³.
hc_split_sinkhornruns all three heads (pre / post / 20-iterSinkhorn over
[n, 4, 4]) inside onevector_section. Up to 18×faster than eager PyTorch on small batches (n ≤ 1024).
sparse_attnis purevector_sectionFlashAttention. Per-headsoftmax stats are stored as full
[H, D]tiles replicated acrossDto dodge a col-major⇄row-major reshape alias the auto-sync analysis
can miss. KV is gathered one position at a time via
pto.load_scalar→ dynamic
pto.slice_view→pto.load. Beats a hand-writtentorch.gather+npu_fused_infer_attention_scorebaseline 1.2–1.6×across the small/medium shapes typical of this op.
How to build, test and benchmark
See examples/aot/deepseek_v4/OVERVIEW.md.
TL;DR:
Sample bench results
sparse_attn, vstorch.gather+npu_fused_infer_attention_score(MQA):hc_split_sinkhorn, vs eager PyTorch reference: