Fine-tune with the API or CLI

Updated at:

Learn how to tune Qwen models in Alibaba Cloud Model Studio using the API (HTTP) and the command line (shell). Model tuning involves three methods: supervised fine-tuning (SFT), continual pre-training (CPT), and direct preference optimization (DPO).

Prerequisites

NoteTraining jobs created via the API support only token-based billing. Model training units (prepaid or postpaid) are not supported. To use training units, create the job in the console.

Tuning file upload

Preparing fine-tuning files

For the data format specifications, packaging rules, size and quantity limits, and API upload quotas of each training method (SFT/DPO/CPT), see Tuning data upload rules. Overview of the file formats supported by each training method:

Training method

File format

SFT text generation

jsonl (ChatML messages multi-turn structure)

SFT multimodal (image/video)

zip (data.jsonl + image/video files)

DPO

jsonl (chosen/rejected preference pairs)

CPT

jsonl (plain text {text})

Evaluation set

xlsx (prompt&completion) / jsonl, xls, xlsx (ChatML-messages)

You can also go to the Model Studio console to download data templates.

On the Create dataset page, below the file upload area, you can find the data template download link.

Upload fine-tuning files to Model Studio

DashScope API

For Windows CMD, replace ${DASHSCOPE_API_KEY} with %DASHSCOPE_API_KEY%. For PowerShell, replace it with $env:DASHSCOPE_API_KEY.

curl --request POST \
'https://dashscope.aliyuncs.com/api/v1/files' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY} \
--form 'files=@"/path/to/your/file.jsonl"' \
--form 'purpose="fine-tune"' \
--form 'descriptions="a sample fine-tune data file for qwen"'

NoteLimitations:

  • The maximum size of a single file is 300 MB.
  • The total storage quota of all active (non-deleted) files is 100 GB.
  • The total count quota of all active (non-deleted) files is 10,000.
  • File storage has no time limit.

Tuning files uploaded via the API are visible and usable both on the model tuning page of the Model Studio console and in API calls.

For more details, see Upload files.

Sample response:

{
  "request_id":"xx",
  "data":{
    "uploaded_files":[{
      "file_id":"976bd01a-f30b-4414-86fd-50c54486e3ef",
      "name":"qwen-fine-tune-sample.jsonl"}],
   "failed_uploads":[]}
 }

Model fine-tuning

Creating, querying, logging, snapshot management, and list/abort/delete operations for tuning jobs are all performed via API. Each interface's complete request/response parameters and examples are on the corresponding API page; this section only outlines the workflow.

Create a tuning job

Call the Create a tuning job interface (POST /api/v1/fine-tunes) to start training. For the request body (model / training_datasets / hyper_parameters / training_type, etc.) and response examples, see that API page.

List of supported base model IDs (model) and training types (training_type):

Supported models

Text generation

NoteTo deploy Qwen3.7-Plus-2026-05-26 after fine-tuning, contact your account manager.

Model service

Model code

CPT full-parameter training

SFT full-parameter training

SFT efficient training

DPO full-parameter training

DPO efficient training

Qwen3.8-27B

qwen3.8-27b

×

✓

✓

×

×

Qwen3.7-Plus-2026-05-26

qwen3.7-plus-2026-05-26

×

✓

×

×

×

Qwen3.6-27B

qwen3.6-27b

×

✓

✓

×

×

Qwen3.6-Flash-2026-04-16

qwen3.6-flash-2026-04-16

×

✓

×

×

×

Qwen3.6-Plus-2026-04-02

qwen3.6-plus-2026-04-02

✓

✓

×

×

×

Qwen3.5-27B

qwen3.5-27b

×

✓

✓

×

×

Qwen3.5-9B

qwen3.5-9b

×

✓

✓

×

×

Qwen3.5-4B

qwen3.5-4b

×

✓

✓

×

×

Qwen3.5-Flash-2026-02-23

qwen3.5-flash-2026-02-23

×

✓

×

×

×

Qwen3.5-Plus-2026-02-15

qwen3.5-plus-2026-02-15

×

✓

×

×

×

Qwen3-32B

qwen3-32b

✓

✓

✓

✓

✓

Qwen3-30B-A3B-Instruct-2507

qwen3-30b-a3b-instruct-2507

✓

✓

✓

×

×

Qwen3-14B

qwen3-14b

×

✓

✓

✓

✓

Qwen3-8B

qwen3-8b

×

✓

✓

✓

✓

Qwen3-4B-Instruct-2507

qwen3-4b-instruct-2507

✓

✓

✓

✓

✓

Qwen3-1.7B

qwen3-1.7b

✓

✓

✓

✓

✓

Qwen3-0.6B

qwen3-0.6b

✓

✓

✓

✓

✓

Qwen2.5-72B-Instruct

qwen2.5-72b-instruct

✓

✓

✓

✓

✓

Qwen2.5-32B-Instruct

qwen2.5-32b-instruct

✓

✓

✓

✓

✓

Qwen2.5-14B-Instruct

qwen2.5-14b-instruct

✓

✓

✓

✓

✓

Qwen2.5-7B-Instruct

qwen2.5-7b-instruct

✓

✓

✓

✓

✓

Qwen-Plus-Character-2025-11-06

qwen-plus-character-2025-11-06

×

✓

✓

✓

✓

NoteDecision models (decision-model-preview-2026-09-24) do not participate in the regular CPT/SFT/DPO training above, but support a dedicated fine-tuning process. For the fine-tuning method, see Decision model fine-tuning best practices.

Visual understanding (Qwen-VL)

Model service

Model code

CPT full-parameter training

SFT full-parameter training

SFT efficient training

DPO full-parameter training

DPO efficient training

Qwen3-VL-8B-Instruct

qwen3-vl-8b-instruct

×

✓

✓

×

×

Qwen3-VL-8B-Thinking

qwen3-vl-8b-thinking

×

✓

✓

×

×

Qwen3-VL-4B-Instruct

qwen3-vl-4b-instruct

×

✓

✓

×

×

Qwen2.5-VL-72B-Instruct

qwen2.5-vl-72b-instruct

×

✓

✓

×

×

Qwen2.5-VL-32B-Instruct

qwen2.5-vl-32b-instruct

×

✓

✓

×

×

Qwen2.5-VL-7B-Instruct

qwen2.5-vl-7b-instruct

×

✓

✓

×

×

Tuning method comparison

Feature

CPT (continual pre-training)

SFT (supervised fine-tuning)

DPO (direct preference optimization)

One-sentence summary

Add knowledge(inject domain knowledge)

Learn to perform tasks(learn to follow instructions)

Do better(align with human preferences)

Input data

10M+ tokens

Unlabeled domain text

1,000+ entries

High-quality "question-answer" pairs

100+ groups

"Better-worse" answer pairs under the same instruction

Core objective

Domain adaptation, learning professional vocabulary and facts

Teach the model conversation format and task execution capabilities

Make model outputs better align with human values and preferences

Learning method

Self-supervised learning (predicting the next token)

Supervised learning(imitating standard answers)

Direct preference learning(increasing the probability of good answers and decreasing the probability of bad answers)

Model stage

Usually before SFT

After CPT, before DPO

Usually after SFT, as the final alignment step

Training mode comparison

Full-parameter training

Efficient training (LoRA, recommended)

Applicable scenarios

• The model needs to learn new capabilities

• Pursuing globally optimal performance

• Optimizing model performance in specific scenarios

• Scenarios sensitive to training time and cost

Training time

Longer, with a slower convergence speed.

Shorter, with a fast convergence speed.

Retrieve tuning job details

Use the job_id to query the task status. For details, see Query tuning task status.

Get tuning job logs

Training logs are retrieved via the Query tuning task logs interface (GET /api/v1/fine-tunes/{job_id}/logs).

Query and publish model parameter snapshots

Checkpoints produced by tuning can be listed and exported (published):

  • List snapshots: see List Checkpoint (GET /api/v1/fine-tunes/{job_id}/checkpoints).
  • Export (publish) a specific snapshot: see Export Checkpoint (GET /api/v1/fine-tunes/{job_id}/export/{checkpoint}?model_name=...), executed asynchronously; poll the status via the list interface.

More tuning operations

API reference

The DashScope command-line invocation reference is included in this topic. For detailed API calls, see API details.

Model deployment and invocation

Model deployment

For more information about model deployment methods, see Deploy a model with the API.

curl "https://dashscope.aliyuncs.com/api/v1/deployments" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "model_name": "qwen3-8b-ft-202511132025-0260",
    "plan": "lora",
    "capacity": 1,
    "name": "qwen3-8b-ft"
}'
curl "https://dashscope.aliyuncs.com/api/v1/deployments" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "name": "my_qwen_plus",
    "model_name": "qwen-plus-2025-12-01",
    "plan": "mu",
    "deploy_spec": "MU1",
    "enable_thinking": true,
    "capacity": 4,
    "max_context_length": 10000,
    "rpm_limit": 500,
    "tpm_limit": 1000
}'

Query deployment status

When the deployment status is RUNNING, the model is currently available for invocation.

curl 'https://dashscope.aliyuncs.com/api/v1/deployments/<your_model_instance_id>' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY}  \
--header 'Content-Type: application/json'

For other deployment operations such as scaling and deprovisioning, see Model Deployment - API Details.

Model invocation

Once the model deployment status is RUNNING, you can use the fine-tuned model just like any other model.

You can also get the model code from the Dedicated Deployment console page.

For more usage methods and parameter settings, see the DashScope API Reference.

curl 'https://dashscope.aliyuncs.com/api/v1/services/aigc/text-generation/generation' \
--header 'Authorization: Bearer '${DASHSCOPE_API_KEY}  \
--header 'Content-Type: application/json' \
--data '{
    "model": "<your_model_instance_id>",
    "input":{
        "messages":[
            {
                "role": "user",
                "content": "Who are you?"
            }
        ]
    },
    "parameters": {
        "result_format": "message"
    }
}'

Model evaluation

The model evaluation feature of Alibaba Cloud Model Studio is available only in the console. Go to the Model Evaluation page to evaluate model training results.

For more information, see Model Evaluation.