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

相关推荐
Akamai中国21 小时前
Linebreak赋能实时化企业转型:专业系统集成商携手Akamai以实时智能革新企业运营
人工智能·云计算·云服务
LiJieNiub1 天前
读懂目标检测:从基础概念到主流算法
人工智能·计算机视觉·目标跟踪
weixin_519535771 天前
从ChatGPT到新质生产力:一份数据驱动的AI研究方向指南
人工智能·深度学习·机器学习·ai·chatgpt·数据分析·aigc
爱喝白开水a1 天前
LangChain 基础系列之 Prompt 工程详解:从设计原理到实战模板_langchain prompt
开发语言·数据库·人工智能·python·langchain·prompt·知识图谱
takashi_void1 天前
如何在本地部署大语言模型(Windows,Mac,Linux)三系统教程
linux·人工智能·windows·macos·语言模型·nlp
OpenCSG1 天前
【活动预告】2025斗拱开发者大会,共探支付与AI未来
人工智能·ai·开源·大模型·支付安全
生命是有光的1 天前
【深度学习】神经网络基础
人工智能·深度学习·神经网络
数字供应链安全产品选型1 天前
国家级!悬镜安全入选两项“网络安全国家标准应用实践案例”
人工智能·安全·web安全
科技新知1 天前
大厂AI各走“开源”路
人工智能·开源
字节数据平台1 天前
火山引擎Data Agent再拓新场景,重磅推出用户研究Agent
大数据·人工智能·火山引擎