All Products
Search
Document Center

Platform For AI:Fine-tune DeepSeek-R1 distill models

Last Updated:Oct 10, 2026

DeepSeek-R1, developed by DeepSeek, excels at math, coding, and reasoning. This topic walks through fine-tuning the DeepSeek-R1-Distill-Qwen-7B model with PAI Model Gallery.

Supported models

PAI Model Gallery supports LoRA supervised fine-tuning (SFT) for six distill models. The following table lists the recommended minimum resource configurations when using default hyperparameters and the provided dataset.

Distill Model

Base Model

Supported Training Method

Minimum Configuration

DeepSeek-R1-Distill-Qwen-1.5B

Qwen2.5-Math-1.5B

LoRA supervised fine-tuning

1 × A10 (24 GB video memory)

DeepSeek-R1-Distill-Qwen-7B

Qwen2.5-Math-7B

1 × A10 (24 GB video memory)

DeepSeek-R1-Distill-Llama-8B

Llama-3.1-8B

1 × A10 (24 GB video memory)

DeepSeek-R1-Distill-Qwen-14B

Qwen2.5-14B

1 × GU8IS (48 GB video memory)

DeepSeek-R1-Distill-Qwen-32B

Qwen2.5-32B

2 × GU8IS (48 GB video memory)

DeepSeek-R1-Distill-Llama-70B

Llama-3.3-70B-Instruct

8 × GU100 (80 GB video memory)

Quick start

  1. Go to the Model Gallery page.

    1. Log on to the PAI console. In the left-side navigation pane, select your target Workspace.

    2. In the left-side navigation pane, choose QuickStart > Model Gallery.

      In the Model Gallery tab, enter DeepSeek-R1-Distill-Qwen-7B in the search box and find the corresponding model card in the search results.

  2. On the Model Gallery page, search for and click DeepSeek-R1-Distill-Qwen-7B. The model details page describes training and deployment, including the required SFT data format and invocation methods.

    SFT training supports the LoRA algorithm. The training dataset supports JSON and JSONL formats, with sample data provided in messages, sharegpt, and alpaca formats.

  3. Click Train in the upper-right corner. Configure the following key parameters:

    • Dataset Configuration: This example uses the default dataset. To use your own data, prepare a custom dataset per the format on the model details page and upload it to an Object Storage Service (OSS) bucket.

    • Model output path: Select an OSS path to store the fine-tuned model.

    • Compute Resource: For Source, select public resource. For Instance type, select ecs.gn7i-c16g1.4xlarge.

    • Hyperparameters: Supported hyperparameters for LoRA SFT. Adjust as needed. Fine-tuning guide for large language models.

      Hyperparameters

      Parameter

      Type

      Default (for 7B model)

      Description

      learning_rate

      float

      5e-6

      Controls the magnitude of model weight updates.

      num_train_epochs

      int

      6

      Number of passes over the training dataset.

      per_device_train_batch_size

      int

      2

      Samples processed per GPU per iteration. Larger values improve throughput but require more GPU memory.

      gradient_accumulation_steps

      int

      2

      The number of gradient accumulation steps.

      max_length

      int

      1024

      Maximum input token length per training iteration.

      lora_rank

      int

      8

      The LoRA dimension.

      lora_alpha

      int

      16

      The LoRA scaling factor.

      lora_dropout

      float

      0

      Dropout rate for LoRA training. Prevents overfitting by randomly dropping neurons.

      lorap_lr_ratio

      float

      16

      The LoRA+ learning rate ratio (λ = ηB/ηA), where ηA and ηB are the learning rates for adapter matrices A and B. LoRA+ applies different learning rates to matrices A and B for better performance and faster convergence without extra compute. Set lorap_lr_ratio to 0 to use standard LoRA.

  4. Click Train. PAI redirects you to the training job page where you can monitor job status and view logs.

    The training job progresses through four stages: Creating, Preparing Environment, Running, and Succeeded, taking approximately 6 minutes. In the Task Logs tab, you can view detailed logs for model checkpoint loading, LoRA weight merging, and merged model export.

    When training succeeds, the fine-tuned model is automatically registered in AI Asset Management - Models, where you can view or deploy it. Register and manage models.

  5. After training completes, click Deploy to deploy the fine-tuned model as an EAS service. Use the same invocation method as the original distill model, described on the model details page and in Deploy DeepSeek-V3 and DeepSeek-R1 models.

Billing

Model Gallery training uses DLC, billed by job duration. Billing for DLC.

FAQ

Q: How do I troubleshoot a failed training job?

  • Set an appropriate max_length in the training configuration. The algorithm discards data exceeding max_length and logs the action:

    [WARNING:swift] There are errors in the dataset, the data will be deleted
    [INFO:swift] Traceback (most recent call last):
      File "/usr/local/lib/python3.10/site-packages/swift/llm/dataset/preprocessor/core.py", line 169, in batched_preprocess
        row = self.preprocess(row)
      File "/usr/local/lib/python3.10/site-packages/swift/llm/dataset/utils.py", line 205, in preprocess
        return self.template.encode(row)
      File "/usr/local/lib/python3.10/site-packages/swift/llm/template/base.py", line 240, in encode
        encoded = self._encode(inputs)
      File "/usr/local/lib/python3.10/site-packages/swift/llm/template/template/deepseek.py", line 134, in _encode
        return super()._encode(inputs)
      File "/usr/local/lib/python3.10/site-packages/swift/llm/template/base.py", line 713, in _encode
        raise MaxLengthError(f'Current length of row({len(input_ids)}) is larger'
    swift.llm.template.base.MaxLengthError: Current length of row(807) is larger than the max_length(512).

    If too much data is discarded, the training or validation dataset might become empty, causing the training job to fail:

    Map: 100%|xxx| 320/320 [00:00<00:00, 17601.17 examples/s]
    [INFO:swift] Dataset filtered, origin length: 320, filtered dataset length: 0
    [rank0]: Traceback (most recent call last):
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/cli/sft.py", line 5, in <module>
    [rank0]:     sft_main()
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/llm/train/sft.py", line 256, in sft_main
    [rank0]:     return SwiftSft(args).main()
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/llm/base.py", line 46, in main
    [rank0]:     result = self.run()
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/llm/train/sft.py", line 111, in run
    [rank0]:     train_dataset, val_dataset = self._get_dataset()
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/llm/train/sft.py", line 84, in _get_dataset
    [rank0]:     train_dataset, val_dataset = load_dataset(
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/llm/dataset/loader.py", line 459, in load_dataset
    [rank0]:     train_dataset, val_dataset = DatasetLoader.post_process(
    [rank0]:   File "/usr/local/lib/python3.10/site-packages/swift/llm/dataset/loader.py", line 337, in post_process
    [rank0]:     assert train_sample > 0
    [rank0]: AssertionError
  • The error failed to compose dlc job specs, resource limiting triggered, you are trying to use more GPU resources than the threshold means the job hit a GPU resource limit. By default, a maximum of 2 GPUs can run simultaneously. Wait for running jobs to complete, or submit a ticket to request a quota increase.

  • The error the specified vswitch vsw-**** cannot create the required resource ecs.gn7i-c32g1.8xlarge, zone not match means the instance type is unavailable in the vSwitch's availability zone. Solutions: 1. Remove the vSwitch setting so DLC auto-selects an available zone. 2. Switch to a different instance type.

Q: Can I download the model after training?

Yes. Set the model output path to an OSS directory when creating the training job. After the job completes, download the model from that OSS path.

Q: What should I do if the model performance is poor?

Try the following:

  1. Use a model with better baseline performance, such as a model from the DeepSeek or Qwen3 series with a higher parameter count.

  2. Refine your prompts.

  3. Increase the max_tokens value.

  4. Break complex tasks into smaller subtasks.

Related topics