How to fine-tune Qwen for production

Alexandra Kane - VP, Revenue
by Alexandra Kane

Most Qwen fine-tuning guides stop at a local LoRA. Here's how to train, evaluate and serve a fine-tuned Qwen in your own cloud, and when it beats a frontier API bill.

December 2, 2026

I'm not a huge fan of saying things are "dead," but it does seem like the tokenmaxxing era is behind us. Almost every sales call has an engineer on the other end getting pressure about costs from everyone from their manager to the CFO. Heavy workloads built on their data are pushing frontier costs way up, and once we bring up tuning an open model on their own data, their eyes light up.

Most guides on how to fine-tune Qwen end in the same place: a LoRA adapter trained on a laptop or a Colab GPU, exported to GGUF, and run once in Ollama to prove it works.

The questions that matter start after the export: where the model runs, who can call it, what happens when Qwen ships the next version, and whether the tuned model beats the frontier API call it was meant to replace. This guide covers the production version of the job: build the training set, fine-tune Qwen on cloud GPUs, evaluate it against the model you're replacing, and serve it in your own cloud.

The fine-tune is the cheap part. A published DataCamp run fine-tuned Qwen3-32B in 42 minutes on one A100 for under $3. The data, the evaluation and the serving are where the work and the risk sit.

Why fine-tune Qwen instead of paying for a frontier model?

Fine-tuning a mid-size open-weight Qwen model makes sense when a frontier API is doing a narrow, high-volume job: classification, extraction, routing, structured summaries. On a narrow task, a tuned 27B model can match the frontier model, and your evaluation tells you whether it does. If it does, you pay for GPU hours instead of a bill that grows with every token.

The math on the frontier side is simple, because it's linear. Take a workload of 2 billion input tokens and 400 million output tokens a month. At list prices on December 2, 2026 (Anthropic, Google):

Model

Price per 1M tokens (input / output)

Monthly bill

Claude Sonnet 5.5

$2 / $10

$8,000

Claude Opus 5.5

$4 / $20

$16,000

Gemini 4 Carbon

$4 / $20

$16,000

Double the traffic and the bill doubles. A self-hosted model works the other way: you pay for the GPUs whether they're busy or idle, so the more steadily you use them, the cheaper each token gets. If the volume is low or spiky, stay on the API. If it's steady and the task is narrow, a tuned open model you run yourself is worth testing.

Before you switch, the tuned model has to pass an evaluation against the frontier model on your data, not on a benchmark, and someone has to own the serving. The rest of this guide covers both.

Which Qwen model should you fine-tune?

Start with the smallest Qwen that passes your evaluation. Training runs are short. Serving cost scales with model size for every hour the model is up.

The current open-weight generation is Qwen3.8 (released August 2026). Two models matter for most teams:

  • Qwen3.8-27B: a dense 27B model with a vision encoder, a 262K-token native context window, and an Apache 2.0 license. This is the practical fine-tuning target. Per Unsloth's Qwen3.8 guide, QLoRA fits in 24GB of VRAM and LoRA needs more than 36GB.
  • Qwen3.8-2.4T-A95B: the open release of the Max-class MoE model, with 2.4T total parameters and 95B active. It ships under its own Qwen license, not Apache 2.0, so read it before you build on it. Fine-tuning it is a multi-node job and out of scope here.

If 27B is more model than your task needs, the previous generation, Qwen3.5, has small sizes from 0.8B to 9B. Unsloth's Qwen3.5 guide lists bf16 LoRA at about 22GB for the 9B.

Can you fine-tune Qwen?

Yes. Open-weight Qwen models support LoRA, QLoRA and full fine-tuning. Fine-tuning adapts a pretrained model to your task with your own examples. It is not pretraining from scratch, and the 27B and smaller sizes fit on a single cloud GPU.

Step 1: Build the training set from production data

Local guides pull a public Hugging Face dataset. A production fine-tune uses your own data, and that brings two problems the tutorials skip.

Leakage: A training row built from today's values for an event that happened last month teaches the model things it could never have known at the time. The model looks great in training and worse in production. Each row has to hold the values that existed when the event happened. Chalk's time-correct evals demo shows the same leak in an evaluation: a dispute-review agent scored 100% with today's values and 81% with point-in-time values.

Governance: Prompts and responses from production often contain customer data. Copying them to a laptop or a third-party notebook to train is the step security teams block.

The format work is the easy part. Use Qwen's chat template for every example, keep prompt-response pairs in the same shape you'll send at inference, and if you're tuning a thinking model, keep reasoning traces in the mix. Unsloth's guidance is to keep at least 75% reasoning-style examples so the model doesn't lose its reasoning behavior.

With Chalk, you build the training set as an offline query. You pass the entities and a timestamp for each row, and Chalk computes each row's features as of that time:

from chalk.client import ChalkClient

dataset = ChalkClient().offline_query(
    input={"ticket.id": ticket_ids},
    input_times=ticket_created_at,
    output=[Ticket.prompt, Ticket.resolution_label],
    dataset_name="ticket_routing_sft",
)
df = dataset.get_data_as_polars()

Each row gets the latest feature values observed before its input time. Re-running with the same dataset_name creates a new revision instead of overwriting the old one. When Chalk is deployed in your cloud, the dataset is stored as parquet files in your own storage buckets. See datasets from offline queries and point-in-time correct training data.

Step 2: Fine-tune Qwen with LoRA on cloud GPUs

The main configuration choice is how much of the model you train.

LoRA trains small adapter matrices. QLoRA quantizes the base model to 4-bit to save memory. Unsloth's Qwen3.8 guide uses QLoRA for the 27B in its training recipe. Unsloth's Qwen3.5 guide recommends against 4-bit training because of quantization error, so check the guide for the generation you're on. Full fine-tuning uses about 4x the VRAM, per the Qwen3.8 guide, and is rarely worth it for a narrow task.

A minimal run, adapted from the SFT recipe in Unsloth's Qwen3.8 guide:

from unsloth import FastModel
from trl import SFTTrainer, SFTConfig

model, tokenizer = FastModel.from_pretrained(
    model_name="unsloth/Qwen3.8-27B-unsloth-bnb-4bit",
    max_seq_length=2048,
    load_in_4bit=True,  # QLoRA
    full_finetuning=False,
    offload_embedding=True,
)
model = FastModel.get_peft_model(
    model,
    finetune_vision_layers=False,
    finetune_language_layers=True,
    finetune_attention_modules=True,
    finetune_mlp_modules=True,
    r=16,
    lora_alpha=16,
    lora_dropout=0,
    bias="none",
    use_gradient_checkpointing="unsloth",
)
trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=train_ds,
    args=SFTConfig(
        dataset_text_field="text",
        max_seq_length=2048,
        per_device_train_batch_size=1,
        gradient_accumulation_steps=4,
        warmup_steps=10,
        max_steps=100,
        learning_rate=2e-4,
        optim="adamw_8bit",
        output_dir="outputs_qwen38",
    ),
)
trainer.train()

Moving the same code off Colab is where the work changes. You need a GPU that's there when the job starts, checkpoints that survive a preempted node, retries, a place for secrets like the Hugging Face token, and logged metrics you can compare across runs.

On Chalk, you wrap the training function in @chalkcompute.training. The function gets the dataset as a Polars frame and returns the trained model, and you install Unsloth and TRL into the run's container image with pip_install. No CUDA base image is needed. Save the LoRA adapter and tokenizer to a directory and pass that path to checkpoint(). Chalk runs the function on a managed container with the GPU you ask for (the GPU type has to match a node pool in your cluster), pins an immutable revision of the dataset so a rerun reads the same rows, and writes checkpoints to managed storage that survives container restarts. For SFT runs, the training dashboard charts training loss and learning rate:

from dataclasses import dataclass
import chalkcompute
from chalk.ml.chalk_train import checkpoint

@dataclass
class QwenConfig:
    lr: float = 2e-4
    max_steps: int = 100

@chalkcompute.training(
    data="ticket_routing_sft",
    cpu="8",
    memory="32Gi",
    gpu="nvidia-a100-80gb",
    image=chalkcompute.Image.debian_slim("3.12").pip_install([
        "chalkcompute==2.13.8",
        "chalkpy[runtime,training]==2.165.0",
        "torch",
        "unsloth",
        "trl",
    ]),
    max_retries=2,
    metadata={"training_method": "sft"},
)
def train_qwen(df, config: QwenConfig):
    df = df.collect()  # run_training() passes a LazyFrame
    ...  # the Unsloth / TRL run above, with train_ds built from df
    model.save_pretrained("adapter")
    tokenizer.save_pretrained("adapter")
    checkpoint(path="adapter")
    return model

run = train_qwen.run_training(config=QwenConfig())
run.wait()

run_training() returns a handle immediately, and wait() blocks until the run finishes. See model training.

Step 3: Evaluate before you ship

Most tutorials check the fine-tune with one prompt before and one after. That tells you the model changed, but not whether it beats what you're running today.

Hold out a slice of the dataset, and score three models on the same rows with the same scorer:

  1. Base Qwen3.8-27B
  2. Your fine-tuned Qwen
  3. The frontier model you're paying for now

This is the evaluation that decides the swap. If the tuned 27B matches the frontier model on your task, the API bill from the table above is what you stop paying. If it doesn't, you found out before your users did.

Chalk evaluations are defined by an evaluation dataset, one task, and one or more scorers. The held-out rows go into that evaluation dataset as plain tabular data. Running the evaluation calls the task once per row, passes each output to every scorer, and writes the scores to a result dataset. Definitions are immutable, so two runs of the same evaluation stay comparable, and each new model version gets its own evaluation. Evaluations are enabled by Chalk support. The reinforcement learning demo uses evaluation scores as the reward to post-train a LoRA adapter for Qwen3-4B on Chalk GPUs. More on how we evaluate LLM outputs before we trust them.

Step 4: Export and serve the fine-tuned model

There are three export paths, and each fits a different job:

  • LoRA adapter on the base model for serving with vLLM. This is what the Chalk checkpoint above holds, and it lets you serve several fine-tunes on one base model.
  • Merged 16-bit weights if you'd rather serve one standalone model.
  • GGUF for llama.cpp, Ollama and local testing.

Three things commonly break after export:

  1. Chat template and EOS mismatch: If serving uses a different chat template or end-of-sequence token than training, output quality drops or generation never stops. Use the same template you trained with.
  2. Serving engine support: New Qwen architectures land in vLLM after the model ships. Check vLLM's supported models list or the recipe linked from the model card before you plan a launch date.
  3. Adapter sprawl: Five fine-tunes as five merged models is five GPUs. Serving adapters on a shared base is often the better trade.

A basic vllm serve runs the base model with the adapter on top. Set --max-lora-rank to the rank you trained with (16 above):

vllm serve Qwen/Qwen3.8-27B \
  --enable-lora \
  --lora-modules ticket-routing=./adapter \
  --max-lora-rank 16 \
  --max-model-len 16384 \
  --gpu-memory-utilization 0.90

Requests pick the adapter by name in the model field, as if it were any other model ("model": "ticket-routing").

On Chalk, you promote the training run's checkpoint into the model registry with promote_model_artifact, then run vLLM's own HTTP server on a GPU scaling group. Scaling groups autoscale on CPU or GPU utilization or on a schedule, and can scale to zero replicas and start again when a request arrives:

chalk scaling-group create \
  --name=qwen-ticket-routing \
  --image=your-registry/vllm-serving:latest \
  --gpu=nvidia-h100-80gb:1 \
  --port=8080 \
  --scale-from-zero-request-policy=hold \
  --entrypoint="python,-m,vllm.entrypoints.openai.api_server,--model,Qwen/Qwen3.8-27B,--enable-lora,--lora-modules,ticket-routing=/models/ticket-routing-adapter,--max-lora-rank,16"

The image needs vLLM installed. By default, requests return an error while a group scales up from zero. --scale-from-zero-request-policy=hold makes them wait instead. Features and resolvers then call the model through the model registry. When Chalk is deployed in your cloud, that's autoscaling GPUs in your own account.

To cut over without a hard switch, put both models behind Chalk's Model Gateway. It's one OpenAI-compatible API that routes to OpenAI, Anthropic, Gemini and your own vLLM server, with a fallback list per provider. If the tuned Qwen times out or returns errors, the request falls back to the frontier model instead of failing. The model routing demo shows the gateway's judge picking a cheap, mid or frontier model for each GitHub issue. For the serving side in more depth, see what is LLM inference.

Can you run Qwen locally?

Yes. Ollama and llama.cpp both run Qwen from GGUF quantizations, and that's the right setup for testing a fine-tune. A shared production endpoint needs a server like vLLM on GPUs you control, with autoscaling and access control in front of it.

Retrain when the data or the model changes

New data arrives and the task drifts. Qwen ships a new version and the base model you tuned is out of date. Each time, you rebuild the dataset, retrain, re-evaluate against what's in production, and redeploy.

Teams usually wire that loop together from four tools: a feature pipeline, a training platform, an eval harness and a serving stack. Each handoff is a place for training and serving data to drift apart. Chalk runs the whole loop in one environment, which can be deployed in your own cloud. The features you train on are the features you serve, and each new model version gets its own evaluation.

Start with Model Serving to see how a fine-tuned open model runs on autoscaling GPUs in your account, or Model Training for the training side.

Frequently asked questions

How much VRAM do you need to fine-tune Qwen?

For Qwen3.8-27B, Unsloth lists QLoRA at 24GB and LoRA at more than 36GB. For the smaller Qwen3.5 sizes, bf16 LoRA runs from about 3GB for the 0.8B to about 22GB for the 9B.

Should you use LoRA or QLoRA for Qwen?

For Qwen3.8-27B, Unsloth's guide trains with QLoRA, which fits in 24GB. LoRA needs more than 36GB. For Qwen3.5 models, Unsloth recommends against 4-bit training because of quantization error.

Can you serve a fine-tuned Qwen with vLLM?

Yes. Serve the adapter on top of the base model with --enable-lora, or merge it into 16-bit weights and serve that. Check that your vLLM version supports the Qwen architecture you tuned, and serve with the same chat template you trained with.

Want to stay up-to-date with Chalk?

Subscribe for updates on what we’re building (and shipping!) at Chalk