TinyInfer: A Custom LLM Inference Engine for Consumer GPUs
A new open-source LLM inference engine, TinyInfer, achieves 235 tokens per second on an RTX 3050 6 GB laptop GPU using hand-written CUDA kernels, according to a detailed project post on Dev.to.

A custom LLM inference engine called tinyinfer has been developed to run on an RTX 3050 6 GB laptop GPU, achieving 235 tokens per second with TinyLlama-1.1B using 4-bit weights and optimized CUDA kernels. The project involved three rounds of optimization, focusing on improving memory bandwidth utilization and reducing computational bottlenecks. The engine is written in C++ and CUDA without relying on PyTorch or cuBLAS, and it matches the HuggingFace reference within 0.1% (1). [1]
The initial version of the engine achieved 66% of the theoretical memory bandwidth limit, but after implementing autotuned multi-row GEMV kernels and GQA-aware flash-decoding attention, performance improved significantly. The speed limit was found to be memory bandwidth rather than computational power, and the engine was able to reach 77% of the hardware's memory-bandwidth limit (1). [1]
Further optimizations, including fused projections and shared-memory attention, contributed to the final performance of 235 tokens per second. The engine was tested against a CPU reference implementation to ensure correctness, and it demonstrated a worst-case relative error of 2.5e-4 with no argmax mismatches (1). [1]
A custom LLM inference engine called tinyinfer has been developed to run on an RTX 3050 6 GB laptop GPU, achieving 235 tokens per second with TinyLlama-1.1B using 4-bit weights and optimized CUDA kernels. The initial version of the engine achieved 66% of the theoretical memory bandwidth limit, but after implementing autotuned multi-row GEMV kernels and GQA-aware flash-decoding attention, performance improved significantly (Dev.to, 2023). This optimization was part of a three-round iterative process aimed at improving the efficiency of the engine, where each round focused on identifying and addressing the most significant performance bottlenecks. The first version of the engine reached 200.7 tokens per second, which was 66% of the theoretical ceiling, with the most significant performance gains coming from the matrix-vector product (GEMV) kernel (Dev.to, 2023). [1]
Advertisement
The first round of optimization focused on improving the efficiency of the matrix operations by allowing each warp to process more rows, which helped to increase the memory bandwidth utilization. This change led to a significant improvement in the performance of the down projection matrix, which increased from 54% to 79% of the theoretical memory bandwidth (Dev.to, 2023). The second round of optimization focused on the attention mechanism, where the engine was modified to use a shared-memory tile and one lane per timestep. This change significantly improved the performance of the attention mechanism, especially for long context lengths (Dev.to, 2023). [1]
The third round of optimization focused on fusing projections and using shared-memory attention, which contributed to the final performance of 235 tokens per second. This optimization also helped to reduce the number of matrix-vector launches per layer, which improved the efficiency of the engine. The correctness of the engine was verified using a CPU reference engine, and the results showed that the engine was accurate within 0.1% of the HuggingFace reference (Dev.to, 2023). The engine is now available as an open-source project and can be used on NVIDIA GPUs from Turing (sm_75) and newer, on Windows and Linux, with CUDA 12 or 13 (Dev.to, 2023). [1]
A custom LLM inference engine called tinyinfer has been developed to run on an RTX 3050 6 GB laptop GPU, achieving 235 tokens per second with TinyLlama-1.1B using 4-bit weights and optimized CUDA kernels. The engine is written from scratch in C++ and CUDA, with no reliance on PyTorch or cuBLAS. This performance is 77% of the theoretical memory bandwidth limit of the GPU, which is 168 GB/s. The development process involved three rounds of optimization, with each round focusing on specific aspects of the engine to improve performance. The first round of optimization focused on improving the efficiency of the matrix operations by allowing each warp to process more rows, which helped to increase the memory bandwidth utilization (1). [1]
The second round of optimization focused on improving the attention mechanism by implementing a GQA-aware flash-decoding attention, which significantly improved performance for long context generation. This optimization helped reduce the time required for attention operations from 124.6 µs to 34.2 µs for 2,048 tokens of context. This improvement was achieved by using a shared-memory tile and allowing each warp to process one query head, which reduced the number of warp reductions required for the softmax operation (1). [1]
Advertisement
The third round of optimization focused on fusing projections and using shared-memory attention, which contributed to the final performance of 235 tokens per second. This optimization involved concatenating the weight matrices for the query, key, and value projections, as well as the gate and up projections, which reduced the number of matrix-vector launches per layer from five to two. This change, along with the other optimizations, resulted in a final performance of 235 tokens per second, which is 77% of the hardware's memory-bandwidth limit (1). [1]
Sources
Prepared with AI assistance from the cited sources.
The Cali Reporter newsletter
The stories worth your time.
California, the country, and what comes next. Join our free newsletter for reporting that keeps you informed.
More in Technology
- Modern Web Guidance 1.0 and Browser Compatibility
Modern Web Guidance 1.0, announced by Chrome for Developers on November 10, introduces browser compatibility data to assist coding agents in building web features. The initiative emphasizes the importance of fallback…
- Apache mod_http2 Vulnerability Detection with Nmap
A new Nmap scripting module has been developed to detect the Apache mod_http2 vulnerability (CVE-2026-119618), addressing the challenges of identifying affected systems accurately.
- Securing Remote Vendor Access in Industrial Networks
Best practices for managing remote vendor access in operational technology (OT) networks emphasize controlled access points, multifactor authentication, and time-bound sessions to reduce cybersecurity risks.
