中文
Il existe généralement deux schémas pour le réglage de Facebook / Llama affinés. L'un est la série Alpaca de Stanford, et l'autre est Vicuna basée sur Sharegpt Corpus. Vicuna utilise un corpus de dialogue multi-ronde, et l'effet de formation est meilleur qu'Alpaca qui est par défaut en dialogue à un seul tour. Par conséquent, il est recommandé de faire affiner les lama en fonction de la vicuna. Les deux façons affinées sont décrites en détail dans les projets suivants (la description du mode LORA dans FastChat est relativement simple).
https://github.com/tloen/alpaca-lora
https://github.com/lm-sys/fastchat
Alpaca-Lora a de faibles exigences de mémoire, environ 12G 2080TI peut prendre en charge, mais la formation de modèles de session multi-ronde comme Vicuna nécessite une mémoire GPU élevée. La formation du modèle Vicuna nécessite au moins 24 g de mémoire GPU [la recommandation officielle est 4 * V100 (32G)]. Si vous avez une carte graphique haut de gamme, suivez simplement le fichier pour vous entraîner. Si vous n'avez qu'une carte graphique 16G mais que vous souhaitez personnaliser le corpus pour reproduire le modèle Vicuna, vous devez penser à de nombreuses façons de réduire en continu la précision de 32 bits à la moitié de la précision 16 bits, puis de 16 bits à 8 bits, et accélérer la méthode de formation pour atteindre l'objectif.
• Utilisez la méthode LORA pour former une seule partie des paramètres
• Le modèle de base adopte la demi-précision LLAMA-7B-HF
• Utilisez Load_in_8bit pour charger le modèle de base
• Utilisez la technologie PEFT pour un réglage fin
• Utilisez des bitsandbytes pour accélérer
Ensuite, nous basés sur FastChat, cet article modifie le code de formation LORA, utilise le Corpus Sharegpt et les affinures sur une carte 16G, occupant environ 13 g de mémoire GPU.
• Système d'exploitation: CentOS ou Ubuntu
• NVIDA P100 ou T4: Mémoire GPU 16G ou supérieure
• Cuda, conda
git clone https://github.com/git-cloner/llama-lora-fine-tuning
cd llama-lora-fine-tuningwget https://pkg-config.freedesktop.org/releases/pkg-config-0.29.2.tar.gz
tar -zxvf pkg-config-0.29.2.tar.gz
cd pkg-config-0.29.2
./configure --with-internal-glib
make -j4
make check
sudo make installwget https://mirrors.aliyun.com/blfs/conglomeration/icu/icu4c-73_1-src.tgz
tar xf icu4c-73_1-src.tgz
cd icu/source
./configure
make
make check
sudo make install
sudo ldconfigconda create -n llama-lora python=3.10
conda activate llama-lora
pip3 install -r requirements.txtVous pouvez télécharger le modèle original et le convertir en demi-précision, ou télécharger le modèle de demi-précision converti directement à partir de https://huggingface.co/decapoda-research/llama-7b-hf.
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1
pip3 install git+https://github.com/juncongmoo/pyllama -i https://pypi.mirrors.ustc.edu.cn/simple --trusted-host=pypi.mirrors.ustc.edu.cn
python -m llama.download --model_size 7BCUDA_VISIBLE_DEVICES=1 python3 ./convert_llama_weights_to_hf.py --input_dir ./pyllama_data --model_size 7B --output_dir ./pyllama_data/output/7BDownload 52k ShareGPT: https: // huggingface.co/datasets/RyokoAI/ShareGPT52K
Other corpora refer to: https: // github.com/Zjh-819/LLMDataHub
Download sg_90k_part1.json and sg_90k_part2.json into the data directorypython3 fastchat/data/merge.py --in ./data/sg_90k_part1.json ./data/sg_90k_part2.json ./data/dummy_cn.json ./data/dummy_en.json --out ./data/sg_90k.jsonpython3 fastchat/data/clean_sharegpt.py --in ./data/sg_90k.json --out ./data/sharegpt_clean.jsonpython3 fastchat/data/optional_clean.py --in ./data/sharegpt_clean.json --out ./data/sharegpt_clean_1.json --skip-lang SOME_LANGUAGE_CODE
The values of SOME_LANGUAGE_CODE are as follows:
en - English
es - Spanish
fr - French
de - German
it - Italian
ja - Japanese
ko - Korean
zh - Chinese
ar - Arabic
ru - Russian
pt - Portuguese
nl - DutchCUDA_VISIBLE_DEVICES=1 python3 fastchat/data/split_long_conversation.py --in ./data/sharegpt_clean.json --out ./data/sharegpt_clean_split.json --model-name ./pyllama_data/output/7B # Disable wandb
wandb disabled
# In order to prevent the SSH terminal from disconnecting and stopping the training, the training can run in the background (remove the # in three places to run in the background)
# If you have multiple GPUs,using --num_gpus parameter
CUDA_VISIBLE_DEVICES=0,1 # nohup
deepspeed --num_gpus=2 fastchat/train/train_lora.py
--deepspeed ./deepspeed-config.json
--lora_r 8
--lora_alpha 16
--lora_dropout 0.05
--model_name_or_path ./pyllama_data/output/7B
--data_path ./data/sharegpt_clean_split.json
--fp16 True
--output_dir ./output
--num_train_epochs 1
--per_device_train_batch_size 14
--per_device_eval_batch_size 14
--gradient_accumulation_steps 1
--evaluation_strategy " no "
--save_strategy " steps "
--save_steps 2400
--save_total_limit 5
--learning_rate 2e-5
--weight_decay 0.
--warmup_ratio 0.03
--lr_scheduler_type " cosine "
--logging_steps 1
--model_max_length 512
--gradient_checkpointing True # >> lora.log 2>&1 &
# If running in the background, tail lora.log to check the training progress
tail -f lora.logLe réglage fin sur P100 (16g) occupe 13,5 g de mémoire. Dans le cas d'un cycle de formation, il faut 120 heures, environ 5 jours, ce qui prend toujours du temps. L'effet du modèle résultant doit être vérifié. Model_Max_Length affectera le temps de formation. S'il est réglé sur 1024, le temps sera divisé par deux par rapport à 2048, mais cela affectera l'effet d'inférence.
Affinement sur le seul A100 et prendre environ 16 heures.
deepspeed fastchat/train/train_lora.py
--deepspeed ./deepspeed-config.json
--lora_r 8
--lora_alpha 16
--lora_dropout 0.05
--model_name_or_path ./pyllama_data/output/7B
--data_path ./data/sharegpt_clean_split.json
--fp16 True
--output_dir ./output
--num_train_epochs 1
--per_device_train_batch_size 56
--per_device_eval_batch_size 56
--gradient_accumulation_steps 1
--evaluation_strategy " no "
--save_strategy " steps "
--save_steps 1200
--save_total_limit 5
--learning_rate 2e-5
--weight_decay 0.
--warmup_ratio 0.03
--lr_scheduler_type " cosine "
--logging_steps 1
--model_max_length 1024
--gradient_checkpointing TrueLe modèle LORA PEFT formé se compose d'adaptor_config.json, adapter_model.bin et dormer_state.json. Vous trouverez ci-dessous la structure de fichiers de PEFT et le modèle LLAMA d'origine.
model
───llama-peft
│ adapter_config.json
│ adapter_model.bin
│ trainer_state.json
│
└──llama_7b
config.json
generation_config.json
pytorch_model-00001-of-00002.bin
pytorch_model-00002-of-00002.bin
pytorch_model.bin.index.json
special_tokens_map.json
tokenizer.json
tokenizer.model
tokenizer_config.jsonCUDA_VISIBLE_DEVICES=0 python generate.py --base_model ./model/llama-7b --lora_weights ./model/llama-peft