Vicuna 模型学习与实战

1 环境搭建

构建python环境

conda create -n vicuna python=3.8    # 创建新环境
source activate vicuna                       # 激活环境

安装 FastChat

pip install fschat

从 github 下载 FastChat repository 安装

  1. clone repository,然后 加入 FastChat folder
git clone https://github.com/lm-sys/FastChat.git
cd FastChat

PS : FastChat commit version : 55051ad0f23fef5eeecbda14a2e3e128ffcb2a98

2 Vicuna Weights 生成

官方提供 的 Vicuna Weights 生成方式

我们将 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 。如果您按照上面的命令进行新的安装,那么您应该得到所有正确的版本。

本项目所使用的的 Vicuna Weights 生成方式

  • 参考: How to Prepare Vicuna Weight
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 。)
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
2.3 构建真正的 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
  • base-model-path:下载好的llama-13b模型的地址
  • delta-path:下载好的vicuna-13b模型的地址:
  • target-model-path:想要输出的最终的vicuna-13b的地址

运行Vicuna模型

python -m fastchat.serve.cli --model-path ./vicuna-7b-weight --style rich  --num-gpus 2

你可能感兴趣的:(LLM,nlp)