Fine-tuning the Model
Complete Data Preprocessing first.
Training parameters
- Adjust
per_device_train_batch_sizeandgradient_accumulation_stepsto fit your VRAM. - Tune
num_train_epochs,lora_rank,lora_dropoutand other settings intrain_sft_argsto the amount and quality of your data. train_sft_argsaccepts every LLaMA Factory argument, see Arguments - LLaMA Factory.
Single-GPU training
weclone-cli train-sftTo train on one GPU of a multi-GPU machine, run
export CUDA_VISIBLE_DEVICES=0first.
The training script reads settings.jsonc and starts fine-tuning. Watch the terminal output to check that the loss goes down.
When training finishes, the LoRA adapter weights are saved in common_args.adapter_name_or_path (./model_output by default), which is also the training output directory. In encrypted mode the weights are stored encrypted.
Multi-GPU training
With several NVIDIA GPUs:
Install DeepSpeed:
bashuv pip install "deepspeed<=0.16.9"Configure DeepSpeed: uncomment the
"deepspeed": "ds_config.json"line insettings.jsonc, or point it to your own DeepSpeed configuration file.Start multi-GPU training:
bashdeepspeed --num_gpus=<number_of_gpus> weclone/train/train_sft.py
WARNING
Encrypted mode doesn't support distributed training yet.
Enable QLoRA (Optional Configuration)
To save more VRAM, enable QLoRA quantized training.
WARNING
After fine-tuning a quantized model, the weights can't be merged into the original model.
Add quantization to train_sft_args in settings.jsonc:
"train_sft_args": {
...
"quantization": {
"quantization_bit": 4,
"quantization_type": "nf4",
"double_quantization": true,
"quantization_method": "bnb"
}
},NOTE
quantization_bitaccepts 2, 4 or 8. Lower values save more VRAM but may slow inference and lower quality slightly.Inference (
webchat-demo,server --inference) uses the same quantization settings.If you see
ImportError: Please install bitsandbytes>=0.45.3, reinstallbitsandbytes:bashuv pip install "bitsandbytes>=0.45.3"