modelscope / modelscope/ms-swift
swift 3.11.0.dev0 seq_cls分类任务推理时输出结果异常,部分输出单个类别,部分输出空类别,部分输出2个类别
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 1.7k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 136
Description
基于qwn2.5-7b-instruct的全参微调任务,自定义分类数据集,60个类别。
【推理结果异常现象】
大部分样本输出为单个类别
约20%样本输出为空[]。但是在top_logprobs中有正常的index结果
约2%样本输出为2个类别。但是在2个类别的logprobs明显有差异
【输出结果样例如下】
单类别
{"response": [10], "labels": 10, "logprobs": {"content": [{"index": [10], "logprobs": [-0.267333984375], "top_logprobs": [{"index": 10, "logprob": -0.267333984375}, {"index": 0, "logprob": -1.7548828125}, {"index": 1, "logprob": -3.265625}, {"index": 22, "logprob": -4.12109375}, {"index": 6, "logprob": -5.08984375},... }]}, "messages": [{"role": "system", "content": "You are a helpful assistant.", "loss": null}, {"role": "user", "content": prompt, "loss": null}, {"role": "assistant", "content": [10]}]}
空类别
{"response": [], "labels": 4, "logprobs": {"content": [{"index": [], "logprobs": [], "top_logprobs": [{"index": 4, "logprob": -1.1015625}, {"index": 1, "logprob": -1.8076171875}, {"index": 5, "logprob": -4.515625}, {"index": 12, "logprob": -4.734375}, {"index": 24, "logprob": -4.76953125}, ...}]}]}, "messages": [{"role": "system", "content": prompt, "loss": null}, {"role": "assistant", "content": []}]}
多类别
{"response": [10, 22], "labels": 10, "logprobs": {"content": [{"index": [10, 22], "logprobs": [-0.36376953125, -0.457763671875], "top_logprobs": [{"index": 10, "logprob": -0.36376953125}, {"index": 22, "logprob": -0.457763671875}, {"index": 0, "logprob": -2.974609375}, {"index": 43, "logprob": -4.16796875}, {"index": 1, "logprob": -4.48046875}, ...}]}]}, "messages": [{"role": "system", "content": "You are a helpful assistant.", "loss": null}, {"role": "user", "content": prompt, "loss": null}, {"role": "assistant", "content": [10, 22]}]}
【推理命令如下】
NPROC_PER_NODE=4
CUDA_VISIBLE_DEVICES=0,1,2,3
swift infer
--model model_dir
--infer_backend pt
--custom_dataset_info /nfs/ybs/ms-swift-data/dataset_info.json
--val_dataset my_test_cls
--temperature 0
--model_type qwen2_5
--torch_dtype float16
--result_path result_path
--num_labels 60
--task_type seq_cls
--use_chat_template true
--problem_type multi_label_classification
【训练yaml如下】
model: qwn2.5-7b-instruct
model_type: qwen2_5
train_type: full
deepspeed: zero3
custom_dataset_info: /nfs/ybs/ms-swift-data/dataset_info.json
dataset: my_dataset_cls
max_length: 4400
split_dataset_ratio: 0
output_dir: output_dir
add_version: False
logging_steps: 10
save_steps: 100
overwrite_output_dir: true
save_only_model: true
per_device_train_batch_size: 4
gradient_accumulation_steps: 1
learning_rate: 6.0e-6
num_train_epochs: 5.0
lr_scheduler_type: cosine
warmup_ratio: 0.0
torch_dtype: bfloat16
ddp_timeout: 180000000
attn_impl: flash_attention_2
weight_decay: 0.1
adam_epsilon: 0.0001
adam_beta1: 0.9
adam_beta2: 0.95
optim: adamw_torch_fused
num_labels: 60
task_type: seq_cls
use_chat_template: true
problem_type: multi_label_classification
【训练命令如下】
NPROC_PER_NODE=8
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
swift sft --config my_config.yaml
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 by reproducing the issue with the provided swift infer command, dataset_info.json, and seq_cls/multi-label settings. Trace the inference path handling response, labels, and logprobs, comparing the empty, single-class, and multi-class examples. Done means the output behavior is explained and corrected or documented for this configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100