Skip to content

model_conversion_zh

ymcui edited this page Jan 28, 2024 · 2 revisions

模型合并与转换

以下介绍了手动将LoRA与原版Mixtral-8x7B-v0.1合并得到完整模型的流程。如网络带宽充足,建议直接下载完整版模型。

准备工作

  1. 运行前确保拉取仓库最新版代码:git pull
  2. 确保机器有足够的内存加载完整模型以进行合并模型操作
  3. 安装依赖库(项目根目录requirements.txt):
$ pip install -r requirements.txt

Step 1: 获取原版Mixtral-8x7B-v0.1模型

原版Mixtral-8x7B-v0.1地址:https://huggingface.co/mistralai/Mixtral-8x7B-v0.1

相关文件(建议只下载safetensors格式权重):

config.json
generation_config.json
model-00001-of-00019.safetensors
model-00002-of-00019.safetensors
...
model-00019-of-00019.safetensors
model.safetensors.index.json
special_tokens_map.json
tokenizer_config.json
tokenizer.json
tokenizer.model

Step 2: 合并LoRA权重,生成全量模型权重

这一步骤会合并LoRA权重,生成全量模型权重(safetensors格式)。执行以下命令:

$ python scripts/merge_mixtral_with_chinese_lora_low_mem.py \
    --base_model path_to_original_mixtral_dir \
    --lora_model path_to_chinese_mixtral_lora \
    --output_dir path_to_output_dir 

参数说明:

  • --base_model:存放原版Mixtral-8x7B-v0.1模型权重和配置文件的目录
  • --lora_model:中文Mixtral/Mixtral-Instruct LoRA解压后文件所在目录,也可使用🤗Model Hub模型调用名称(会自动下载)
  • --output_dir:指定保存全量模型权重的目录,默认为./
  • (可选)--verbose:显示合并过程中的详细信息