Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR mainly involves the following aspects:
QLoRA overall logic:
Modifications to the model structure:
int4
in the model parameter files in the foldersrc/config
, which acts as a switch to control whether to use QLoRA. Corresponding adjustments need to be made in other relevant structures (Attention
/SelfAttentionBlock
/FFNBlock
/TransformerBlock
/DenseGatedACT
/FeedForward
/Encoder
/CPMBee
) to load the appropriate models based on the int4 field.src/cpm_live/layers/feedforward.py
, add classLinear4bit
as the QLoRA method linear layer; add classParams4bit
as the weight forLinear4bit
; add classDistributedParameter4Int8
to meet encapsulation needs.Add scripts/sample code/README:
src/quantize_state_dict.py
is the code for compressing the initial weights. QLoRA needs to load the compressed dict as model weights.src/finetune_cpm_bee_qlora.py
is the fine-tuning sample code.src/scripts/finetune_cpm_bee_qlora.sh
is the fine-tuning sample script.tutorials/basic_task_finetune/README_qlora.md
is the fine-tuning tutorial for QLoRA.Other considerations:
src/finetune_cpm_bee_qlora.py
, asuint8
does not supportstd
andvar
.BMTrain.blocklayer
whereuint8
typerequires_grad
cannot be passed in.