赞
踩
- $ conda create -n py310_chat python=3.10 # 创建新环境
- $ source activate py310_chat # 激活环境
- $ git clone https://github.com/lm-sys/FastChat.git
- $ cd FastChat
- $ pip install --upgrade pip
- $ pip install -e .
我们将 Vicuna Weights 作为 delta weights 发布,以符合LLaMA模型许可证。您可以将我们的delta添加到 原始 LLaMA Weights 中,以获得 Vicuna Weights 。说明:
按照 此处 的说明,以 huggingface format 获取原始 LLaMA Weights;
使用以下脚本通过应用我们的delta来获得 Vicuna weights 。他们会自动从我们的 Hugging Face account 下载 Vicuna Weights 。
注:权重v1.1 仅与 transformers>=4.28.0 和 fschat>=0.2.0 兼容。请相应地更新您的 本地package 。如果您按照上面的命令进行新的安装,那么您应该得到所有正确的版本。
3.2.1 下载 Vicuna Weight
当前版本的MiniGPT-4是建立在v0版本的 Vicuna-13B 之上的。请参考我们的说明来准备 Vicuna weights。最终的权重将在结构类似于以下的单个文件夹中:
注:Vicuna是一个开源的基于llama的LLM,其性能接近ChatGPT。我们目前使用的是v0版本的Vicuna-13B。
$ git lfs install $ git clone https://huggingface.co/lmsys/vicuna-13b-delta-v1.1 # more powerful, need at least 24G gpu memory $ # or $ git clone https://huggingface.co/lmsys/vicuna-7b-delta-v1.1 # smaller, need 12G gpu memory
请注意,这不是直接的 working weight ,而是LLAMA-13B的 working weight 与 original weight 的差值。(由于LLAMA的规则,我们无法分配LLAMA的 weight 。)
3.2.2 下载 原始LLAMA-7B或LLAMA-13B权重
然后,您需要按照HuggingFace提供的原始权重 或 从互联网上获取 HuggingFace格式的原始LLAMA-7B或LLAMA-13B 权重。
注:这里 直接 从 HuggingFace 下载 已转化为 HuggingFace格式的原始LLAMA-7B或LLAMA-13B 权重。
- $ git lfs install
- $ git clone https://huggingface.co/decapoda-research/llama-13b-hf # more powerful, need at least 24G gpu memory
- $ # or
- $ git clone https://huggingface.co/decapoda-research/llama-7b-hf # smaller, need 12G gpu memory
3.23 构建真正的 working weight
当这两个 weight 备好后,我们可以使用Vicuna团队的工具来创建真正的 working weight 。
执行如下命令创建最终 working weight
$ python -m fastchat.model.apply_delta --base /path/to/llama-13bOR7b-hf/ --target /path/to/save/working/vicuna/weight/ --delta /path/to/vicuna-13bOR7b-delta-v1.1/ --low-cpu-mem >>> The tokenizer class you load from this checkpoint is not the same type as the class this function is called from. It may result in unexpected tokenization. The tokenizer class you load from this checkpoint is 'LLaMATokenizer'. The class this function is called from is 'LlamaTokenizer'. Split files for the base model to /tmp/tmptu2g17_d 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████| 33/33 [01:47<00:00, 3.26s/it] Split files for the delta model to /tmp/tmpol8jc2oy 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [01:03<00:00, 31.92s/it] Applying the delta 33it [02:09, 3.91s/it] Saving the target model to vicuna/weight/
注:低CPU内存需加入--low-cpu-mem,可以把大的权重文件分割成多个小份,并使用磁盘作为临时存储。可以使峰值内存保持在16GB以下。不然无法载入vicuna增量文件,CPU内存占满,程序直接被kill,
output
config.json pytorch_model-16.bin pytorch_model-23.bin pytorch_model-30.bin pytorch_model-8.bin pytorch_model-0.bin pytorch_model-17.bin pytorch_model-24.bin pytorch_model-31.bin pytorch_model-9.bin pytorch_model-10.bin pytorch_model-18.bin pytorch_model-25.bin pytorch_model-32.bin pytorch_model.bin.index.json pytorch_model-11.bin pytorch_model-19.bin pytorch_model-26.bin pytorch_model-3.bin special_tokens_map.json pytorch_model-12.bin pytorch_model-1.bin pytorch_model-27.bin pytorch_model-4.bin tokenizer_config.json pytorch_model-13.bin pytorch_model-20.bin pytorch_model-28.bin pytorch_model-5.bin tokenizer.model pytorch_model-14.bin pytorch_model-21.bin pytorch_model-29.bin pytorch_model-6.bin pytorch_model-15.bin pytorch_model-22.bin pytorch_model-2.bin pytorch_model-7.bin
3.0.1 ValueError: Tokenizer class LLaMATokenizer does not exist or is not currently imported.
参考:
打开fastchat.model.apply_delta.py
使用文本替换,将所有的
AutoTokenizer 替换为 LlamaTokenizer
AutoModelForCausalLM 替换为 LlamaForCausalLM
保存
重新运行上面的命令即可。
3.0.2 如果你的CPU内存不足,您也可以尝试通过这些方法来减少权重转换对 CPU 内存的要求
方案一:将 --low-cpu-mem 追加到上面的命令中,这会将大权重文件拆分为较小的文件,并将磁盘用作临时存储。 这可以将峰值内存保持在 16GB 以下;
$ python -m fastchat.model.apply_delta --base /mnt/kaimo/data/chat/llama-7b-hf/ --target /mnt/kaimo/data/chat/vicuna/weight/ --delta /mnt/kaimo/data/chat/vicuna-7b-delta-v0/ --low-cpu-mem
方案二:创建一个大的交换文件并依靠操作系统自动的将磁盘当作虚拟内存。
3.0.3 tensor尺度不一致
bug:tensor尺度不一致
RuntimeError: The size of tensor a (32000) must match the size of tensor b (32001) at non-singleton dimension 0
当使用v0版本时,生成vicuna权重出错(bug:tensor尺度不一致),而换为v1.1版本即可解决。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。