使用MS-SWIF框架对大模型进行SFT微调

MS-SWIFT训练框架
Qwen3最佳实践

GPU资源:Tesla V100S x4(32G x 4)

底座模型:Qwen3-1.7B

SFT数据集:
alpaca-gpt4-data-en
alpaca-gpt4-data-zh
自我认知微调数据集

训练

export CUDA_VISIBLE_DEVICES=0,1,2,3

swift sft

--model Qwen/Qwen3-1.7B

--train_type lora

--dataset 'AI-ModelScope/alpaca-gpt4-data-zh#500'

'AI-ModelScope/alpaca-gpt4-data-en#500'

'swift/self-cognition#500'

--torch_dtype bfloat16

--num_train_epochs 1

--per_device_train_batch_size 1

--per_device_eval_batch_size 1

--learning_rate 1e-4

--lora_rank 8

--lora_alpha 32

--target_modules all-linear

--gradient_accumulation_steps 16

--eval_steps 50

--save_steps 50

--save_total_limit 2

--logging_steps 5

--max_length 2048

--output_dir output

--system 'You are a helpful assistant.'

--warmup_ratio 0.05

--dataloader_num_workers 4

--model_author swift

--model_name swift-robot

推理

swift infer

--adapters output/vx-xxx/checkpoint-xxx

--stream true

--temperature 0

--max_new_tokens 2048

swift infer

--adapters /workspace/codes/oss/ms-swift/output/v3-20250905-012245/checkpoint-94

--stream true

--temperature 0

--max_new_tokens 2048

merge-lora并使用vLLM进行推理加速

swift infer

--adapters output/vx-xxx/checkpoint-xxx

--stream true

--merge_lora true

--infer_backend vllm

--max_model_len 8192

--temperature 0

--max_new_tokens 2048

swift infer

--adapters /workspace/codes/oss/ms-swift/output/v3-20250905-012245/checkpoint-94

--stream true

--merge_lora true

--infer_backend vllm

--max_model_len 8192

--temperature 0

--max_new_tokens 2048

报错:ValueError: Bfloat16 is only supported on GPUs with compute capability of at least 8.0. Your Tesla V100S-PCIE-32GB GPU has compute capability 7.0. You can use float16 instead by explicitly setting the dtype flag in CLI, for example: --dtype=half.

原因:用 Bfloat16(Brain Floating Point 16) 数据类型来节省显存、加速训练,需要GPU 计算能力 ≥ 8.0

使用SGlang推理

SGLANG_USE_MODELSCOPE=true python -m sglang.launch_server --model-path /workspace/codes/oss/ms-swift/output/v3-20250905-012245/checkpoint-94-merged --reasoning-parser qwen3

报错:RuntimeError: SGLang only supports sm75 and above.

原因:SGLang 只支持计算能力(Compute Capability)为 sm_75 及以上的 GPU,你的 GPU 的计算能力低于 sm_75,因此无法运行

模型发布

swift export

--adapters /workspace/codes/oss/ms-swift/output/v3-20250905-012245/checkpoint-94

--push_to_hub true

--hub_model_id 'lzhawesome/my-lora-model-Qwen3-1.7B'

--hub_token 'xxxxx'

--use_hf false

相关推荐
阿杰学AI4 分钟前
AI核心知识86——大语言模型之 Superalignment(简洁且通俗易懂版)
人工智能·深度学习·ai·语言模型·超级对齐·superalignment·#ai安全
CV@CV8 分钟前
拆解自动驾驶核心架构——感知、决策、控制三层逻辑详解
人工智能·机器学习·自动驾驶
海心焱12 分钟前
从零开始构建 AI 插件生态:深挖 MCP 如何打破 LLM 与本地数据的连接壁垒
jvm·人工智能·oracle
阿杰学AI13 分钟前
AI核心知识85——大语言模型之 RLAIF(简洁且通俗易懂版)
人工智能·深度学习·ai·语言模型·aigc·rlaihf·基于ai反馈的强化学习
Coco恺撒13 分钟前
【脑机接口】难在哪里,【人工智能】如何破局(2.研发篇)
人工智能·深度学习·开源·人机交互·脑机接口
kebijuelun19 分钟前
ERNIE 5.0:统一自回归多模态与弹性训练
人工智能·算法·语言模型·transformer
Network_Engineer21 分钟前
从零手写LSTM:从门控原理到PyTorch源码级实现
人工智能·pytorch·lstm
芝士爱知识a24 分钟前
AlphaGBM 深度解析:下一代基于 AI 与蒙特卡洛的智能期权分析平台
数据结构·人工智能·python·股票·alphagbm·ai 驱动的智能期权分析·期权
weixin_66825 分钟前
GitHub 2026年AI项目热度分析报告-AI分析-分享
人工智能·github
vlln26 分钟前
【论文速读】达尔文哥德尔机 (Darwin Gödel Machine): 自进化智能体的开放式演化
人工智能·深度学习·ai agent