Add Inkling attention prologue MXFP8 tau path - #327
Open
yuankuns wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Inkling attention-prologue support to the XPU extension stack, extending the existing verify/decode/extend kernels with per-token log_scaling_tau handling on the Q path and an MXFP8 quantized-Q + MXFP8 KV-store path (including the upstream scale-buffer layout), plus focused XPU reference tests.
Changes:
- Extend Inkling attention prologue kernels (SYCL + Torch registrations + Python wrapper) with
log_scaling_taufor Q and MXFP8 quantization / KV scale-buffer writes. - Add a scoped
inkling_attn_prologue_opsextension target and adjust build/link/install wiring to keep schemas out ofcommon_ops. - Add comprehensive XPU reference tests covering scalar tau, MXFP8 verify/decode/extend, slot-gating, and no-store behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_inkling_attn_prologue.py |
Adds reference-model tests for verify/decode/extend, including tau and MXFP8 store/scale-layout checks. |
src/torch_extension_inkling_attn_prologue.cc |
Registers Inkling attention prologue Torch schemas in a scoped extension module. |
src/sycl/InklingAttnPrologue.cpp |
Implements SYCL kernels for verify/decode/extend, plus MXFP8 Q quantization and MXFP8 KV store with scale-buffer writes. |
src/CMakeLists.txt |
Excludes the scoped Inkling extension source from common_ops build compilation unit list. |
src/BuildOnLinux.cmake |
Builds/installs the scoped inkling_attn_prologue_ops module and adjusts linking so common_ops doesn’t transitively load the Inkling SYCL lib. |
python/sgl_kernel/inkling_attn_prologue.py |
Python wrapper that loads the scoped extension, routes to MXFP8 vs non-MXFP8 ops, and normalizes tau inputs. |
python/sgl_kernel/__init__.py |
Exposes Inkling attention prologue entry points at package top-level. |
include/sgl_kernel_ops.h |
Declares the new Inkling attention prologue C++ entry points (including MXFP8 variants). |
Comments suppressed due to low confidence (4)
src/torch_extension_inkling_attn_prologue.cc:32
- In the Torch schema,
k_cacheandv_cacheare both annotated asTensor(a!)(andk_buf/v_bufare also bothTensor(a!)), implying all four may alias. These are separate mutable tensors and should have distinct alias sets to keep PyTorch’s alias analysis correct.
"inkling_attn_prologue_decode(Tensor qkvr, Tensor(a!) k_cache, Tensor(a!) v_cache, "
"Tensor cache_indices, Tensor cache_mask, Tensor k_weight, Tensor v_weight, "
"Tensor? track_mask, Tensor? track_indices, Tensor q_gamma, Tensor k_gamma, float eps, "
"Tensor loc, Tensor(a!) k_buf, Tensor(a!) v_buf, int q_off, int k_off, int v_off, "
src/torch_extension_inkling_attn_prologue.cc:42
- In the Torch schema,
k_cacheandv_cacheare both annotated asTensor(a!)(andk_buf/v_bufare also bothTensor(a!)), implying these mutable tensors may alias each other. They are logically distinct buffers and should use distinct alias sets.
"inkling_attn_prologue_extend(Tensor qkvr, Tensor(a!) k_cache, Tensor(a!) v_cache, "
"Tensor cache_indices, Tensor cache_mask, Tensor has_initial_state, Tensor cu, Tensor si, "
"Tensor k_weight, Tensor v_weight, Tensor? track_rows, Tensor? track_mask, Tensor? track_dst, "
"Tensor q_gamma, Tensor k_gamma, float eps, Tensor loc, Tensor(a!) k_buf, Tensor(a!) v_buf, "
src/torch_extension_inkling_attn_prologue.cc:59
- In the MXFP8 decode schema,
k_cacheandv_cacheare both annotated asTensor(a!), implying they may alias. They are distinct mutable tensors and should not share an alias set.
"inkling_attn_prologue_decode_mxfp8(Tensor qkvr, Tensor(a!) k_cache, Tensor(a!) v_cache, "
src/torch_extension_inkling_attn_prologue.cc:69
- In the MXFP8 extend schema,
k_cacheandv_cacheare both annotated asTensor(a!), implying they may alias. They are distinct mutable tensors and should not share an alias set.
"inkling_attn_prologue_extend_mxfp8(Tensor qkvr, Tensor(a!) k_cache, Tensor(a!) v_cache, "
Comment on lines
+22
to
+23
| "Tensor(a!) k_inter, Tensor(a!) v_inter, Tensor q_gamma, Tensor k_gamma, float eps, " | ||
| "Tensor loc, Tensor(a!) k_buf, Tensor(a!) v_buf, int q_off, int k_off, int v_off, " |
| m.def( | ||
| "inkling_attn_prologue_verify_mxfp8(Tensor qkvr, Tensor k_cache, Tensor v_cache, " | ||
| "Tensor cache_indices, Tensor cache_mask, Tensor k_weight, Tensor v_weight, " | ||
| "Tensor(a!) k_inter, Tensor(a!) v_inter, Tensor q_gamma, Tensor k_gamma, float eps, " |
Comment on lines
+92
to
+102
| sf_shape = (k_view.shape[0] // page_size, dkv // 128, 32, page_size // 32, 4) | ||
| if k_view.shape[0] % page_size != 0: | ||
| raise ValueError("MXFP8 k_buf slots must be divisible by page_size") | ||
| if tuple(sfk.shape) != sf_shape or tuple(sfv.shape) != sf_shape: | ||
| raise ValueError( | ||
| "MXFP8 fused prologue requires interleaved K/V scale buffers " | ||
| f"with shape {sf_shape}, got {tuple(sfk.shape)} and {tuple(sfv.shape)}." | ||
| ) | ||
| if not sfk.is_contiguous() or not sfv.is_contiguous(): | ||
| raise ValueError("MXFP8 fused prologue requires contiguous interleaved SFK/SFV") | ||
| return k_view, v_view, sfk.view(torch.uint8), sfv.view(torch.uint8) |
yuankuns
force-pushed
the
port-inkling-attn-prologue-mxfp8-tau-to-sglang-xpu-ops
branch
from
July 25, 2026 16:45
b6aa54b to
817ca2e
Compare
yuankuns
force-pushed
the
port-inkling-attn-prologue-mxfp8-tau-to-sglang-xpu-ops
branch
from
August 5, 2026 22:59
b5cf266 to
c21f85b
Compare
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.
Summary
log_scaling_tausupport for verify/decode/extend q paths.[pages, Hkv, 32, page_size / 32, 4]layout.Tests
SKIP=black-jupyter python3 -m pre_commit run --files include/sgl_kernel_ops.h python/sgl_kernel/inkling_attn_prologue.py src/sycl/InklingAttnPrologue.cpp src/torch_extension_inkling_attn_prologue.cc tests/test_inkling_attn_prologue.py --show-diff-on-failuredocker exec sglang-syk bash -lc 'source /opt/intel/oneapi/setvars.sh --force >/dev/null 2>&1; cd /workspace/worktrees/sgl-kernel-xpu/port-inkling-kernel-to-sglang; build_dir=$(cat /tmp/sgl_kernel_attn_mxfp8_build_dir); ninja -C "$build_dir" inkling_attn_prologue_ops'docker exec sglang-syk bash -lc 'source /opt/intel/oneapi/setvars.sh --force >/dev/null 2>&1; cd /workspace/worktrees/sgl-kernel-xpu/port-inkling-kernel-to-sglang; build_dir=$(cat /tmp/sgl_kernel_attn_mxfp8_build_dir); pkg_root=$(mktemp -d /tmp/sgl_kernel_attn_mxfp8_pkg.XXXXXX); mkdir -p "$pkg_root/sgl_kernel"; touch "$pkg_root/sgl_kernel/__init__.py"; ln -s "$PWD/python/sgl_kernel/inkling_attn_prologue.py" "$pkg_root/sgl_kernel/inkling_attn_prologue.py"; ln -s "$build_dir/src/inkling_attn_prologue_ops.abi3.so" "$pkg_root/sgl_kernel/inkling_attn_prologue_ops.abi3.so"; LD_LIBRARY_PATH="$build_dir/src:${LD_LIBRARY_PATH:-}" PYTHONPATH="$pkg_root:/workspace/python-targets/py312-xpu:$PWD/tests" ZE_AFFINITY_MASK=0 ONEAPI_DEVICE_SELECTOR=level_zero:gpu /root/miniforge3/envs/py312/bin/python -m pytest -q tests/test_inkling_attn_prologue.py'Dependency
b6aa54bfor the MXFP8/tau delta.