Tuning algorithms¶
LLaMA-Factory supports multiple fine-tuning algorithms, including: Full Parameter Fine-tuning, Freeze, LoRA, Galore, BAdam.
Full Parameter Fine-tuning¶
Full parameter fine-tuning refers to updating all weights of the pre-trained model during training, but it requires a huge amount of memory.
If you need to perform full parameter fine-tuning, please set finetuning_type to full. Here is an example:
### examples/train_full/qwen3_full_sft.yaml
# ...
finetuning_type: full
# ...
#deepspeed:
deepspeed: examples/deepspeed/ds_z3_config.json
Freeze¶
Freeze (Freeze Fine-tuning) refers to updating only a small portion of the model’s weights during training, which can reduce memory requirements.
If you need to perform freeze fine-tuning, please set finetuning_type to freeze and set related parameters, such as the number of frozen layers freeze_trainable_layers, trainable module names freeze_trainable_modules, etc.
Here is an example:
...
### method
stage: sft
do_train: true
finetuning_type: freeze
freeze_trainable_layers: 8
freeze_trainable_modules: all
...
Parameter Name |
Type |
Description |
|---|---|---|
freeze_trainable_layers |
int |
The number of trainable layers. A positive number indicates the last n layers are set as trainable, a negative number indicates the first n layers are set as trainable. Default value is |
freeze_trainable_modules |
str |
The names of trainable layers. Use |
freeze_extra_modules[Optional] |
str |
Names of modules that can be trained besides hidden layers; the specified modules will be set as trainable. Use commas to separate multiple modules. Default value is |
LoRA¶
If you need to perform LoRA fine-tuning, please set finetuning_type to lora and set related parameters. Here is an example:
...
### method
stage: sft
do_train: true
finetuning_type: lora
lora_target: all
lora_rank: 8
lora_alpha: 16
lora_dropout: 0.1
...
Parameter Name |
Type |
Description |
|---|---|---|
additional_target[Optional] |
[str,] |
Names of modules besides LoRA layers that are set as trainable and saved in the final checkpoint. Use commas to separate multiple modules. Default value is |
lora_alpha[Optional] |
int |
LoRA scaling factor. Generally lora_rank * 2, default value is |
lora_dropout |
float |
Dropout rate in LoRA fine-tuning. Default value is |
lora_rank |
int |
The intrinsic dimensionality |
lora_target |
str |
Names of modules to apply LoRA method to. Use commas to separate multiple modules, use |
loraplus_lr_ratio[Optional] |
float |
LoRA+ learning rate ratio ( |
loraplus_lr_embedding[Optional] |
float |
Learning rate for LoRA+ embedding layer, default value is |
use_rslora |
bool |
Whether to use Rank-Stabilized LoRA, default value is |
use_dora |
bool |
Whether to use Weight-Decomposed LoRA, default value is |
pissa_init |
bool |
Whether to initialize PiSSA adapter, default value is |
pissa_iter |
int |
Number of iteration steps for FSVD execution in PiSSA. Use |
pissa_convert |
bool |
Whether to convert PiSSA adapter to normal LoRA adapter, default value is |
create_new_adapter |
bool |
Whether to create a new adapter with randomly initialized weights, default value is |
LoRA+¶
In LoRA, adapter matrices A and B have the same learning rate. You can adjust the learning rate ratio by setting loraplus_lr_ratio. In LoRA+, the learning rate ηA of adapter matrix A is the optimizer learning rate. The learning rate ηB of adapter matrix B is λ * ηA. Where λ is the value of loraplus_lr_ratio.
rsLoRA¶
LoRA fine-tunes by adding low-rank adapters, however increasing lora_rank often leads to gradient collapse, making training unstable. This makes it difficult to achieve satisfactory results when using larger lora_rank for LoRA fine-tuning. rsLoRA (Rank-Stabilized LoRA) makes model training more stable by modifying the scaling factor. When using rsLoRA, you only need to set use_rslora to True and set the desired lora_rank.
DoRA¶
DoRA (Weight-Decomposed Low-Rank Adaptation) proposes that although LoRA significantly reduces inference costs, there is still a gap between the performance achieved by this method and full fine-tuning.
DoRA decomposes the weight matrix into the product of a magnitude and a unit direction matrix, and further fine-tunes both (the direction matrix is further decomposed using LoRA), thereby achieving a balance between LoRA and Full Fine-tuning.
If you need to use DoRA, please set use_dora to True.
PiSSA¶
In LoRA, adapter matrix A is initialized by kaiming_uniform, while adapter matrix B is initialized to 0. This causes initial inputs not to change model outputs and results in smaller gradients and slower convergence. PiSSA initializes by directly decomposing the original weight matrix through singular value decomposition, with the advantage that it can converge faster and better.
If you need to use PiSSA, please set pissa_init to True.
Galore¶
When you need to use the GaLore (Gradient Low-Rank Projection) algorithm in training, you can configure it by setting parameters in GaloreArguments.
Here is an example:
...
### method
stage: sft
do_train: true
finetuning_type: full
use_galore: true
galore_layerwise: true
galore_target: mlp,self_attn
galore_rank: 128
galore_scale: 2.0
...
Warning
Do not use LoRA together with GaLore/BAdam.
When
galore_layerwiseistrue, please do not set thegradient_accumulationparameter.
Parameter Name |
Type |
Description |
|---|---|---|
use_galore |
bool |
Whether to use the GaLore algorithm, default value is |
galore_target |
str |
Names of modules to apply GaLore to. Use commas to separate multiple modules, use |
galore_rank |
int |
Rank of GaLore gradient, default value is |
galore_update_interval |
int |
Step interval for updating GaLore projection, default value is |
galore_scale |
float |
Scaling factor for GaLore, default value is |
galore_proj_type |
Literal |
Type of GaLore projection, available values are: |
galore_layerwise |
bool |
Whether to enable layer-wise updates to further save memory, default value is |
BAdam¶
BAdam is a memory-efficient full parameter optimization method. You can configure it in detail by setting parameters in BAdamArgument. Here is an example:
### model
...
### method
stage: sft
do_train: true
finetuning_type: full
use_badam: true
badam_mode: layer
badam_switch_mode: ascending
badam_switch_interval: 50
badam_verbose: 2
pure_bf16: true
...
Warning
Do not use LoRA together with GaLore/BAdam.
When using BAdam, please set
finetuning_typetofullandpure_bf16toTrue.When
badam_mode = layer, only single-card or multi-card training using DeepSpeed ZeRO3 is supported.When
badam_mode = ratio, only single-card training is supported.
Parameter Name |
Type |
Description |
|---|---|---|
use_badam |
bool |
Whether to use the BAdam optimizer, default value is |
badam_mode |
Literal |
Mode of BAdam usage, available values are |
badam_start_block |
Optional[int] |
Starting block index for layer-wise BAdam, default value is |
badam_switch_mode |
Optional[Literal] |
Block update strategy in layer-wise BAdam, available values are: |
badam_switch_interval |
Optional[int] |
Step interval for block updates in layer-wise BAdam. Use |
badam_update_ratio |
float |
Update ratio in ratio-wise BAdam, default value is |
badam_mask_mode |
Literal |
Mask mode for BAdam optimizer, available values are |
badam_verbose |
int |
Verbose output level for BAdam optimizer, 0 means no output, 1 means output block prefix, 2 means output trainable parameters. Default value is |