submission 671767
Itay Etelis · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 127 lines, June 9 Researcher Reciprocity License v1.0.
submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-amd-mixed-mla-671767?include=source"interfacepython
Compatibility
measured onAMD Instinct MI355X
declared hardwareAMD Instinct MI355X
architecturesgfx950
dtypesbf16, int32
Benchmark evidence
1 measurement across 1 GPU, fastest first.
Operation / workload
Hardware
Latency
Rank
Observed
Reported · How evidence levels are derived →
Source and license
sourceavailable
revision digestsha256:6ae5c6f7c6966faed737a1fa2620f2089b56f383b9e674a42805d00784268643
license declaredunknown
license concludedunknown
authorsItay Etelis
imported2026-08-26
Kernel source
submission.py127 lines
"""
mixed-mla — custom_kernel submission
=====================================
DeepSeek R1 forward_absorb MLA decode, AMD MI355X.
fp8 Q + fp8 KV path (matches reference a8w8).
"""
import torch
from task import input_t, output_t
from aiter.mla import mla_decode_fwd
from aiter import dtypes as aiter_dtypes
from aiter import get_mla_metadata_info_v1, get_mla_metadata_v1
NUM_HEADS = 16
NUM_KV_HEADS = 1
KV_LORA_RANK = 512
QK_ROPE_DIM = 64
QK_HEAD_DIM = KV_LORA_RANK + QK_ROPE_DIM # 576
V_HEAD_DIM = KV_LORA_RANK # 512
SM_SCALE = 1.0 / (QK_HEAD_DIM ** 0.5)
PAGE_SIZE = 1
NUM_KV_SPLITS = 32
FP8_DTYPE = aiter_dtypes.fp8
def _quant_fp8(x):
finfo = torch.finfo(FP8_DTYPE)
amax = x.abs().amax().clamp(min=1e-12)
scale = amax / finfo.max
fp8 = (x / scale).clamp(min=finfo.min, max=finfo.max).to(FP8_DTYPE)
return fp8, scale.to(torch.float32).reshape(1)
def _make_metadata(batch_size, max_q_len, nhead, nhead_kv,
q_dtype, kv_dtype, qo_indptr, kv_indptr,
kv_last_page_len, num_kv_splits):
info = get_mla_metadata_info_v1(
batch_size, max_q_len, nhead, q_dtype, kv_dtype,
is_sparse=False, fast_mode=False,
num_kv_splits=num_kv_splits, intra_batch_mode=True,
)
work = [torch.empty(s, dtype=t, device="cuda") for s, t in info]
(work_metadata, work_indptr, work_info_set,
reduce_indptr, reduce_final_map, reduce_partial_map) = work
get_mla_metadata_v1(
qo_indptr, kv_indptr, kv_last_page_len,
nhead // nhead_kv,
nhead_kv,
True, # is_causal
work_metadata, work_info_set, work_indptr,
reduce_indptr, reduce_final_map, reduce_partial_map,
page_size=PAGE_SIZE,
kv_granularity=max(PAGE_SIZE, 16),
max_seqlen_qo=max_q_len,
uni_seqlen_qo=max_q_len,
fast_mode=False,
max_split_per_batch=num_kv_splits,
intra_batch_mode=True,
dtype_q=q_dtype,
dtype_kv=kv_dtype,
)
return {
"work_meta_data": work_metadata,
"work_indptr": work_indptr,
"work_info_set": work_info_set,
"reduce_indptr": reduce_indptr,
"reduce_final_map": reduce_final_map,
"reduce_partial_map": reduce_partial_map,
}
def custom_kernel(data: input_t) -> output_t:
q, kv_data, qo_indptr, kv_indptr, config = data
batch_size = config["batch_size"]
nq = config["num_heads"]
nkv = config["num_kv_heads"]
dq = config["qk_head_dim"]
dv = config["v_head_dim"]
q_seq_len = config["q_seq_len"]
# FP8 Q + FP8 KV
q_fp8, q_scale = _quant_fp8(q)
kv_buffer_fp8, kv_scale = kv_data["fp8"]
total_kv = int(kv_indptr[-1].item())
kv_indices = torch.arange(total_kv, dtype=torch.int32, device="cuda")
kv_last_page_len = (kv_indptr[1:] - kv_indptr[:-1]).to(torch.int32)
kv_buffer_4d = kv_buffer_fp8.view(
kv_buffer_fp8.shape[0], PAGE_SIZE, nkv, kv_buffer_fp8.shape[-1]
)
meta = _make_metadata(
batch_size, q_seq_len, nq, nkv,
q_fp8.dtype, kv_buffer_fp8.dtype,
qo_indptr, kv_indptr, kv_last_page_len,
num_kv_splits=NUM_KV_SPLITS,
)
o = torch.empty((q.shape[0], nq, dv), dtype=torch.bfloat16, device="cuda")
mla_decode_fwd(
q_fp8.view(-1, nq, dq),
kv_buffer_4d,
o,
qo_indptr,
kv_indptr,
kv_indices,
kv_last_page_len,
q_seq_len,
page_size=PAGE_SIZE,
nhead_kv=nkv,
sm_scale=SM_SCALE,
logit_cap=0.0,
num_kv_splits=NUM_KV_SPLITS,
q_scale=q_scale,
kv_scale=kv_scale,
intra_batch_mode=True,
**meta,
)
return o
scrolls · 127 lines total
Source code from GPU Mode and the KernelBot dataset · June 9 Researcher Reciprocity License v1.0
Best evidence level for this revision: reported
JSON