Skip to main content

hk-dsl

PyPI CI License: MIT Docs

Documentation: https://vivienfanghuagood.github.io/hk-dsl/

hk-dsl makes vLLM and SGLang faster on Radeon GPUs, and is the Python DSL those kernels are written in. Install it next to your engine and its kernels replace the engine's where they measured faster, on the Radeon W7900 / RX 7900 (RDNA3) and R9700 / RX 9070 (RDNA4). Or write your own AMD GPU kernels in it, for RDNA and CDNA, with build-time checks against the errors that fail silently (spills, missing waits, MFMA hazards). What it is and is not.

The same 8,192-token prompt to MiniCPM-V-4.7-1B, stock vLLM (left) and vLLM with hk-dsl (right), 256 identical output tokens: first token after 0.60 s and 0.24 s, decode at 48 and 61 tokens/s

Radeon PRO W7900D, MiniCPM-V-4.7-1B with its production settings (eager mode), stock vLLM vs vLLM with hk-dsl 0.9.19, in one process. Both sides get the same prompt, 8,192 input tokens, with prefix caching off, and produce 256 output tokens with identical text (greedy, ignore_eos). Over 5 rounds, the medians: first token 0.60 s -> 0.24 s (2.52x sooner), decode 48 -> 61 tokens/s (1.27x faster). The GIF plays the round closest to those medians (2.51x, 1.27x) at real speed (how, scorecard).

Quick start

Faster vLLM and SGLang on Radeon. One command, in the environment that runs your engine; hk's plugin loads by itself:

pip install hk-dsl && vllm serve Qwen/Qwen3-8B                       # vLLM
pip install hk-dsl && python3 -m sglang.launch_server --model-path Qwen/Qwen3-8B \
    --attention-backend triton --disable-cuda-graph                 # SGLang (W7900 / RX 7900)

The server's log then has a [hk] vLLM routes on: ... (or [hk] SGLang routes on: ...) line per process. HK_DISABLE=1 gives you the stock engine back. No vLLM yet? On an R9700 one docker run does both: hk in vLLM. Each engine's page has the GPUs and models, how to check it worked, and troubleshooting: hk in vLLM · hk in SGLang.

Your first kernel. pip install hk-dsl, plus ROCm's hipcc and a ROCm build of torch (install). Write only the math; a template builds the kernel:

# my_kernels.py
import hk
from hk import templates as T

gelu_and_mul = T.elementwise(lambda g, u: hk.math.gelu(g) * u)  # the math of one element

@T.rowwise                                                       # the math of one row
def rms_norm(x, w, *, EPS=1e-6):
    return x * (T.row_mean(x * x) + EPS).rsqrt() * w

def bias_gelu(acc, ctx):                                         # fused into a GEMM's store
    acc += ctx.bias
    return hk.templates.gemm.gelu_tanh(acc)

def linear_bias_gelu(x, w, b):
    return hk.templates.gemm(x, w, epilogue=bias_gelu, bias=b)
python3 -m hk.check my_kernels.py:rms_norm \
    --ref "lambda x, w: x * torch.rsqrt((x * x).mean(-1, keepdim=True) + 1e-6) * w" \
    --inputs "bf16[4096,4096], bf16[4096]"

Call them with torch tensors, as rms_norm(h, w). hk.check reports the registers, occupancy and spills, the error against the reference, and the time against torch eager and torch.compile on your GPU. It exits with 0 (pass), 1 (wrong) or 2 (error). Next: quickstart, templates, GEMM epilogues, hk.check.

Where it runs

GPU arch level engine routes on by default
Radeon PRO W7900, Radeon PRO W7900D, Radeon RX 7900 gfx1100 (RDNA3) tested 19
Radeon AI PRO R9700, Radeon RX 9070 gfx1201 (RDNA4) tested 11
Instinct MI300X, Instinct MI325X gfx942 (CDNA3) compile-only none
Instinct MI355X, Instinct MI350X gfx950 (CDNA4) tested 5

Tested: measured on the part and run by CI's GPU tier. What the language and each engine route do on each GPU: supported hardware.

  • Compilers (hipcc's clang): clang 22 (ROCm 7.2.x) in CI's GPU tier; clang 23 (ROCm 10.0), tested on gfx950; clang 24 (ROCm 10.1) from 0.9.0, not in CI (toolchains).
  • Python: wheels for CPython 3.10 to 3.13 (install).

What it is

hk-dsl has three layers:

  • The language (hk, hk.templates, hk.check) is general. You control tiles in registers and LDS, matrix instructions and waits. hk-dsl lowers the kernel through its MLIR dialect to HipKittens C++ for hipcc. It catches spills, unwaited LDS reads and MFMA hazards at build time.
  • Kernels (hk.ops) are written in the language. They show that it works, and they are how its gains reach a model.
  • Engine routes (hk.integration) are thin adapters that send some of vLLM's and SGLang's calls to hk.ops.

How it compares, and the numbers

Triton is much cheaper to write: use it unless you need control of tiles, LDS and waits. FlyDSL gives similar control and is CDNA-first. hk-dsl emits HipKittens C++, checks it at build time, and treats RDNA3 and RDNA4 as first-class; it is not a faster code generator than that C++ (what it is and is not).

We quote only end-to-end serving results, from the scorecard. On an Instinct MI355X, DeepSeek-V4.1-Flash on vLLM (TP2), hk's default routes on top of AITER's tuned paths give about +5% on 8k-token prefill, decode unchanged. Radeon results come with the RDNA scorecard.

Documentation

What it is and is not · getting started · templates · hk.check · the language · API · hk in vLLM · hk in SGLang · scorecard · every page · changelog · docs site

The language, when you need control

import hk

@hk.kernel(grid=lambda p: (p.o.rows * hk.cdiv(p.o.cols, p.CW), 1, 1))
def gelu_mul(a: hk.Tensor[hk.T], b: hk.Tensor[hk.T], o: hk.Tensor[hk.T], *, CW=512):   # hk.T: the call's dtype
    S = hk.RS(hk.fp32, 1, CW, 8)                  # a register strip: one row, 8 16-bit values (16 B) a lane
    per_row = hk.cdiv(o.cols, CW)
    row = hk.arch.block_idx.x // per_row
    c0 = (hk.arch.block_idx.x - row * per_row) * CW
    x = a.at[row, c0].load(S, bounded=True)       # bf16 / fp16 -> fp32 on the load; past the end reads 0
    x.gelu(into=x)                                # hk.math.gelu: the tanh form, fp32 only
    x *= b.at[row, c0].load(S, bounded=True)
    o.at[row, c0].store(x, bounded=True)          # fp32 -> the output's dtype on the store

print(gelu_mul.trace(T=hk.bf16).dump())   # the hk MLIR module for bf16 -- needs nothing
print(gelu_mul.source(T=hk.bf16))         # the HipKittens C++ -- needs nothing
print(gelu_mul.build(T=hk.bf16).report()) # hipcc and the resource gate -- no GPU

python3 -m hk.check checks and times it like any other kernel (check). More: the language, examples.

On gfx950 there is more:

flowchart LR
    A["kernel body<br/>or template hook"] -->|trace| B["hk MLIR dialect"]
    B -->|"passes: waits, LDS,<br/>layouts, races"| C["HipKittens C++"]
    C -->|"hipcc + resource gate"| D["code object"]
    D -->|launch| E["torch, vLLM, SGLang"]

The passes refuse what fails silently: an MMA above its wait, a spill, a slow operand layout, a copy racing a barrier (the traps).

Install

pip install hk-dsl, for CPython 3.10 to 3.13 on Linux x86_64 with glibc 2.35 or newer (Ubuntu 22.04 and later). The release is 0.9.20: one manylinux_2_35 wheel for each of cp310, cp311, cp312 and cp313, all built on glibc 2.35. A wheel carries the HipKittens headers, so at run time it needs ROCm's hipcc (on PATH, or HK_HIPCC) and, to launch, a ROCm build of torch (not a dependency). Another CPython has no wheel: build from source.

Which ROCm and hipcc versions are tested, and which are known not to work, is in install.

From source, with the HipKittens submodule:

git clone --recursive https://github.com/vivienfanghuagood/hk-dsl.git && cd hk-dsl
scripts/build_mlir.sh && scripts/build_hk_mlir.sh   # MLIR 23.1.3 (~20 min on 64 cores), then hk (~1 min)
export PYTHONPATH=$PWD/python

Details: install, building.

In vLLM and SGLang

Installed, hk is on by default: the engine loads hk's plugin, which applies every route that met the default-on rule on your GPU (at least 1.15x the engine's best kernel on a real model's shapes, the correctness suite, and an end-to-end check), and sends a call to hk only where hk measured faster. How to check it, the GPUs and models, and how to turn it off: hk in vLLM, hk in SGLang. What each route replaces: vLLM routes, SGLang routes; every switch: integration.

For coding agents

llms.txt (or llms-full.txt, every doc in one file), the hk-kernel skill, the generated API reference, and python3 -m hk.check FILE.py:NAME --json - as the loop's one command (--arch gfx1100,gfx950 builds for the GPU that is not in the machine).

Contributing, license, acknowledgements

Issues and pull requests welcome: CONTRIBUTING.md (new kernels add no kernel-specific helpers or one-off DSL ops; the reviewer checklist), testing, how numbers are taken. MIT (LICENSE). hk-dsl began in a fork of HipKittens (HazyResearch), whose headers stay under its MIT License (NOTICE) and which brings ThunderKittens' tiles to AMD GPUs. The control-flow rewrite follows CUTLASS's CuTe DSL.

Metadata

Release files for hk-dsl 0.9.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for hk-dsl 0.9.20
File Actions
hk_dsl-0.9.20-cp313-cp313-manylinux_2_35_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.35+ x86-64 Details for hk_dsl-0.9.20-cp313-cp313-manylinux_2_35_x86_64.whl
hk_dsl-0.9.20-cp312-cp312-manylinux_2_35_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.35+ x86-64 Details for hk_dsl-0.9.20-cp312-cp312-manylinux_2_35_x86_64.whl
hk_dsl-0.9.20-cp311-cp311-manylinux_2_35_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.35+ x86-64 Details for hk_dsl-0.9.20-cp311-cp311-manylinux_2_35_x86_64.whl
hk_dsl-0.9.20-cp310-cp310-manylinux_2_35_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.35+ x86-64 Details for hk_dsl-0.9.20-cp310-cp310-manylinux_2_35_x86_64.whl

Total release size: 53.2 MB

Release files / hk_dsl-0.9.20-cp313-cp313-manylinux_2_35_x86_64.whl

Download URL hk_dsl-0.9.20-cp313-cp313-manylinux_2_35_x86_64.whl
Size 13.3 MB
Tags CPython 3.13 Linux glibc 2.35+ x86-64
SHA-256 checksum
How to use checksums
0b7c6e07c5c307e7b8ddce2dbe6cea69e87ee7533bcda23eb42758bb3cda9ecd
BLAKE2b-256 checksum
How to use checksums
19f97369684afdd259b9e385dda33787510747dbc1c9eecb92b7e7ec5b85a365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / hk_dsl-0.9.20-cp312-cp312-manylinux_2_35_x86_64.whl

Download URL hk_dsl-0.9.20-cp312-cp312-manylinux_2_35_x86_64.whl
Size 13.3 MB
Tags CPython 3.12 Linux glibc 2.35+ x86-64
SHA-256 checksum
How to use checksums
ee4dd650147182e7178b2db938f0f20ef749eba0845146d5e3fd19155fbaa123
BLAKE2b-256 checksum
How to use checksums
f01f99de92f11c2037730d3599c722ae218bbf96bfa0e800fb088c692d3a1a10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / hk_dsl-0.9.20-cp311-cp311-manylinux_2_35_x86_64.whl

Download URL hk_dsl-0.9.20-cp311-cp311-manylinux_2_35_x86_64.whl
Size 13.3 MB
Tags CPython 3.11 Linux glibc 2.35+ x86-64
SHA-256 checksum
How to use checksums
2e969d0fc4cad5e3b0bc83bbcbb135220e8024438704d7af1ba860e96153749e
BLAKE2b-256 checksum
How to use checksums
1c3f30157775e149823b5e1fe32ffa2e9dae472ab2fb15ac015fdc6493c9574c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / hk_dsl-0.9.20-cp310-cp310-manylinux_2_35_x86_64.whl

Download URL hk_dsl-0.9.20-cp310-cp310-manylinux_2_35_x86_64.whl
Size 13.3 MB
Tags CPython 3.10 Linux glibc 2.35+ x86-64
SHA-256 checksum
How to use checksums
c355c72d2c5a3acf9577afeefed32a63b1f98ff5f9efe7bf0bf664bd7e73d21f
BLAKE2b-256 checksum
How to use checksums
d625d4d00e50324737dd7e90add3fb82bb1bc2a6a309700450e7aa049b9c32ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for hk-dsl 0.9.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.9.20 This release

4 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page