使用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

相关推荐
我是宝库19 小时前
英文专业论文,可以用维普AIGC检测查AI率吗?
人工智能·aigc·英文论文·论文查重·turnitin系统·turnitin·维普aigc检测
我星期八休息19 小时前
Linux系统编程—基础IO
linux·运维·服务器·c语言·c++·人工智能·算法
大拿爱科技19 小时前
低清视频修复怎么接入批处理?AI画质增强流程拆解
人工智能·自动化·aigc·音视频
zyk_computer19 小时前
AI 时代,或许 Rust 比 Python 更合适
人工智能·后端·python·ai·rust·ai编程·vibe coding
m0_6346667319 小时前
OpenDeepThink:让大模型不再只沿着一条思路硬想
人工智能·深度学习·机器学习
Wilber的技术分享19 小时前
【大模型面试八股 3】大模型微调技术:LoRA、QLoRA等
人工智能·深度学习·面试·lora·peft·qlora·大模型微调
kaixuan_dashen19 小时前
Codex使用DeepSeek API的方法(cc switch + codex bridge方案)
人工智能·codex·deepseek·cc switch·codex bridge
threelab20 小时前
Three.js 初中数学函数可视化 | 三维可视化 / AI 提示词
开发语言·前端·javascript·人工智能·3d·着色器
咖啡里的茶i20 小时前
视觉显著目标的自适应分割与动态网格生成算法研究
人工智能·算法·目标跟踪
怪祝浙20 小时前
AI实战之RAG知识库构建和私有化agent设计
人工智能