git clone https://github.com/Control-derek/InternVL2-Tutorial.git
cd InternVL2-Tutorial
环境配置
conda create -n lmdeploy python=3.10 -y
conda activate lmdeploy
pip install lmdeploy gradio==4.44.1 timm==1.0.9
执行 python demo.py



配置训练环境
conda create --name xtuner-env python=3.10 -y
conda activate xtuner-env
pip install -U 'xtuner[deepspeed]' timm==1.0.9
pip install torch==2.4.1 torchvision==0.19.1 torchaudio==2.4.1 --index-url https://download.pytorch.org/whl/cu121
pip install transformers==4.39.0
配置文件
cp /root/InternVL2-Tutorial/xtuner_config/internvl_v2_internlm2_2b_lora_finetune_food.py /root/xtuner/xtuner/configs/internvl/v2/internvl_v2_internlm2_2b_lora_finetune_food.py
path: 需要微调的模型路径,在InternStudio环境下,无需修改。data_root: 数据集所在路径。data_path: 训练数据文件路径。image_folder: 训练图像根路径。prompt_temple: 配置模型训练时使用的聊天模板、系统提示等。使用与模型对应的即可,此处无需修改。max_length: 训练数据每一条最大token数。batch_size: 训练批次大小,可以根据显存大小调整。accumulative_counts: 梯度累积的步数,用于模拟较大的batch_size,在显存有限的情况下,提高训练稳定性。dataloader_num_workers: 指定数据集加载时子进程的个数。max_epochs:训练轮次。optim_type:优化器类型。lr: 学习率betas: Adam优化器的beta1, beta2weight_decay: 权重衰减,防止训练过拟合用max_norm: 梯度裁剪时的梯度最大值warmup_ratio: 预热比例,前多少的数据训练时,学习率将会逐步增加。save_steps: 多少步存一次checkpointsave_total_limit: 最多保存几个checkpoint,设为-1即无限制r: 低秩矩阵的秩,决定了低秩矩阵的维度。lora_alpha缩放因子,用于调整低秩矩阵的权重。lora_dropoutdropout 概率,以防止过拟合。
开始微调
xtuner train internvl_v2_internlm2_2b_lora_finetune_food --deepspeed deepspeed_zero2


python finetune/xtuner/xtuner/configs/internvl/v1_5/convert_to_official.py finetune/xtuner/xtuner/configs/internvl/v2/internvl_v2_internlm2_2b_lora_finetune_food.py work_dirs/internvl_v2_internlm2_2b_lora_finetune_food/iter_640.pth work_dirs/internvl_v2_internlm2_2b_lora_finetune_food/lr35_ep10/
完成后,修改demo.py,再次执行

1047

被折叠的 条评论
为什么被折叠?



