Skip to main content
Qwen model tuning

Introduction to model fine-tuning

You can use model fine-tuning in Alibaba Cloud Model Studio if a model's performance does not meet your expectations after you have tried optimization methods such as prompt engineering and plugin calls. As a core strategy for improving model performance, model fine-tuning can significantly enhance a model's capabilities in specific industries or business scenarios, align its outputs with human preferences, and reduce output latency. Model fine-tuning includes three training methods: supervised fine-tuning (SFT), continual pre-training (CPT), and direct preference optimization (DPO).

Introduction to model fine-tuning

Model fine-tuning is an important method for optimizing model performance. It can:
  • Improve model performance in specific industries or for specific business needs
  • Reduce model output latency
  • Suppress model hallucination
  • Align the model with human values or preferences
  • Replace larger models with fine-tuned lightweight models
During the fine-tuning process, the model learns business-specific or scenario-specific features from the training data, such as knowledge, tone, expression styles, and self-awareness. Because the model has already learned many examples for specific industries or scenarios during training, its one-shot or zero-shot prompt performance after training is better than its few-shot performance before training. This saves input tokens and reduces model output latency.

Model fine-tuning process

image
For more information, see:

Supported models

  • Singapore
  • North China 2 (Beijing)
  • Text generation
  • Visual understanding (Qwen-VL)

Model name

Model code

SFT full-parameter training (sft)

SFT efficient training (efficient_sft)

Qwen3-14B

qwen3-14b

×

Supported

Comparison of tuning methods

Feature

CPT (Continual Pre-training)

SFT (Supervised Fine-tuning)

DPO (Direct Preference Optimization)

Summary

Supplements knowledge (Injects domain knowledge)

Learns to perform tasks (Follows instructions)

Performs tasks better (Aligns with human preferences)

Input data

10 million+ tokens

Unlabeled domain text

Over 1,000 entries

High-quality "question-answer" pairs

100+ sets

"Better-worse" response pairs for the same instruction

Core objective

Domain adaptation. Learns specialized vocabulary and facts.

Teaches the model conversation formats and task execution capabilities.

Makes model outputs better align with human values and preferences.

Learning method

Self-supervised learning (Predicts the next word)

Supervised learning (Imitates the ground truth)

Direct preference learning (Increases the probability of good responses and decreases the probability of bad responses)

Model stage

Typically before SFT

After CPT and before DPO

Typically after SFT, as the final step for alignment.

Comparison of training patterns

Full-parameter training

Efficient training (LoRA, recommended)

Scenarios

• The model needs to acquire new capabilities

• Achieving optimal global performance.

• Optimizing model performance for specific scenarios.

• For cost-sensitive and time-sensitive scenarios.

Training time

Longer, with slower convergence.

Shorter, with faster convergence.

Billing

Billing methodPay-as-you-go based on the amount of training data
Billing formulaModel training fee = (Total tokens in training data + Total tokens in mixed training data) × Number of epochs × Training unit price (Minimum billing unit: 1 token)
You can view the estimated training fee at the bottom of the Model Fine-tuning console and click Billing Details to view the total number of training tokens, number of epochs, and training unit price.

Training unit price

The following table lists the training unit prices for pre-built models. The training unit price for a custom model is the same as that for the corresponding pre-built model.
  • Singapore
  • North China 2 (Beijing)
  • Qwen
  • Qwen-VL

Model service

Model code

Price

Qwen3-14B

qwen3-14b

$0.0016/1,000 tokens

Before you fine-tune a model

  • Although text generation model fine-tuning can achieve excellent results in specific business scenarios, it has the following limitations:
    • Time-consuming: This includes creating a large-scale CPT dataset (at least 50 million tokens), building an effective SFT dataset (1,000+ entries), collecting enough bad cases (100+) to build an effective DPO dataset, and the slow speed of model optimization iterations.
    • High cost: A fine-tuned model can only be used after deployment, and the model deployment billing is high.
  • Alibaba Cloud Model Studio recommends that you first try using Prompt Engineering or Function Calling to customize your application. Model fine-tuning is usually the "last resort" for improving model performance. This is because:
    1. In many tasks, a model may initially perform poorly, but applying the correct prompt techniques can improve the results without requiring model fine-tuning.
    2. Iteratively optimizing prompts and plugins is more agile and cost-effective than model fine-tuning iterations, because fine-tuning may require re-collecting, cleaning, and optimizing data, collecting bad cases, and conducting customer surveys.
    3. Even if you ultimately decide to perform model fine-tuning, the initial work on prompt engineering and plugin optimization will not be wasted. This preliminary work can be fully reused when building the fine-tuning dataset.

Getting started

Fine-tune a model using the console

Fine-tuning steps

Console screenshot

Step 1: On the Model Fine-tuning page, click Create Training Task.

On the Create Training Task page, complete the following configurations:

  1. Set the training type to SFT Fine-tuning Training.

  2. Select Qwen3-8B as the model.

  3. Set the training method to Efficient Training.

  4. In the hyperparameter configuration, set batch_size to 16 (range: [8, 1024], step: 8).

  5. In the Training Task Summary panel on the right, confirm the billing method is token-based billing and that 10% of the training set is automatically split as the validation set, then click Start Training.

Step 2: Configure training

  • Training Method: Supervised Fine-tuning (SFT)

  • Select Model: Qwen3-8B

  • Training Method: Efficient Training

  • Configure Parameters: You can keep the default settings because Model Studio provides recommended configurations for fine-tuning hyperparameters.

This combination has a short training time and low data requirements.

Step 3: Configure data

  • Training Set: Select the uploaded fine-tuning dataset to build the model.

    Data sample: SFT-ChatML_format_example.jsonl.

  • Mixed Training: Disabled

  • Validation Set: When set to Automatic Splitting, 10% of the data is used as the validation set.

Step 4: Configure model parameter snapshot (checkpoint) saving parameters

  • For Model Name, keep the default name.

  • Maximum Export Count: Retain the default value.

  • Checkpoint save interval: Keep the default value.

After model fine-tuning is complete, you can export a parameter snapshot on the Model Studio platform. You can then deploy the model on Model Studio based on this parameter snapshot.

The exported parameter snapshots are saved in cloud storage and cannot be accessed or downloaded.

Step 5: Click "Start Training" and wait for the model training to complete.

Step 6: Use the Deployments feature of Alibaba Cloud Model Studio to deploy the trained custom model. After deployment, you can evaluate the fine-tuned model. For more information, see Model deployment.

Typical fine-tuning process

The three fine-tuning methods provided by Model Studio are not mutually exclusive but are progressive and complementary. CPT (optional) → SFT → DPO (optional)
  1. CPT (continual pre-training) - Supplements knowledge (General models have broad but shallow knowledge, which may not meet the depth and precision requirements of professional fields)
    • Finance model: Learns financial terms
    • Medical model: Memorizes drug pathology
    • Legal model: Understands legal articles and precedents
  2. SFT (supervised fine-tuning) - Learns how to perform tasks
    • Customer service bot: Learns customer service procedures
    • Code assistant: Learns programming paradigms
    • Tool calling (Agent): Learns to use MCP
  3. DPO (direct preference optimization) - Performs tasks better
    • Safety and responsibility: Rejects harmful suggestions
    • Conciseness and effectiveness: Provides concise answers
    • Objectivity and neutrality: Evaluates fairly and objectively

Fine-tuning data format

  • SFT training set
SFT ChatML (Chat Markup Language) format training data supports multi-turn conversations and various role settings.
The OpenAI name and weight parameters are not supported. All assistant outputs will be trained.
# A single line of training data (in JSON format) has the following typical structure when expanded:
{"messages": [
  {"role": "system", "content": "System input 1"},
  {"role": "user", "content": "User input 1"},
  {"role": "assistant", "content": "Expected model output 1"},
  {"role": "user", "content": "User input 2"},
  {"role": "assistant", "content": "Expected model output 2"}
  ...
]}
For information about the differences between system, user, and assistant, see Overview. Sample training datasets: SFT-ChatML_format_example.jsonl, SFT-ChatML_format_example.xlsx. XLS and XLSX formats support only single-turn conversations.All assistant lines in a single training data entry support the "loss_weight" parameter, which sets the relative importance of that line during training. (Range: 0.0 to 1.0. A larger value indicates higher importance.)
This parameter is available for invitational preview. To use it, contact your account manager.
 {"role": "assistant", "content": "Expected model output 1", "loss_weight": 1.0},
 {"role": "assistant", "content": "Expected model output 2", "loss_weight": 0.5}

Dataset building tips

Dataset size requirements

For CPT, the dataset requires at least 50 million tokens of high-quality pre-training data. For SFT, the dataset requires at least 1,000 high-quality fine-tuning data entries. For DPO, the dataset generally requires hundreds of human preference data entries. If the model evaluation results after data fine-tuning are not satisfactory, the simplest way to improve is to collect more data for training. If you lack data, we recommend building an agent application and using a knowledge base index to enhance the model's capabilities. In many complex business scenarios, you can also use a combination of model fine-tuning and knowledge base retrieval. For example, in a customer service scenario, you can use model fine-tuning to address issues with the customer service agent's tone, expression styles, and self-awareness. Professional knowledge related to the scenario can be dynamically introduced into the model's context using a knowledge base. Alibaba Cloud Model Studio recommends that you first build and test a retrieval-augmented generation (RAG) application. After collecting enough application data, you can then use model fine-tuning to further improve the model's performance. You can also use the following strategies to expand your dataset:
  1. Use a large language model (LLM) to simulate the generation of content for specific business scenarios to help you generate more data for fine-tuning. (We recommend selecting a larger, high-performing model for generation.)
  2. Acquire more data through various methods, such as collecting from application scenarios, web scraping, social media and online forums, public datasets, partners and industry resources, and user contributions.

Data diversity and balance

The requirements for model fine-tuning vary by scenario. For example, professionalism is critical for specific business scenarios, whereas versatility is more important for Q&A scenarios. You need to design data use cases based on the business modules or usage scenarios the model is responsible for. Therefore, the training effectiveness depends not only on the data volume but also on the professionalism and diversity of the data for the specific scenario. For example, in an intelligent AI conversation scenario, a professional and diverse dataset should include the following business scenarios:

Specific business

Diverse scenarios/businesses

E-commerce customer service

Promotion pushes, pre-sales consultation, in-sales guidance, after-sales service, after-sales follow-up, complaint handling, etc.

Financial services

Loan consultation, investment and wealth management advice, credit card services, bank account management, etc.

Online healthcare

Symptom consultation, appointment registration, visit instructions, drug information inquiry, health tips, etc.

AI secretary

IT information, administrative information, HR information, employee benefit inquiries, company calendar queries, etc.

Travel assistant

Travel planning, entry and exit guides, travel insurance consultation, destination customs and culture introductions, etc.

Corporate legal counsel

Contract review, intellectual property protection, compliance checks, labor law Q&A, cross-border transaction consultation, individual case legal analysis, etc.

It is also important to note that the amount of data for each scenario/business should be relatively balanced, and the data proportion should match the actual scenario proportion. This avoids having too much data of one type, which could cause the model to be biased towards learning those features and affect its generalization ability.

Splitting the training and validation sets

You can perform model fine-tuning in the console.
  • Automatically split a complete training dataset and randomly sample a small amount of data to form a validation set.
  • Choose to upload a separate dataset.
The console displays the validation set loss and token accuracy in real time during training. The Data Configuration page also includes a Mixed Training toggle (disabled by default). When Auto Split is selected, 10% of the training set is randomly split as the validation set by default.

FAQ

Can I fine-tune my own model?

Model Studio does not support fine-tuning, uploading your own models, or exporting downloaded models.
Token Plan
Model Playground
  • Music generation
Statistics and Monitoring
Support