Fine-tuning
1. Introduction to Fine-tuning
Model fine-tuning is a technique that involves further training an existing pre-trained model using a specific task dataset. This allows the model to retain its general knowledge learned from large datasets while adapting to the nuances of specific tasks. The benefits of using fine-tuned models include:
- Improved Performance: Fine-tuning can significantly enhance a model’s performance on specific tasks.
- Reduced Training Time: Fine-tuning typically requires less training time and computational resources compared to training from scratch.
- Adaptation to Specific Domains: Fine-tuning helps models better adapt to data and tasks specific to certain domains.
SiliconCloud platform provides efficient model fine-tuning capabilities. Currently, the following models support fine-tuning:
-
Image Generation Models:
- black-forest-labs/FLUX.1-dev
-
Chat Models:
- Qwen/Qwen2.5-7B-Instruct
- Qwen/Qwen2.5-14B-Instruct
- Qwen/Qwen2.5-32B-Instruct
- Qwen/Qwen2.5-72B-Instruct
- meta-llama/Meta-Llama-3.1-8B-Instruct
For the latest supported models, refer to Model Fine-Tuning.
2. Usage Flow
2.1 Data Preparation
2.2.1 Data Preparation for Image Generation Models
The dataset requirements are as follows:
7. 对于 FLUX.1
模型,图片描述信息不超过 512
tokens,过长内容会被截断
- The dataset should include both images and corresponding text descriptions in the same local folder.
- Each dataset can contain up to 100 images and their text descriptions.
- Supported image formats include .jpg, .jpeg, .png, .webp. It is recommended to have a resolution of 1024×1024, 1024×768, or 768×1024.
- Images that do not meet the above resolution will be resized and cropped to the specified resolution during training.
- Text descriptions should be saved as .txt files with the same name as the images.
- The entire dataset should not exceed 300MB, and each text description file should not exceed 128KB.
- For the FLUX.1 model, the text description should not exceed 512 tokens. Longer content will be truncated. Example of a local dataset folder:
2.2.2 Data Preparation for Language Models
Only .jsonl
files are supported, and they must meet the following requirements:
- Each line is an independent JSON object.
- Each object must contain an array with the key messages, and the array must not be empty.
- Each element in the messages array must contain role and content fields.
- role can only be system, user, or assistant.
- If there are system role messages, they must be at the beginning of the array.
- The first non-system message must be from the user role.
- user and assistant role messages should alternate and appear in pairs, with at least one pair.
Example of data:
2.2 Create and Configure Fine-Tuning Task
- Choose Chat Model Fine-Tuning or Image Generation Model Fine-Tuning
- Fill in the task name
- Select the base model
- Upload or select already uploaded training data
- Set validation data, which can be split from the training set (default 10%) or selected separately
- Configure training parameters
2.3 Start Training
- Click “Start Fine-Tuning”
- Wait for the task to complete
- Get the model identifier
2.4 Call Fine-Tuned Model
2.4.1 Calling Fine-Tuned Image Generation Model
- Copy the model identifier
- Call the fine-tuned LoRA through the
/image/generations
API. For more details, see the API documentation. Example:
2.4.2 Calling Fine-Tuned Chat Model
- Copy the model identifier
In the Fine-Tuning Page, copy the corresponding model identifier.
- Call the fine-tuned model directly through the
/chat/completions
API.
Example using the OpenAI chat.completions interface:
3. Detailed Configuration of Parameters
- Basic Training Parameters
Parameter Name | Description | Value Range | Suggested Value | Usage Recommendation |
---|---|---|---|---|
Trigger Word | 【[Only for Image Generation] Trigger Word | Added to the beginning of the description of each image during training | ||
Number of Repeats | [Only for Image Generation] Number of times to train a single image | |||
Learning Rate | Learning Rate | 0-0.1 | 0.0001 | |
Number of Epochs | Number of Training Epochs | 1-10 | 3 | |
Batch Size | Batch Size | 1-32 | 8 | |
Max Tokens | Maximum Number of Tokens | 0-4096 | 4096 | Set based on actual dialogue length needs |
- LoRA Parameters
Parameter Name | Description | Value Range | Suggested Value | Usage Recommendation |
---|---|---|---|---|
LoRA Rank | Matrix Rank | 1-64 | 8 | |
LoRA Alpha | Scaling Factor | 1-128 | 32 | |
LoRA Dropout | Dropout Rate | 0-1.0 | 0.05 |
- Scenario Configuration Scheme
Chat Models
Scenario | Learning Rate | Epochs | Batch Size | LoRA Rank | LoRA Alpha | Dropout |
---|---|---|---|---|---|---|
Standard Scheme | 0.0001 | 3 | 8 | 8 | 32 | 0.05 |
Effect Priority | 0.0001 | 5 | 16 | 16 | 64 | 0.1 |
Lightweight Fast | 0.0001 | 2 | 8 | 4 | 16 | 0.05 |
4. Optimizing Business Practice with SiliconCloud Fine-Tuning Service
Previously, SiliconCloud developed the Zhi Shuo Xin Yu application, providing a complex prompt to let the large model generate “golden sentence” style descriptions.
Now, we can use the platform’s fine-tuning function to compress the prompt and enhance the effect, making the text generation style more uniform, faster, and further optimizing costs.
4.1 Fine-tune the data from the “Zhi Shuo Xin Yu” corpus on the platform
according to the above steps. See Model Fine-Tuning Usage Flow for details. Detailed corpus and test code can be found in siliconcloud-cookbook.
4.2 Compare the effects before and after fine-tuning.
See Model Fine-Tuning Call Model for usage.
4.2.1 Model Input
-
Before Fine-Tuning: Qwen2.5-7B-Instruct System Prompt:
-
Qwen2.5-7B-Instruct+Zhi Shuo Xin Yu Fine-Tuned Prompt:
4.2.2 Model Output
Input | Qwen2.5-7B-Instruct Model | Qwen2.5-7B-Instruct Fine-Tuned Model |
---|---|---|
五道口 | VLG,不过是知识的轻轨与资本的交汇站,文青与土豪在此擦肩而过,孰是求知的信徒,孰是逐利的信徒,全凭幸存者的微笑。 | 知识的殿堂与商业的洪流交织,学人的笔记与商人的谈资齐飞,地名犹在,荣光已非。 |
新时代 | claimed to break旧 mold yet still clings to the stirring rhetoric of progress, like a fashion plate who ignores the evolution of fashion。 | 新时代的号角已吹响,然砥砺前行时,方显初心易失之难。 |
创新 | 看似凤凰涅槃的奇迹,实则多数人不过是换汤不换药的换皮游戏。 | 标新立异本是勇气的象征,却在同质化的社会中成了猎奇的代名词。 |
降维打击 | 所谓降维打击,实则是现代文明中的一种高级愚民术,用高深莫测的科技iscard,让普通人以为自己正生活在理性与进步之中,却不知已在智力与道德的低维空间中遭受碾压。。 | 高维智慧轻而易举地碾压低维凡尘,却不知低维众生早已习于在自己的平庸中寻觅慰藉,哪里还懂得高维打击的意义。 |
基金 | 看似为财富增值保驾护航的金融巨轮,实则多数人不过是随波逐流的浮萍,最终沦为填补市场波动的牺牲品。 | 投资者的白日梦,用钱铺路,却常跌入夜的陷阱。 |
4.2.3 Fine-Tuning Summary
- The output content after fine-tuning is more uniform in style, and the output effect is more stable and controllable.
- The entire input length is significantly reduced after fine-tuning, from 553 tokens to 8 tokens, greatly reducing the input token length, making it faster and further optimizing costs.