赞
踩
我们目前正在致力于训练更大尺寸的版本(如果可行的话,13B、33B 和 65B)。感谢您的耐心等待。
我们的对抗性蒸馏框架的高级概述,其中我们基于高级闭源 LLM 制作了一个紧凑的学生 LLM,该 LLM 服务于三个角色:教师**、裁判员和生成器**。从左到右,迭代分为三个阶段:
我们将提供最新型号供您尽可能长时间地试用。您可以向 Lion 提出一些问题,我们很高兴听到您的反馈!
演示链接(72小时后过期,因此我们会定期更新链接)
由于训练数据是英文指令示例,因此您最好用英文提问。然而,我们发现Lion在一定程度上也能理解其他语言的指令。请看下面的案例:
我们将 Lion 权重发布为增量权重,以符合 LLaMA 模型许可证。
您可以将我们的增量添加到原始 LLaMA 权重中以获得 Lion 权重。指示:
python src/weight_diff.py recover --path_raw huggyllama/llama-7b --path_diff YuxinJiang/Lion --path_tuned <path_to_store_recovered_weights>
对于Lion的推理和训练,请首先安装要求:
pip install -r requirements.txt
我们为Lion提供了解码脚本,它读取输入文件并为每个样本生成相应的响应,最后将它们合并到输出文件中。它可以在具有 16GB GPU 的单台机器上运行。
python src/lion_inference.py \
--model_dir <path_to_hf_converted_lion_ckpt_and_tokenizer> \
--data_dir <path_to_input_json_file> \
--output_dir <path_to_output_json_file> \
--num_gpus 1
下面显示了我们的对抗性蒸馏框架的一种迭代。
python src/chatgpt_inference.py \
-q <path_to_json_file_for_the_Train_Pool> \
-o <path_to_chatgpt_inference_for_the_Train_Pool> \
--api_key <your_openai_api_key>
微调是在具有 8 个 A100 80G GPU 的机器上进行的。
torchrun --nproc_per_node=8 --master_port=<your_random_port> src/train.py \ --model_name_or_path <path_to_hf_converted_ckpt_and_tokenizer> \ --data_path <path_to_chatgpt_inference_for_the_Train_Pool> \ --bf16 True \ --output_dir result \ --num_train_epochs 3 \ --model_max_length 1024 \ --per_device_train_batch_size 2 \ --per_device_eval_batch_size 2 \ --gradient_accumulation_steps 8 \ --evaluation_strategy "no" \ --save_strategy "steps" \ --save_steps 500 \ --save_total_limit 1 \ --learning_rate 2e-5 \ --weight_decay 0. \ --warmup_ratio 0.03 \ --lr_scheduler_type "cosine" \ --logging_steps 1 \ --fsdp "full_shard auto_wrap" \ --fsdp_transformer_layer_cls_to_wrap 'LlamaDecoderLayer' \ --tf32 True
解决 OOM
简单来说,微调 7B 模型需要大约 7 x 8 x 2 = 112 GB 的 VRAM。上面给出的命令启用参数分片,因此任何 GPU 上都不会存储冗余模型副本。如果您想进一步减少内存占用,可以选择以下一些选项:
打开 FSDP 的 CPU 卸载--fsdp "full_shard auto_wrap offload"
。这可以节省 VRAM,但代价是运行时间更长。
根据我们的经验,DeepSpeed stage-3(带卸载)有时比带卸载的 FSDP 具有更高的内存效率。以下是使用具有 8 个 GPU 的 DeepSpeed stage-3 以及参数和优化器卸载的示例:
deepspeed src/train_deepspeed.py \ --model_name_or_path <path_to_hf_converted_ckpt_and_tokenizer> \ --data_path <path_to_chatgpt_inference_for_the_Train_Pool> \ --output_dir result \ --num_train_epochs 3 \ --model_max_length 1024 \ --per_device_train_batch_size 16 \ --per_device_eval_batch_size 1 \ --gradient_accumulation_steps 1 \ --evaluation_strategy "no" \ --save_strategy "steps" \ --save_steps 600 \ --save_total_limit 1 \ --learning_rate 2e-5 \ --warmup_ratio 0.03 \ --logging_steps 1 \ --lr_scheduler_type "cosine" \ --report_to "tensorboard" \ --gradient_checkpointing True \ --deepspeed srcs/configs/deepspeed_config.json \ --fp16 True
LoRA微调查询、键和值嵌入头的低秩切片。这可以将总内存占用量从 112GB 减少到大约 7x4=28GB。我们将来可能会发布对此的重新实现,但目前peft代码库可能是一个有用的资源。
python src/chatgpt_inference.py \
-q <path_to_json_file_for_the_Cache_Pool> \
-o <path_to_chatgpt_inference_for_the_Cache_Pool> \
--api_key <your_openai_api_key>
python src/lion_inference.py \
--model_dir <path_to_hf_converted_lion_ckpt_and_tokenizer> \
--data_dir <path_to_json_file_for_the_Cache_Pool> \
--output_dir <path_to_lion_inference_for_the_Cache_Pool> \
--num_gpus 8
python src/chatgpt_referee.py \
-a <path_to_chatgpt_inference_for_the_Cache_Pool> <path_to_lion_inference_for_the_Cache_Pool> \
-o <path_to_output_review_file> \
--api_key <your_openai_api_key>
python src/discrimination.py \
--review_path <path_to_output_review_file> \
--chatgpt_inference_path <path_to_chatgpt_inference_for_the_Cache_Pool> \
--lion_inference_path <path_to_lion_inference_for_the_Cache_Pool> \
--hard_save_path <path_to_identified_hard_instructions> \
--easy_save_path <path_to_identified_easy_instructions>
python -m src/generate_hard_instruction generate_instruction_following_data \
--seed_tasks_path <path_to_identified_hard_instructions> \
--output_dir <path_to_generated_hard_instructions> \
--num_instructions_to_generate 3000 \
--api_key <your_openai_api_key>
python -m src/generate_easy_instruction generate_instruction_following_data \
--seed_tasks_path <path_to_identified_easy_instructions> \
--output_dir <path_to_generated_easy_instructions> \
--num_instructions_to_generate 3000 \
--api_key <your_openai_api_key>
我们利用 GPT-4 自动评估两个模型在 80 个未见过的Vicuna 指令上的响应质量(分数从 1 到 10)。ChatGPT 已被选为参考模型来评估不同法学硕士的相对能力。相对分数以百分比形式报告,计算为分数总和的比率。
相对整体响应质量:
不同任务类别的相对响应质量:
我们采用 Askel 等人提出的对齐标准。(2021),其中定义如果助理具有乐于助人、诚实和无害(HHH)的特点,则被认为是一致的。我们对 252 个UserOriented-Instructions进行了人工评估。为了估计获胜率,我们比较了下面每对模型之间获胜、平局和失败的频率。
如果您使用此存储库中的代码,请引用我们的论文。
@article{DBLP:journals/corr/abs-2305-12870, author = {Yuxin Jiang and Chunkit Chan and Mingyang Chen and Wei Wang}, title = {Lion: Adversarial Distillation of Closed-Source Large Language Model}, journal = {CoRR}, volume = {abs/2305.12870}, year = {2023}, url = {https://doi.org/10.48550/arXiv.2305.12870}, doi = {10.48550/arXiv.2305.12870}, eprinttype = {arXiv}, eprint = {2305.12870}, timestamp = {Fri, 26 May 2023 11:29:33 +0200}, biburl = {https://dblp.org/rec/journals/corr/abs-2305-12870.bib}, bibsource = {dblp computer science bibliography, https://dblp.org} }
Xiv},
eprint = {2305.12870},
timestamp = {Fri, 26 May 2023 11:29:33 +0200},
biburl = {https://dblp.org/rec/journals/corr/abs-2305-12870.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
## 免责声明
⚠️Lion**仅供研究使用**并获得许可。**严禁**商业用途。任何版本的Lion生成的内容都会受到随机性等不可控变量的影响,因此本项目无法保证输出的准确性。本项目对模型输出的内容不承担任何法律责任,也不承担因使用相关资源和输出结果而产生的任何损失。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。