What do you do when you want to run an LLM on a consumer AMD card, but you don’t want to rely on heavy frameworks? You build the entire stack yourself.
VTE (Vector Tensor Engine) is an inference engine built directly on top of the AMD HIP runtime. There is no llama.cpp, no ONNX Runtime, no vLLM, and no PyTorch underneath it. VTE parses the GGUF file, generates the HIP C++ kernels on the fly, compiles them with hipcc at runtime, and drives amdhip64.dll through a hand-written Python ctypes bridge.
The entire project was developed, tuned, and verified on a single consumer desktop card: an AMD Radeon RX 7600 (RDNA3, gfx1102, 8GB VRAM), running Qwen2.5-1.5B-Instruct in Q4_K_M quantization.
Why build from scratch?
The goal wasn’t to compete with enterprise data-center runners, but to gain complete, granular control over every single byte moving between VRAM and the ALUs, and study about what AMD can reach. On a consumer card with tighter memory bandwidth and limited Compute Units (CUs), enterprise defaults don’t always make sense.
Single-Sequence Decode (Batch = 1)
| Stage | Throughput | What Changed |
|---|---|---|
| Naive per-thread GEMV | ~18.8 tok/s | Baseline: One thread per output element, no coalescing. |
| Coalesced GEMV | ~31.5 tok/s | Threads in a block cooperate on one output neuron; coalesced weight reads. |
| In-kernel Dequantization | ~37.9 tok/s | FFN weights dequantized inline during GEMV (No-Sync Direct Unpack) instead of a separate pass. |
| QKV Two-Pass Split-K Fusion | ~41.0 tok/s | Fills all 32 CUs instead of leaving most idle. |
Batched Decode Throughput
Using lockstep generation for same-length prompts, VTE scales up smoothly until hitting physical hardware limits:
-
Batch 1: 110.7 tok/s (Prefill/Base)
-
Batch 2: 165.3 tok/s (75% efficiency vs ideal linear scaling)
-
Batch 4: 204.2 tok/s (Peak performance)
-
Batch 8: 193.5 tok/s (Regression due to 32MB Infinity Cache thrashing)
The Infinity Cache Bottleneck: At batch=8, performance drops because the FFN weights (~27.5MB per layer) no longer fit comfortably inside the RX 7600’s 32MB Infinity Cache alongside the rest of the operational data.
How It Fits Together
The codebase is split cleanly into three main layers:
-
vte/bridge: The driver interface. Houses a custom ctypes wrapper foramdhip64.dll, a slab allocator to bypass repeatedhipMallocoverhead, a Kernel Watchdog to prevent Windows TDR hangs, and a userspace duty-cycle limiter to keep your desktop responsive by capping sustained GPU utilization at 95%. -
vte/compiler: The translation layer. Features GGUF parsers, byte-exact Q4_K/Q6_K dequantizers, an IR graph builder that analyzes RDNA3 VGPR/LDS limits for safe kernel fusion, and a from-scratch byte-level BPE tokenizer mirroring thetiktokenalgorithm without external dependencies. -
vte/core: The orchestrator. Captures the entire per-token decode path into a HIP Graph once and replays it, completely wiping out Python-side dispatch overhead.
Hunting Silent Data Corruptions
When building an engine from scratch, the hardest bugs don’t crash the code—they give you highly fluent, beautifully formatted garbage. A few notable bugs caught by layer-by-layer NumPy diffing included:
-
The SwiGLU Black Hole: The SwiGLU kernel expected
total_elements(batch * seq_len * intermediate_size), but the argument builder passed them as three separate values. The kernel readtotal_elements = 1, gracefully processed exactly one out of 8,960 elements, and discarded the rest. -
The Hidden 16-bit Swapping: The matmul kernel outputted FP16, but the host buffer read it back as FP32. Adjacent pairs of FP16 values were reinterpreted as single FP32 floats, creating massive logit magnitudes (~1e7 instead of ±40) from a perfectly healthy hidden state.
-
The Overlapping KV Cache: An early layout mistake caused every layer’s V-cache to overwrite the previous layer’s K-cache space. The model ran perfectly smoothly, but completely lost its mind across layer transitions.