Step3-VL-10B 多模态模型微调指南。用于在 GPU 服务器上进行 Step3-VL 模型的 LoRA/全量微调。包含配置、训练、推理完整流程。
Step3-VL-10B 是一个多模态视觉语言模型,支持图像理解和文本生成。本指南涵盖模型架构、微调配置、训练流程和推理方法。
| 组件 | 配置 |
|---|---|
| LLM | Qwen3 (4096 hidden, 36 layers, GQA) |
| 视觉 |
问题: Step3-VL 使用自定义模型架构,forward() 方法期望 patchpixelvalues,但 HuggingFace processor 只输出 pixel_values。
解决方案: 使用 monkey patch 重写 forward 函数,跳过多模态特征,仅使用语言模型部分训练。
python
def patched_forward(
self,
input_ids: torch.Tensor,
attention_mask: torch.Tensor,
position_ids: torch.Tensor = None,
kwargs
):
# 跳过视觉编码器,直接使用语言模型
inputsembeds = self.model.languagemodel.getinputembeddings()(input_ids)
outputs = self.model.language_model(
inputsembeds=inputsembeds,
attentionmask=attentionmask,
positionids=positionids,
return_dict=True,
use_cache=False
)
logits = self.model.languagemodel.lmhead(outputs.lasthiddenstate)
return CausalLMOutputWithPast(logits=logits, loss=None)
问题: PEFT 库检查 vocab_size,但 StepRoboticsConfig 没有这个属性。
解决方案: 重写 _save() 方法,直接保存 adapter 权重到 bin 文件。
python
def saveadapter(model, outputdir):
绕过 PEFT 的 vocab_size 检查,直接保存 adapter 权重
adapter_weights = {}
for name, param in model.named_parameters():
if param.requires_grad:
adapter_weights[name] = param.data.cpu()
os.makedirs(outputdir, existok=True)
torch.save(adapterweights, os.path.join(outputdir, adapter_model.bin))
config = {
r: 16,
lora_alpha: 32,
targetmodules: [qproj, vproj, kproj, o_proj]
}
with open(os.path.join(outputdir, adapterconfig.json), w) as f:
json.dump(config, f)
问题: 计算出的 loss 在 CPU,模型在 GPU。
解决方案: 显式将 loss 移到 GPU。
python
loss = lossfn(logits.view(-1, vocabsize), labels.view(-1))
loss = loss.to(cuda:0) # 显式移到 GPU
/app/
├── dataset.py # 数据集加载
├── model_utils.py # 模型加载 + LoRA
├── inference.py # 推理脚本
├── processor_simple.py # 简化版 processor
└── output/final/ # 输出目录
├── adapter_model.bin
└── adapter_config.json
必须设置以下环境变量:
bash
export NCCLP2PDISABLE=1
export NCCLIBDISABLE=1
export CUDAVISIBLEDEVICES=2 # 单卡训练
RTX 40 系列显卡的 NCCL 通信有兼容问题,禁用 P2P 和 IB 后才能正常训练。
json
{
id: sample_001,
image: images/example.jpg,
conversations: [
{role: user, content: 描述这张图片的内容},
{role: assistant, content: 这张图片展示了一个...}
]
}
| 指标 | 值 |
|---|---|
| 模型参数 | 10.17B |
| LoRA 可训练参数 |
bash
python
from modelutils import loadmodelandprocessor
model, processor = loadmodeland_processor(
model_path=/data/algorithm/tracking/Checkpoints/Step3-VL-10B,
lora_path=/app/output/final,
device=cuda
)
RuntimeError: NCCL error in: /path/to/nccl.cpp
解决: 设置 NCCLP2PDISABLE=1 和 NCCLIBDISABLE=1
AttributeError: StepRoboticsConfig object has no attribute vocab_size
解决: 使用自定义的 save_adapter() 函数,绕过 PEFT 检查
TypeError: forward() got an unexpected keyword argument pixel_values
解决: 使用 monkey patch 重写 forward 方法
解决方案:
优化方案:
该技能支持在以下平台通过对话安装:
帮我安装 SkillHub 和 step3-vl-finetune-1775912101 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 step3-vl-finetune-1775912101 技能
skillhub install step3-vl-finetune-1775912101
文件大小: 3.83 KB | 发布时间: 2026-4-12 11:31