<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: 张逸群</title>
    <description>The latest articles on Forem by 张逸群 (@zhangyiqun018).</description>
    <link>https://forem.com/zhangyiqun018</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2805106%2F9a9f8aae-5269-494c-8d66-072ac7b93a2a.jpeg</url>
      <title>Forem: 张逸群</title>
      <link>https://forem.com/zhangyiqun018</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/zhangyiqun018"/>
    <language>en</language>
    <item>
      <title>GRPO踩坑记录2</title>
      <dc:creator>张逸群</dc:creator>
      <pubDate>Tue, 04 Feb 2025 00:44:27 +0000</pubDate>
      <link>https://forem.com/zhangyiqun018/grpocai-keng-ji-lu-2-4ee1</link>
      <guid>https://forem.com/zhangyiqun018/grpocai-keng-ji-lu-2-4ee1</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndvy1jje53ll4ownbwym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fndvy1jje53ll4ownbwym.png" alt="Image description" width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;这次我更换了任务，结合了MMLUPro、MELD和MATH三个数据集，并统一使用了相同的系统提示，模型仍然采用Qwen2.5-0.5B-Instruct （足够小，且不需要冷启动）。&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PROMPT=(
    "A conversation between User and Assistant. The user asks a question, and the Assistant solves it. "
    "The assistant first thinks about the reasoning process in the mind and then provides the user with the answer. The reasoning "
    "process and answer are enclosed with &amp;lt;think&amp;gt; &amp;lt;/think&amp;gt; and &amp;lt;answer&amp;gt; &amp;lt;/answer&amp;gt; tags, respectively, i.e.., "
    "&amp;lt;think&amp;gt; reasoning process here &amp;lt;/think&amp;gt; &amp;lt;answer&amp;gt; answer here &amp;lt;/answer&amp;gt;"
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;奖励函数分为两种：第一种是 &lt;code&gt;format_reward&lt;/code&gt;，顾名思义，用于检测输出是否符合指定的格式 &lt;code&gt;&amp;lt;think&amp;gt; &amp;lt;/think&amp;gt; &amp;lt;answer&amp;gt; &amp;lt;/answer&amp;gt;&lt;/code&gt;；第二种是 &lt;code&gt;accuracy_reward&lt;/code&gt;，用于检测输出的准确性。&lt;br&gt;
从训练日志中可以清楚地看到，format_reward经历了一次显著的提升（这是否可以被称为一种涌现现象？），而accuracy_reward则一直在大幅波动，没有明显的上升趋势。这表明，模型只是通过“模仿”特定格式来提高得分，而没有通过先思考后行动的方式来显著提升任务性能。&lt;br&gt;
我测试了一道题目，能够看到模型只是在拙劣的模仿这种格式，而没有学会真的思考。&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;think&amp;gt; 
First, we need to understand what's happening when we "double" a number. Doubling a number means multiplying it by 2, so if we have a number x, doubling it will be represented as 2x.
&amp;lt;/think&amp;gt;

&amp;lt;answer&amp;gt;Let's denote the number as x. According to the problem, doubling the number and then increasing it by 5 gives 15.

According to our formula, it would look like this: 
\[ 2x + 5 = 15 \]

Now we need to solve for x by first subtracting 5 from both sides of the equation:
\[ 2x + 5 - 5 = 15 - 5 \]
\[ 2x = 10 \]

Afterwards, we divide both sides by 2 to solve for x:
\[ \frac{2x}{2} = \frac{10}{2} \]
\[ x = 5 \]

Therefore, the number in question is 5.&amp;lt;/answer&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;分析了一下，原因可能有两个：（1）模型尺寸太小；（2）奖励函数设置有问题。&lt;/p&gt;

</description>
    </item>
    <item>
      <title>GRPO Pitfalls Record</title>
      <dc:creator>张逸群</dc:creator>
      <pubDate>Sun, 02 Feb 2025 14:44:32 +0000</pubDate>
      <link>https://forem.com/zhangyiqun018/grpo-pitfalls-record-1130</link>
      <guid>https://forem.com/zhangyiqun018/grpo-pitfalls-record-1130</guid>
      <description>&lt;p&gt;I discovered that Hugging Face has adapted the core technology GRPO of DeepSeek-R1, so I decided to give it a try. I chose the ERC task (Emotion Recognition in Conversations) to see if a smaller model could be cold-start trained on a single task using reinforcement learning and improve task performance.&lt;/p&gt;

&lt;p&gt;First, this technology is very memory-intensive. I initially tried to train &lt;code&gt;gemma-2–2b&lt;/code&gt; and &lt;code&gt;qwen-2.5–3b-instruct&lt;/code&gt; using an A100–80G, but the memory was insufficient. &lt;/p&gt;

&lt;p&gt;After switching to &lt;code&gt;qwen-2.5–0.5b-instruct&lt;/code&gt;, the memory issue was resolved. Secondly, the inference speed is particularly slow because the same prompt needs to be repeatedly sampled during training. &lt;/p&gt;

&lt;p&gt;Fortunately, Hugging Face quickly adapted vLLM, improving efficiency. However, this brought new issues:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using vLLM to assist GRPO training requires at least two GPUs, which actually increases the resource demand, merely shifting the inference load to a dedicated card.&lt;/li&gt;
&lt;li&gt;There was a persistent strange error &lt;code&gt;_assert_memory_footprint_increased_during_profiling&lt;/code&gt;. After checking the issues in trl, it seems that upgrading vLLM to version 0.7 is necessary to resolve it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;datasets==3.0.1
trl==0.14.0
transformers==4.48.2
peft==0.14.0
accelerate==1.3.0
deepspeed==0.15.3
torch==2.5.1
vllm==0.7.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqmy0qlhdbihnsxkorkw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqmy0qlhdbihnsxkorkw.png" alt="wandb" width="800" height="328"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk3tviix304lcqfaunzh6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk3tviix304lcqfaunzh6.png" alt="gpus quote" width="800" height="318"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  chinese version
&lt;/h1&gt;

&lt;p&gt;发现Hugging Face已经对DeepSeek-R1的核心技术GRPO进行了适配，我决定尝试一下。我选择了ERC任务（对话情绪识别），想看看一个较小的模型能否通过强化学习在单一任务上进行冷启动训练，并提升任务性能。&lt;br&gt;
首先，这项技术非常耗费显存。我最初尝试用A100–80G来训练gemma-2–2b和qwen-2.5–3b-instruct，但显存不够用。调整为qwen-2.5–0.5b-instruct后，显存才不再爆掉。其次，推理速度特别慢，因为训练过程中需要对同一个提示反复进行采样。不过，值得庆幸的是，Hugging Face很快适配了vLLM，提高了效率。但这又带来了新的问题：&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;使用vLLM来辅助GRPO训练至少需要两张显卡，对资源的需求实际上更高了，只是把推理负载转移到一张专门的卡上。&lt;/li&gt;
&lt;li&gt;一直出现奇怪的错误&lt;code&gt;_assert_memory_footprint_increased_during_profiling&lt;/code&gt;，查了一下trl的issue，似乎需要把vLLM提升到0.7版本才能解决。&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>deepseek</category>
      <category>huggingface</category>
    </item>
  </channel>
</rss>
