Fine-tune a language model in Rust on your GPU
Ferrotensor fine-tunes Llama-style language models, such as SmolLM2, TinyLlama and Qwen2, with LoRA on your own GPU. It is a Rust framework with its own WGSL kernels, which run through Vulkan, Metal and DX12, on NVIDIA GPUs and Apple silicon. The guide walks through a full run. This page is the short version.
What LoRA does here
The base weights stay frozen, and a small adapter is trained on top of them. finetune writes the adapter as lora_adapters.safetensors into --out, outputs/run by default, with the state that --resume needs. The loss counts the response tokens and ignores the prompt.
Plan, then train
Install the command with cargo install ferrotensor-cli (Rust 1.88 or newer). plan reads the memory of your GPU and picks a batch size, sequence length and rank that fit. finetune trains with that plan:
ferrotensor plan --model DIR --json
ferrotensor finetune --model DIR --data train.jsonl --jsonDIR is a Hugging Face checkpoint directory, or a model id that is already in the local Hugging Face cache.
Data format
The training data is a .jsonl file with one {"prompt": ..., "response": ...} object per line, with an optional "system", or a .json array of the same objects. Prompts are wrapped in ChatML unless you pass --no-chat-template.
Evaluate, chat and export
ferrotensor eval --model DIR --data val.jsonl --lora outputs/run/lora_adapters.safetensors --json
ferrotensor chat --model DIR --lora outputs/run/lora_adapters.safetensors
ferrotensor merge --model DIR --lora outputs/run/lora_adapters.safetensors --out outputs/merged
ferrotensor export-gguf --model outputs/merged --out model.ggufeval reports the held-out loss and perplexity. chat --lora talks to the fine-tuned model, and running models covers generate and chat. merge folds the adapter into the base weights, and export-gguf writes a GGUF file for llama.cpp and Ollama. For PyTorch, export-adapter writes a PEFT adapter directory:
ferrotensor export-adapter --model DIR --lora outputs/run/lora_adapters.safetensors --output outputs/peftWhat has been measured
Every number comes from a run with its machine written down.
- LoRA gradients match PyTorch autograd below 1e-6. The largest difference was 9.5e-7, on a tiny Llama-style model, on one NVIDIA A10G through Vulkan, 15 Nov 2026.
- SmolLM2-1.7B fine-tunes in 5,313 MiB of peak GPU memory with
--checkpoint-blocks, on one NVIDIA A10G (24 GB), f16 base weights, batch 1 with 8-step accumulation, sequence length 256. - Held-out loss was within 0.004 of PyTorch + PEFT on the same A10G with the same recipe (the code in 0.7.1, 19 Nov 2026).
The tables are in the LoRA walkthrough and the benchmarks.
How to fine-tune a language model in Rust?
Install the command with cargo install ferrotensor-cli. Run ferrotensor plan --model DIR --json to see what fits your GPU, then ferrotensor finetune --model DIR --data train.jsonl --json to train a LoRA adapter on prompt and response pairs.
How much GPU memory does it need?
SmolLM2-1.7B peaked at 5,313 MiB with --checkpoint-blocks on one NVIDIA A10G (24 GB), with f16 base weights, batch 1 with 8-step accumulation and sequence length 256. ferrotensor plan reads the memory of your GPU and picks settings that fit.
Can the result be used in PyTorch, llama.cpp or Ollama?
Yes. export-adapter writes a PEFT adapter directory for PyTorch. merge folds the adapter into the base weights, and export-gguf writes a GGUF file for llama.cpp and Ollama. For Ollama, write a Modelfile that holds FROM ./model.gguf, then run:
ollama create NAME -f Modelfile
ollama run NAMEOllama picks the chat template from the file (checked with Ollama 0.40.17).
Which models and GPUs does it support?
Llama-style decoder models such as SmolLM2, TinyLlama and Qwen2, on NVIDIA GPUs and Apple silicon through Vulkan and Metal. Models larger than SmolLM2-1.7B are untested, and so are AMD and Intel GPUs.
More
- Guide: a full fine-tuning run, with output from a real one
- Run language models in Rust and train one from scratch
- Questions and the docs
- Source on GitHub