Skip to main content
Fine-tuning

Fine-tuning video generation models

When using for image-to-video , if prompt optimization or calling the official video effects does not meet your custom requirements for specific actions, effects, or styles , use model fine-tuning .

Applicable scope

  • Applicable region: The features described in this document are available only in the Singapore region. You must use an API key created in this region.
  • Fine-tuning method supported: Efficient SFT-LoRA fine-tuning.
  • Models supported for fine-tuning:
    • Image-to-video (first-frame-based): wan2.7-i2v, wan2.6-i2v, wan2.5-i2v-preview, wan2.2-i2v-flash.
    • Image-to-video (first-and-last-frame-based): wan2.2-kf2v-flash.

How to fine-tune a model

  • Image-to-video (first-frame-based)
  • Image-to-video (first-and-last-frame-based)
Fine-tuning goal: Train a LoRA model for the money rain effect.Expected result: Input a first-frame image. No prompt is needed. The model generates a video with the money rain effect.
Input first-frame image
image_3
Output video (before fine-tuning)
You cannot generate a consistent money rain effect every time using prompts. Motion is not controllable.
Output video (after fine-tuning)
The fine-tuned model reproduces the specific money rain effect from the training dataset without prompts.
Before running the code below, retrieve your API key and API host, and configure your API key.

Step 1: Upload your dataset

Upload your local dataset (in .zip format) to Alibaba Cloud Model Studio. Retrieve the file ID (id). Sample training dataset: See the training set for format details. Request example
This example uses the first-frame-based image-to-video model. Only upload the training set. The system automatically splits part of it as the validation set.Uploading a dataset takes several minutes. Exact time depends on file size.
curl --location --request POST 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/files' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--form 'file=@"./wan-i2v-training-dataset.zip"' \
--form 'purpose="fine-tune"'
Response example Save the id. This is the unique identifier for your uploaded dataset.
{
    "id": "file-ft-b2416bacc4d742xxxx",
    "object": "file",
    "bytes": 73310369,
    "filename": "wan-i2v-training-dataset.zip",
    "purpose": "fine-tune",
    "status": "processed",
    "created_at": 1766127125
}

Step 2: Fine-tune the model

Step 2.1 Create a fine-tuning job
Start training using the file ID from Step 1. Request example Replace <replace with training dataset file ID> fully with the id from the previous step.
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "model": "wan2.7-i2v",
    "training_file_ids": [
        "<your-training-dataset-file-id>"
    ],
    "training_type": "efficient_sft",
    "hyper_parameters": {
        "n_epochs": 50,
        "batch_size": 1,
        "learning_rate": 2e-5,
        "split": 0.9,
        "max_split_val_dataset_sample": 5,
        "eval_epochs": 20,
        "max_pixels": 102400,
        "save_total_limit": 10,
        "lora_rank": 32,
        "lora_alpha": 32
    }
}'
Hyperparameters
FieldTypeRequiredDescriptionRecommended value
batch_sizeintYesBatch size. The number of data samples sent to the model for training at once.This parameter is a per-instance configuration. We recommend using the default value for each model. Do not adjust unless necessary.
  • wan2.7-i2v: Recommended value: 1.
  • wan2.6-i2v: Recommended value: 1.
  • wan2.5-i2v-preview: Recommended value: 4.
  • wan2.2-i2v-flash: Recommended value: 4.
  • wan2.2-kf2v-flash: Recommended value: 4.
The actual number of instances running for a training job is determined by platform scheduling. The Global Step output in training logs may differ from estimated results, but this does not change the total amount of training data or affect the final model performance.
Model-dependent
n_epochsintYesTraining epochs. steps = n_epochs x ceiling(dataset size / batch_size). Total steps should be >= 800.
Example: dataset has 5 samples, batch_size=4, steps per epoch = ceiling(5/4) = 2, minimum n_epochs = 800/2 = 400.
The recommended number of training epochs adjusts automatically based on data volume. Less data requires more epochs to learn sufficiently; more data means each epoch contains more samples, so fewer epochs are needed. 50 epochs is mainly suitable for very small datasets of about 2 samples; when data volume reaches 50-60 videos, training approximately 3000-5000 steps is typically recommended.
50
learning_ratefloatYesLearning rate. Controls the magnitude of model weight updates. Too high may degrade the model; too low may result in negligible changes.2e-5
eval_epochsintYesEvaluation interval. Value must be >= n_epochs/10. Specifies how many epochs between each evaluation and checkpoint save.20
max_pixelsintYesMaximum resolution for training videos (total pixels = width x height). The system only scales videos that exceed this value.
  • wan2.7-i2v: Recommended 102400. Range: 36864-123904.
  • wan2.6-i2v: Recommended 36864. Range: 16384-36864.
  • wan2.5-i2v-preview: Recommended 36864. Range: 16384-36864.
  • wan2.2-i2v-flash: Recommended 262144. Range: 65536-262144.
  • wan2.2-kf2v-flash: Recommended 262144. Range: 65536-262144.
Model-dependent
splitfloatNoTraining set split ratio. Value range: (0,1). Only takes effect when validation_datasets is not specified.0.9
max_split_val_dataset_sampleintNoMaximum number of validation samples from auto-split. Validation count = min(total x (1 - split), this value).5
save_total_limitintNoMaximum number of checkpoints to keep. The system only retains the last N checkpoints.10
lora_rankintNoLoRA low-rank matrix dimension. Value must be 2n (16/32/64).32
lora_alphaintNoLoRA weight scaling coefficient. Value must be 2n (16/32/64).32
Response example Check these three key parameters in output:
  • job_id: Job ID. Use it to check progress.
  • finetuned_output: Name of the new fine-tuned model. Use this name for deployment.
  • status: Training status. After creating the job, the initial status is PENDING. Training has not started yet.
{
    ...
    "output": {
        "job_id": "ft-202511111122-xxxx",
        "status": "PENDING",
        "finetuned_output": "xxxx-ft-202511111122-xxxx",
        ...
    }
}
Step 2.2 Check the fine-tuning job status
Use the job_id from Step 2.1 to check progress. Poll this endpoint until status becomes SUCCEEDED.
This fine-tuning job takes several hours. Exact time depends on the model. Wait patiently.
Request example Replace <replace with fine-tuning job job_id> in the URL fully with the value of job_id.
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<your-job-id>' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json'
Response example Check these two parameters in the output field:
  • status: When this value becomes SUCCEEDED, training is complete. You can deploy the model.
  • usage: Total tokens used for training. Used for billing.
{
    ...
    "output": {
        "job_id": "ft-202511111122-xxxx",
        "status": "SUCCEEDED",
        "usage": 432000,
        ...
    }
}

Step 3: Deploy the fine-tuned model

Step 3.1 Deploy the model as an online service
After the fine-tuning job status is SUCCEEDED, deploy the model as an online service. Request example Replace <replace with model name model_name> fully with the value of finetuned_output from creating the fine-tuning job.
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/deployments' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
    "model_name": "<your-model-name>",
    "aigc_config": {
        "use_input_prompt": false,
        "prompt": "Provide a video description based on the image content. The description must include the phrase “Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding them. The bills continue to fall, while the camera slowly zooms in, they stretch their arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.”\nOutput Template:\nThe video begins with a shot of [subject description]. [Environment description]. Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding them. The bills continue to fall, while the camera slowly zooms in, they stretch their arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.\nExample:\nThe video begins showing a young woman standing in front of a brick wall covered with ivy. She has long, smooth reddish-brown hair, wearing a white sleeveless dress, a shiny silver necklace, and a smile on her face. The brick wall in the background is covered with green vines, appearing rustic and natural. Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding her. The bills continue to fall, while the camera slowly zooms in, she stretches her arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.",
        "lora_prompt_default": "Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding the main character. The bills continue to fall, while the camera slowly zooms in, the main character stretches their arms upward, neck slightly tilted back, with a surprised expression, completely immersed in this wild money rain."
    },
    "capacity": 1,
    "plan": "lora"
}'
Response example Check these two parameters in output:
  • deployed_model: Name of the deployed model. Use it to check deployment status and call the model.
  • status: Deployment status. After deploying the fine-tuned model, the initial status is PENDING. Deployment has not started yet.
{
    ...
    "output": {
        "deployed_model": "xxxx-ft-202511111122-xxxx",
        "status": "PENDING",
        ...
    }
}
Step 3.2 Check deployment status
Poll this endpoint until status becomes RUNNING.
Deploying this fine-tuned model takes about 5–10 minutes.
Request example Replace <replace with deployed_model> fully with the value of deployed_model from Step 3.1. Response example Check these two parameters in the output field:
  • status: When the status becomes RUNNING, the model is deployed successfully. You can start calling it.
  • deployed_model: Name of the deployed model.
{
    ...
    "output": {
        "status": "RUNNING",
        "deployed_model": "xxxx-ft-202511111122-xxxx",
        ...
    }
}

Step 4: Call the model to generate videos

After successful model deployment (when the deployment status is RUNNING ), you can start calling the model.
Request exampleReplace <replace with deployed_model name> with the deployed_model value output from the previous step.
  • Image-to-video (first-frame-based)
  • Image-to-video (first-and-last-frame-based)
Expected result: Input a first-frame image. No prompt is needed. The model automatically generates a video with the "money rain effect" based on the image.

Wan2.7 model call

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--header 'X-DashScope-Async: enable' \
--data '{
    "model": "<replace with deployed_model name>",
    "input": {
        "media": [
            {
                "type": "first_frame",
                "url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20251219/xmvyqn/lora.webp"
            }
        ]
    },
    "parameters": {
        "resolution": "720P",
        "prompt_extend": false
    }
}'

Wan2.6/Wan2.5/Wan2.2 model call

curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json' \
--header 'X-DashScope-Async: enable' \
--data '{
    "model": "<replace with deployed_model name>",
    "input": {
        "img_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20251219/xmvyqn/lora.webp"
    },
    "parameters": {
        "resolution": "720P",
        "prompt_extend": false
    }
}'
Response exampleCopy and save the task_id for querying results in the next step.
{
    "output": {
        "task_status": "PENDING",
        "task_id": "0385dc79-5ff8-4d82-bcb6-xxxxxx"
    },
    "request_id": "4909100c-7b5a-9f92-bfe5-xxxxxx"
}
Input parameter description
When calling a fine-tuned LoRA model, Wan2.7 input parameter usage is mostly the same as Wan2.7 - image-to-video. For Wan2.6/Wan2.5/Wan2.2, refer to Wan - image-to-video - first frame API reference (2.1-2.6).The table below lists only LoRA-specific parameter usage or restrictions. For general parameters not listed here (such as duration), refer to the API documentation.

Field

Type

Required

Description

Example value

model

string

Yes

Model name.

You must use a fine-tuned model that is successfully deployed and has a RUNNING status.

xxxx-ft-202511111122-xxxx

input.prompt

string

No

Text prompt.

Whether this parameter takes effect depends on the aigc_config.use_input_prompt setting:

  • If use_input_prompt=true, this parameter takes effect. The system generates the video based on this prompt.

  • If use_input_prompt=false, this parameter is ignored. The system uses the preset template aigc_config.prompt to auto-generate the prompt.

-

parameters.resolution

string

No

Resolution of the generated video.

wan2.2 and wan2.5 models: 480P, 720P. Default is 720P.

wan2.6 models: 720P, 1080P. Default is 720P.

wan2.7 models: 720P, 1080P. Default is 1080P.

720P

parameters.prompt_extend

boolean

No

Enable prompt rewriting.

When calling a fine-tuned LoRA model, disable this. Set it to false.

false

Poll the task status using the task_id until task_status becomes SUCCEEDED. Then get the video URL.Request example
Replace 86ecf553-d340-4e21-xxxxxxxxx with the real task_id.
curl -X GET https://dashscope-intl.aliyuncs.com/api/v1/tasks/86ecf553-d340-4e21-xxxxxxxxx \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response example
The video URL is valid for 24 hours. Download the video promptly.
{
    "request_id": "c87415d2-f436-41c3-9fe8-xxxxxx",
    "output": {
        "task_id": "a017e64c-012b-431a-84fd-xxxxxx",
        "task_status": "SUCCEEDED",
        "submit_time": "2025-11-12 11:03:33.672",
        "scheduled_time": "2025-11-12 11:03:33.699",
        "end_time": "2025-11-12 11:04:07.088",
        "orig_prompt": "",
        "video_url": "https://dashscope-result-sh.oss-cn-shanghai.aliyuncs.com/xxx.mp4?Expires=xxxx"
    },
    "usage": {
        "duration": 5,
        "video_count": 1,
        "SR": 480
    }
}

Build a custom dataset

In addition to using the sample datasets in this guide, you can build your own dataset for fine-tuning. Your dataset must include a training set (required) and may include a validation set (optional, supports automatic splitting from the training set). Package all files into a .zip file. Use only English letters, numbers, underscores, or hyphens in filenames.

Dataset format

Training set: Required

  • Image-to-video (first-frame-based)
  • Image-to-video (first-and-last-frame-based)
The training set includes first-frame images, training videos, and an annotation file (data.jsonl).
wan-i2v-training-dataset.zip
├── data.jsonl        # Must be named data.jsonl. Max size: 20 MB.
├── image_1.jpeg      # Max resolution: 4096×4096. Formats: BMP, JPEG, PNG, WEBP.
├── video_1.mp4       # Max resolution: 4096×4096. Formats: MP4, MOV.
├── image_2.jpeg
└── video_2.mp4
  • Annotation file (data.jsonl): Each line is one training sample. It must be a JSON object. Structure:
{
    "prompt": "The video begins showing a young woman standing in front of a brick wall covered with ivy. She has long, smooth reddish-brown hair, wearing a white sleeveless dress, a shiny silver necklace, and a smile on her face. The brick wall in the background is covered with green vines, appearing rustic and natural. Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding her. The bills continue to fall, she stretches her arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.",
    "first_frame_path": "image_1.jpg",
    "video_path": "video_1.mp4"
}

Validation set: Optional

  • Image-to-video (first-frame-based)
  • Image-to-video (first-and-last-frame-based)
The validation set includes first-frame images and an annotation file (data.jsonl). Videos are not required. At each evaluation point, the training job automatically calls the model service to generate preview videos using the validation images and prompts.
wan-i2v-valid-dataset.zip
├── data.jsonl       # Must be named data.jsonl. Max size: 20 MB.
├── image_1.jpeg     # Max resolution: 4096×4096. Formats: BMP, JPEG, PNG, WEBP.
└── image_2.jpeg
  • Annotation file (data.jsonl): Each line is one validation sample. It must be a JSON object. Structure:
{
    "prompt": "The video begins showing a scene of a young man standing in front of a cityscape. He is wearing a black and white checkered jacket over a black hoodie, with a smile on his face and a confident expression. The background is a city skyline at sunset, with a famous domed building and layered roofs visible in the distance, the sky filled with clouds showing warm orange-yellow hues. Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding him. The bills continue to fall while the camera slowly zooms in, he stretches his arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.",
    "first_frame_path": "image_1.jpg"
}

Data scale and limits

  • Data volume: Provide at least 10 samples. More training data yields better results. We recommend 20–100 samples for stable performance.
  • ZIP archive: When uploading via API, total size ≤ 1 GB.
  • Training image requirements:
    • Formats: BMP, JPEG, PNG, WEBP.
    • Resolution ≤ 4096×4096.
    • No hard limit on individual file size (system pre-processes automatically).
  • Training video requirements:
    • Formats: MP4, MOV.
    • Resolution ≤ 4096×4096.
    • No hard limit on individual file size (system pre-processes automatically).
    • Duration per video: wan2.2 models 2–5 seconds recommended; wan2.5 models 2–10 seconds recommended; wan2.6 and wan2.7 models 2–10 seconds recommended.

Data collection and cleaning

1. Define the fine-tuning scenario
Wanxiang supports fine-tuning for image-to-video in these scenarios:
  • Fixed video effects: Teach the model a specific visual change, such as a carousel or magic costume change.
  • Fixed character actions: Improve the model’s ability to reproduce specific body movements, such as dance moves or martial arts techniques.
  • Fixed camera motion: Replicate complex cinematography, such as push, pull, pan, tilt, or orbit shots.
2. Collect raw assets
  • AI generation and filtering: Use the Wanxiang foundation model to batch-generate videos. Manually select high-quality samples that best match your target effect. This is the most common method.
  • Real-world filming: If you need high realism for interactive scenes (e.g., hugging, shaking hands), use real footage.
  • 3D software rendering: For effects or abstract animations requiring precise control, use 3D software (e.g., Blender, Cinema 4D).
3. Clean the data

Dimension

Positive Requirements

Negative example

Consistency

Core features must be highly uniform.

Example: For training “360-degree rotation”, all videos must rotate clockwise at roughly the same speed.

Mixed directions.

The dataset contains both clockwise and counterclockwise rotations. The model does not know which direction to learn.

Diversity

More variety in subjects and scenes is better.

Cover different subjects (men, women, children, animals, buildings) and compositions (close-ups, wide shots, high angles, low angles). Also vary resolution and aspect ratio.

Single scene or subject.

All videos show “a person in red clothes rotating in front of a white wall”. The model may mistakenly treat “red clothes” and “white wall” as part of the effect. It fails when clothes change.

Balance

Data types should be balanced.

If multiple styles exist, their counts should be roughly equal.

Severe imbalance.

90% are portrait videos, 10% are landscape videos. The model may perform poorly on landscape videos.

Purity

Clean and clear visuals.

Use original assets without interference.

Interfering elements.

Videos contain subtitles, logos, watermarks, obvious black bars, or noise. The model may learn the watermark as part of the effect.

Duration

Asset duration ≤ target duration.

If you want 5-second videos, crop assets to 4–5 seconds.

Too long assets.

You want 5-second videos but feed the model 8-second assets. This leads to incomplete action learning and a choppy feel.

Video annotation: Write prompts for videos

In the dataset annotation file (data.jsonl), each video has a corresponding prompt. The prompt describes the video content. Prompt quality directly determines what the model learns.
Prompt exampleThe video begins with a young woman standing in front of a brick wall covered with ivy. She has long, smooth reddish-brown hair, wearing a white sleeveless dress, a shiny silver necklace, and a smile on her face. The background is a brick wall covered with green vines, appearing rustic and natural. Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding her. The bills continue to fall, she stretches her arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.

Prompt writing formula

Prompt = [Subject description] + [Background description] + [Trigger word] + [Motion description]

Prompt element

Description

Guidance

Example

Subject description

Describe people or objects present in the frame

Required

The video begins with a young woman...

Background description

Describe the environment where the subject is located

Required

The background is a brick wall covered with green vines...

Trigger word

A rare, meaningless word

Recommended

s86b5p or m01aa

Motion description

Describe the dynamic changes during the effect in detail

Recommended

Countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain...

About trigger words

  • What is a trigger word? It acts as a "visual anchor". Many complex motions (e.g., a unique dance path or light effect) are hard to describe in text. A trigger word forces the model to generate that exact visual effect when it sees the word.
  • Why use it? Fine-tuning builds a mapping between text and video features. The trigger word binds a hard-to-describe effect to a unique word so the model can lock onto the target.
  • If we have a trigger word, why describe motion in detail? They serve different roles and work better together.
    • Motion description explains what happens in the scene. It tells the model basic physical actions and logic. Motion descriptions are usually consistent across samples.
    • Trigger word explains what the action specifically looks like. It represents unique changes and features that words cannot describe.

How to write good prompts

Follow consistency rules for effect descriptions
For all samples containing the same effect, keep the motion description part as consistent as possible. Apply this rule to both training and validation sets.
  • Purpose: When the model sees s86b5p followed by the same fixed description and always sees money rain, it learns that s86b5p = money rain visual effect.
  • Example: Whether the subject is a “young woman” or a “man in a suit”, the prompt ends the same way for the money rain effect: “...then the s86b5p money rain effect begins, countless US dollar bills pour down like a torrential rain...”

    Sample type

    Prompt content (Note consistency in underlined parts)

    Training sample 1

    The video begins with a young woman standing in front of a brick wall... (environment description omitted)...

    Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding her. The bills continue to fall, she stretches her arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.

    Training sample 2

    The video begins with a man in a suit in a high-end restaurant... (environment description omitted)...

    Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding him. The bills continue to fall, he stretches his arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.

    Validation sample 1

    The video begins with a young child standing in front of a cityscape... (environment description omitted)...

    Then the s86b5p money rain effect begins, countless huge-sized US dollar bills (beige background/dark green patterns) pour down like a torrential rain, densely hitting and surrounding him. The bills continue to fall while the camera slowly zooms in, he stretches his arms upward, neck slightly tilted back, expression surprised, completely immersed in this wild money rain.

Use AI to generate prompts
To get high-quality prompts, use multimodal large language models such as Qwen-VL to assist.
  1. Use AI to generate initial descriptions
    1. Free-form brainstorming (find inspiration): If you’re unsure how to describe the effect, let AI explore freely.
      • Send “Describe the video content in detail” and observe the model’s output.
      • Focus on terms the model uses for motion trajectory (e.g., “pour down like a torrential rain”, “camera slowly zooms in”). These terms can be used for later optimization.
    2. Fixed-format prompting (standardize output): Once you have a rough idea, design a fixed format to guide AI to generate prompts that match your template.
      See visual understanding for API call details.
      import os
      from openai import OpenAI
      
      client = OpenAI(
          # API keys differ between Beijing and Singapore regions. Get your API key: https://www.alibabacloud.com/help/zh/model-studio/get-api-key
          # If you haven’t set environment variables, replace the next line with: api_key="sk-xxx".
          api_key=os.getenv("DASHSCOPE_API_KEY"),
          # Base URL for Singapore region. For Beijing region, replace with: https://dashscope.aliyuncs.com/compatible-mode/v1
          base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
      )
      completion = client.chat.completions.create(
          model="qwen3-vl-plus",
          messages=[
              {"role": "user","content": [{
                  # When passing a video file directly, set type to video_url.
                  # With OpenAI SDK, frames are sampled every 0.5 seconds by default and cannot be changed. For custom frame rates, use DashScope SDK.
                  "type": "video_url",
                  "video_url": {"url": "https://cloud.video.taobao.com/vod/Tm1s_RpnvdXfarR12RekQtR66lbYXj1uziPzMmJoPmI.mp4"}},
                  {"type": "text", "text": "Analyze the video carefully and generate a detailed video description using the following fixed format:"
                                          "Format template: The video begins with [subject description]. The background is [background description]. Then the s86b5p melting effect begins, [detailed motion description]."
                                          "Requirements:"
                                          "1.[Subject description]: Describe people or objects in the frame in detail, including appearance, clothing, and expressions."
                                          "2.[Background description]: Describe the environment, lighting, and weather in detail."
                                          "3.[Motion description]: Describe dynamic changes during the effect (e.g., how objects move, how lighting changes, how the camera moves)."
                                          "4.Integrate all content naturally into the format. Do not keep “[ ]” symbols or add unrelated text."}]
               }]
      )
      print(completion.choices[0].message.content)
      
  2. Extract effect templates
    1. Run the process multiple times on samples with the same effect. Identify high-frequency, accurate phrases used to describe the effect. Extract a generic “effect description”.
    2. Copy and paste this standardized effect description into all samples for that effect.
    3. Keep unique “subject” and “background” descriptions for each sample. Replace only the “effect description” part with the unified template.
  3. Manual review AI may hallucinate or make detection errors. As a final step, perform a manual check. For example, confirm that the descriptions of the entity and background match the actual scene.

Evaluate the model using a validation set

Specify a validation set

A fine-tuning job requires a training set. A validation set is optional. You can choose to let the system split automatically or upload manually. Specify as follows:
Method 1: No validation set uploaded (system splits automatically)
When you create a fine-tuning job, if you do not upload a separate validation set, meaning the validation_file_ids parameter is not passed, the system automatically splits a portion of the training set to use as the validation set based on the following two hyperparameters:
  • split: Proportion of training data to split. For example, 0.9 means 90% for training and 10% for validation.
  • max_split_val_dataset_sample: Maximum number of samples for the auto-split validation set.
Validation set split rule: The system selects the smaller value between dataset size × (1 - split) and max_split_val_dataset_sample.
  • Example: Suppose you upload only a training set with 100 samples, split=0.9 (10% for validation), and max_split_val_dataset_sample=5.
    • Theoretical split: 100 × 10% = 10 samples.
    • Actual split: min(10, 5)=5. So the system uses only 5 samples for the validation set.
Method 2: Upload a validation set manually (using validation_file_ids)
If you prefer to evaluate checkpoints using your own prepared data instead of relying on random system splits, upload a custom validation set. Note: Once you choose manual upload, the system ignores the automatic split rules above and validates only with your uploaded data.

Steps: Upload a validation set manually

  1. Prepare the validation set: Package validation data into a standalone .zip file. See validation set format.
  2. Upload the validation set: Call the upload dataset API to upload this .zip file. Get a dedicated file ID.
  3. Specify the validation set when creating the job: When calling the create fine-tuning job API, put this file ID in the validation_file_ids parameter.
{
    "model":"wan2.5-i2v-preview",
    "training_file_ids":[ "<training set file ID>" ],
    "validation_file_ids": [ "<custom validation set file ID>" ],
    ...
}

Select the best checkpoint for deployment

During training, the system saves periodic “snapshots” (checkpoints). By default, the system outputs the final checkpoint as the fine-tuned model. But intermediate checkpoints may outperform the final version. You can pick the best one for deployment. The system runs checkpoints on the validation set and generates preview videos at intervals defined by the hyperparameter eval_epochs.
  • Evaluation: Judge by watching the preview videos directly.
  • Selection criteria: Pick the checkpoint with the best visual quality and no motion distortion.

Procedure

Step 1.1 List validated checkpoints
This API returns only checkpoints that passed validation and successfully generated preview videos. Failed checkpoints are not listed.Request example
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<replace_with_fine-tuning_job_id>/validation-results' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header 'Content-Type: application/json'
Response exampleThis API returns a list of checkpoint names that passed validation.
{
    "request_id": "da1310f5-5a21-4e29-99d4-xxxxxx",
    "output": [
        {
            "checkpoint": "checkpoint-160"
        },
        ...
    ]
}
Step 1.2 View validation results for a checkpoint
Select one checkpoint from the list above (e.g., “checkpoint-160”) and view its video result.Request example
  • <replace_with_fine-tuning_job_id>: Replace fully with the job_id from creating the fine-tuning job.
  • <replace_with_selected_checkpoint>: Replace fully with the checkpoint value, e.g., “checkpoint-160”.
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<replace_with_fine-tuning_job_id>/validation-details/<replace_with_selected_checkpoint>?page_no=1&page_size=10' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response exampleThe preview video URL is video_path. It is valid for 24 hours. Download and review promptly. Repeat this step to compare multiple checkpoints and find the best one.
{
    "request_id": "375b3ad0-d3fa-451f-b629-xxxxxxx",
    "output": {
        "page_no": 1,
        "page_size": 10,
        "total": 1,
        "list": [
            {
                "video_path": "https://finetune-result.oss-cn-wulanchabu.aliyuncs.com/xxx.mp4?Expires=xxxx",
                "prompt": "The video begins with a young man sitting in a cafe...",
                "first_frame_path": "https://finetune-result.oss-cn-wulanchabu.aliyuncs.com/xxx.jpeg"
            }
        ]
    }
}
Step 2.1 Export the model
Assume “checkpoint-160” gives the best result. Now export it.Request example
  • <replace_with_fine_tuning_job_id>: Replace fully with the job_id from creating the fine-tuning job.
  • <replace_with_checkpoint_to_export>: Replace fully with the checkpoint value, e.g., “checkpoint-160”.
  • <replace_with_exported_model_name_for_console_display>: Replace fully with a custom model name for console display, e.g., “wan2.5-checkpoint-160”. This name must be globally unique. Duplicate names are not allowed. For parameter guidance, see export checkpoint.
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<replace_with_fine-tuning_job_id>/export/<replace_with_checkpoint_to_export>?model_name=<replace_with_exported_model_name_for_console_display>' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response exampleThe response parameter output=true means the export request was created successfully.
{
    "request_id": "0817d1ed-b6b6-4383-9650-xxxxx",
    "output": true
}
Step 2.2 Query the new model name after deployment
Query all checkpoint statuses to confirm export completion and get the unique model name (model_name) for deployment.Request example
curl --location 'https://dashscope-intl.aliyuncs.com/api/v1/fine-tunes/<replace_with_fine-tuning_job_id>/checkpoints' \
--header "Authorization: Bearer $DASHSCOPE_API_KEY"
Response exampleIn the returned list, locate the exported checkpoint (e.g., checkpoint-160). When its status becomes SUCCEEDED, export succeeded. The model_name field is the new model name for deployment and calls.
{
    "request_id": "b0e33c6e-404b-4524-87ac-xxxxxx",
    "output": [
         ...,
        {
            "create_time": "2025-11-11T13:27:29",
            "full_name": "ft-202511111122-496e-checkpoint-160",
            "job_id": "ft-202511111122-496e",
            "checkpoint": "checkpoint-160",
            "model_name": "xxxx-ft-202511111122-xxxx-c160", // Important field. Use for model deployment and calls.
            "model_display_name": "xxxx-ft-202511111122-xxxx",
            "status": "SUCCEEDED" // Successfully exported checkpoint.
        },
        ...

    ]
}
After successfully exporting the checkpoint and getting the model_name, follow these steps:
  • Model deployment: In the input parameter model_name, enter the specific value obtained after export.
  • Model call: Follow the API documentation to call the deployed model.

Go live

In production, if the initial trained model performs poorly (e.g., distorted visuals, weak effects, inaccurate motion), tune along these dimensions: 1. Check data and prompts
  • Data consistency: Consistency is critical. Check for “bad samples” with opposite directions or vastly different styles.
  • Sample count: Increase high-quality data to 20+ samples.
  • Prompt: Ensure trigger words are meaningless, rare terms (e.g., s86b5p). Avoid common words (e.g., running) that cause interference.
2. Adjust hyperparameters:
  • n_epochs (training epochs)
    • Default: 50. Use the default unless necessary. If adjusting, follow the rule: “Total training steps ≥ 800”.
    • Total steps formula: steps = n_epochs × ceiling (training set size / batch_size).
    • n_epochs minimum formula: n_epochs = 800 / ceiling (dataset size / batch_size).
    • Example: Assume a training set of 5 samples, using the Wan2.5 model (batch_size=4).
      • Steps per epoch: 5 / 4 = 1.25, rounded up to 2. Total epochs: n_epochs = 800 / 2 = 400. This is the recommended minimum. You can increase it as needed.
  • batch_size (batch size)
    • Batch size. The number of data samples sent to the model for training at once.
    • This parameter is a per-instance configuration. We recommend using the default value for each model. Do not adjust unless necessary.
    • wan2.7-i2v: Recommended value: 1.
    • wan2.5-i2v-preview: Recommended value: 4.
    • wan2.2-i2v-flash: Recommended value: 4.
    • wan2.2-kf2v-flash: Recommended value: 4.
    The actual number of instances running for a training job is determined by platform scheduling. The Global Step output in training logs may differ from estimated results, but this does not change the total amount of training data or affect the final model performance.
  • learning_rate (learning rate): Use the default value (2e-5). Typically does not require modification.

Billing

  • Model training: Charged.
  • Model deployment: Free.
  • Model calls: Charged.
    • Billed according to the standard call price of the fine-tuned foundation model. See model pricing.

API reference

Video and image generation model fine-tuning API

FAQ

Q: How are training and validation set data volumes calculated?

A: The training set is required, the validation set is optional. Calculation methods are as follows:
  • When no validation set is provided: The uploaded training set is the "total dataset size". The system automatically splits part of the data for validation.
    • Validation set size = min(total dataset size × (1 − split), max_split_val_dataset_sample). For an example, see specify a validation set.
    • Training set size = total dataset size − validation set size.
  • When a validation set is uploaded manually: The system no longer splits the validation set from the training data.
    • Training set size = Uploaded training set data volume.
    • Validation set size = Uploaded validation set data volume.

Q: How do I design a good trigger word?

A: Follow these rules:
  • Use meaningless letter combinations, such as sksstyle, a8z2_bbb.
  • Avoid common English words (e.g., beautiful, fire, dance). This prevents polluting the model's original understanding of these words.

Q: Can fine-tuning change video resolution or duration?

A: No. Fine-tuning learns "content" and "dynamics", not "specifications". Output video format (resolution, frame rate, maximum duration) is still determined by the foundation model.
Token Plan
Model Playground
  • Music generation
Statistics and Monitoring
Support