Fine-tune Qwen in Alibaba Cloud Model Studio using an HTTP API.
This topic is applicable only to the International Edition (Singapore region).
Prerequisites
You understand fine-tuning concepts, procedures, and data format requirements.
You have activated Model Studio and got an API key. See Create an API key.
Fine-tuning overview
Fine-tuning improves model performance:
Improve performance for specific industries or businesses
Reduce output latency
Suppress hallucinations
Align outputs with human values or preferences
Replace larger models with fine-tuned lightweight models
During fine-tuning, the model learns business- and scenario-specific features from your training data, such as domain knowledge, tone, communication style, and self-awareness. Because the model has already learned many industry- or scenario-specific examples during pre-training, its zero-shot or one-shot performance after fine-tuning surpasses the base model’s few-shot performance. This reduces input tokens and lowers output latency.
Overall procedure
Supported models
Text generation
Name | Model code | Full-parameter SFT (sft) | Efficient SFT (efficient_sft) |
Qwen3-32B | qwen3-32b | ||
Qwen3-14B | qwen3-14b | ||
Qwen3-VL-8B-Instruct | qwen3-vl-8b-instruct | ||
Qwen3-VL-8B-Thinking | qwen3-vl-8b-thinking |
Compare training modes
Full-parameter training | Efficient training (LoRA, recommended) | |
Scenarios | • Learn new capabilities. • Achieve optimal overall performance. | • Optimize performance in specific scenarios. • Time- and cost-sensitive. |
Training duration | Longer, with slower convergence. | Shorter, with faster convergence. |
Billing
Method | Billed by the volume of training data. |
Formula | Model training fee = (Total tokens in training data + Total tokens in mixed training data) × Number of epochs × Training unit price (Minimum billing unit: 1 token) |
Dataset tips
Size requirements
SFT datasets require at least 1,000 high-quality entries. If evaluation results are unsatisfactory, collect more training data.
If you do not have enough data, consider building an agent application with a knowledge base. In many complex business scenarios, fine-tuning and knowledge base retrieval work best together.
For example, in a customer service scenario, fine-tune the model to adjust its tone, expression habits, and self-awareness, then use a knowledge base to dynamically inject domain knowledge into the context.
Try retrieval-augmented generation (RAG) first. After collecting enough data, use fine-tuning to further improve performance.
You can expand your dataset using the following strategies:
Use a larger, high-performing model to generate content for specific businesses or scenarios.
Manually collect data from various sources, such as application scenarios, web scraping, social media, forums, public datasets, partners, industry resources, and user contributions.
Data diversity and balance
For domain-specific use cases, domain expertise is the most important factor. For Q&A scenarios, generalization matters more. Design data samples based on your business modules or scenarios. Training quality depends on data volume, domain specificity, and diversity.
For example, in an AI assistant scenario, a professional and diverse dataset should include the following:
Business | Diverse scenarios and use cases |
E-commerce customer service | Promotion pushes, pre-sales consultation, in-sales guidance, after-sales service, follow-up visits, complaint handling, and more. |
Financial services | Loan consultation, investment and financial advice, credit card services, bank account management, and more. |
Online healthcare | Symptom consultation, appointment scheduling, visit instructions, drug information queries, health tips, and more. |
AI secretary | IT information, administrative information, HR information, employee benefit Q&A, company calendar queries, and more. |
Travel assistant | Travel planning, entry and exit guides, travel insurance consultation, destination customs and culture introductions, and more. |
Corporate legal counsel | Contract review, intellectual property protection, compliance checks, labor law Q&A, cross-border transaction consultation, case-specific legal analysis, and more. |
Balance the data volume across scenarios to match actual usage ratios. This prevents bias toward any single feature type and improves generalization.
Upload a training dataset
Prepare a dataset
SFT training set
SFT uses training data in Chat Markup Language (ChatML) format, which supports multi-turn conversations and multiple role settings.
The OpenAInameandweightparameters are not supported. All assistant outputs are trained.
# A line of training data (JSON format), the typical structure is as follows 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 details about the system, user, and assistant roles, see Overview of text generation models. Sample training sets: SFT-ChatML_format_example.jsonl and SFT-ChatML_format_example.xlsx. XLS and XLSX formats support only single-turn conversations.
For a single training entry, all assistant rows support the "loss_weight" parameter, which sets the relative importance during training. The valid values range from 0.0 to 1.0. Higher values indicate greater importance.
This parameter is in invitational preview. To use it, you can 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}SFT for thinking model
The training data supports multi-turn conversations and multiple role settings, but only the final assistant output is trained.
The \n characters before and after the think tags must be retained.# A line of training data (JSON format), the typical structure is as follows when expanded:
{"messages": [
{"role": "system", "content": "System input 1"},
{"role": "user", "content": "User input 1"},
{"role": "assistant", "content": "Model output 1"}, --Intermediate assistant outputs should not have <think> tags
...
{"role": "user", "content": "User input 2"},
{"role": "assistant", "content": "<think>\nExpected thinking content 2\n</think>\n\nExpected output 2"} --Thinking content can only be included in the final assistant output.
]}For details about the system, user, and assistant roles, see Overview of text generation models. Sample training set: SFT-deep_thinking_content_example.jsonl.
You can configure the model to omit the <think> tag in training samples. If you use this output method, do not enable the thinking mode for calls after the model is trained.
{"role": "assistant", "content": "Expected model output 2"} --Tells the model not to enable thinkingThe final assistant row of a single training entry supports the "loss_weight" parameter, which sets the relative importance during training. The valid values range from 0.0 to 1.0. Higher values indicate greater importance.
This parameter is in invitational preview. To use it, you can contact your account manager.
{"role": "assistant", "content": "<think>\nExpected thinking content 2\n</think>\n\nExpected output 2", "loss_weight": 1.0}SFT for image understanding (Qwen-VL)
The OpenAInameandweightparameters are not supported. All assistant outputs are trained.
For more information about the differences between the system, user, and assistant roles, see Overview of text generation models. Sample training data in ChatML format:
# A line of training data (JSON format), the typical structure is as follows when expanded:
{"messages":[
{"role":"user",
"content":[
{"text":"User input 1"},
{"image":"Image file name 1"}]},
{"role":"assistant",
"content":[
{"text":"Expected model output 1"}]},
{"role":"user",
"content":[
{"text":"User input 2"}]},
{"role":"assistant",
"content":[
{"text":"Expected model output 2"}]},
...
...
...
]}If you train a thinking model, you must follow the data format requirements for SFT for thinking model.
The following are the requirements for ZIP files:
Format: ZIP. Maximum size: 2 GB. The folder and file names within the ZIP file must contain only ASCII letters (a–z, A–Z), numbers (0–9), underscores (_), and hyphens (-).
The training text data file must be named
data.jsonland placed in the root directory of the ZIP file. Ensure that the data.jsonl file appears immediately when you open the ZIP file.A single image cannot exceed 1024 pixels in width or height. The maximum size is 10 MB. Supported formats:
.bmp,.jpeg /.jpg,.png,.tif /.tiff, and.webp.Image file names cannot be duplicated, even if the files are stored in different folders.
ZIP file directory structure:
Single-level directory (recommended)
The image files and the
data.jsonlfile reside in the root directory of the ZIP file.Trainingdata_vl.zip |--- data.jsonl # Note: Do not wrap in an outer folder |--- image1.png |--- image2.jpgMulti-level directory
The data.jsonl file must be in the root directory of the ZIP file.
In the data.jsonl file, you can declare only the image file name, not the file path. For example:
Correct:
image1.jpg. Incorrect:jpg_folder/image1.jpg.Image file names must be globally unique within the ZIP file.
Trainingdata_vl.zip |--- data.jsonl # Note: Do not wrap in an outer folder |--- jpg_folder | └── image1.jpg |--- png_folder └── image2.png
Upload the training file
HTTP
For Windows CMD, you can replace${DASHSCOPE_API_KEY}with%DASHSCOPE_API_KEY%. For PowerShell, you can replace it with$env:DASHSCOPE_API_KEY
curl -X POST https://dashscope-intl.aliyuncs.com/compatible-mode/v1/files \
-H "Authorization: Bearer $DASHSCOPE_API_KEY" \
--form 'file=@"path/to/your/sample.jsonl"' \
--form 'purpose="fine-tune"'Limits:
The maximum file size is 1 GB.
The total storage quota for all active (not deleted) files is 5 GB.
The maximum number of active (not deleted) files is 100.
There is no time limit for file storage.
Response:
{
"id": "file-ft-e73cafa11cef43a0ab75fb8e",
"object": "file",
"bytes": 23149,
"filename": "qwen-fine-tune-sample.jsonl",
"purpose": "fine-tune",
"status": "processed",
"created_at": 1769138847
}Fine-tuning
Create a fine-tuning job
HTTP
For Windows CMD, you can replace${DASHSCOPE_API_KEY}with%DASHSCOPE_API_KEY%. For PowerShell, you can replace it with$env:DASHSCOPE_API_KEY
curl --location "https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes" \
--header "Authorization: Bearer ${DASHSCOPE_API_KEY}" \
--header 'Content-Type: application/json' \
--data '{
"model":"qwen3-14b",
"training_file_ids":[
"<Replace with the file ID of training dataset 1>",
"<Replace with the file ID of training dataset 2>"
],
"hyper_parameters":
{
"n_epochs": 1,
"batch_size": 16,
"learning_rate": "1.6e-5",
"split": 0.9,
"warmup_ratio": 0.0,
"eval_steps": 1,
"save_strategy": "epoch",
"save_total_limit": 10
},
"training_type":"sft"
}'Input parameters
Field | Required | Type | Location | Description |
training_file_ids | Yes | Array | Body | Training set file IDs. |
validation_file_ids | No | Array | Body | Validation set file IDs. |
model | Yes | String | Body | Base model ID, or the ID of a model generated by a previous fine-tuning job. |
hyper_parameters | No | Map | Body | Hyperparameters for fine-tuning. Default values are used if omitted. |
training_type | No | String | Body | Fine-tuning method. Valid values:
|
job_name | No | String | Body | Job name. |
model_name | No | String | Body | Name of the fine-tuned model. The model ID is generated by the system. |
Sample response
{
"request_id": "635f7047-003e-4be3-b1db-6f98e239f57b",
"output":
{
"job_id": "ft-202511272033-8ae7",
"job_name": "ft-202511272033-8ae7",
"status": "PENDING",
"finetuned_output": "qwen3-14b-ft-202511272033-8ae7",
"model": "qwen3-14b",
"base_model": "qwen3-14b",
"training_file_ids":
[
"9e9ffdfa-c3bf-436e-9613-6f053c66aa6e"
],
"validation_file_ids":
[],
"hyper_parameters":
{
"n_epochs": 1,
"batch_size": 16,
"learning_rate": "1.6e-5",
"split": 0.9,
"warmup_ratio": 0.0,
"eval_steps": 1,
"save_strategy": "epoch",
"save_total_limit": 10
},
"training_type": "sft",
"create_time": "2025-11-27 20:33:15",
"workspace_id": "llm-8v53etv3hwb8orx1",
"user_identity": "1654290265984853",
"modifier": "1654290265984853",
"creator": "1654290265984853",
"group": "llm",
"max_output_cnt": 10
}
}hyper_parameters supported settings
Query job details
Use the returned job_id to query the job status.
HTTP
curl 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<job_id>' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json'Input parameters
Field | Type | Location | Required | Description |
job_id | String | Path Parameter | Yes | Job ID. |
Sample successful response
{
"request_id": "d100cddb-ac85-4c82-bd5c-9b5421c5e94d",
"output":
{
"job_id": "ft-202511272033-8ae7",
"job_name": "ft-202511272033-8ae7",
"status": "RUNNING",
"finetuned_output": "qwen3-14b-ft-202511272033-8ae7",
"model": "qwen3-14b",
"base_model": "qwen3-14b",
"training_file_ids":
[
"9e9ffdfa-c3bf-436e-9613-6f053c66aa6e"
],
"validation_file_ids":
[],
"hyper_parameters":
{
"n_epochs": 1,
"batch_size": 16,
"learning_rate": "1.6e-5",
"split": 0.9,
"warmup_ratio": 0.0,
"eval_steps": 1,
"save_strategy": "epoch",
"save_total_limit": 10
},
"training_type": "sft",
"create_time": "2025-11-27 20:33:15",
"workspace_id": "llm-8v53etv3hwb8orx1",
"user_identity": "1654290265984853",
"modifier": "1654290265984853",
"creator": "1654290265984853",
"group": "llm",
"max_output_cnt": 10
}
}Job status | Meaning |
PENDING | Training is about to begin. |
QUEUING | Job is queued. Only one job can run at a time. |
RUNNING | Job is running. |
CANCELING | Job is being canceled. |
SUCCEEDED | Job succeeded. |
FAILED | Job failed. |
CANCELED | Job was canceled. |
After training succeeds, finetuned_output contains the ID of the fine-tuned model, which you can use for model deployment.
Get job logs
HTTP
curl 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<job_id>/logs?offset=0&line=1000' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json' Use the offset and line parameters to retrieve a specific range of logs. The offset parameter specifies the starting position and line specifies the maximum number of log entries.
Sample response:
{
"request_id":"1100d073-4673-47df-aed8-c35b3108e968",
"output":{
"total":57,
"logs":[
"{Log output 1}",
"{Log output 2}",
...
...
...
]
}
}Query and publish checkpoints
Only SFT fine-tuning (efficient_sftandsft) supports saving and publishing checkpoints of intermediate states.
Query checkpoints
curl 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<job_id>/checkpoints' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json'Input parameters
Field | Type | Location | Required | Description |
job_id | String | Path Parameter | Yes | Job ID. |
Sample successful response
{
"request_id": "c11939b5-efa6-4639-97ae-ed4597984647",
"output": [
{
"create_time": "2025-11-11T16:25:42",
"full_name": "ft-202511272033-8ae7-checkpoint-20",
"job_id": "ft-202511272033-8ae7",
"checkpoint": "checkpoint-20",
"model_name": "qwen3-14b-instruct-ft-202511272033-8ae7",
"status": "SUCCEEDED"
}
]
}Snapshot publishing status | Description |
PENDING | The checkpoint is pending export. |
PROCESSING | The checkpoint is being exported. |
SUCCEEDED | The checkpoint was exported. |
FAILED | The checkpoint failed to export. |
The checkpoint parameter refers to the checkpoint ID, which is used to specify the checkpoint to export in the model publishing API. The model_name parameter refers to the model ID, which can be used for model deployment. The finetuned_output parameter returns the model_name of the last checkpoint.
Publish a model
You can export a checkpoint after fine-tuning is complete. Export the checkpoint before deploying the model in Model Studio.
Exported checkpoints are stored in cloud storage and cannot be accessed or downloaded.
curl --request GET 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<job_id>/export/<checkpoint_id>?model_name=<model_name>' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json'Input parameters
Field | Type | Location | Required | Description |
job_id | String | Path Parameter | Yes | Job ID. |
checkpoint_id | String | Path Parameter | Yes | Checkpoint ID. |
model_name | String | Path Parameter | Yes | Expected model ID after export. |
Sample successful response
{
"request_id": "ed3faa41-6be3-4271-9b83-941b23680537",
"output": true
}Export is asynchronous. Monitor the export status by querying the checkpoint list.
Additional operations
List jobs
curl 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json' Cancel a job
Terminate a running fine-tuning job.
curl --request POST 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<job_id>/cancel' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json' Delete a job
Running jobs cannot be deleted.
curl --request DELETE 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<job_id>' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json' Model deployment
Fine-tuned models support only Model Unit deployment.
Go to the Model Deployment console (Singapore) to deploy a model. For more information about billing and other details, see Billing by usage duration (Model Unit).
Call the model
After deploying a model, call it using OpenAI compatible APIs, Dashscope, or the Assistant SDK.
Set the model parameter to the model’s code. Go to the Model Deployment console (Singapore) to view the Model Code.
curl 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--header 'Content-Type: application/json' \
--data '{
"model": "<Replace with the model instance Code after successful deployment>",
"input":{
"messages":[
{
"role": "user",
"content": "Who are you?"
}
]
},
"parameters": {
"result_format": "message"
}
}'FAQ
Can I upload and deploy my own models?
Uploading and deploying your own models is not currently supported. Follow the latest updates from Alibaba Cloud Model Studio.
However, Platform for AI (PAI) supports the deployment of your own models. See Deploy large language models in PAI-LLM.