Vicuna 模型学习

1. 构建环境

    $ conda create -n py310_chat python=3.10       # 创建新环境
    $ source activate py310_chat                   # 激活环境

2. 安装 FastChat

2.2.2 从 github 下载 repository 安装

  1. clone repository,然后 加入 FastChat folder

    $ git clone https://github.com/lm-sys/FastChat.git
    $ cd FastChat
    $ pip install --upgrade pip
    $ pip install -e .

三、Vicuna Weights 生成

3.1 官方提供 的 Vicuna Weights 生成方式

我们将 Vicuna Weights 作为 delta weights 发布,以符合LLaMA模型许可证。您可以将我们的delta添加到 原始 LLaMA Weights 中,以获得 Vicuna Weights 。说明:

  1. 按照 此处 的说明,以 huggingface format 获取原始 LLaMA Weights;

  2. 使用以下脚本通过应用我们的delta来获得 Vicuna weights 。他们会自动从我们的 Hugging Face account 下载 Vicuna Weights 。

注:权重v1.1 仅与 transformers>=4.28.0 和 fschat>=0.2.0 兼容。请相应地更新您的 本地package 。如果您按照上面的命令进行新的安装,那么您应该得到所有正确的版本。

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

参考:How to Prepare Vicuna Weight

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 填坑手册

3.0.1 ValueError: Tokenizer class LLaMATokenizer does not exist or is not currently imported.

参考:

  1. MiniGPT-4 本地部署 RTX 3090

  2. LLaMATokenizer does not exist or is not currently imported- LLaMA 4-bit 

  1. 打开fastchat.model.apply_delta.py

  2. 使用文本替换,将所有的

    1. AutoTokenizer 替换为 LlamaTokenizer

    2. AutoModelForCausalLM 替换为 LlamaForCausalLM

    3. 保存

  3. 重新运行上面的命令即可。

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版本即可解决。

<think>好的,我现在需要回答用户关于Vicuna模型的介绍及其应用的问题。首先,我需要根据用户提供的引用内容来组织信息。用户给了四个引用,分别涉及Vicuna的部署教程、MiniGPT-4的构建、新闻机构的应用案例,以及Vicuna的开源背景。 首先,Vicuna的简介部分,引用[4]提到它是基于LLaMA和Alpaca的开源模型,由多个大学的研究者共同开发。这点很重要,需要放在简介的开头,说明其来源和背景。引用[1]提到Vicuna的定义,可能可以结合这两部分,介绍模型的基本信息和目标。 接下来是技术特点,引用[4]提到13B参数规模和优化方法,比如调整训练损失函数和优化器,以及支持长文本对话。这些技术细节需要展开说明,但要注意用户可能不熟悉术语,需要用通俗的语言解释。 关于应用场景,引用[3]给出了新闻机构使用Wizard Vicuna 13B辅助内容创作的例子,可以具体说明如何应用。另外,引用[2]提到MiniGPT-4基于Vicuna-13B,说明其在多模态领域的应用,比如图像理解。这部分需要分点列出,清晰展示不同领域的应用。 部署部分,引用[1]详细说明了在Linux和Windows下的部署步骤,需要概括安装流程,但用户可能不需要太详细的步骤,只需提到支持多平台和社区资源即可。 最后,生成相关问题需要考虑用户可能的后续疑问,比如技术优化、应用案例比较、部署的硬件要求等。需要确保问题覆盖模型的各个方面,便于用户进一步探索。 现在需要检查是否符合系统级指令:使用正确的中文,数学公式用$...$,独立公式用$$...$$,不过用户的问题不涉及数学公式,所以这点可能不需要。但需要确保引用标识正确,每个引用结束加上[^n],比如在提到部署教程时加[^1],应用案例加[^3]等。 可能需要注意引用内容中的细节,比如Vicuna-13B的参数规模,优化方法中的监督微调(SFT)和RLHF,以及训练数据的规模。需要准确转述这些信息,避免错误。 最后,确保回答结构清晰,分点明确,语言通顺,符合用户要求的结构:简介、技术特点、应用场景、部署信息,然后相关问题。</think>### Vicuna 模型介绍及应用 #### 一、Vicuna 简介 Vicuna 是一个开源的 13B 参数规模大语言模型(LLM),由加州大学伯克利分校、卡内基梅隆大学等机构的研究者联合开发。它基于 Meta 的 LLaMA 模型框架,并借鉴了 Stanford Alpaca 项目的优化方法,旨在降低大模型的应用门槛,推动研究和实际场景的落地[^4]。Vicuna 通过监督微调(SFT)和人类反馈强化学习(RLHF)技术优化,支持长文本对话和多轮交互。 #### 二、技术特点 1. **高效训练**:使用约 7 万条用户对话数据进行微调,训练成本显著低于同类模型。 2. **性能优化**:调整了损失函数和优化器设计,减少内存占用并提升推理速度。 3. **多场景支持**:支持最长 2048 token 的上下文理解,适用于复杂对话任务。 #### 三、应用场景 1. **内容创作辅助** 新闻机构可利用 Wizard Vicuna 13B 快速生成文章初稿。例如,输入关键词或提纲后,模型自动生成文本,再由人工润色,效率提升约 40%[^3]。 2. **多模态模型开发** MiniGPT-4 基于 Vicuna-13B 构建,结合视觉编码器实现图像理解与对话功能,应用场景包括智能客服、教育工具等[^2]。 3. **定制化聊天机器人** 支持在 Linux/Windows 系统部署,用户可通过修改提示词模板构建个性化对话系统。 #### 四、部署与生态 - **安装要求**:需 Python 3.8+ 环境及至少 16GB 显存(GPU部署) - **开源社区**:提供完整的权重文件和技术文档,开发者可二次优化模型结构[^2]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值