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

相关推荐
xsd202411186 小时前
智驾多传感器时间同步:从硬件触发到软触发PPS+GPRMC
人工智能
飞哥数智坊6 小时前
Personal Agent 火了,新酿还是旧酒?
人工智能·agent
秦先生在广东6 小时前
HyperFrames 深度解析:面向 AI 代理的确定性视频渲染框架
人工智能
秦先生在广东6 小时前
Impeccable:为 AI 编码代理重塑前端设计确定性的开源技能框架深度解析
人工智能
水如烟6 小时前
孤能子视角:AI如何找物理规律——观察符分辨率切换的扫描机制
人工智能
生活愉甜6 小时前
森马SEMIR LAB全球首家概念店落地武康路,“WUKANG368”新地标就位
大数据·人工智能
乐迪信息6 小时前
港口船舶逆行怎么管?AI防爆摄像机搭载智能检测算法
大数据·人工智能·深度学习·算法·计算机视觉
秦先生在广东7 小时前
Context Mode 深度解析:重构 AI 编码代理的上下文管理范式
人工智能
可乐ea7 小时前
从第一性原理构建 AI Agent:提示词、工具、技能与记忆全解剖
数据库·人工智能·工具调用·ai智能体·提示词工程·agent开发·智能体记忆
东方佑7 小时前
事件发生与智能:微观一致性与宏观涌现性
人工智能·深度学习·自然语言处理·架构·gru