<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>Pai-Megatron - 标签 - vllbc02&#39;s blogs</title>
        <link>https://blog.vllbc.top/tags/pai-megatron/</link>
        <description>Pai-Megatron - 标签 - vllbc02&#39;s blogs</description>
        <generator>Hugo -- gohugo.io</generator><language>zh-CN</language><copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright><lastBuildDate>Thu, 20 Nov 2025 00:00:00 &#43;0000</lastBuildDate><atom:link href="https://blog.vllbc.top/tags/pai-megatron/" rel="self" type="application/rss+xml" /><item>
    <title>ai阅读megatron</title>
    <link>https://blog.vllbc.top/ai%E9%98%85%E8%AF%BBmegatron/</link>
    <pubDate>Thu, 20 Nov 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/ai%E9%98%85%E8%AF%BBmegatron/</guid>
    <description><![CDATA[<h1 id="megatron-lm-详尽文档">Megatron-LM 详尽文档</h1>
<h2 id="目录">目录</h2>
<ol type="1">
<li>项目概述</li>
<li>架构设计</li>
<li>核心组件</li>
<li>训练脚本</li>
<li>并行策略</li>
<li>数据处理</li>
<li>优化器与调度器</li>
<li>模型实现</li>
<li>示例与工具</li>
<li>性能优化</li>
</ol>
<hr />
<h2 id="项目概述">项目概述</h2>
<h3 id="什么是-megatron-lm">什么是 Megatron-LM？</h3>
<p><strong>Megatron-LM</strong> 是 NVIDIA 开发的用于大规模训练
Transformer 模型的 GPU 优化库。它包含两个主要部分：</p>]]></description>
</item>
<item>
    <title>hf2megatron</title>
    <link>https://blog.vllbc.top/hf2megatron/</link>
    <pubDate>Fri, 14 Nov 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/hf2megatron/</guid>
    <description><![CDATA[<p>需要： - rice vit的hf权重 - llm的hf权重 - 转换代码</p>
<table>
<thead>
<tr>
<th>对比项</th>
<th>Qwen2.5 ViT</th>
<th>RiCE ViT</th>
</tr>
</thead>
<tbody>
<tr>
<td>Attention 类型</td>
<td>Window Attention</td>
<td>Global Attention</td>
</tr>
<tr>
<td>Class Token</td>
<td>无</td>
<td>使用 Class Token</td>
</tr>
<tr>
<td>激活函数</td>
<td>SiLU</td>
<td>GeLU</td>
</tr>
<tr>
<td>layer数</td>
<td>32</td>
<td>24</td>
</tr>
</tbody>
</table>]]></description>
</item>
<item>
    <title>training_model</title>
    <link>https://blog.vllbc.top/training_model/</link>
    <pubDate>Wed, 12 Nov 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/training_model/</guid>
    <description><![CDATA[<h2 id="整体训练流程架构">整体训练流程架构</h2>
<p>这是一个基于Megatron-LM框架的多模态（视觉-语言）模型训练脚本。训练流程从<code>__main__</code>入口开始：</p>
<div class="sourceCode" id="cb1"><pre
class="sourceCode 427:439:examples/qwen2_5_vl/pretrain_qwen.py"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="va">__name__</span> <span class="op">==</span> <span class="st">&quot;__main__&quot;</span>:</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>    train_valid_test_dataloaders_provider.is_distributed <span class="op">=</span> <span class="va">True</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>    pretrain(</span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>        train_valid_test_dataloaders_provider,</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>        model_provider,</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>        ModelType.encoder_or_decoder,</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>        forward_step,</span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>        args_defaults<span class="op">=</span>{<span class="st">&#39;tokenizer_type&#39;</span>: <span class="st">&#39;Qwen2VLTokenizer&#39;</span>},</span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>        extra_args_provider<span class="op">=</span>get_patch_args,</span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a>        process_non_loss_data_func<span class="op">=</span>write_online_eval_to_tensorboard,</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a>        non_loss_data_func<span class="op">=</span>run_online_eval,</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a>    )</span></code></pre></div>
<h2 id="核心组件详解">核心组件详解</h2>
<h3 id="模型构建-model_provider">1. <strong>模型构建
(<code>model_provider</code>)</strong></h3>
<div class="sourceCode" id="cb2"><pre
class="sourceCode 70:133:examples/qwen2_5_vl/pretrain_qwen.py"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> model_provider(</span>
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>    pre_process<span class="op">=</span><span class="va">True</span>, post_process<span class="op">=</span><span class="va">True</span>, add_encoder<span class="op">=</span><span class="va">True</span>, add_decoder<span class="op">=</span><span class="va">True</span>, vp_stage: Optional[<span class="bu">int</span>] <span class="op">=</span> <span class="va">None</span></span>
<span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a>) <span class="op">-&gt;</span> Union[Qwen2_5VLModel]:</span>
<span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a>    args <span class="op">=</span> get_args()</span>
<span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a>    print_rank_0(<span class="st">&quot;start building qwen2-vl model ...&quot;</span>)</span>
<span id="cb2-6"><a href="#cb2-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-7"><a href="#cb2-7" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Config of vit, llm and projector</span></span>
<span id="cb2-8"><a href="#cb2-8" aria-hidden="true" tabindex="-1"></a>    config <span class="op">=</span> core_transformer_config_from_args(args, Qwen2VLTransformerConfig)</span>
<span id="cb2-9"><a href="#cb2-9" aria-hidden="true" tabindex="-1"></a>    use_te <span class="op">=</span> args.transformer_impl <span class="op">==</span> <span class="st">&quot;transformer_engine&quot;</span></span>
<span id="cb2-10"><a href="#cb2-10" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">not</span> use_te:</span>
<span id="cb2-11"><a href="#cb2-11" aria-hidden="true" tabindex="-1"></a>        <span class="cf">raise</span> <span class="pp">NotImplementedError</span>(<span class="st">&quot;The Qwen2-VL model is only implemented with TransformerEngine!&quot;</span>)</span>
<span id="cb2-12"><a href="#cb2-12" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb2-13"><a href="#cb2-13" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> args.rotary_seq_len_interpolation_factor <span class="kw">is</span> <span class="kw">not</span> <span class="va">None</span> <span class="kw">or</span> args.rotary_seq_len_interpolation_factor <span class="op">!=</span> <span class="dv">1</span>:</span>
<span id="cb2-14"><a href="#cb2-14" aria-hidden="true" tabindex="-1"></a>        print_rank_0(<span class="st">&#39;Multimodal RoPE currently not support RoPE interpolation, set to None...&#39;</span>)</span>
<span id="cb2-15"><a href="#cb2-15" aria-hidden="true" tabindex="-1"></a>        args.rotary_seq_len_interpolation_factor <span class="op">=</span> <span class="va">None</span></span>
<span id="cb2-16"><a href="#cb2-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-17"><a href="#cb2-17" aria-hidden="true" tabindex="-1"></a>    vision_config <span class="op">=</span> get_vision_model_config(args, deepcopy(config))</span>
<span id="cb2-18"><a href="#cb2-18" aria-hidden="true" tabindex="-1"></a>    vision_config.pipeline_model_parallel_size <span class="op">=</span> <span class="dv">1</span></span>
<span id="cb2-19"><a href="#cb2-19" aria-hidden="true" tabindex="-1"></a>    vision_config.num_layers_in_first_pipeline_stage <span class="op">=</span> <span class="va">None</span></span>
<span id="cb2-20"><a href="#cb2-20" aria-hidden="true" tabindex="-1"></a>    vision_projector_config <span class="op">=</span> get_vision_projection_config(deepcopy(config), vision_config.hidden_size, vision_config.spatial_merge_size)</span>
<span id="cb2-21"><a href="#cb2-21" aria-hidden="true" tabindex="-1"></a>    </span>
<span id="cb2-22"><a href="#cb2-22" aria-hidden="true" tabindex="-1"></a>    print_rank_0(<span class="st">&quot;building Qwen2-5-VL model in TE...&quot;</span>)</span>
<span id="cb2-23"><a href="#cb2-23" aria-hidden="true" tabindex="-1"></a>    <span class="co"># Layer Specs of vit, llm and projector</span></span>
<span id="cb2-24"><a href="#cb2-24" aria-hidden="true" tabindex="-1"></a>    transformer_layer_spec <span class="op">=</span> get_gpt_layer_with_transformer_engine_spec(args.qk_layernorm)</span>
<span id="cb2-25"><a href="#cb2-25" aria-hidden="true" tabindex="-1"></a>    vision_model_spec <span class="op">=</span> get_qwen2vl_vision_model_spec()</span>
<span id="cb2-26"><a href="#cb2-26" aria-hidden="true" tabindex="-1"></a>    vision_projector_spec <span class="op">=</span> get_mlp_module_spec(add_norm<span class="op">=</span><span class="va">False</span>).submodules</span>
<span id="cb2-27"><a href="#cb2-27" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-28"><a href="#cb2-28" aria-hidden="true" tabindex="-1"></a>    model <span class="op">=</span> Qwen2_5VLModel(</span>
<span id="cb2-29"><a href="#cb2-29" aria-hidden="true" tabindex="-1"></a>        language_transformer_config<span class="op">=</span>config,</span>
<span id="cb2-30"><a href="#cb2-30" aria-hidden="true" tabindex="-1"></a>        language_transformer_layer_spec<span class="op">=</span>transformer_layer_spec,</span>
<span id="cb2-31"><a href="#cb2-31" aria-hidden="true" tabindex="-1"></a>        language_vocab_size<span class="op">=</span>args.padded_vocab_size,</span>
<span id="cb2-32"><a href="#cb2-32" aria-hidden="true" tabindex="-1"></a>        language_max_sequence_length<span class="op">=</span>args.max_position_embeddings,</span>
<span id="cb2-33"><a href="#cb2-33" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-34"><a href="#cb2-34" aria-hidden="true" tabindex="-1"></a>        vision_transformer_config<span class="op">=</span>vision_config,</span>
<span id="cb2-35"><a href="#cb2-35" aria-hidden="true" tabindex="-1"></a>        vision_transformer_layer_spec<span class="op">=</span>vision_model_spec,</span>
<span id="cb2-36"><a href="#cb2-36" aria-hidden="true" tabindex="-1"></a>        drop_vision_class_token<span class="op">=</span><span class="va">False</span>, <span class="co"># </span><span class="al">NOTE</span><span class="co">: no class token to drop?</span></span>
<span id="cb2-37"><a href="#cb2-37" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-38"><a href="#cb2-38" aria-hidden="true" tabindex="-1"></a>        vision_projection_config<span class="op">=</span>vision_projector_config,</span>
<span id="cb2-39"><a href="#cb2-39" aria-hidden="true" tabindex="-1"></a>        vision_projection_layer_spec<span class="op">=</span>vision_projector_spec, </span>
<span id="cb2-40"><a href="#cb2-40" aria-hidden="true" tabindex="-1"></a>        vision_projection_type<span class="op">=</span><span class="st">&#39;mlp&#39;</span>,</span>
<span id="cb2-41"><a href="#cb2-41" aria-hidden="true" tabindex="-1"></a>        allow_missing_vision_projection_checkpoint<span class="op">=</span> <span class="va">False</span>, <span class="co"># </span><span class="al">TODO</span><span class="co">: may parameterized</span></span>
<span id="cb2-42"><a href="#cb2-42" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-43"><a href="#cb2-43" aria-hidden="true" tabindex="-1"></a>        language_position_embedding_type<span class="op">=</span>args.position_embedding_type,</span>
<span id="cb2-44"><a href="#cb2-44" aria-hidden="true" tabindex="-1"></a>        language_rotary_percent<span class="op">=</span>args.rotary_percent,</span>
<span id="cb2-45"><a href="#cb2-45" aria-hidden="true" tabindex="-1"></a>        language_rotary_base<span class="op">=</span>args.rotary_base,</span>
<span id="cb2-46"><a href="#cb2-46" aria-hidden="true" tabindex="-1"></a>        </span>
<span id="cb2-47"><a href="#cb2-47" aria-hidden="true" tabindex="-1"></a>        pre_process<span class="op">=</span>pre_process,</span>
<span id="cb2-48"><a href="#cb2-48" aria-hidden="true" tabindex="-1"></a>        post_process<span class="op">=</span>post_process,</span>
<span id="cb2-49"><a href="#cb2-49" aria-hidden="true" tabindex="-1"></a>        add_decoder<span class="op">=</span>add_decoder,</span>
<span id="cb2-50"><a href="#cb2-50" aria-hidden="true" tabindex="-1"></a>        add_encoder<span class="op">=</span>add_encoder,</span>
<span id="cb2-51"><a href="#cb2-51" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-52"><a href="#cb2-52" aria-hidden="true" tabindex="-1"></a>        fp16_lm_cross_entropy<span class="op">=</span>args.fp16_lm_cross_entropy,</span>
<span id="cb2-53"><a href="#cb2-53" aria-hidden="true" tabindex="-1"></a>        parallel_output<span class="op">=</span><span class="va">True</span>,</span>
<span id="cb2-54"><a href="#cb2-54" aria-hidden="true" tabindex="-1"></a>        language_share_embeddings_and_output_weights<span class="op">=</span><span class="kw">not</span> args.untie_embeddings_and_output_weights,</span>
<span id="cb2-55"><a href="#cb2-55" aria-hidden="true" tabindex="-1"></a>        vp_stage<span class="op">=</span>vp_stage</span>
<span id="cb2-56"><a href="#cb2-56" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb2-57"><a href="#cb2-57" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-58"><a href="#cb2-58" aria-hidden="true" tabindex="-1"></a>    model.freeze(</span>
<span id="cb2-59"><a href="#cb2-59" aria-hidden="true" tabindex="-1"></a>        freeze_language_model<span class="op">=</span><span class="bu">getattr</span>(args, <span class="st">&#39;freeze_LM&#39;</span>, <span class="va">False</span>), </span>
<span id="cb2-60"><a href="#cb2-60" aria-hidden="true" tabindex="-1"></a>        freeze_vision_model<span class="op">=</span><span class="bu">getattr</span>(args, <span class="st">&#39;freeze_ViT&#39;</span>, <span class="va">False</span>), </span>
<span id="cb2-61"><a href="#cb2-61" aria-hidden="true" tabindex="-1"></a>        freeze_vision_projection<span class="op">=</span><span class="va">False</span></span>
<span id="cb2-62"><a href="#cb2-62" aria-hidden="true" tabindex="-1"></a>    )</span>
<span id="cb2-63"><a href="#cb2-63" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb2-64"><a href="#cb2-64" aria-hidden="true" tabindex="-1"></a>    <span class="cf">return</span> model</span></code></pre></div>
<p><strong>作用</strong>：构建Qwen2.5-VL多模态模型 -
创建三个组件的配置：语言模型、视觉模型、视觉投影层 -
使用TransformerEngine实现（强制要求） -
支持冻结语言模型或视觉模型的参数</p>]]></description>
</item>
<item>
    <title>llavaov_1_5</title>
    <link>https://blog.vllbc.top/llavaov_1_5/</link>
    <pubDate>Fri, 07 Nov 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/llavaov_1_5/</guid>
    <description><![CDATA[<h1
id="llava-onevision-1.5-模型与megatron训练框架详细文档">LLaVA-OneVision-1.5
模型与Megatron训练框架详细文档</h1>
<h2 id="目录">目录</h2>
<ol type="1">
<li><a href="#1-项目概述">项目概述</a></li>
<li><a href="#2-架构设计">架构设计</a></li>
<li><a href="#3-模型实现">模型实现</a></li>
<li><a href="#4-训练框架">训练框架</a></li>
<li><a href="#5-数据处理">数据处理</a></li>
<li><a href="#6-训练流程">训练流程</a></li>
<li><a href="#7-模型转换">模型转换</a></li>
<li><a href="#8-配置与优化">配置与优化</a></li>
</ol>
<hr />
<h2 id="项目概述">1. 项目概述</h2>
<h3 id="项目介绍">1.1 项目介绍</h3>
<p>LLaVA-OneVision-1.5
是一个完全开源的大规模多模态模型(LMM)训练框架，具有以下特点： -
<strong>原生分辨率图像处理</strong>：支持高分辨率图像输入 -
<strong>SOTA性能</strong>：在多个多模态基准测试上达到业界领先水平 -
<strong>高效训练</strong>：基于Megatron-LM优化，全流程训练成本约$16,000
-
<strong>完全开源</strong>：提供完整的训练框架、配置、数据集和训练日志</p>]]></description>
</item>
<item>
    <title>cr阅读记录</title>
    <link>https://blog.vllbc.top/cr%E9%98%85%E8%AF%BB%E8%AE%B0%E5%BD%95/</link>
    <pubDate>Mon, 03 Nov 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/cr%E9%98%85%E8%AF%BB%E8%AE%B0%E5%BD%95/</guid>
    <description><![CDATA[<p>核心文件： - vision_transformer_block.py - transformer_block.py -
transformer_config.py - layer_specs.py - visionmodel.py - model.py -
llm.py ## model.py</p>
<p>最顶层的为model.py，组装visionmodel和llm</p>
<h2 id="layer_specs.py">layer_specs.py</h2>
<p>layer_specs.py声明llm或者vit的整体架构，其定义和用法如下（以llm的架构为例子）：</p>]]></description>
</item>
<item>
    <title>qwen3vl&#43;deepseek</title>
    <link>https://blog.vllbc.top/qwen3vl-deepseek/</link>
    <pubDate>Wed, 29 Oct 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/qwen3vl-deepseek/</guid>
    <description><![CDATA[<p>我来分析一下将 DeepSeek-V2 作为 LLM，同时使用 Qwen3-VL
的视觉编码器和投影器是否可行。</p>
<h2 id="可行性分析">🔍 可行性分析</h2>
<h3 id="理论上可行但需要解决多个关键技术问题">✅
<strong>理论上可行，但需要解决多个关键技术问题</strong></h3>
<hr />
<h2 id="主要挑战和兼容性分析">📊 主要挑战和兼容性分析</h2>
<h3 id="位置编码兼容性问题-重大挑战">1️⃣
<strong>位置编码兼容性问题</strong> ⚠️ 重大挑战</h3>
<p><strong>Qwen3-VL 使用 M-RoPE（多模态旋转位置编码）：</strong> - 3D
位置编码：<code>position_ids</code> 形状为
<code>[3, batch, seq_len]</code>（T/H/W 三个维度） - 需要
<code>mrope_section</code> 配置来分配维度 - 在 <code>gpt_model.py</code>
中专门处理 M-RoPE</p>]]></description>
</item>
<item>
    <title>快速入门</title>
    <link>https://blog.vllbc.top/%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/</link>
    <pubDate>Mon, 27 Oct 2025 00:00:00 &#43;0000</pubDate>
    <author>vllbc</author>
    <guid>https://blog.vllbc.top/%E5%BF%AB%E9%80%9F%E5%85%A5%E9%97%A8/</guid>
    <description><![CDATA[<h1 id="pai-megatron-patch-项目深度学习总结文档">Pai-Megatron-Patch
项目深度学习总结文档</h1>
<blockquote>
<p>本文档基于对Pai-Megatron-Patch项目的系统性代码阅读和分析，总结了该项目的核心架构、设计理念、技术实现和最佳实践。</p>]]></description>
</item>
</channel>
</rss>
