|
|
||
|---|---|---|
| docs | ||
| tools | ||
| .gitignore | ||
| bench.sh | ||
| build.sh | ||
| LLAMA_CPP_COMMIT | ||
| README.md | ||
| run.sh | ||
llama.cpp-rx480
Under construction. Scripts and numbers are still being finalized.
llama.cpp, made fast on the AMD Radeon RX 480 (8 GB, Polaris/GCN, Vulkan) for one model: Inkling 2 Mini at up to 128k context.
This repository does not contain llama.cpp. build.sh downloads llama.cpp at a pinned commit
(LLAMA_CPP_COMMIT, release b12600), applies one patch
(patches/llama.cpp-rx480.patch) and builds the Vulkan backend.
Speed as the context grows
Measured with ./bench.sh (the settings of run.sh): llama-bench, 512-token prompt and 64 generated tokens on top
of a context already holding the given number of tokens. Raw output: docs/bench.txt; chart:
python3 docs/make_chart.py. The RX 480 runs at its 110 W power limit, so a hot card is up to ~15% slower than these
numbers.
What the patch does
- Inkling support. The model architecture, its relative-position attention bias and the attention sinks.
- Attention bias inside the attention kernel. Without this, the bias is built as a separate tensor of context × batch × 24 heads per layer, which does not fit in 8 GB beyond ~32k context.
- A decode attention kernel for GCN. Inkling attends over the whole context in 8 of its 48 layer passes per token, and that attention is the only part of a token whose cost grows with the context. The kernel reads the 4-bit KV cache directly, splits the context over all 36 compute units, and is 2.2× faster than stock llama.cpp's at 128k.
- Strided
SCALEon the GPU. Inkling scales a non-contiguous view; stock Vulkan sent it back to the CPU, which split each token's graph into ~200 pieces (10 → 16 t/s).
Each part has an environment switch to turn it off (GGML_VK_FA_DEC=0 for the decode kernel).
The model
Inkling-2-Mini-AD-IQ1_M.gguf from AtomicChat/Inkling-2-Mini-GGUF,
with its output head re-quantized from Q6_K to Q4_0 (260 MB instead of 380 MB: faster, and it is what makes 128k fit):
python3 tools/make_model.py Inkling-2-Mini-AD-IQ1_M.gguf models/Inkling-2-Mini-IQ1_M-outq4.gguf
Run it after ./build.sh (it uses llama.cpp's gguf-py; needs numpy). IQ1_M is the largest quantization that
fits 8 GB together with a 128k cache.
Build
Requirements: an RX 480 (or RX 470/580) with Mesa's RADV Vulkan driver, cmake, a C++ compiler, the Vulkan headers
and glslc.
./build.sh
After pulling a newer patch: ./build.sh --reset.
Run
./run.sh
This starts llama-server with 128k context on port 8080: a web UI at http://localhost:8080 and an OpenAI-compatible
API at /v1. CTX, PORT, MODEL and DEV (the Vulkan device, found automatically) can be overridden; extra
arguments go to llama-server.
The settings that matter:
| setting | why |
|---|---|
-fa on -ctk q4_0 -ctv q4_0 |
flash attention with a 4.5-bit KV cache |
LLAMA_KV_SWA_TYPE=q4_0 |
4-bit cache for the 1,024-token window layers as well (f16 is slightly more accurate, but then only ~96k fits) |
-ub 512 |
larger prompt batches read prompts faster, but their buffers no longer fit next to a 128k cache |
-bs |
sample on the GPU (CPU sampling over the 200k vocabulary is slow on a 4-core host) |