【Qwen】train()函数说明
train()函数文档train(attn_implementationflash_attention_2)Runs the main training loop for Qwen VL (Qwen2-VL, Qwen2.5-VL, Qwen3-VL, or Qwen3-VL-MoE) instruction tuning.Parses command-line arguments for model, data, and training config; loads the appropriate model class and processor; optionally applies LoRA or configures which modules to tune (vision encoder, MLP merger, LLM); builds the supervised data module and Hugging FaceTrainer, runs training (with optional resume), then saves the final model and processor tooutput_dir.ParametersNameTypeDefaultDescriptionattn_implementationstrflash_attention_2Attention implementation passed to the model (e.g.flash_attention_2for Flash Attention 2).Command-line arguments (parsed viaHfArgumentParser)ModelArgumentsmodel_name_or_path(str) – HuggingFace model id or path (e.g.Qwen/Qwen2.5-VL-3B-Instruct,Qwen/Qwen3-VL-8B-Instruct). Used to select model class (Qwen2-VL, Qwen2.5-VL, Qwen3-VL, or Qwen3-VL-MoE).tune_mm_llm(bool) – Whether to train the language model (andlm_head).tune_mm_mlp(bool) – Whether to train the vision merger (MLP).tune_mm_vision(bool) – Whether to train the vision encoder.DataArgumentsdataset_use(str) – Comma-separated dataset names (with optional%Nsampling, e.g.dataset1%50).data_flatten(bool) – Whether to flatten/concat batch sequences.data_packing(bool) – Whether to use packed data (requires preprocessing withpack_data.py).max_pixels(int) – Max image pixels (default28*28*576).min_pixels(int) – Min image pixels (default28*28*16).video_max_frames,video_min_frames,video_max_pixels,video_min_pixels,video_fps– Video sampling and resolution settings.TrainingArguments(extendstransformers.TrainingArguments)cache_dir(str, optional) – Cache directory for model/processor.model_max_length(int) – Maximum sequence length for tokenizer.lora_enable(bool) – IfTrue, apply LoRA and ignoretune_mm_*for the base model.lora_r,lora_alpha,lora_dropout– LoRA rank, alpha, and dropout.mm_projector_lr,vision_tower_lr– Optional learning rates for projector and vision tower.Plus standard Trainer args:output_dir,bf16,per_device_train_batch_size,gradient_accumulation_steps,learning_rate,num_train_epochs,save_steps,gradient_checkpointing,deepspeed, etc.ReturnsNone. Model and processor are saved undertraining_args.output_dir.NotesIfoutput_diralready containscheckpoint-*directories, training is resumed withresume_from_checkpointTrue.Whendata_flattenordata_packingis enabled, the Qwen2 VL attention class is replaced for compatibility.Qwen3-VL MoE models useQwen3VLMoeForConditionalGeneration; other Qwen3-VL models useQwen3VLForConditionalGeneration; Qwen2.5-VL and Qwen2-VL use the corresponding classes inferred frommodel_name_or_path.Example# Typical usage: arguments are passed via command line (e.g. from scripts/sft_qwen3_4b.sh)torchrun --nproc_per_node4qwenvl/train/train_qwen.py\--model_name_or_path Qwen/Qwen3-VL-8B-Instruct\--dataset_use my_dataset\--data_flatten True\--tune_mm_vision False --tune_mm_mlp True --tune_mm_llm True\--output_dir ./output\--bf16 --per_device_train_batch_size4--gradient_accumulation_steps4\--learning_rate 1e-5 --num_train_epochs0.5# Programmatic call (still requires sys.argv or explicit parse for HfArgumentParser)fromqwenvl.train.train_qwenimporttrain train(attn_implementationflash_attention_2)

相关新闻

论文写作智能化:6款AI工具提升效率与成果

论文写作智能化:6款AI工具提升效率与成果

学术写作领域涌现出多款集成人工智能技术的辅助工具,它们基于先进的自然语言处理算法实现论文结构智能生成、文本质量优化及查重检测等核心功能,尤其适用于学位论文撰写与学术报告整理场景。需要强调的是,这些智能化平台应当定位为研究效率的…

2026/5/17 3:26:53 阅读更多 →
免费vs付费AIGC工具:10款主流选项性能对比

免费vs付费AIGC工具:10款主流选项性能对比

�� 10大降AIGC平台核心对比速览 排名 工具名称 降AIGC效率 适用场景 免费/付费 1 askpaper ⭐⭐⭐⭐⭐ 学术论文精准降AI 付费 2 秒篇 ⭐⭐⭐⭐⭐ 快速降AIGC降重 付费 3 Aibiye ⭐⭐⭐⭐ 多学科论文降AI 付费 4 Aicheck ⭐⭐⭐⭐…

2026/5/17 3:26:53 阅读更多 →
《道德经》 德经第一章

《道德经》 德经第一章

《道德经》分为道经(前37章)和德经(后44章)两部分。 你提到的“德经第一章”,在传统通行本(王弼本等)中对应的是全书第38章,通常被视为德经的开篇,也是全书非常核心的一…

2026/5/17 3:26:53 阅读更多 →

最新新闻

AI 压测数据回放:让模型读报告之前先校准口径

AI 压测数据回放:让模型读报告之前先校准口径

AI 压测数据回放:让模型读报告之前先校准口径 一、压测报告不能直接丢给模型 AI 可以帮助分析压测结果,但前提是输入数据口径清楚。很多压测报告里混着预热阶段、限流阶段、错误重试、下游故障和业务噪声。如果直接让模型总结,很容易得到一段…

2026/7/5 1:22:14 阅读更多 →
AI工具链选型:GitHub Copilot与Cursor、Codeium企业开发场景实测对比

AI工具链选型:GitHub Copilot与Cursor、Codeium企业开发场景实测对比

AI工具链选型:GitHub Copilot与Cursor、Codeium企业开发场景实测对比 一、评测体系设计与方法论 AI编码助手已成为开发效率的关键杠杆。本次评测聚焦三项主流工具的实际表现。从四个维度建立可复现的量化评测框架。 %%{init: {theme: base}}%% radartitle AI编码助手…

2026/7/5 1:20:14 阅读更多 →
PyTorch 数据加载瓶颈:GPU 空等时先看 DataLoader

PyTorch 数据加载瓶颈:GPU 空等时先看 DataLoader

PyTorch 数据加载瓶颈:GPU 空等时先看 DataLoader 一、训练慢不一定是模型慢 PyTorch 训练时,很多人看到速度慢就先改模型、调 batch size、换显卡。但如果 GPU 利用率忽高忽低,可能瓶颈根本不在模型,而在数据加载。图片解码、文本…

2026/7/5 1:20:14 阅读更多 →
群晖DSM 7.2.2视频管理终极解决方案:免费恢复Video Station完整功能

群晖DSM 7.2.2视频管理终极解决方案:免费恢复Video Station完整功能

群晖DSM 7.2.2视频管理终极解决方案:免费恢复Video Station完整功能 【免费下载链接】Video_Station_for_DSM_722 Script to install Video Station in DSM 7.2.2 and DSM 7.3 项目地址: https://gitcode.com/gh_mirrors/vi/Video_Station_for_DSM_722 你是否…

2026/7/5 1:20:14 阅读更多 →
云原生可观测性:构建全链路监控体系

云原生可观测性:构建全链路监控体系

引言在微服务架构和容器化部署成为主流的当下,系统的复杂性呈指数级增长。一个请求可能跨越数十个服务实例,传统的日志查看和单点监控已无法满足故障排查的需求。云原生可观测性(Observability)应运而生,它通过Metrics…

2026/7/5 1:18:13 阅读更多 →
工训赛智能小车 PCB 自制指南:从 BTN7971B 四路驱动到主控布局的 5 个要点

工训赛智能小车 PCB 自制指南:从 BTN7971B 四路驱动到主控布局的 5 个要点

工训赛智能小车PCB设计实战:从四路驱动到主控布局的进阶指南在工程训练综合能力竞赛的智能物流搬运赛项中,一辆性能卓越的小车往往始于精良的PCB设计。当现成模块难以满足定制化需求时,自主设计PCB不仅能显著降低成本,更能实现整车…

2026/7/5 1:18:13 阅读更多 →

日新闻

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容 【免费下载链接】BiliTools A cross-platform bilibili toolbox. 跨平台哔哩哔哩工具箱,支持下载视频、番剧等等各类资源 项目地址: https://gitcode.com/GitHub_Trending/bilit/BiliTools …

2026/7/5 0:03:34 阅读更多 →
威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型的陌生现状在忙碌疲惫的一天里,参与了关于混合后量子密码学的讨论,应付端点攻击找茬的人,还参与留言板讨论后,发现“威胁模型”对多数人仍是陌生概念,且多被当作时髦用语。有趣的相关画作有一幅由 Embyr 创作的…

2026/7/5 0:03:34 阅读更多 →
渗透测试入门指南:从零基础到实战环境搭建

渗透测试入门指南:从零基础到实战环境搭建

1. 从“看热闹”到“入门”:我理解的渗透测试到底是什么?每次看到新闻里说某个大公司的数据被“黑”了,或者某个网站被攻击导致服务瘫痪,你是不是和我一样,心里会冒出两个念头:一是“这黑客真厉害”&#x…

2026/7/5 0:07:38 阅读更多 →

周新闻

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容

B站视频下载神器BiliTools:5分钟学会轻松保存任何B站内容 【免费下载链接】BiliTools A cross-platform bilibili toolbox. 跨平台哔哩哔哩工具箱,支持下载视频、番剧等等各类资源 项目地址: https://gitcode.com/GitHub_Trending/bilit/BiliTools …

2026/7/5 0:03:34 阅读更多 →
威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型全解析:从新手入门到实战应用,助你构建安全产品!

威胁模型的陌生现状在忙碌疲惫的一天里,参与了关于混合后量子密码学的讨论,应付端点攻击找茬的人,还参与留言板讨论后,发现“威胁模型”对多数人仍是陌生概念,且多被当作时髦用语。有趣的相关画作有一幅由 Embyr 创作的…

2026/7/5 0:03:34 阅读更多 →
渗透测试入门指南:从零基础到实战环境搭建

渗透测试入门指南:从零基础到实战环境搭建

1. 从“看热闹”到“入门”:我理解的渗透测试到底是什么?每次看到新闻里说某个大公司的数据被“黑”了,或者某个网站被攻击导致服务瘫痪,你是不是和我一样,心里会冒出两个念头:一是“这黑客真厉害”&#x…

2026/7/5 0:07:38 阅读更多 →

月新闻