Fine-tune Qwen on RunPod with Tensorant
Build a support-ticket classifier with Qwen, review labeled examples, compare a LoRA adapter against the base model, and publish an API.
What you will build
Train, evaluate, and publish a Qwen support-ticket router.
Steps in this guide
Fine-tuning is useful when a general model understands your input but needs to follow a specific decision rule consistently. A support-ticket router is a good first project: it reads a customer message and returns one label that your application can validate.
In this guide, use Qwen/Qwen3-4B-Instruct-2507 to classify tickets as billing, account, technical, or other. Tensorant creates a dataset version, evaluates the base model, trains a LoRA adapter on your RunPod GPU, and compares both models on the same held-out examples. Publish the adapter as support-router once its answers meet your requirements.
The official Qwen model card describes a 4-billion-parameter instruction model (3.6 billion without embeddings, 36 layers, 32 query and 8 key-value attention heads) with a chat template, which answers directly, without a reasoning block. It is also on Tensorant's supported model list. Start with this small text model to make the complete workflow easier to inspect before moving to a larger model.
1. Define the routing contract
Decide label boundaries before collecting data. Otherwise, fine-tuning teaches inconsistent decisions.
| Label | Route here when the main issue concerns |
|---|---|
billing |
Charges, invoices, refunds, or payment methods |
account |
Login, passwords, account access, or profile settings |
technical |
A product failure, error, broken integration, or unexpected behavior |
other |
Sales, general questions, or a request without enough information to route |
Choose a rule for mixed tickets. For this example, use the issue preventing the customer's next action. A customer who cannot log in to download an invoice goes to account; a customer disputing an invoice goes to billing. Include these boundary cases in your examples.
Use the same system instruction during training and in your application:
Classify the support ticket as billing, account, technical, or other. Reply with exactly one label and no other text.A label is a routing decision, not permission to change an account or issue a refund. Keep downstream actions behind your application's normal authorization checks.
2. Prepare representative examples
Collect resolved tickets with labels verified by your support team. Remove secrets and customer identifiers before import. Preserve the actual problem: replacing every ticket with a generic sentence makes the task artificially easy.
Save UTF-8 JSON Lines, one conversation per line. These four example rows show the format for support-tickets.jsonl:
{"messages":[{"role":"system","content":"Classify the support ticket as billing, account, technical, or other. Reply with exactly one label and no other text."},{"role":"user","content":"My card was charged twice for the same monthly subscription."},{"role":"assistant","content":"billing"}],"category":"billing"}
{"messages":[{"role":"system","content":"Classify the support ticket as billing, account, technical, or other. Reply with exactly one label and no other text."},{"role":"user","content":"The password reset email never arrives, so I cannot sign in."},{"role":"assistant","content":"account"}],"category":"account"}
{"messages":[{"role":"system","content":"Classify the support ticket as billing, account, technical, or other. Reply with exactly one label and no other text."},{"role":"user","content":"The CSV export fails with an error whenever I select last month."},{"role":"assistant","content":"technical"}],"category":"technical"}
{"messages":[{"role":"system","content":"Classify the support ticket as billing, account, technical, or other. Reply with exactly one label and no other text."},{"role":"user","content":"Can someone help me with this?"},{"role":"assistant","content":"other"}],"category":"other"}Build a pilot dataset from, for example, 200 distinct tickets covering all labels, mixed issues, short messages, and unfamiliar wording. That is a planning target, not a minimum that guarantees quality. Four format examples alone are insufficient for a useful comparison.
Keep related conversations and paraphrases together when planning the split. Tensorant groups identical prompts, shared source documents, and shared images, but it cannot recognize every related ticket. Do not distribute near copies of one ticket across training and test. See evaluation data leakage.
3. Connect RunPod compute and storage
This guide trains in your own RunPod account, which comes with the Own compute subscription. To skip this step, use Tensorant compute instead: an owner adds credits under Plan and billing, and your data is kept in Tensorant's storage (see credits). Then choose Tensorant compute as the provider wherever the steps below mention RunPod.
To use your own RunPod account, an organization owner completes this once:
- Create a RunPod API key with read and write access.
- On the Home setup checklist, or in Connections (choose your name at the foot of the sidebar, then Settings), choose Connect RunPod, paste the key into RunPod API key, and choose Connect RunPod.
- Create a RunPod network volume in a datacenter with both the GPUs you need and S3 API support. Check RunPod's supported datacenters.
- Create a separate S3 API key. Choose Connect storage, pick your volume under Network volume, and enter the S3 access key and S3 secret key.
- Choose Connect storage.
Tensorant starts GPUs in your RunPod account and keeps project data on your network volume. See Connections for connection tests and billing visibility.
4. Create the project and import the dataset
- Open the project switcher at the top of the sidebar and choose New project.
- Choose Classification as the use case and enter
Support routeras the Project name. - Enter
Qwen/Qwen3-4B-Instruct-2507as the Hugging Face base model. - Set the Goal to consistent ticket routing using the four labels, then choose Create project.
- Open Sources, choose Add sources, and upload
support-tickets.jsonl. - Under Use these sources for, choose Training and validation, then Import files. Standard
messagesrecords are detected as conversations.
Read the import report. Skipped rows commonly mean invalid JSON, incorrect role order, or message fields other than role and content. Fix those rows before continuing. You do not need a generation endpoint or a recipe for already labeled examples. See Sources.
5. Review and create a version
Open Review and inspect each ticket and its label. Under More, set Answer type for quality checks to Classification label where appropriate. Correct disagreements, save changes with Save & recheck, and approve only examples you want the model to learn or be scored against.
Use Find similar questions to find word overlap, and inspect related tickets yourself. Imported examples do not have generated source quotes; they can still be approved.
Open Versions and choose Create version. The first version needs examples from at least 10 different documents (independent sources), and every version needs training, validation, and test examples. Roughly a tenth of documents go to validation and a tenth to test. To reserve a separate test file, import it for Test (held out) instead. See group splitting.
Read Readiness for training below the versions, with the default Training window (tokens) of 2,048. Fix overlong conversations before training, then create a new version if necessary. Aim for test examples from at least 10 documents so the comparison can show a likely range.
6. Configure and launch a controlled experiment
Open Experiments, choose New experiment, and select the Dataset version. Use these starting settings:
| Setting | Starting choice |
|---|---|
| Training objective | SFT, for the labeled conversations in this guide |
| Training method | LoRA |
| Training parameters | Keep the defaults: 2 epochs, rank 16, alpha 32, learning rate 0.0002 |
| Training window (tokens) | 2,048, if dataset readiness confirms it fits |
| Serving context (tokens) | 4,096, if every prompt plus answer fits |
| Answers are and Main metric | Classification and Classification accuracy |
| Longest answer (tokens) | 32 |
| Allowed labels | billing, account, technical, other, one per line |
Choose an available Training GPU and Serving GPU with memory headroom. Set price limits and time limits you are willing to approve. Readiness uses an estimate, so longer inputs or larger batches can still exhaust memory.
Set acceptance thresholds before seeing the result. For example, set Minimum tuned score (%) to 90, Minimum improvement (points) to 2, and Minimum test documents to 10. These are example product requirements; choose yours based on misrouting costs. Accept only a clear improvement requires the likely range to be above zero and needs at least 10 test documents.
Leave Continue automatically on unless you want to inspect each stage. Choose Check and review launch and resolve any failed readiness checks. In the approval, read "Up to $X at today's prices" and the ceiling at your price limits, then choose Approve and start. See Experiments.
7. Inspect the comparison before publishing
When complete, choose Compare answers. Read regressed answers and inspect accuracy by category. A high overall score can hide poor other handling or confusion between account and billing issues.
Review the confusion matrix in the evaluation results. If technical tickets containing the word “invoice” go to billing, collect new independent examples that teach the boundary. Record the failure under Record follow-up, add training examples, and create a new version. Do not turn individual test answers into memorization targets.
If the adapter does not clearly improve routing, keep the base model as your candidate and fix data or prompting first. See evaluating a fine-tuned LLM.
8. Publish the adapter and call it
Once the full run shows Adapter ready or Completed and its GPU is released, an owner can open Models and choose Publish a model, or choose Use this adapter and then Publish for API. Name it support-router, select the adapter under Model to serve, and choose the Wake on request card for occasional traffic or Always on for steady traffic. Choose Review to check the GPU and cost settings before publishing.
On API keys, create a server-side key and store it as TENSORANT_API_KEY in your secrets manager. Call Tensorant's API at https://api.tensorant.io/v1:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.tensorant.io/v1",
api_key=os.environ["TENSORANT_API_KEY"],
)
answer = client.chat.completions.create(
model="support-router",
temperature=0,
max_tokens=32,
messages=[
{"role": "system", "content": "Classify the support ticket as billing, account, technical, or other. Reply with exactly one label and no other text."},
{"role": "user", "content": "My export stops at 90% and reports a timeout."},
],
)
choice = answer.choices[0]
label = (choice.message.content or "").strip().lower()
if choice.finish_reason != "stop" or label not in {"billing", "account", "technical", "other"}:
label = "other"
print(label)Install the client with pip install openai. Send the other fallback queue to human review, including incomplete or invalid responses. A wake-on-request model may return 503 model_starting during a cold start; follow Retry-After with a bounded retry policy. Use API quickstart for key creation and adapter deployment for serving checks. Validate labels in your application and monitor reviewed routing mistakes as traffic changes.