hk
A local LLM runtime and model container, written in Zig. One static binary pulls a model from Hugging Face, converts it to the .hk format while it downloads, and runs it, either in your terminal or as an OpenAI compatible server.
I built it because running models locally on an ordinary laptop was a bad experience. Loading a 1B model took gigabytes of RAM for no good reason, and getting a GGUF file into any other tool meant another conversion step. hk is my attempt at the version where memory is the thing that gets treated seriously.
What works today
- Pull and convert in one step.
hk pull owner/namestreams a model from the Hub and writes a.hkfile as the bytes arrive. GGUF and safetensors repositories both work, including sharded ones. You never keep the original file. The download is checked against the Hub's SHA-256, resumes after a dropped connection, and the converter's memory use stays flat no matter how big the model is. - Run it.
hk run,hk chatandhk serveuse a CPU engine written for this project. Weights are memory mapped from the file, so nothing is copied into RAM. - OpenAI compatible server.
/v1/chat/completionsand/v1/completionswith streaming, several conversations at once, a shared prompt cache, API key support and a/metricsroute. - Models. Llama, Qwen2 and Qwen3 style dense models (this covers Llama 2 and 3, Mistral without sliding window, SmolLM2, Qwen2.5 and Qwen3). 26 storage formats, from f32 down to the 1 and 2 bit IQ and ternary types.
- Tokenizers and chat templates. Byte-level BPE and SentencePiece, checked against llama.cpp on 301,948 tokens of real text. Chat templates run on a built-in Jinja subset, checked against Python's jinja2.
Try it
zig build -Doptimize=ReleaseFast # needs Zig 0.17.0 or newer
./zig-out/bin/hk pull Qwen/Qwen3-0.6B
./zig-out/bin/hk run Qwen/Qwen3-0.6B "What is the capital of France?" --chat --temp 0
./zig-out/bin/hk chat Qwen/Qwen3-0.6B
./zig-out/bin/hk serve Qwen/Qwen3-0.6B --port 8080
A GGUF repository works the same way and picks Q4_K_M unless you ask for another quant:
hk pull bartowski/SmolLM2-135M-Instruct-GGUF:Q8_0
Already have a GGUF on disk? hk convert-gguf model.gguf model.hk.
How it compares with llama.cpp
Measured on a Ryzen 7 7445HS (6 cores), CPU only, 6 threads, same models. Medians of 5 alternating runs; the machine was not idle, so differences under about 5 percent are noise. Full table, method and the GPU comparison are in benchmarks/results.md and the Benchmarks page; hk-compare reproduces them.
| hk vs llama.cpp (CPU) | |
|---|---|
| Private memory while generating | 5 to 9 times lower for most models (8 to 10 MiB against 45 to 109 on SmolLM2-135M, 30 against 182 on Qwen3-0.6B) |
| Prompt processing | faster on 8 of 10 models (106 to 240 percent), tied on f16, 91 percent on IQ4_XS |
| Decode speed | slightly behind: 92 to 99 percent, tied on f16 |
So memory is a clear win, prompt processing is mostly ahead, and decode is a few percent behind. I have not closed that gap.
On the GPU (one RTX 3050 6 GB laptop, 4 real models, hk and llama.cpp loading the same GGUF bytes, 3 interleaved repeats; tables with memory in benchmarks/results/2026-10-21-four-models.md):
| hk CUDA vs llama.cpp CUDA | hk Vulkan vs llama.cpp Vulkan | |
|---|---|---|
| Prompt processing, Q8_0 | 97 % | 74 % |
| Prompt processing, Q4_K_M (three models) | 74 to 77 % | 47 to 55 % |
| Decode, Q8_0 | 94 % | 82 % |
| Decode, Q4_K_M (three models) | 92 to 98 % | 69 to 89 % |
Perplexity agrees with llama.cpp and Transformers (Qwen3-0.6B Q8_0 on wikitext-2: 23.64 to 23.68 for hk against 23.67 to 23.68 for llama.cpp and 23.73 for Transformers on the original weights). The numbers are one laptop; read them as "same ballpark, not yet equal".
What it does not do yet
I would rather you hear this from me.
- Only Llama, Qwen2 and Qwen3 style dense models run. No Gemma, Phi, Mistral with sliding window, mixture of experts, or vision models.
- The tokenizer.json importer handles byte-level BPE only, so a safetensors repository with a SentencePiece or Unigram tokenizer is refused with a message. Its GGUF version will work.
- GPU support is a CUDA backend (tensor cores on compute capability 8.0 and newer) and a Vulkan backend (cooperative matrices when the driver has them), chosen automatically (
--backend auto|cpu|vulkan|cuda,-ngl Nfor a number of layers); a model that does not fit in device memory runs its leading layers on the device and the rest on the CPU. Everything was tested on one NVIDIA laptop GPU only. The Vulkan backend is the slower of the two (K-quant models especially); nothing was run on AMD, Intel or Apple GPUs. There is no Metal, ROCm or TPU backend. - The CPU kernels are built for each instruction set level (AVX-512 VNNI, AVX2, generic on x86; NEON with and without dot product on ARM) and chosen at startup. The ARM kernels pass the portable tests but have not been run on ARM hardware, and the older x86 levels have not been benchmarked on real older CPUs.
- Split GGUF files (
-00001-of-00003.gguf) are not downloaded yet. - No grammar or JSON-schema constrained decoding, and no tool-call parsing.
- Interrupted conversions restart from the beginning. The download itself resumes, the conversion does not.
The other half of the project
The .hk container and the Python package carry a number of research features that predate the engine work above: growing a model's layers and vocabulary (Net2Net), a version history stored inside the file with hash chaining and rollback, 2:4 structured sparsity, in-place metadata edits, and a training and self-play pipeline in Python. They work in their unit tests. I have not validated them against large models or compared them with other training stacks, so treat them as experimental. Each has a page in the wiki that says what is tested and what is not.
Install
| What | How |
|---|---|
| CLI and server | build from source: zig build -Doptimize=ReleaseFast (Zig 0.17.0 or newer) |
| Python package | pip install hknt (1.1.1 and later bundle the current native library and CLI; 1.1.0 has the old engine; 2.0 adds the CUDA engine, partial offload and the container seal) |
| Node.js | npm install hkntf |
| C, C++, Rust, Go, C#, Java | bindings in bindings/ over the C header include/hk.h |
Tests: zig build test for the Zig side, zig build test-e2e for the CLI, server and downloader tests against the built binary, and pytest tests for the Python package.
Docs
Start with Getting Started. The rest of the wiki covers the CLI, downloading models, serving, the file format, and what each model, format and platform supports in the compatibility page.
License
Apache 2.0, see LICENSE.
Metadata
Release files for hknt 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hknt-2.0.0.tar.gz | 27.3 MB | Without provenance | Details for hknt-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hknt-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for hknt-2.0.0-py3-none-any.whl |
Total release size: 54.9 MB
Release files / hknt-2.0.0.tar.gz
| Download URL | hknt-2.0.0.tar.gz |
|---|---|
| Size | 27.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3a6aab2821dbec339f12cc185f005c715c6079f2a209c78e767bc33836b5d0c
|
|
BLAKE2b-256 checksum How to use checksums |
668148d9360e3ae931fddc15f1c10f436b7e3aa5b45ee3d73c21a9a316a365aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / hknt-2.0.0-py3-none-any.whl
| Download URL | hknt-2.0.0-py3-none-any.whl |
|---|---|
| Size | 27.6 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5c4f667cbd1ea57e8c4d50b77b8f6f7d1c38e8900d71be7042db8d311f52cf9
|
|
BLAKE2b-256 checksum How to use checksums |
08255459beca9f4377ae15eacdffccd1cd542bebfe221ca8bd16150eff73b63c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for hknt 2.0.0
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.