Step-by-Step Guide to Fine-Tuning QWEN2.5

Introduction

This practical guide uses the 0.5B model of QWEN2.5 for fine-tuning on the Ruozhi Bar dataset.

As we all know, there are many absurd questions in the Ruozhi Bar.Although these nonsensical questions may seem like forced ambiguity of Chinese semantics from a human perspective, they actually provide high-quality training data for the model to enhance its logical capabilities.
Through this practical guide, I hope everyone can master the following skills:

1. How to quickly obtain affordable computing power

2. How to perform full parameter fine-tuning on the QWEN model

Computing Power Preparation

πŸš€ New Platform Launch, First Offering of 4090 GPU

The SuperTi GPU computing power rental platform is officially launched! We are excited to introduce the highly anticipated NVIDIA RTX 4090 GPU. Users who register for the first time and complete real-name verification willreceive 9 hours of free usage rights for the NVIDIA RTX 4090 GPU. This is not only our sincere welcome to new users but also an excellent opportunity for you to experience the charm of cloud acceleration. No complex configurations, no cost concerns, just a click and you can enjoy unprecedented computing performance in the cloud, allowing your AI projects to progress rapidly on the SuperTi platform.

🎁 Exclusive for New Registrations, 9 Hours Free Experience

To help more users easily embrace the unlimited potential of cloud computing power, we have specially launched a new user registration event. Users who register for the first time and complete real-name verification willreceive 9 hours of free usage rights for the NVIDIA RTX 4090 GPU. This is not only our sincere welcome to new users but also an excellent opportunity for you to experience the charm of cloud acceleration. No complex configurations, no cost concerns, just unleash your creativity and passion, allowing your AI projects to progress rapidly on the SuperTi platform.

Step-by-Step Guide to Fine-Tuning QWEN2.5

πŸ’° Limited Time Special Card at 1.98 Yuan/Hour, Best Value Choice

In addition to the shocking benefits for new users, we have also launched a limited-time special card event to thank users for their support. From now until March 30, 2025, each card is only 1.98 Yuan/hour, and members can enjoy an incredible discount of as low as 1.52 Yuan/hour for monthly subscriptions. This price is not only far below the market average but also a strong support for your project cost control. Whether for small-scale testing or large-scale deployment, we can provide you with flexible and efficient computing power solutions.

[Exclusive Link] πŸ‘‰ www.superti-cloud.com πŸ‘ˆ

Environment Configuration

In this practical guide, our hardware configuration uses the 4090 for training. Since the model size is small, we directly use full parameter fine-tuning. The training framework used is llamafactory.

Hardware Configuration Process

Step-by-Step Guide to Fine-Tuning QWEN2.5

Step-by-Step Guide to Fine-Tuning QWEN2.5

As shown in the figure, we choose one 4090 for training. After selecting the configuration, create an instance.

Step-by-Step Guide to Fine-Tuning QWEN2.5

Step-by-Step Guide to Fine-Tuning QWEN2.5

As recorded in the figure, our training process includes dataset downloading, Python environment installation, and related fine-tuning training tasks. Only the final training requires GPU resources, so after creating the instance, we first click the shutdown button, wait for it to shut down, and then click the no-card mode startup button to save resources.

Step-by-Step Guide to Fine-Tuning QWEN2.5

Step-by-Step Guide to Fine-Tuning QWEN2.5

As recorded in the figure, we first click the copy token button and then enter JupyterLab.

Step-by-Step Guide to Fine-Tuning QWEN2.5

After the first appearance of the security verification interface, we paste the token we just copied into it and log in.

Step-by-Step Guide to Fine-Tuning QWEN2.5

Dataset and Model Preparation

(1) This practical guide fine-tunes the 0.5B QWEN2.5 model on the Ruozhi Bar dataset.
First, enable the conda functionality and execute the following command:
/root/miniconda3/bin/conda init
(2) Then open a new terminal.
(3) Next, create the environment:
conda create -n sft python=3.10
(4) After installation, enter the environment
conda activate sft
(5) Install the modelscope package in the environment
pip install modelscope -i https://pypi.tuna.tsinghua.edu.cn/simple
We use the modelscope package to download the dataset and model
(6) Run the following commands to download the dataset and model
modelscope download --dataset zhuangxialie/SFT-Chinese-Dataset ruozhiba/ruozhiout_qa_cn.jsonl --local_dir your_dataset_pathmodelscope download --model Qwen/Qwen2.5-0.5B --local_dir your_dataset_path
Model Training
The training framework used in this practical guide is llamafactory. The installation command is as follows:
git clone https://github.com/hiyouga/LLaMA-Factory.gitcd LLaMA-Factorypip install -e ".[torch,metrics]" -i https://pypi.tuna.tsinghua.edu.cn/simple
We create a qwen-inference.yaml file under the LLaMA-Factory directory. The configuration content is as follows:
model_name_or_path: your_model_pathtemplate: qweninfer_backend: huggingface  # choices: [huggingface, vllm]trust_remote_code: true
Then run the inference command in the LLaMA-Factory directory:
llamafactory-cli chat qwen-inference.yaml

After running the command and loading the model, we tested it with classic questions from the Ruozhi Bar:

Step-by-Step Guide to Fine-Tuning QWEN2.5

It can be seen that the un-fine-tuned model still lacks logical capability and tends to ramble.Next, we will start fine-tuning.

We need to enter the data directory under the LLaMA-Factory project directory to make simple configurations for the dataset. After entering the data directory, open dataset_info.json and add the following configuration:

Step-by-Step Guide to Fine-Tuning QWEN2.5

Change the file_name to the path of the Ruozhi Bar jsonl dataset, then create a training configuration file qwen2.5_full_sft.yaml

### modelmodel_name_or_path: your_model_pathtrust_remote_code: true
### methodstage: sftdo_train: truefinetuning_type: full#deepspeed: examples/deepspeed/ds_z3_config.json  # choices: [ds_z0_config.json, ds_z2_config.json, ds_z3_config.json]
### datasetdataset: ruozhibatemplate: qwencutoff_len: 2048overwrite_cache: truepreprocessing_num_workers: 16
### outputoutput_dir: save_pathlogging_steps: 10save_steps: 500plot_loss: trueoverwrite_output_dir: true
### trainper_device_train_batch_size: 1gradient_accumulation_steps: 2learning_rate: 1.0e-5num_train_epochs: 3.0lr_scheduler_type: cosinewarmup_ratio: 0.1bf16: trueddp_timeout: 180000000
### evalval_size: 0.1per_device_eval_batch_size: 1eval_strategy: stepseval_steps: 500

Paths that need to be modified:

(1) Change the content of the model_name_or_path field to the path of the model you downloaded.
(2) Change the output_dir field content to the path where the model will be saved after training.

Then use the following command to train

llamafactory-cli train qwen2.5_full_sft.yaml
The training process is quick, as shown in the figure below

Step-by-Step Guide to Fine-Tuning QWEN2.5

After training is complete, we can perform inference testing; simply modify the model path in the previous inference configuration file qwen-inference.yaml to the path of the model saved after training, and run the inference command:

llamafactory-cli chat qwen-inference.yaml

Once loaded, you can start testing

Step-by-Step Guide to Fine-Tuning QWEN2.5

It can be found that the large model, after training, can provide logical answers to some questions.

Take Action Now, Create the Future Together

Choosing the SuperTi GPU computing power rental platform means choosing a high-performance, low-cost, flexible, and convenient cloud solution. We are committed to promoting industry development through technological innovation, making powerful computing capabilities a solid backing for your success. Don’t hesitate any longer, visit our official website now to start your cloud computing power discount journey! For more details and inquiries, please contact our customer service team directly. Let us work hand in hand to create brilliance!

At the SuperTi GPU computing power rental platform, every computation is an investment in the future. Now, let’s explore the infinite possibilities of computing power in the cloud together!

πŸ”₯Click here now to start your computing power rental journey!πŸ”₯

Leave a Comment