Skip to content

Case Studies · LLM Fine-tuning · · Updated

STEM reasoning LLMs: fine-tuning Qwen3-14B and gpt-oss-20b with Unsloth

By Khadim Hussain · 6 min read

In short

I fine-tuned Qwen3-14B and gpt-oss-20b with Unsloth and QLoRA for STEM reasoning and Q&A, on 4,260 training and 474 evaluation examples. Each model is published three ways: a LoRA adapter, a merged bf16 model, and GGUF quantizations that run locally in Ollama, llama.cpp and LM Studio. The Qwen3-14B run took about 23 minutes for three epochs on one RTX 5090, after I cut the sequence length and LoRA rank to fit in 32 GB and converted to GGUF with llama.cpp because Unsloth's GGUF export failed on Qwen3. Recorded eval loss was 0.692 for Qwen3-14B and 0.837 for gpt-oss-20b. As of 27 October 2026 the two GGUF repos have 1,304 downloads between them, against 149 for the two adapters.

4,260

training examples

1.3k+

GGUF downloads

3

formats

  • Unsloth
  • QLoRA
  • PEFT
  • GGUF
  • Ollama
  • llama.cpp
  • Hugging Face
  • Transformers
STEM reasoning model training results
Contents

I fine-tuned Qwen3 with Unsloth for STEM questions, and gpt-oss-20b the same way: QLoRA on one RTX 5090, with 4,260 training examples and 474 held out for evaluation. Each model is published three ways, as a LoRA adapter, a merged 16-bit model and GGUF files that run locally. Below are the Qwen3-14B run in detail, the results for both models, and which format people actually downloaded. The gpt-oss export and the Harmony chat template it needs have their own walkthrough.

What was trained?

Two open-weight models, fine-tuned with QLoRA through Unsloth:

Base modelTaskEpochsPublished as
openai/gpt-oss-20bSTEM reasoning1LoRA adapter, merged bf16 model, GGUF (f16, Q8_0, Q4_K_M)
Qwen3-14BSTEM Q&A3LoRA adapter, merged bf16 model, GGUF (f16, Q4_K_M)

QLoRA trains a small low-rank adapter on top of a 4-bit quantized copy of the base model, which cuts the GPU memory a 20B fine-tune needs to a fraction of a full fine-tune.

How do you fine-tune Qwen3 with Unsloth on one GPU?

The data is a hand-curated CSV of STEM questions, each with a context field and an answer, and no synthetic or scraped examples: 4,740 rows. Six had an empty question or answer and were dropped, leaving 4,734. A short script converted the rest to Alpaca-style JSONL (question to instruction, context to input, answer to output), shuffled them with seed 42 and split them 90/10 into 4,260 training and 474 evaluation examples.

kllm, the small toolkit I train with, renders each example in Qwen's ChatML format, with the instruction and the context joined by a blank line and no system prompt or thinking block:

<|im_start|>user
{instruction}
 
{input}<|im_end|>
<|im_start|>assistant
{output}<|im_end|>

The settings that fit in 32 GB, from configs/qwen3_14b.yaml and my run notes:

SettingValue
Base modelQwen/Qwen3-14B, loaded in 4-bit
LoRArank 32, alpha 64, dropout 0, on the q, k, v, o, gate, up and down projections
Sequence length2,048 tokens, with packing
Effective batch size16
Schedule3 epochs, 801 steps, cosine with 5% warmup, weight decay 0.01
Optimizer and precisionAdamW 8-bit, bf16
Evaluationonce per epoch
Hardware and timeone RTX 5090 (32 GB), about 23 minutes

The model card records learning rate 1e-4 and batch size 1 with gradient accumulation 16. The Qwen3 config in the kllm repo says 2e-4, with batch size 2 and accumulation 8. Both give an effective batch of 16; I report the card's values in the results below and flag the difference here.

After training, the adapter is merged into the base model at 16 bits, and the merged model is what gets converted to a GGUF model file. The adapter on its own converts only to a GGUF LoRA, which llama.cpp loads on top of a base model.

What broke while fine-tuning Qwen3?

It took about nine attempts to get one clean run. In order:

  • The first configuration (4,096 tokens, rank 64, alpha 128) ran out of memory, and the process died without an error message. dmesg | grep -i oom showed the kernel's out-of-memory killer had stopped it, and halving the sequence length and the rank fixed it.
  • Any nonzero lora_dropout crashed Unsloth with an UnboundLocalError, so dropout is 0.
  • Evaluating every few steps spiked memory, so evaluation moved to the end of each epoch.
  • I dropped Docker and installed into a uv virtual environment. vLLM 0.15.0 needs exactly transformers 4.57.3, so that pin has to be forced after vLLM is installed, or imports fail.
  • The build needed the python3.12-dev headers, and the output folder needed its owner fixed before the model could be saved.
  • Unsloth's own GGUF export failed on Qwen3 with "GGUF conversion failed: EOF when reading a line". I converted the merged model with llama.cpp's convert_hf_to_gguf.py instead, then quantized it with llama-quantize.

The verified environment is in the kllm setup guide: Ubuntu 24.04, CUDA 12.8 toolkit, Python 3.12.3, PyTorch 2.9.1, Unsloth 2026.1.4 and transformers 4.57.3.

Why three formats?

Each format is for a different user:

  • A LoRA adapter for people who already run the base model and want to load the fine-tune on top
  • A merged bf16 model for serving with Transformers or vLLM without handling adapters
  • GGUF for running on a laptop or a single consumer GPU

The file sizes decide what hardware works:

FileSize
gpt-oss-20b LoRA adapter61 MB
Qwen3-14B LoRA adapter514 MB
gpt-oss-20b Q4_K_M15.8 GB
gpt-oss-20b Q8_022.3 GB
gpt-oss-20b f1641.9 GB
gpt-oss-20b merged bf1641.8 GB
Qwen3-14B Q4_K_M9.0 GB
Qwen3-14B f1629.5 GB
Qwen3-14B merged bf1629.5 GB

How do I run the gpt-oss-20b GGUF in Ollama?

Each GGUF repo ships a Modelfile with the right chat template. gpt-oss needs OpenAI's Harmony format, so this is the reliable route:

# after downloading a .gguf and the Modelfile from the repo
ollama create gpt-oss-20b-stem -f Modelfile
ollama run gpt-oss-20b-stem

ollama run hf.co/khadim-hussain/gpt-oss-20b-stem-reasoning-GGUF:Q4_K_M also works, but it uses the template embedded in the GGUF file rather than the Modelfile. The full walkthrough, from the QLoRA settings to the Harmony template, is in Fine-tuning gpt-oss-20b with Unsloth and running it in Ollama.

The Qwen3-14B GGUF works the same way with its own ChatML Modelfile:

ollama create qwen3-14b-stem -f Modelfile
ollama run qwen3-14b-stem "What is DNA?"

Both Modelfiles first shipped with a template that used only {{ .Prompt }}. That renders a single question correctly, but Ollama treats it as a legacy template and garbles the conversation history from the second message on. Both repos now ship templates that loop over .Messages instead.

The LoRA adapters no longer load in Ollama, which dropped adapter support in version 0.34.1. Running a LoRA adapter after Ollama removed support shows how to serve the Qwen3-14B adapter with llama.cpp instead.

Training results

ModelTrain lossEval lossExamples (train / eval)
gpt-oss-20b1.0870.8374,260 / 474
Qwen3-14B0.4610.6924,260 / 474

Both runs used LoRA rank 32, alpha 64, learning rate 1e-4, batch size 1 with gradient accumulation 16, and AdamW 8-bit, as recorded on the model cards.

The chart at the top of this page is the gpt-oss-20b run. Its loss fell from about 3 to below 1 within the first 80 steps and then flattened out. One epoch was about 266 steps, and the learning rate warmed up to about 1e-4 and then followed a cosine curve down. The gradient-norm panel logged NaN at several steps while the loss kept falling.

These losses measure the training objective on held-out examples. They are not accuracy scores, and the two shouldn't be compared with each other: the models use different tokenizers and prompt formats, and trained for different numbers of epochs. kllm includes an lm-evaluation-harness script, but I haven't published benchmark results for these models.

What I have measured is a change in behaviour. In the tests for the Ollama adapter post, I asked "What is DNA?" through llama.cpp with the Qwen3-14B adapter switched off and on. The base model opened a <think> block and was still reasoning when it hit the 160-token limit. With the adapter on, it answered in 74 tokens and stopped. The merged GGUF in Ollama also answered directly, in 49 tokens.

What got used?

All-time downloads on Hugging Face, read on 27 October 2026:

Formatgpt-oss-20bQwen3-14B
GGUF749555
Merged 16-bit8759
LoRA adapter7277

The Qwen3-14B GGUF had 295 of its 555 downloads in the last 30 days. The adapters and merged models have far fewer, so most people who use a fine-tune want it in a format that runs locally.

If you need a model trained and tested on your own task, that is what my LLM fine-tuning and consulting service covers.

Next

Frequently asked questions

How long does it take to fine-tune Qwen3-14B with Unsloth?

My run took about 23 minutes: three epochs, 801 steps, over 4,260 examples at a 2,048-token sequence length, with QLoRA on one RTX 5090. Getting to a configuration that fit in memory and ran cleanly took about nine attempts.

How much VRAM does fine-tuning Qwen3-14B need?

The kllm README lists about 16 GB for Qwen3-14B with QLoRA. My first configuration, with a 4,096-token sequence length and LoRA rank 64, still ran out of memory on a 32 GB card; 2,048 tokens and rank 32 fit.

Why does Unsloth's GGUF export fail for Qwen3?

On my run, Unsloth's save_pretrained_gguf stopped with "GGUF conversion failed: EOF when reading a line". I merged the adapter into a 16-bit model and converted that with llama.cpp's convert_hf_to_gguf.py and llama-quantize instead.

Can I run the gpt-oss-20b GGUF in Ollama?

Yes. Download a .gguf file and the Modelfile from the repo and run ollama create, so the model gets the Harmony chat template it was trained with. ollama run hf.co/khadim-hussain/gpt-oss-20b-stem-reasoning-GGUF:Q4_K_M also works, but it uses the template embedded in the GGUF file. The Q4_K_M file is 15.8 GB.

Can Ollama load the LoRA adapters?

Not since Ollama 0.34.1, which rejects any Modelfile with an ADAPTER line. Use the merged GGUF in Ollama, or serve the adapter with llama.cpp's llama-server --lora on top of a base GGUF.

Is the fine-tuned model better than the base model?

I haven't benchmarked it. The recorded losses measure the training objective on held-out examples, not accuracy. What I have observed is a change in behaviour: asked what DNA is, the Qwen3-14B fine-tune answers directly in 74 tokens, while the base model opens a thinking block and is still reasoning at a 160-token limit.

Want a second pair of eyes on this?

Book a 15-minute intro call. Bring the problem, and you leave with a concrete next step.