submission 693793
zwang86 · python · License unknown
Use it
Vendorable · source mirrored · license unknownView source →
No package. Vendor the mirrored source: 130 lines, June 9 Researcher Reciprocity License v1.0.
submission.py
curl "https://kernelindex.com/api/v1/implementations/kernelbot-amd-mixed-mla-693793?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:6a06b07f320bf238104524519152ce5b783c09a232f6a1ca4f1149fa90a715f6
license declaredunknown
license concludedunknown
authorszwang86
imported2026-08-26
Kernel source
submission.py130 lines
#!POPCORN leaderboard amd-mixed-mla
#!POPCORN gpu MI355X
# v10-compile: v9 + torch.compile fused Q quantization.
# Eliminates .item() sync AND fuses Q quant ops into fewer kernel launches.
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
QK_HEAD_DIM = 576
V_HEAD_DIM = 512
SM_SCALE = 1.0 / (QK_HEAD_DIM ** 0.5)
PAGE_SIZE = 1
NUM_KV_SPLITS = 32
FP8_DTYPE = aiter_dtypes.fp8
_FP8_FINFO = torch.finfo(FP8_DTYPE)
_FP8_MAX = _FP8_FINFO.max
_FP8_MIN = _FP8_FINFO.min
_cache = {}
@torch.compile(fullgraph=True)
def _quantize_fp8_compiled(tensor):
amax = tensor.abs().amax().clamp(min=1e-12)
scale = amax / _FP8_MAX
fp8_tensor = (tensor / scale).clamp(min=_FP8_MIN, max=_FP8_MAX).to(FP8_DTYPE)
return fp8_tensor, scale.to(torch.float32).reshape(1)
def _get_or_build_cache(batch_size, total_kv, q_dtype, kv_dtype,
qo_indptr, kv_indptr):
key = (batch_size, total_kv, q_dtype, kv_dtype)
cached = _cache.get(key)
if cached is not None:
return cached
max_q_len = 1
nq, nkv = NUM_HEADS, NUM_KV_HEADS
kv_last_page_len = (kv_indptr[1:] - kv_indptr[:-1]).to(torch.int32)
kv_indices = torch.arange(total_kv, dtype=torch.int32, device="cuda")
info = get_mla_metadata_info_v1(
batch_size, max_q_len, nq, 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,
nq // nkv, nkv, True,
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,
)
output_buf = torch.empty((batch_size, nq, V_HEAD_DIM),
dtype=torch.bfloat16, device="cuda")
cached = {
"meta": {
"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,
},
"kv_indices": kv_indices,
"kv_last_page_len": kv_last_page_len,
"output_buf": output_buf,
}
_cache[key] = cached
return cached
def custom_kernel(data: input_t) -> output_t:
q, kv_data, qo_indptr, kv_indptr, config = data
batch_size = config["batch_size"]
kv_buffer_fp8, kv_scale = kv_data["fp8"]
q_fp8, q_scale = _quantize_fp8_compiled(q)
total_kv = batch_size * config["kv_seq_len"]
cached = _get_or_build_cache(
batch_size, total_kv, q_fp8.dtype, kv_buffer_fp8.dtype,
qo_indptr, kv_indptr,
)
kv_4d = kv_buffer_fp8.view(total_kv, PAGE_SIZE, NUM_KV_HEADS, QK_HEAD_DIM)
o = cached["output_buf"]
mla_decode_fwd(
q_fp8.view(-1, NUM_HEADS, QK_HEAD_DIM),
kv_4d,
o,
qo_indptr,
kv_indptr,
cached["kv_indices"],
cached["kv_last_page_len"],
1,
page_size=PAGE_SIZE,
nhead_kv=NUM_KV_HEADS,
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,
**cached["meta"],
)
return o
scrolls · 130 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