|
| 1 | +# LLM&VLM训练、推理、部署、评测常见问题 |
| 2 | + |
| 3 | +下面是swift使用过程中遇到的一些常见问题。 |
| 4 | + |
| 5 | +## 训练 |
| 6 | + |
| 7 | +### Q1: Swift微调支持的模型和数据集有哪些? |
| 8 | +详见文档[支持的模型和数据集](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E6%94%AF%E6%8C%81%E7%9A%84%E6%A8%A1%E5%9E%8B%E5%92%8C%E6%95%B0%E6%8D%AE%E9%9B%86.html)。 |
| 9 | + |
| 10 | +### Q2: 使用自定义数据集训练时支持的数据格式有哪些? |
| 11 | +llm自定义数据集格式见文档[自定义与拓展](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%8E%E6%8B%93%E5%B1%95.html);vlm自定义数据集格式,不同模型对图像数量的支持不同, 具体参考模型对应的最佳实践文档[Multi-Modal文档](https://swift.readthedocs.io/zh-cn/latest/Multi-Modal/index.html)。 |
| 12 | + |
| 13 | +### Q3: 自定义数据集dataset_info.json格式,如何通过这种方式使用自定义数据集? |
| 14 | +dataset_info.json格式见文档[自定义与拓展](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%8E%E6%8B%93%E5%B1%95.html)。命令行,`--custom_dataset_info xxx.json`,`--dataset dataset_name`。 |
| 15 | + |
| 16 | +### Q4: 如何在界面训练使用自定义数据集? |
| 17 | +界面训练使用自定义数据集与命令行一致,参考文档[自定义与拓展](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%8E%E6%8B%93%E5%B1%95.html)。 |
| 18 | + |
| 19 | +### Q5: 数据集jsonl文件里的一行能不能写成这样?{"index": "00000", "query": "11111", "response": "22222", 'source':'qqq'} |
| 20 | +可以有额外字段的,这些字段不会被使用。 |
| 21 | + |
| 22 | +### Q6: 命令行参数在哪个文档中查看? |
| 23 | +详见文档[命令行参数](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0.html)。 |
| 24 | + |
| 25 | +### Q7: 离线环境训练需要配置的参数有哪些? |
| 26 | +`--model_id_or_path 本地路径`,`--check_model_is_latest false`,详见[命令行参数](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0.html)。 |
| 27 | + |
| 28 | +### Q8: model_type在哪儿查看? |
| 29 | +查看文档[支持的模型和数据集](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E6%94%AF%E6%8C%81%E7%9A%84%E6%A8%A1%E5%9E%8B%E5%92%8C%E6%95%B0%E6%8D%AE%E9%9B%86.html)。 |
| 30 | + |
| 31 | +### Q9: 模型训练完能直接转gguf格式吗? |
| 32 | +目前只支持导出ModelFile,详见文档[OLLaMA导出文档](https://swift.readthedocs.io/zh-cn/latest/LLM/OLLAMA%E5%AF%BC%E5%87%BA%E6%96%87%E6%A1%A3.html)。 |
| 33 | + |
| 34 | +### Q10: swift支持预训练吗,我看只有sft? |
| 35 | +支持,命令行`swift pt`,数据集格式见[自定义与拓展](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%8E%E6%8B%93%E5%B1%95.html)。 |
| 36 | + |
| 37 | +### Q11: 想问一下用lora微调的模型,如果想断点续训的话,是应该先把它合成一整个模型吗,还是可以不合起来,直接通过路径来指定原模型和lora块 |
| 38 | +不合并,`--resume_from_checkpoint output/xxx/vx-xxx/checkpoint-xxx`,详见[命令行参数](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0.html)。 |
| 39 | + |
| 40 | +### Q12: 我想控制一下从网上下载下来的原始模型权重的位置,怎么才能做到把原始的模型放在指定的文件夹里呢? |
| 41 | +可以配置环境变量`MODELSCOPE_CACHE=your_path`将原始的模型存到指定路径;如果用sdk下载,通过`cache_dir="本地地址"`;也可以使用`modelscope download`命令行工具或`git`下载,详见modelscope文档[模型下载](https://modelscope.cn/docs/%E6%A8%A1%E5%9E%8B%E7%9A%84%E4%B8%8B%E8%BD%BD)。训练时`--model_id_or_path`配置本地路径即可。如果需要在离线环境训练,配置`--check_model_is_latest false`,详见[命令行参数](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0.html)。 |
| 42 | + |
| 43 | +### Q13: 有人在用ms-swift遇到过这个问题? |
| 44 | +```text |
| 45 | +[rank6]: pydantic_core._pydantic_core.ValidationError: 1 validation error for DeepSpeedZeroConfig |
| 46 | +[rank6]: stage3_prefetch_bucket_size |
| 47 | +[rank6]: Input should be a valid integer, got a number with a fractional part [type=int_from_float,input_value=11560550.4,in put_type=float] |
| 48 | +[rank6]: For further information visit https://errors.pydantic.dev/2.8/v/int_fro_float |
| 49 | +``` |
| 50 | +`deepspeed`版本降到`0.14.*`。 |
| 51 | + |
| 52 | +### Q14: 有微调qwen-2-vl的完整的教程和命令行吗? |
| 53 | +[Qwen2-VL 最佳实践](https://swift.readthedocs.io/zh-cn/latest/Multi-Modal/qwen2-vl%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5.html)。 |
| 54 | + |
| 55 | +### Q15: 多模态大模型微调有什么支持的trick吗,类似llm的neftune? |
| 56 | +`piassa/olora/dora`这些`lora`的变种或者`fourierft`都可以尝试。参考`sft`参数里面的各种trick,有一些不一定在多模态上适用。 |
| 57 | + |
| 58 | +### Q16: 训练过程中eval得到的acc和对应保存的ckpt去重新推理一遍计算得到的acc不是一致的 |
| 59 | +训练时候的eval_acc和推理时候的acc 计算方式不一样的。`acc_strategy`: 默认为`'token'`, 可选择的值包括: `'token'`, `'sentence'`. |
| 60 | + |
| 61 | +### Q17: 魔搭官方镜像与swift环境 |
| 62 | +`docker run`命令启动容器即可,如:`docker run --gpus all -p 8000:8000 -it -d --name ms registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py310-torch2.3.0-tf2.16.1-1.16.0 /bin/bash`,启动容器后拉最新代码安装swift。 |
| 63 | + |
| 64 | +### Q18: 多机多卡训练命令行 |
| 65 | +```shell |
| 66 | +# 多机多卡 |
| 67 | +# 如果非共用磁盘请在各机器sh中额外指定`--save_on_each_node true`. |
| 68 | +# node0 |
| 69 | +CUDA_VISIBLE_DEVICES=0,1,2,3 \ |
| 70 | +NNODES=2 \ |
| 71 | +NODE_RANK=0 \ |
| 72 | +MASTER_ADDR=127.0.0.1 \ |
| 73 | +NPROC_PER_NODE=4 \ |
| 74 | +swift sft \ |
| 75 | + --model_id_or_path qwen/Qwen-7B-Chat \ |
| 76 | + --dataset AI-ModelScope/blossom-math-v2 \ |
| 77 | + --output_dir output \ |
| 78 | +# node1 |
| 79 | +CUDA_VISIBLE_DEVICES=0,1,2,3 \ |
| 80 | +NNODES=2 \ |
| 81 | +NODE_RANK=1 \ |
| 82 | +MASTER_ADDR=xxx.xxx.xxx.xxx \ |
| 83 | +NPROC_PER_NODE=4 \ |
| 84 | +swift sft \ |
| 85 | + --model_id_or_path qwen/Qwen-7B-Chat \ |
| 86 | + --dataset AI-ModelScope/blossom-math-v2 \ |
| 87 | + --output_dir output \ |
| 88 | +``` |
| 89 | +详见[LLM微调文档](https://swift.readthedocs.io/zh-cn/latest/Instruction/LLM%E5%BE%AE%E8%B0%83%E6%96%87%E6%A1%A3.html) |
| 90 | + |
| 91 | +### Q19: 如何选择template? |
| 92 | +见[issue](https://github.com/modelscope/ms-swift/issues/1813)。 |
| 93 | + |
| 94 | +### Q20: 多卡训练torchrun和swift sft如何使用? |
| 95 | +`swift sft`走的就是`torchrun`。 |
| 96 | + |
| 97 | +### Q21: 有个问题,因为我的sft数据集太大了,然后每次tokenize都需要很久,有解决方案吗? |
| 98 | +使用`lazy_tokenize`,详见[命令行参数](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0.html)。 |
| 99 | + |
| 100 | +### Q22: 训练时,如果两个数据集直接追加一起放在训练集中,模型在训练的时候内部会有shuffle的流程吗?还是按顺序取数据去训练? |
| 101 | +trainer中会随机。 |
| 102 | + |
| 103 | +## 推理 |
| 104 | + |
| 105 | +### Q1:swift推理有文档吗? |
| 106 | +swift支持python脚本、命令行、ui界面推理,详见[LLM推理文档](https://swift.readthedocs.io/zh-cn/latest/Instruction/LLM%E6%8E%A8%E7%90%86%E6%96%87%E6%A1%A3.html)。 |
| 107 | + |
| 108 | +### Q2: 训练后的模型如何使用数据集推理? |
| 109 | +参数`--load_dataset_config true`或`--val_dataset <your-val-dataset>`,见文档[LLM微调文档](https://swift.readthedocs.io/zh-cn/latest/Instruction/LLM%E5%BE%AE%E8%B0%83%E6%96%87%E6%A1%A3.html#%E5%BE%AE%E8%B0%83%E5%90%8E%E6%A8%A1%E5%9E%8B)。 |
| 110 | + |
| 111 | +### Q3: swift推理的时候可以指定下载好的模型吗? |
| 112 | +`--model_id_or_path`配置本地路径即可,详见[命令行参数](https://swift.readthedocs.io/zh-cn/latest/Instruction/%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0.html)。 |
| 113 | + |
| 114 | +### Q4: 我想在一个没有label的数据集上推理,怎么做呢?我看文档里面的数据集格式都是训练集 |
| 115 | +配置参数`--val_dataset <your-val-dataset>`。 |
| 116 | + |
| 117 | +### Q5: 遇到报错ValueError: Input length of input_ids is 35, but `max_length` is set to 20.如何解决? |
| 118 | +```text |
| 119 | +raise ValueError( |
| 120 | +ValueError: Input length of input_ids is 35, but `max_length` is set to 20. This can lead to unexpected behavior. You should consider increasing `max_length` or, better yet, setting `max_new_tokens`. |
| 121 | +``` |
| 122 | +设置model.generation_config.max_new_tokens。 |
| 123 | + |
| 124 | +### Q6: qwen2-vl推理爆显存 |
| 125 | +设置环境变量,SIZE_FACTOR=8 MAX_PIXELS=602112,见文档[Qwen2-VL 最佳实践](https://swift.readthedocs.io/zh-cn/latest/Multi-Modal/qwen2-vl%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5.html)。 |
| 126 | + |
| 127 | +## 部署 |
| 128 | + |
| 129 | +### Q1: 如何部署训练后的模型? |
| 130 | +`swift deploy --ckpt_dir xxx`,见文档[VLLM推理加速与部署](https://swift.readthedocs.io/zh-cn/latest/LLM/VLLM%E6%8E%A8%E7%90%86%E5%8A%A0%E9%80%9F%E4%B8%8E%E9%83%A8%E7%BD%B2.html)。 |
| 131 | + |
| 132 | +### Q2: 如何使用vllm部署进行多卡部署? |
| 133 | +`RAY_memory_monitor_refresh_ms=0 CUDA_VISIBLE_DEVICES=0,1,2,3 swift deploy --model_type qwen-7b --tensor_parallel_size 4`,见文档[VLLM推理加速与部署](https://swift.readthedocs.io/zh-cn/latest/LLM/VLLM%E6%8E%A8%E7%90%86%E5%8A%A0%E9%80%9F%E4%B8%8E%E9%83%A8%E7%BD%B2.html)。 |
| 134 | + |
| 135 | +### Q3: 请问用vllm部署的时候,客户端怎么传入图片? |
| 136 | +详见多模态文档,[vLLM推理加速文档](https://swift.readthedocs.io/zh-cn/latest/Multi-Modal/vLLM%E6%8E%A8%E7%90%86%E5%8A%A0%E9%80%9F%E6%96%87%E6%A1%A3.html)。 |
| 137 | + |
| 138 | +### Q4: 有个问题想问一下,qwen2-7b部署后使用客户端时,调用openai的api要使用client.completions.create,不能使用client.chat.completions.create,但是使用qwen2-7b-instruct-q5_k_m.gguf的时候可以使用client.chat.completions.create,这是为什么呀? |
| 139 | +base模型可以用client.chat.completions.create的,不过这个是兼容行为。 |
| 140 | + |
| 141 | +### Q5: 使用两张卡用swift deploy启动服务端后,用Ctrl+C退出后,会一直有一个python进程,一直占用一张卡的显存,这是正常现象吗? |
| 142 | +需要kill 一下, 这是vllm的问题。 |
| 143 | + |
| 144 | +## 评测 |
| 145 | + |
| 146 | +### Q1: swift支持的评测集有哪些? |
| 147 | +纯文本评测: |
| 148 | +```text |
| 149 | +'obqa', 'cmb', 'AX_b', 'siqa', 'nq', 'mbpp', 'winogrande', 'mmlu', 'BoolQ', 'cluewsc', 'ocnli', 'lambada', |
| 150 | +'CMRC', 'ceval', 'csl', 'cmnli', 'bbh', 'ReCoRD', 'math', 'humaneval', 'eprstmt', 'WSC', 'storycloze', |
| 151 | +'MultiRC', 'RTE', 'chid', 'gsm8k', 'AX_g', 'bustm', 'afqmc', 'piqa', 'lcsts', 'strategyqa', 'Xsum', 'agieval', |
| 152 | +'ocnli_fc', 'C3', 'tnews', 'race', 'triviaqa', 'CB', 'WiC', 'hellaswag', 'summedits', 'GaokaoBench', |
| 153 | +'ARC_e', 'COPA', 'ARC_c', 'DRCD' |
| 154 | +``` |
| 155 | + |
| 156 | +多模态评测: |
| 157 | +```text |
| 158 | +'COCO_VAL', 'MME', 'HallusionBench', 'POPE', 'MMBench_DEV_EN', 'MMBench_TEST_EN', 'MMBench_DEV_CN', 'MMBench_TEST_CN', |
| 159 | +'MMBench', 'MMBench_CN', 'MMBench_DEV_EN_V11', 'MMBench_TEST_EN_V11', 'MMBench_DEV_CN_V11', |
| 160 | +'MMBench_TEST_CN_V11', 'MMBench_V11', 'MMBench_CN_V11', 'SEEDBench_IMG', 'SEEDBench2', |
| 161 | +'SEEDBench2_Plus', 'ScienceQA_VAL', 'ScienceQA_TEST', 'MMT-Bench_ALL_MI', 'MMT-Bench_ALL', |
| 162 | +'MMT-Bench_VAL_MI', 'MMT-Bench_VAL', 'AesBench_VAL', 'AesBench_TEST', 'CCBench', 'AI2D_TEST', 'MMStar', |
| 163 | +'RealWorldQA', 'MLLMGuard_DS', 'BLINK', 'OCRVQA_TEST', 'OCRVQA_TESTCORE', 'TextVQA_VAL', 'DocVQA_VAL', |
| 164 | +'DocVQA_TEST', 'InfoVQA_VAL', 'InfoVQA_TEST', 'ChartQA_TEST', 'MathVision', 'MathVision_MINI', |
| 165 | +'MMMU_DEV_VAL', 'MMMU_TEST', 'OCRBench', 'MathVista_MINI', 'LLaVABench', 'MMVet', 'MTVQA_TEST', |
| 166 | +'MMLongBench_DOC', 'VCR_EN_EASY_500', 'VCR_EN_EASY_100', 'VCR_EN_EASY_ALL', 'VCR_EN_HARD_500', |
| 167 | +'VCR_EN_HARD_100', 'VCR_EN_HARD_ALL', 'VCR_ZH_EASY_500', 'VCR_ZH_EASY_100', 'VCR_ZH_EASY_ALL', |
| 168 | +'VCR_ZH_HARD_500', 'VCR_ZH_HARD_100', 'VCR_ZH_HARD_ALL', 'MMDU', 'MMBench-Video', 'Video-MME', |
| 169 | +'MMBench_DEV_EN', 'MMBench_TEST_EN', 'MMBench_DEV_CN', 'MMBench_TEST_CN', 'MMBench', 'MMBench_CN', |
| 170 | +'MMBench_DEV_EN_V11', 'MMBench_TEST_EN_V11', 'MMBench_DEV_CN_V11', 'MMBench_TEST_CN_V11', 'MMBench_V11', |
| 171 | +'MMBench_CN_V11', 'SEEDBench_IMG', 'SEEDBench2', 'SEEDBench2_Plus', 'ScienceQA_VAL', 'ScienceQA_TEST', |
| 172 | +'MMT-Bench_ALL_MI', 'MMT-Bench_ALL', 'MMT-Bench_VAL_MI', 'MMT-Bench_VAL', 'AesBench_VAL', |
| 173 | +'AesBench_TEST', 'CCBench', 'AI2D_TEST', 'MMStar', 'RealWorldQA', 'MLLMGuard_DS', 'BLINK' |
| 174 | +``` |
| 175 | + |
| 176 | +详见文档[LLM评测文档](https://swift.readthedocs.io/zh-cn/latest/Instruction/LLM%E8%AF%84%E6%B5%8B%E6%96%87%E6%A1%A3.html)。 |
| 177 | + |
| 178 | +### Q2: 如何使用自定义评测集? |
| 179 | +纯文本、多模态自定义评测集必须和某个官方评测集数据格式(pattern)保持一致,见文档[LLM评测文档](https://swift.readthedocs.io/zh-cn/latest/Instruction/LLM%E8%AF%84%E6%B5%8B%E6%96%87%E6%A1%A3.html)。 |
0 commit comments