KTransformers is a research framework for running and fine-tuning large Mixture-of-Experts (MoE) language models using CPU-GPU heterogeneous computing. It's built for developers and researchers who want to serve or train models like DeepSeek-V3/R1, Kimi-K2, GLM, and Qwen3-MoE on hardware that doesn't have enough GPU memory to hold the full model, by offloading experts and computation across CPU and GPU.
The project splits into two user-facing pieces: kt-kernel for inference, and an SFT integration with LlamaFactory for fine-tuning. Both rely on the same underlying idea: keep hot experts on GPU, push cold experts to CPU, and use optimized CPU kernels (AMX, AVX512, AVX2) to make that offloading fast instead of a bottleneck.
KTransformers fits teams that need to run or fine-tune very large MoE models (hundreds of billions of parameters) on hardware that can't fit the full model in GPU VRAM, such as a single 24GB card or a handful of consumer GPUs. It's a good match for production serving setups that pair kt-kernel with SGLang, and for researchers experimenting with quantized DeepSeek-V3/R1, Kimi-K2, or GLM variants on CPU-heavy servers (Xeon, AMD EPYC with AVX512/AMX).
It's also useful for fine-tuning workflows: LoRA or full-parameter SFT of MoE models like DeepSeek-V3, DeepSeek-R1, or Qwen3-30B-A3B on a small number of RTX 4090s via the LlamaFactory integration, when full-parameter training on standard multi-GPU clusters isn't affordable.
It is not the right tool if you're serving small dense models that already fit comfortably on a single GPU, or if you need a plug-and-play hosted inference API rather than a framework you deploy and tune yourself. Teams without access to CPUs with AVX512/AMX (or comparable) or without the patience to work through quantization/precision configuration will find the setup more involved than a standard Transformers pipeline.
For inference with the kt-kernel:
cd kt-kernel
pip install .
This installs the CPU-optimized kernel package with a Python API for integration into SGLang or other serving frameworks. See the kt-kernel README for model-specific tutorials (DeepSeek, Kimi-K2, GLM, Qwen3-Next, and others) and hardware-specific notes (AMX, ROCm, Intel Arc, Ascend NPU).
For fine-tuning with LlamaFactory:
cd /path/to/LLaMA-Factory
python -m pip install -e .
python -m pip install "ktransformers[sft]==0.7.0"
python -m pip install "sglang-kt==0.7.0"
CUDA_VISIBLE_DEVICES=0,1,2,3 accelerate launch \
--config_file examples/ktransformers/accelerate/fsdp2_kt_int8.yaml \
src/train.py \
examples/ktransformers/train_lora/qwen3_5moe_lora_sft_kt.yaml
The repository also provides a full Fine-Tuning Cookbook covering hardware checks, BF16/FP8/INT8 configuration, LoRA vs full fine-tuning, resource planning, and troubleshooting for specific model families like Kimi K2.5/K2.6.