modelscope / modelscope/ms-swift
Qwen3-VL 多标签序列分类(seq_cls, num_labels>2, multi_label_classification)训练后无法用 vLLM 部署
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 1.7k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 136
Description
Checklist / 检查清单
- I have searched existing issues, and this is a new bug report. / 我已经搜索过现有的 issues,确认这是一个新的 bug report。
Bug Description / Bug 描述
ms-swift 版本:3.12.0.dev0
基座模型:Qwen/Qwen3-VL-8B-Instruct
任务:多模态序列分类(seq_cls)
训练参数:--task_type seq_cls --problem_type multi_label_classification --num_labels 20
微调方式:full sft(也复现过 LoRA)
vLLM 版本:0.11.0
问题描述
训练参考脚本:https://github.com/modelscope/ms-swift/blob/release/3.12/examples/train/seq_cls/multi_label/vlm.sh
我用 ms-swift参考上面的脚本 对 Qwen3-VL-8B 做了多标签序列分类微调(num_labels=20,problem_type=multi_label_classification),训练本身正常,得到的 checkpoint 里 score.weight 形状为 [20, 4096],config.json 里也带了 20 项的 id2label / label2id 和 problem_type=multi_label_classification。
用 PtEngine / swift infer --infer_backend pt 推理完全正常,能正确输出 20 维概率。
但问题是:ms-swift 导出的 checkpoint config.json 里 architectures 仍然是 Qwen3VLForConditionalGeneration(生成架构),而不是分类架构。这导致下游用 vLLM 部署时无论怎么配都失败:
复现步骤
- 训练:
swift sft \
--model Qwen/Qwen3-VL-8B-Instruct \
--task_type seq_cls \
--problem_type multi_label_classification \
--num_labels 20 \
--dataset <多标签数据集> \
...
- 查看导出的
config.json:
{
"architectures": ["Qwen3VLForConditionalGeneration"], // ← 仍是生成架构
"model_type": "qwen3_vl",
"problem_type": "multi_label_classification",
"id2label": { "0": "LABEL_0", ..., "19": "LABEL_19" }, // 20 项
"label2id": { "LABEL_0": 0, ..., "LABEL_19": 19 }
}
- 尝试用 vLLM 部署(三种方式全部失败):
方式一:覆盖架构为 Qwen3VLForSequenceClassification
vllm serve ./checkpoint-400/ --runner pooling \
--hf-overrides '{"architectures": ["Qwen3VLForSequenceClassification"], "problem_type": "multi_label_classification"}'
报错(vLLM 该类硬编码为 reranker 的 2 分类头,忽略 num_labels):
AssertionError: Tried to load weights of size torch.Size([20, 4096])
to a parameter of size torch.Size([2, 4096])
方式二:不覆盖架构,仅 --runner pooling
vllm serve ./checkpoint-400/ --runner pooling \
--hf-overrides '{"problem_type": "multi_label_classification"}'
报错(退化成 embedding 模型,没有分类头):
ValueError: There is no module or parameter named 'score' in Qwen3VLForEmbedding.
方式三:保留 config 里的 Qwen3VLForConditionalGeneration
被当作生成模型加载,/classify 端点不可用。
期望行为
希望 ms-swift 在导出 seq_cls 多标签模型时能做到以下之一,方便下游 vLLM 部署:
- 导出时把
config.json的architectures写成对应的分类架构名(如Qwen3VLForSequenceClassification),而不是保留基座的Qwen3VLForConditionalGeneration; - 或在文档中明确说明:Qwen3-VL 这类多模态 seq_cls 模型(num_labels>2)目前只能用
pt后端部署,不支持裸 vLLM,并给出swift deploy --infer_backend pt的推荐用法; - 或提供一个导出为 vLLM 兼容格式的选项(如
swift export时正确写入分类头与架构名)。
疑问
- ms-swift 训练 seq_cls 时,导出 config 的
architectures保留生成架构名是有意为之,还是可以改进为分类架构名? swift deploy --infer_backend vllm对多模态多标签 seq_cls 模型是否已支持?如果支持,正确的参数是什么?
目前的可用方案
pt 后端一切正常:
from swift.llm import PtEngine, BaseArguments
model_path = './checkpoint-400/'
args = BaseArguments.from_pretrained(model_path)
engine = PtEngine(model_path, task_type='seq_cls',
num_labels=args.num_labels, problem_type=args.problem_type)
感谢!
How to Reproduce / 如何复现
vllm serve ./checkpoint-400/ --runner pooling
--hf-overrides '{"architectures": ["Qwen3VLForSequenceClassification"], "problem_type": "multi_label_classification"}'
Additional Information / 补充信息
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with examples/train/seq_cls/multi_label/vlm.sh and inspect the exported checkpoint config.json, especially architectures, num_labels, and problem_type. Compare the PtEngine entry point with the three vLLM commands in the report; done means the supported export or deployment path is documented or validated for this multi-label Qwen3-VL case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100