AI知识库

53AI知识库

学习大模型的前沿技术与行业应用场景


XTuner 微调 Llama3 图片多模态
发布日期:2024-05-03 11:23:24 浏览次数: 1908





cd ~
git clone https://github.com/SmartFlowAI/Llama3-Tutorial

git clone https://github.com/SmartFlowAI/Llama3-Tutorial:用于克隆一个远程 Git 仓库到本地。

  • git clone: Git 的一个子命令,用于克隆远程仓库。
  • https://github.com/SmartFlowAI/Llama3-Tutorial:要克隆的远程仓库的 URL。在这里,它指的是名为 "Llama3-Tutorial" 的仓库,位于 GitHub 上的 SmartFlowAI 组织下。

mkdir -p ~/model
cd ~/model
ln -s /root/share/new_models/meta-llama/Meta-Llama-3-8B-Instruct .


  • ln -s /root/share/new_models/meta-llama/Meta-Llama-3-8B-Instruct .:这是一个 ln 命令,用于创建符号链接。
    • -s 选项表示创建符号链接。
    • /root/share/new_models/meta-llama/Meta-Llama-3-8B-Instruct 是要创建符号链接指向的目标文件或目录的路径。 "Meta-Llama-3-8B-Instruct" 的文件或目录,位于 /root/share/new_models/meta-llama/ 目录下。
    • . 表示当前目录,即当前工作目录下的 "model" 目录。

mkdir -p ~/model
cd ~/model
ln -s /root/share/new_models/openai/clip-vit-large-patch14-336 .



mkdir -p ~/model
cd ~/model
ln -s /root/share/new_models/xtuner/llama3-llava-iter_2181.pth .cd ~
git clone https://github.com/InternLM/tutorial -b camp2
python ~/tutorial/xtuner/llava/llava_data/repeat.py \
 -i ~/tutorial/xtuner/llava/llava_data/unique_data.json \
 -o ~/tutorial/xtuner/llava/llava_data/repeated_data.json \
 -n 200

git clone https://github.com/InternLM/tutorial -b camp2:使用 Git 克隆一个名为 "tutorial" 的仓库,从指定的分支 "camp2" 中获取内容。具体解释如下:

  • git clone:这是 Git 的一个子命令,用于克隆远程仓库。
  • https://github.com/InternLM/tutorial:这是要克隆的远程仓库的 URL,即 GitHub 上的 "tutorial" 仓库。
  • -b camp2:这是 Git 克隆时的选项,表示只克隆指定分支的内容,这里指定的是名为 "camp2" 的分支。

python ~/tutorial/xtuner/llava/llava_data/repeat.py -i ~/tutorial/xtuner/llava/llava_data/unique_data.json -o ~/tutorial/xtuner/llava/llava_data/repeated_data.json -n 200:运行 Python 脚本文件 "repeat.py",并传递一些参数。具体解释如下:

  • python:这是 Python 解释器的命令,用于执行 Python 脚本。
  • ~/tutorial/xtuner/llava/llava_data/repeat.py:指定要执行的 Python 脚本文件的路径。
  • -i ~/tutorial/xtuner/llava/llava_data/unique_data.json:指定输入文件的路径,这里的 -i 选项表示输入文件。
  • -o ~/tutorial/xtuner/llava/llava_data/repeated_data.json:指定输出文件的路径,这里的 -o 选项表示输出文件。
  • -n 200:指定参数 -n 的值为 200,可能是用于指定重复次数。


xtuner train ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py --work-dir ~/llama3_llava_pth --deepspeed deepspeed_zero2

使用 "xtuner" 程序进行模型训练的命令:

  • xtuner train: 这是命令行的一部分,指示要使用 "xtuner" 程序来进行训练任务。
  • ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py:指定的模型训练配置文件的路径。该配置文件可能包含了模型的结构、超参数等信息。
  • --work-dir ~/llama3_llava_pth: 一个选项参数,用于指定模型训练过程中的工作目录,即训练过程中生成的文件(如日志、模型参数等)存放的位置。
  • --deepspeed deepspeed_zero2: 另一个选项参数,可能用于指定使用 DeepSpeed 进行训练,并且使用 deepspeed_zero2 配置。

xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py \
 ~/model/llama3-llava-iter_2181.pth \
 ~/llama3_llava_pth/pretrain_iter_2181_hf

xtuner convert pth_to_hf ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py \
 ~/llama3_llava_pth/iter_1200.pth \
 ~/llama3_llava_pth/iter_1200_hf

这两个命令都是使用 "xtuner" 程序进行文件格式的转换,将 PyTorch 模型文件(.pth 格式)转换为 Hugging Face 模型文件(HF 格式):

  • xtuner convert pth_to_hf: 这是一个命令行指令,表示要使用 "xtuner" 程序进行文件格式的转换,将 PyTorch 模型文件转换为 Hugging Face 模型文件。
  • ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py: 这是指定的模型配置文件的路径,该文件用于指定模型的结构和参数。
  • ~/model/llama3-llava-iter_2181.pth: 这是指定的 PyTorch 模型文件的路径。
  • ~/llama3_llava_pth/pretrain_iter_2181_hf: 这是指定的转换后的 Hugging Face 模型文件的保存路径。
  • xtuner convert pth_to_hf: 与第一个命令类似,仍然表示文件格式的转换,将 PyTorch 模型文件转换为 Hugging Face 模型文件。
  • ~/Llama3-Tutorial/configs/llama3-llava/llava_llama3_8b_instruct_qlora_clip_vit_large_p14_336_lora_e1_finetune.py: 同样是指定的模型配置文件的路径。
  • ~/llama3_llava_pth/iter_1200.pth: 这是另一个指定的 PyTorch 模型文件的路径。
  • ~/llama3_llava_pth/iter_1200_hf: 这是另一个指定的转换后的 Hugging Face 模型文件的保存路径。


export MKL_SERVICE_FORCE_INTEL=1
xtuner chat /root/model/Meta-Llama-3-8B-Instruct \
 --visual-encoder /root/model/clip-vit-large-patch14-336 \
 --llava /root/llama3_llava_pth/pretrain_iter_2181_hf \
 --prompt-template llama3_chat \
 --image /root/tutorial/xtuner/llava/llava_data/test_img/oph.jpg

用于启动一个名为 "xtuner" 的对话系统,其作用是根据指定的模型进行对话生成。具体解释如下:

  • export MKL_SERVICE_FORCE_INTEL=1:这是一个环境变量设置,用于强制使用 Intel 的 MKL 服务。
  • xtuner chat: 这是一个命令行指令,表示要使用 "xtuner" 程序进行对话生成。
  • /root/model/Meta-Llama-3-8B-Instruct: 这是指定的对话系统的模型文件的路径,即 Meta-Llama-3-8B-Instruct 模型。
  • --visual-encoder /root/model/clip-vit-large-patch14-336: 这是指定的图像编码器模型文件的路径,即 clip-vit-large-patch14-336 模型。
  • --llava /root/llama3_llava_pth/pretrain_iter_2181_hf: 这是指定的 LLAVA 模型文件的路径,即经过预训练后的模型。
  • --prompt-template llama3_chat: 这是指定的对话提示模板,可能是用于指定对话的格式或样式。
  • --image /root/tutorial/xtuner/llava/llava_data/test_img/oph.jpg: 这是指定的要输入的图像文件的路径,即要进行对话的图像。

export MKL_SERVICE_FORCE_INTEL=1
xtuner chat /root/model/Meta-Llama-3-8B-Instruct \
 --visual-encoder /root/model/clip-vit-large-patch14-336 \
 --llava /root/llama3_llava_pth/iter_1200_hf \
 --prompt-template llama3_chat \
 --image /root/tutorial/xtuner/llava/llava_data/test_img/oph.jpg



53AI,企业落地应用大模型首选服务商

产品:大模型应用平台+智能体定制开发+落地咨询服务

承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业

联系我们

售前咨询
186 6662 7370
预约演示
185 8882 0121

微信扫码

与创始人交个朋友

回到顶部

 
扫码咨询