Introduction
KTransformers is an inference framework designed to run large language models on heterogeneous hardware. It lets you split model layers across CPU and GPU, making it possible to run models that exceed your GPU memory by offloading parts to system RAM while maintaining reasonable throughput.
What KTransformers Does
- Splits model layers across CPU and GPU for mixed-hardware inference
- Runs models larger than available VRAM by offloading to system memory
- Optimizes inference throughput with custom CUDA kernels
- Supports quantized models to reduce memory requirements
- Provides an OpenAI-compatible API server for easy integration
Architecture Overview
KTransformers analyzes the transformer architecture and assigns each layer to the most appropriate compute device. Attention layers that benefit from parallelism go to the GPU, while less compute-intensive layers can run on CPU. A scheduler coordinates data transfer between devices, minimizing PCIe bottleneck. The framework includes optimized kernels for both CPU (AVX/AMX) and GPU (CUDA) execution paths.
Self-Hosting & Configuration
- Install via pip with CUDA toolkit and compatible PyTorch
- Specify a model path or Hugging Face model ID
- Configure CPU/GPU layer split ratios in the config file
- Set quantization level (4-bit, 8-bit) for memory optimization
- Launch the built-in API server for OpenAI-compatible access
Key Features
- Heterogeneous execution across CPU and GPU devices
- Runs 70B+ parameter models on consumer hardware with sufficient RAM
- Custom optimized kernels for both CPU and GPU paths
- Quantization support for reduced memory footprint
- Drop-in OpenAI API compatibility for existing applications
Comparison with Similar Tools
- llama.cpp — Pure CPU/Metal inference in C++; KTransformers focuses on hybrid CPU+GPU with Python integration
- vLLM — High-throughput GPU serving; KTransformers targets heterogeneous hardware when full GPU memory is unavailable
- ExLlamaV2 — GPU-focused quantized inference; KTransformers adds CPU offloading for larger models
- Ollama — User-friendly local LLM runner; KTransformers gives more control over layer placement and optimization
FAQ
Q: What hardware do I need to run KTransformers? A: A CUDA-capable GPU with at least 8 GB VRAM and sufficient system RAM. Larger models require more RAM for CPU-offloaded layers.
Q: How does KTransformers compare to running entirely on GPU? A: Pure GPU inference is faster, but KTransformers lets you run models that would not fit in VRAM by offloading layers to CPU.
Q: Does KTransformers support fine-tuning? A: Yes, it supports fine-tuning optimizations alongside inference on heterogeneous hardware.
Q: What model formats does KTransformers support? A: It supports Hugging Face Transformers format and various quantization formats including GPTQ and AWQ.