doc/en/SFT/KTransformers-Fine-Tuning_Quick-Start.md
Last updated: 2026-04-30
This Quick Start is for LLaMA-Factory users who want to run KTransformers-backed MoE LoRA SFT. KTransformers has supported fine-tuning since v0.4.1 and later releases; v0.6.1 refactors and upgrades the existing KT SFT path with a pip-installable package entry, a cleaner dependency boundary, and LLaMA-Factory-compatible examples.
src/train.py and YAML configsktransformers[sft]torch==2.9.1KT inference uses a separate SGLang-KT package path. See KT Inference Packages.
Start from a clean environment:
conda create -n kt-sft python=3.11 -y
conda activate kt-sft
Install the PyTorch baseline:
pip install \
--extra-index-url https://download.pytorch.org/whl/cu130 \
torch==2.9.1 \
torchvision==0.24.1 \
torchaudio==2.9.1
If you already have a working torch==2.9.1 environment, you can reuse it. Plain PyPI or mirror installs usually resolve torch==2.9.1 to a CUDA 12.8 wheel; the PyTorch cu130 index resolves to the CUDA 13.0 wheel. In both cases, the Python package version remains torch==2.9.1.
Use a LLaMA-Factory checkout that contains the KT examples and requirements/ktransformers.txt. Related integration PR:
https://github.com/hiyouga/LLaMA-Factory/pull/10430
Confirm the checkout contains:
requirements/ktransformers.txtexamples/ktransformers/Install in this order:
cd /path/to/LLaMA-Factory
pip install -e .
pip install -r requirements/ktransformers.txt
requirements/ktransformers.txt should contain one line:
ktransformers[sft]
This entry installs the KT SFT stack:
ktransformerskt-kerneltransformers-ktaccelerate-ktIf your LLaMA-Factory checkout does not yet provide requirements/ktransformers.txt, you can install the KT SFT package entry directly:
pip install "ktransformers[sft]"
For LLaMA-Factory users, the requirements file is preferred because it keeps the examples and optional dependency flow together.
python - <<'PY'
import importlib.metadata as md
import torch
import transformers
import accelerate
import kt_kernel
import ktransformers
from accelerate.utils.dataclasses import KTransformersPlugin
print("torch =", torch.__version__)
print("transformers =", transformers.__version__)
print("accelerate =", accelerate.__version__)
print("kt_kernel =", kt_kernel.__version__)
print("ktransformers =", ktransformers.__version__)
print("transformers-kt dist =", md.version("transformers-kt"))
print("accelerate-kt dist =", md.version("accelerate-kt"))
print("KTransformersPlugin =", KTransformersPlugin.__name__)
PY
Expected values should be close to:
torch = 2.9.1+cu128 or 2.9.1+cu130transformers = 5.6.0accelerate = 1.14.0kt_kernel = 0.6.1ktransformers = 0.6.1KTransformersPlugin = KTransformersPluginReference configs:
examples/ktransformers/accelerate/fsdp2_kt_int8.yamlexamples/ktransformers/train_lora/qwen3_5moe_lora_sft_kt.yamlBefore running, open the train YAML and adjust these fields for your local setup:
model_name_or_pathdatasetoutput_dircutoff_lenmax_stepsRun:
cd /path/to/LLaMA-Factory
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
| Model path | accelerate config | train yaml |
|---|---|---|
| Qwen3 MoE BF16 | examples/ktransformers/accelerate/fsdp2_kt_bf16.yaml | examples/ktransformers/train_lora/qwen3moe_lora_sft_kt.yaml |
| Qwen3.5 MoE INT8 | examples/ktransformers/accelerate/fsdp2_kt_int8.yaml | examples/ktransformers/train_lora/qwen3_5moe_lora_sft_kt.yaml |
| DeepSeek-V2 MoE | examples/ktransformers/accelerate/ KT configs | examples/ktransformers/train_lora/deepseek_v2_lora_sft_kt.yaml |
| DeepSeek-V3 MoE | examples/ktransformers/accelerate/ KT configs | examples/ktransformers/train_lora/deepseek_v3_lora_sft_kt.yaml |
Start from the example kt_config, use_kt: true, and LoRA settings, then adjust model paths and resource-related fields for your hardware.
KT inference uses the SGLang-KT path:
pip install kt-kernel sglang-kt
LLaMA-Factory KT SFT continues to use:
pip install -r requirements/ktransformers.txt
with:
ktransformers[sft]
Keep sglang-kt out of LLaMA-Factory SFT requirements.
ValueError: unknown keys (['kt_config'])This usually means the environment is still using upstream accelerate. Reinstall in this order from the LLaMA-Factory checkout:
pip install -e .
pip install -r requirements/ktransformers.txt
Then rerun the post-install check and confirm accelerate = 1.14.0 and KTransformersPlugin imports successfully.
kt_kernel or ktransformers is missingConfirm that the KT SFT dependency step was run from the LLaMA-Factory checkout:
pip install -r requirements/ktransformers.txt
Try the following first:
cutoff_len