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

相关推荐
zskj_qcxjqr10 分钟前
数字大健康崛起:艾灸机器人重构就业生态,传统与科技如何共生?
大数据·人工智能·科技·机器人
云澈ovo10 分钟前
AI+传统工作流:Photoshop/Excel的智能插件开发指南
人工智能·excel·photoshop
kalvin_y_liu23 分钟前
【深度相机术语与概念】
人工智能·数码相机·具身智能
山烛30 分钟前
计算机视觉:OpenCV+Dlib 人脸检测
图像处理·人工智能·opencv·计算机视觉·人脸识别·dlib
小苑同学33 分钟前
研究生如何看懂文献?
人工智能·安全·网络安全·安全性测试
补三补四33 分钟前
图卷积网络 (GCN)
网络·人工智能·深度学习·神经网络·算法·机器学习
zhglhy39 分钟前
大语言模型在金融风控中的应用
人工智能·语言模型·自然语言处理
小椿_1 小时前
AI 驱动视频处理与智算革新:蓝耘MaaS释放海螺AI视频生产力
人工智能·深度学习·音视频
AI technophile1 小时前
OpenCV计算机视觉实战(25)——立体视觉详解
人工智能·opencv·计算机视觉
机器之心1 小时前
大神爆肝一个月,复刻DeepMind世界模型,300万参数就能玩实时交互像素游戏
人工智能·openai