<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>GRPO on MakiNaruto's Blog</title><link>https://makinaruto.github.io/tags/grpo/</link><description>Recent content in GRPO on MakiNaruto's Blog</description><generator>Hugo</generator><language>zh-cn</language><lastBuildDate>Tue, 21 Jan 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://makinaruto.github.io/tags/grpo/index.xml" rel="self" type="application/rss+xml"/><item><title>LLM - Training PipLine</title><link>https://makinaruto.github.io/posts/nlp/llm_learning/llm-pipline/</link><pubDate>Tue, 21 Jan 2025 00:00:00 +0000</pubDate><guid>https://makinaruto.github.io/posts/nlp/llm_learning/llm-pipline/</guid><description>&lt;h1 id="大模型工作流程">大模型工作流程&lt;a class="anchorjs-link" href="#%e5%a4%a7%e6%a8%a1%e5%9e%8b%e5%b7%a5%e4%bd%9c%e6%b5%81%e7%a8%8b">&lt;/a>&lt;/h1>&lt;p>预训练、有监督微调、RLHF(奖励建模、强化学习训练)和DPO(直接偏好优化)的主要流程图如下图所示:&lt;br>
&lt;figure>
 &lt;a class="paragraph-image">
 &lt;img
 data-src="https://makinaruto.github.io/content_img/NLP/LLM_Learning/LLM-Pipline/gpt_training.jpg"
 data-action="zoom"
 alt="GPT训练流程"
 
 class="lazyload">
 &lt;/a>
 
&lt;/figure>
&lt;/p>
&lt;p>下面会分开介绍, 每个流程训练时, 所处理的数据, 以及loss等核心模块做了什么.&lt;/p>
&lt;h2 id="pt">PT&lt;a class="anchorjs-link" href="#pt">&lt;/a>&lt;/h2>&lt;h3 id="数据">数据&lt;a class="anchorjs-link" href="#%e6%95%b0%e6%8d%ae">&lt;/a>&lt;/h3>&lt;p>数据格式要求: 清洗过的大段连续文本即可, 如txt.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-txt" data-lang="txt">&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1&lt;/span>&lt;span>第一章论
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2&lt;/span>&lt;span>传染病是指由病原微生物，如朊粒、病毒、衣原体、立克次体、支原体（mycoplasma)细菌真菌、螺旋体和寄生虫，如原虫、蠕虫、医学昆虫感染人体后产生的有传染性、在一定条件下可造成流行的疾病。感染性疾病是指由病原体感染所致的疾病，包括传染病和非传染性感染性疾病。
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3&lt;/span>&lt;span>传染病学是一门研究各种传染病在人体内外发生、发展、传播、诊断、治疗和预防规律的学科。重点研究各种传染病的发病机制、临床表现、诊断和治疗方法，同时兼顾流行病学和预防措施的研究，做到防治结合。
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4&lt;/span>&lt;span>传染病学与其他学科有密切联系，其基础学科和相关学科包括病原生物学、分子生物学、免疫学、人体寄生虫学、流行病学、病理学、药理学和诊断学等。掌握这些学科的基本知识、基本理论和基本技能对学好传染病学起着非常重要的作用。
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5&lt;/span>&lt;span>...
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>将文本全部拼接, 并按照 block_size = 1024进行分割. 将数据集最终处理成如下格式.&lt;br>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1&lt;/span>&lt;span>训练数据集
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2&lt;/span>&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3&lt;/span>&lt;span> &amp;#39;input_ids&amp;#39;: [116947, 67831, 114393, 104442, 67071, ..., 33108, 101304, 100178, 100645], # 1024长度
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4&lt;/span>&lt;span> &amp;#39;attention_mask&amp;#39;: [1, 1, 1, 1, 1, ..., 1, 1, 1, 1], # 1024长度
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5&lt;/span>&lt;span> &amp;#39;labels&amp;#39;: [116947, 67831, 114393, 104442, 67071, ..., 33108, 101304, 100178, 100645] # 1024长度
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6&lt;/span>&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>其中:&lt;br>
&lt;b>input_ids&lt;/b>: 字典对应的token, 训练时会根据其id在embedding层中找到其对应的权重.&lt;br>
&lt;b>attention_mask&lt;/b>: 1表示该token是会被关注的信息, 0表示不关注. 在计算注意力分数softmax时，attention_mask为0的值将为0, 因此其他的信息会获得更多的关注.&lt;br>
&lt;b>labels&lt;/b>: 用于预测时, 计算loss.&lt;br>&lt;/p></description></item></channel></rss>