{
  "id": 574262,
  "title": "5th place solution",
  "content": "<p>First, I would like to express my sincere gratitude to XTX Markets and Kaggle for hosting this excellent competition. Organizing an event of this quality and scale is a significant undertaking. I also extend my appreciation to all the participants for their dedication and contributions.<br>\n<strong>Solution Details (luck + 14b-awq + lmdeploy):</strong></p>\n<ul>\n<li><strong>Public Score:</strong> 28</li>\n<li><strong>Private Score:</strong> 29</li>\n<li><strong>Model:</strong> Deepseek-R1 Distill-Qwen-14B-AWQ (<a href=\"https://huggingface.co/casperhansen/deepseek-r1-distill-qwen-14b-awq\" target=\"_blank\">https://huggingface.co/casperhansen/deepseek-r1-distill-qwen-14b-awq</a> - MIT License)</li>\n<li><strong>Inference Server:</strong> lmdeploy (<a href=\"https://github.com/InternLM/lmdeploy\" target=\"_blank\">https://github.com/InternLM/lmdeploy</a> - Apache 2.0 License)</li>\n<li><strong>Notebook:</strong> <a href=\"https://www.kaggle.com/code/stuveee/aimo-lmdeploy\" target=\"_blank\">https://www.kaggle.com/code/stuveee/aimo-lmdeploy</a></li>\n<li><strong>Key References:</strong> <a href=\"https://www.kaggle.com/code/yekenot/aimo-2-deepseek-r1-distill-qwen-7b-awq\" target=\"_blank\">https://www.kaggle.com/code/yekenot/aimo-2-deepseek-r1-distill-qwen-7b-awq</a> (public notebook of Vladimir Demidov)</li>\n<li><strong>E2E handler for HF Endpoints:</strong> <a href=\"https://huggingface.co/usernameeeeeeee/r1-distill-14b-awq-casperhansen-e2e-solution-handler\" target=\"_blank\">https://huggingface.co/usernameeeeeeee/r1-distill-14b-awq-casperhansen-e2e-solution-handler</a></li>\n<li><strong>Computational Resources (to reach the winning submission):</strong> Kaggle's L4x4 GPU (15h/week)</li>\n</ul>\n<h2>Overview</h2>\n<p>Compared to Vladimir Demidov's public notebook, I utilized the 14B-AWQ version of the DeepSeek-R1 Distill-Qwen model and implemented inference using lmdeploy, resulting in a 28% throughput gain over vllm. I learned these from the public model and discussion shared by the imagination-research team – whose insights were greatly appreciated.<br>\nI attribute my 5th place finish largely to fortunate circumstances, as a near identical submission achieved a public score of only 23. I share this outcome with those who may have more contributions or developed stronger models, yet did not experience the same favorable results. I hope everyone has the opportunity to benefit from a similar stroke of luck in future events.<br>\nFinally, I am also sharing a simulation technique applied during this competition, which reduces evaluation compute from O(N) to O(1). To avoid potential submission waste or a slight performance downgrade, I directly adopted answer extraction/voting codes and prompts from Vladimir Demidov's notebook (though I had my own version). I am very grateful for the original author(s) for their work.</p>\n<h2>Throughput</h2>\n<p>Compared to vllm, lmdeploy increases the throughput by 28% in the 14b-awq setting.</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th>lmdeploy</th>\n<th>sglang</th>\n<th>vllm 0.7.2</th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>14b-awq bs 9 seqlen 13500</td>\n<td>Question Time</td>\n<td>400s</td>\n<td>462s</td>\n<td>511s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td></td>\n<td>Throughput</td>\n<td>304 token/s</td>\n<td>263 tokens/s</td>\n<td>238 tokens/s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>32b-awq bs 9 seqlen 9000</td>\n<td>Question Time</td>\n<td>355s</td>\n<td>374s</td>\n<td>396s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td></td>\n<td>Throughput</td>\n<td>228 token/s</td>\n<td>193 tokens/s</td>\n<td>183 tokens/s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>7b-awq bs 32 seqlen 13500</td>\n<td>Question Time</td>\n<td>403s</td>\n<td>391s</td>\n<td>505s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td></td>\n<td>Throughput</td>\n<td>1073 token/s</td>\n<td>1103 tokens/s</td>\n<td>856 tokens/s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Throughput testing code: <a href=\"https://www.kaggle.com/code/stuveee/aimo2-throughput-sglang-lmdeploy-vllm\" target=\"_blank\">https://www.kaggle.com/code/stuveee/aimo2-throughput-sglang-lmdeploy-vllm</a></li>\n<li>I gave up on vllm engine v1 during the competition because I couldn't reproduce Vladimir Demidov's score on public lb with engine v1 and there were also accuracy downgrade problems reported in the forum. (Later, it seemed that overfitting was the actual cause.)</li>\n<li>note: according to team imagination-research's and tascj's great solution writeups, using int8 kv quantization can further enhance throughput without sacrificing accuracy.</li>\n</ul>\n<h2>Details and Strategies</h2>\n\n<h3>Running details:</h3>\n<ul>\n<li>temperature: 0.9</li>\n<li>top_p: 0.9</li>\n<li>min_p: 0.05</li>\n<li>stop_words: ['&lt;/think&gt;']</li>\n<li>batchsize: 9</li>\n<li>seqlen: 13500</li>\n</ul>\n<h3>Strategies:</h3>\n<ul>\n<li>To avoid complexity, I use the same batchsize and cutoff length for all questions, just to ensure the entire run to complete in about 4.5~4.7h.</li>\n<li>For each question, 9 requests run concurrently, and cutoff at seqlen 13500. Majority vote is applied to get the answer.</li>\n<li>Note: a question-level early stop strategy saves about 4.5~9% tokens without losing accuracy (see next section). However, it might bring bugs and implementing it in lmdeploy turbomind seemed effort consuming during the competition, so I didn't apply it.</li>\n</ul>\n<h2>Simulations</h2>\n<h3>Overview:</h3>\n<p>Doing simulations can help saving compute resource from O(N) to O(1) by alternating the evaluation steps. It helped me to save a lot of submissions and compute resources during the competition.<br>\nVanilla Evaluation:</p>\n<pre><code>For each new scheme:\n   Use llm to generate sufficient samples of this scheme\n   Obtain evaluation result\n</code></pre>\n<p>Simulation:</p>\n<pre><code>Use llm to generate sufficient samples as the 'groundtruth' \nFor each new scheme:\n   Sample from the 'groundtruth' the outputs of this scheme (until the evaluation result converges)\n   Obtain evaluation result\n</code></pre>\n<p>Note that step 1 of simulation only needs to be conducted once, and there is no need to generate new outputs when evaluating new schemes. Also, more samples lead to a more accurate 'groundtruth'.<br>\ncode: <a href=\"https://www.kaggle.com/code/stuveee/aimo2-simulation\" target=\"_blank\">https://www.kaggle.com/code/stuveee/aimo2-simulation</a><br>\nI conducted simulations for the purposes including:</p>\n<ul>\n<li>grid search - batchsize &amp; seqlen</li>\n<li>grid search - temperature</li>\n<li>estimate early stop benefits and losses</li>\n</ul>\n<h2>Grid Search - Batchsize &amp; Seqlen:</h2>\n<p>I empirically used max_question_time = 410s to estimate the seqlen and batchsize that ensures the entire run to finish in 4.5~4.7h, resulting in:</p>\n<table>\n<thead>\n<tr>\n<th>Batchsize</th>\n<th>5</th>\n<th>6</th>\n<th>7</th>\n<th>8</th>\n<th>9</th>\n<th>10</th>\n<th>11</th>\n<th>12</th>\n<th>13</th>\n<th>14</th>\n<th>15</th>\n<th>16</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>seqlen</td>\n<td>20000</td>\n<td>17000</td>\n<td>15500</td>\n<td>14500</td>\n<td>13800</td>\n<td>13300</td>\n<td>12800</td>\n<td>12200</td>\n<td>11600</td>\n<td>11100</td>\n<td>10600</td>\n<td>10200</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>The simulation runs show that the optimal (batchsize, seqlen) is at (10, 13300) or (9, 13800).<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F9089026a7616f70127aa745c9c533bbb%2Fimage-14.png?generation=1745164795971663&amp;alt=media\" alt=\"\"></li>\n</ul>\n<h3>Grid Search - Temperature:</h3>\n<ul>\n<li>Temperature 0.9 seems to have an observable advantage over temperature 0.8 for the 14b model:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2Fc34fb7d42207f0867510bc34f098ad69%2Fimage-15.png?generation=1745164761238215&amp;alt=media\" alt=\"\"></li>\n<li>In the meantime, temperature 0.85/0.95 do not seem better than 0.9:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F0ef08ba151431a6433aedd6206417a40%2Fimage-16.png?generation=1745164883466768&amp;alt=media\" alt=\"\"></li>\n</ul>\n<h3>Estimate Early Stop Benefits and Losses:</h3>\n<ul>\n<li>According to the simulation, at batchsize 9, a radical early stop strategy saves about 9% tokens, while a conservative strategy saves about 4.5%. Both the radical strategy and the conservative strategy have no accuracy loss when batchsize &lt; 12.\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2Faea29449ae85ce167a6f3ecc6393392f%2Fimage-11.png?generation=1745164981705719&amp;alt=media\" alt=\"\"><br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F8ecc3aa403e71d259834161dbe44269f%2Fimage-17.png?generation=1745164842429171&amp;alt=media\" alt=\"\"><br>\nDetails of the strategies are as follows:</li>\n<li>conservative<ul>\n<li>stop when: running_requests + 2nd_most_answer &lt;= 1st_most_answer</li></ul></li>\n<li>radical<ul>\n<li>In addition, stop when: 1st_most_answer &gt;= current_answers * (80% - (current_answers - 5) / (batchsize - 5) * 30%)</li>\n<li>i.e., linearly interpolate between:<ul>\n<li>4 consistent answers when 5 are obtained</li>\n<li>50% consistent answers when all obtained</li></ul></li></ul></li>\n</ul>\n<h2>Failed Attempts</h2>\n<h3>AWQ enhancement</h3>\n<p><strong>groupsize 128 -&gt; 32:</strong> not supported by lmdeploy<br>\n<strong>customized AWQ:</strong></p>\n<ol>\n<li>calib_data: <ul>\n<li>mit-han-lab/pile-val-backup -&gt; selective samples from lightr1-stage2.json (I appreciate LightR1 team for their work), question + solution</li></ul></li>\n<li>max_calib_data_seqlen: <ul>\n<li>512 -&gt; 20000</li></ul></li>\n<li>increasing sample num<br>\n&nbsp;<br>\nNote: though the original AWQ paper shows that AWQ is robust to and don't need a large scale of calibration data, I still made an attempt.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F58aee13b07eb3405e32fdb082952597b%2Fimage-19.png?generation=1745164814021926&amp;alt=media\" alt=\"\"><br>\nThe AIME25 result shows that 14b-awqv2 (i.e., customized AWQ) with 8 calibration samples performs better than 14b-awq-casperhansen. However, it couldn't outperform 14b-awq-casperhansen in my few submission attempts.</li>\n</ol>\n<h3>SFT</h3>\n<p>I failed to conduct SFT because the sequence lengths for reasoning tasks were too large, and there was not enough GPU memory to fit, causing GPU OOMs even with lora.</p>\n<h3>failure of reproducing the public notebook</h3>\n<p>I could not reproduce the score of Vladimir Demidov's notebook in my own code. I spent 20 submissions, bisected the code differences, and ended up finding that either change below leads to a score downgrade from 23~26 to 18~21:</p>\n<ol>\n<li>merely changing vllm engine from v0 to v1</li>\n<li>merely using vllm-0.6.3.post1 engine v0 without seed</li>\n</ol>\n<h2>Appreciation</h2>\n<p>Finally, I would like to once again thank XTX Markets and Kaggle for hosting this wonderful competition, and to all the participants for their incredible effort and dedication. I am also deeply grateful to everyone who supported me throughout this journey. Their encouragement was truly invaluable.</p>",
  "comments": [
    {
      "id": 3183960,
      "author_name": "Arindam Singh",
      "author_url": "",
      "post_date": "2025-04-21T13:25:47.487000",
      "content": "<p>Good Work By the way. <br>\nJust wanted to ask if you find any good solution to this, please add it in the op. </p>\n<blockquote>\n  <p>I failed to conduct SFT because the sequence lengths for reasoning tasks were too large, and there was not enough GPU memory to fit, causing GPU OOMs even with lora.</p>\n</blockquote>",
      "votes": 0,
      "replies": [
        {
          "id": 3184095,
          "author_name": "usernam",
          "author_url": "",
          "post_date": "2025-04-21T16:32:39.303000",
          "content": "<hr>\n<p>Update: </p>\n<ul>\n<li><p><strong>TLDR</strong>:</p>\n<ul>\n<li><p><strong>Solutions to reduce activation memory for long sequence training</strong>:</p>\n<ul>\n<li>(1) MLA + recompute activation</li>\n<li>(2) activation offloading to RAM, may reduce offload overhead to 0 by pin memory.</li></ul></li>\n<li><p><strong>14B full SFT</strong>: Model + Gradient + Optimizer States &gt; 200G, a large server is needed. </p></li>\n<li><p><strong>14B LoRA</strong>: (no guaranteed result)</p>\n<ul>\n<li>A100 40G:<ul>\n<li>implement either or both of solution (1) and (2)</li></ul></li>\n<li>L4x4: <ul>\n<li>Try a training framework supports LoRA + Model Parallelism. Possible options:<ul>\n<li>NeMo-Megatron</li>\n<li>DeepSpeed</li></ul></li></ul></li></ul></li></ul></li>\n</ul>\n\n<p>&nbsp;</p>\n<ul>\n<li>I tried 14B LoRA with Llamafactory and 40GB VRAM:</li>\n</ul>\n<table>\n<thead>\n<tr>\n<th>seqlen</th>\n<th>0 (before forward)</th>\n<th>2000</th>\n<th>5000</th>\n<th>10000</th>\n<th>20000</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>memory (GB)</td>\n<td>30.4</td>\n<td>31.0</td>\n<td>33.1</td>\n<td>37.1</td>\n<td>OOM</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;<br>\nAlso see the bold part below for the updated approach.</p>\n<hr>\n<p>Thank you for your comment!</p>\n<p>For 14B with LoRA, I just did a theoretical VRAM calculation:</p>\n<ul>\n<li>Parameters (16-bit): ~28GB</li>\n<li>Optimizer/Gradient States: ~1GB</li>\n<li>Activations (with gradient checkpointing, seqlen=20000, batchsize=1): ~10.4GB<br>\n<br>\n(seqlen * 16/8 * (intermidiate_size + hidden_size * num_layers) / 1,000,000,000 = 20000 * 16 / 8 * (13824 + 5120 * 48) / 1,000,000,000 = 10.4)</li>\n</ul>\n<p>Total is theoretically around  39.4G,  which is not likely to fit into a 40GB A100 considering other overheads omitted in the compute. <strong>However, I believe using MLA can reduce the activation memory to &lt; 3G. Another approach is to offload activations to RAM, and I guess if pin memory is used smoothly, the offload process might have 0 overhead.</strong></p>\n<p>Kaggle's L4x4 VRAM should be sufficient in aggregate, but successfully utilizing it requires a training framework that supports LoRA combined with model parallelism. I guess NeMo-Megatron or DeepSpeed might work?</p>\n<p>Furthermore, I haven't encountered reports of LoRA alone achieving strong performance on reasoning tasks requiring such long sequences.</p>\n<p>For 14B full SFT, the parameter, gradient, and optimizer states alone sum to roughly 200GB, making it infeasible without a larger server.</p>",
          "votes": 3,
          "replies": [
            {
              "id": 3184925,
              "author_name": "Arindam Singh",
              "author_url": "",
              "post_date": "2025-04-22T16:34:03.823000",
              "content": "<p>DeepSpeed is a strong candidate, as it handles LoRA and model parallelism well, especially with ZeRO Stage 3 for memory optimization. NeMo-Megatron could also work but might require more configuration for LoRA-specific tasks. Hugging Face’s Accelerate with FSDP is another option to explore for distributed training.On LoRA’s performance for long-sequence reasoning tasks, your skepticism is warranted. LoRA tends to underperform on complex reasoning with extended contexts compared to full fine-tuning, as it only updates low-rank adapters. There’s limited evidence of LoRA excelling in such scenarios, especially at this scale, so you might need to experiment or combine it with techniques like prompt tuning or sparse attention.</p>",
              "votes": 0,
              "replies": []
            },
            {
              "id": 3185277,
              "author_name": "",
              "author_url": "",
              "post_date": "2025-04-23T04:47:05.390000",
              "content": "",
              "votes": 0,
              "replies": []
            }
          ]
        }
      ]
    }
  ],
  "comment_count": 4,
  "messages": [
    {
      "id": 3183564,
      "postDate": "2025-04-21T02:19:00.730Z",
      "content": "<p>First, I would like to express my sincere gratitude to XTX Markets and Kaggle for hosting this excellent competition. Organizing an event of this quality and scale is a significant undertaking. I also extend my appreciation to all the participants for their dedication and contributions.<br>\n<strong>Solution Details (luck + 14b-awq + lmdeploy):</strong></p>\n<ul>\n<li><strong>Public Score:</strong> 28</li>\n<li><strong>Private Score:</strong> 29</li>\n<li><strong>Model:</strong> Deepseek-R1 Distill-Qwen-14B-AWQ (<a href=\"https://huggingface.co/casperhansen/deepseek-r1-distill-qwen-14b-awq\" target=\"_blank\">https://huggingface.co/casperhansen/deepseek-r1-distill-qwen-14b-awq</a> - MIT License)</li>\n<li><strong>Inference Server:</strong> lmdeploy (<a href=\"https://github.com/InternLM/lmdeploy\" target=\"_blank\">https://github.com/InternLM/lmdeploy</a> - Apache 2.0 License)</li>\n<li><strong>Notebook:</strong> <a href=\"https://www.kaggle.com/code/stuveee/aimo-lmdeploy\" target=\"_blank\">https://www.kaggle.com/code/stuveee/aimo-lmdeploy</a></li>\n<li><strong>Key References:</strong> <a href=\"https://www.kaggle.com/code/yekenot/aimo-2-deepseek-r1-distill-qwen-7b-awq\" target=\"_blank\">https://www.kaggle.com/code/yekenot/aimo-2-deepseek-r1-distill-qwen-7b-awq</a> (public notebook of Vladimir Demidov)</li>\n<li><strong>E2E handler for HF Endpoints:</strong> <a href=\"https://huggingface.co/usernameeeeeeee/r1-distill-14b-awq-casperhansen-e2e-solution-handler\" target=\"_blank\">https://huggingface.co/usernameeeeeeee/r1-distill-14b-awq-casperhansen-e2e-solution-handler</a></li>\n<li><strong>Computational Resources (to reach the winning submission):</strong> Kaggle's L4x4 GPU (15h/week)</li>\n</ul>\n<h2>Overview</h2>\n<p>Compared to Vladimir Demidov's public notebook, I utilized the 14B-AWQ version of the DeepSeek-R1 Distill-Qwen model and implemented inference using lmdeploy, resulting in a 28% throughput gain over vllm. I learned these from the public model and discussion shared by the imagination-research team – whose insights were greatly appreciated.<br>\nI attribute my 5th place finish largely to fortunate circumstances, as a near identical submission achieved a public score of only 23. I share this outcome with those who may have more contributions or developed stronger models, yet did not experience the same favorable results. I hope everyone has the opportunity to benefit from a similar stroke of luck in future events.<br>\nFinally, I am also sharing a simulation technique applied during this competition, which reduces evaluation compute from O(N) to O(1). To avoid potential submission waste or a slight performance downgrade, I directly adopted answer extraction/voting codes and prompts from Vladimir Demidov's notebook (though I had my own version). I am very grateful for the original author(s) for their work.</p>\n<h2>Throughput</h2>\n<p>Compared to vllm, lmdeploy increases the throughput by 28% in the 14b-awq setting.</p>\n<table>\n<thead>\n<tr>\n<th></th>\n<th></th>\n<th>lmdeploy</th>\n<th>sglang</th>\n<th>vllm 0.7.2</th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n<th></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>14b-awq bs 9 seqlen 13500</td>\n<td>Question Time</td>\n<td>400s</td>\n<td>462s</td>\n<td>511s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td></td>\n<td>Throughput</td>\n<td>304 token/s</td>\n<td>263 tokens/s</td>\n<td>238 tokens/s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>32b-awq bs 9 seqlen 9000</td>\n<td>Question Time</td>\n<td>355s</td>\n<td>374s</td>\n<td>396s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td></td>\n<td>Throughput</td>\n<td>228 token/s</td>\n<td>193 tokens/s</td>\n<td>183 tokens/s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td>7b-awq bs 32 seqlen 13500</td>\n<td>Question Time</td>\n<td>403s</td>\n<td>391s</td>\n<td>505s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n<tr>\n<td></td>\n<td>Throughput</td>\n<td>1073 token/s</td>\n<td>1103 tokens/s</td>\n<td>856 tokens/s</td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n<td></td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>Throughput testing code: <a href=\"https://www.kaggle.com/code/stuveee/aimo2-throughput-sglang-lmdeploy-vllm\" target=\"_blank\">https://www.kaggle.com/code/stuveee/aimo2-throughput-sglang-lmdeploy-vllm</a></li>\n<li>I gave up on vllm engine v1 during the competition because I couldn't reproduce Vladimir Demidov's score on public lb with engine v1 and there were also accuracy downgrade problems reported in the forum. (Later, it seemed that overfitting was the actual cause.)</li>\n<li>note: according to team imagination-research's and tascj's great solution writeups, using int8 kv quantization can further enhance throughput without sacrificing accuracy.</li>\n</ul>\n<h2>Details and Strategies</h2>\n\n<h3>Running details:</h3>\n<ul>\n<li>temperature: 0.9</li>\n<li>top_p: 0.9</li>\n<li>min_p: 0.05</li>\n<li>stop_words: ['&lt;/think&gt;']</li>\n<li>batchsize: 9</li>\n<li>seqlen: 13500</li>\n</ul>\n<h3>Strategies:</h3>\n<ul>\n<li>To avoid complexity, I use the same batchsize and cutoff length for all questions, just to ensure the entire run to complete in about 4.5~4.7h.</li>\n<li>For each question, 9 requests run concurrently, and cutoff at seqlen 13500. Majority vote is applied to get the answer.</li>\n<li>Note: a question-level early stop strategy saves about 4.5~9% tokens without losing accuracy (see next section). However, it might bring bugs and implementing it in lmdeploy turbomind seemed effort consuming during the competition, so I didn't apply it.</li>\n</ul>\n<h2>Simulations</h2>\n<h3>Overview:</h3>\n<p>Doing simulations can help saving compute resource from O(N) to O(1) by alternating the evaluation steps. It helped me to save a lot of submissions and compute resources during the competition.<br>\nVanilla Evaluation:</p>\n<pre><code>For each new scheme:\n   Use llm to generate sufficient samples of this scheme\n   Obtain evaluation result\n</code></pre>\n<p>Simulation:</p>\n<pre><code>Use llm to generate sufficient samples as the 'groundtruth' \nFor each new scheme:\n   Sample from the 'groundtruth' the outputs of this scheme (until the evaluation result converges)\n   Obtain evaluation result\n</code></pre>\n<p>Note that step 1 of simulation only needs to be conducted once, and there is no need to generate new outputs when evaluating new schemes. Also, more samples lead to a more accurate 'groundtruth'.<br>\ncode: <a href=\"https://www.kaggle.com/code/stuveee/aimo2-simulation\" target=\"_blank\">https://www.kaggle.com/code/stuveee/aimo2-simulation</a><br>\nI conducted simulations for the purposes including:</p>\n<ul>\n<li>grid search - batchsize &amp; seqlen</li>\n<li>grid search - temperature</li>\n<li>estimate early stop benefits and losses</li>\n</ul>\n<h2>Grid Search - Batchsize &amp; Seqlen:</h2>\n<p>I empirically used max_question_time = 410s to estimate the seqlen and batchsize that ensures the entire run to finish in 4.5~4.7h, resulting in:</p>\n<table>\n<thead>\n<tr>\n<th>Batchsize</th>\n<th>5</th>\n<th>6</th>\n<th>7</th>\n<th>8</th>\n<th>9</th>\n<th>10</th>\n<th>11</th>\n<th>12</th>\n<th>13</th>\n<th>14</th>\n<th>15</th>\n<th>16</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>seqlen</td>\n<td>20000</td>\n<td>17000</td>\n<td>15500</td>\n<td>14500</td>\n<td>13800</td>\n<td>13300</td>\n<td>12800</td>\n<td>12200</td>\n<td>11600</td>\n<td>11100</td>\n<td>10600</td>\n<td>10200</td>\n</tr>\n</tbody>\n</table>\n<ul>\n<li>The simulation runs show that the optimal (batchsize, seqlen) is at (10, 13300) or (9, 13800).<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F9089026a7616f70127aa745c9c533bbb%2Fimage-14.png?generation=1745164795971663&amp;alt=media\" alt=\"\"></li>\n</ul>\n<h3>Grid Search - Temperature:</h3>\n<ul>\n<li>Temperature 0.9 seems to have an observable advantage over temperature 0.8 for the 14b model:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2Fc34fb7d42207f0867510bc34f098ad69%2Fimage-15.png?generation=1745164761238215&amp;alt=media\" alt=\"\"></li>\n<li>In the meantime, temperature 0.85/0.95 do not seem better than 0.9:<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F0ef08ba151431a6433aedd6206417a40%2Fimage-16.png?generation=1745164883466768&amp;alt=media\" alt=\"\"></li>\n</ul>\n<h3>Estimate Early Stop Benefits and Losses:</h3>\n<ul>\n<li>According to the simulation, at batchsize 9, a radical early stop strategy saves about 9% tokens, while a conservative strategy saves about 4.5%. Both the radical strategy and the conservative strategy have no accuracy loss when batchsize &lt; 12.\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2Faea29449ae85ce167a6f3ecc6393392f%2Fimage-11.png?generation=1745164981705719&amp;alt=media\" alt=\"\"><br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F8ecc3aa403e71d259834161dbe44269f%2Fimage-17.png?generation=1745164842429171&amp;alt=media\" alt=\"\"><br>\nDetails of the strategies are as follows:</li>\n<li>conservative<ul>\n<li>stop when: running_requests + 2nd_most_answer &lt;= 1st_most_answer</li></ul></li>\n<li>radical<ul>\n<li>In addition, stop when: 1st_most_answer &gt;= current_answers * (80% - (current_answers - 5) / (batchsize - 5) * 30%)</li>\n<li>i.e., linearly interpolate between:<ul>\n<li>4 consistent answers when 5 are obtained</li>\n<li>50% consistent answers when all obtained</li></ul></li></ul></li>\n</ul>\n<h2>Failed Attempts</h2>\n<h3>AWQ enhancement</h3>\n<p><strong>groupsize 128 -&gt; 32:</strong> not supported by lmdeploy<br>\n<strong>customized AWQ:</strong></p>\n<ol>\n<li>calib_data: <ul>\n<li>mit-han-lab/pile-val-backup -&gt; selective samples from lightr1-stage2.json (I appreciate LightR1 team for their work), question + solution</li></ul></li>\n<li>max_calib_data_seqlen: <ul>\n<li>512 -&gt; 20000</li></ul></li>\n<li>increasing sample num<br>\n&nbsp;<br>\nNote: though the original AWQ paper shows that AWQ is robust to and don't need a large scale of calibration data, I still made an attempt.<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F58aee13b07eb3405e32fdb082952597b%2Fimage-19.png?generation=1745164814021926&amp;alt=media\" alt=\"\"><br>\nThe AIME25 result shows that 14b-awqv2 (i.e., customized AWQ) with 8 calibration samples performs better than 14b-awq-casperhansen. However, it couldn't outperform 14b-awq-casperhansen in my few submission attempts.</li>\n</ol>\n<h3>SFT</h3>\n<p>I failed to conduct SFT because the sequence lengths for reasoning tasks were too large, and there was not enough GPU memory to fit, causing GPU OOMs even with lora.</p>\n<h3>failure of reproducing the public notebook</h3>\n<p>I could not reproduce the score of Vladimir Demidov's notebook in my own code. I spent 20 submissions, bisected the code differences, and ended up finding that either change below leads to a score downgrade from 23~26 to 18~21:</p>\n<ol>\n<li>merely changing vllm engine from v0 to v1</li>\n<li>merely using vllm-0.6.3.post1 engine v0 without seed</li>\n</ol>\n<h2>Appreciation</h2>\n<p>Finally, I would like to once again thank XTX Markets and Kaggle for hosting this wonderful competition, and to all the participants for their incredible effort and dedication. I am also deeply grateful to everyone who supported me throughout this journey. Their encouragement was truly invaluable.</p>",
      "rawMarkdown": "\nFirst, I would like to express my sincere gratitude to XTX Markets and Kaggle for hosting this excellent competition. Organizing an event of this quality and scale is a significant undertaking. I also extend my appreciation to all the participants for their dedication and contributions.\n\n**Solution Details (luck + 14b-awq + lmdeploy):**\n\n*   **Public Score:** 28\n*   **Private Score:** 29\n*   **Model:** Deepseek-R1 Distill-Qwen-14B-AWQ ([https://huggingface.co/casperhansen/deepseek-r1-distill-qwen-14b-awq](https://huggingface.co/casperhansen/deepseek-r1-distill-qwen-14b-awq) - MIT License)\n*   **Inference Server:** lmdeploy ([https://github.com/InternLM/lmdeploy](https://github.com/InternLM/lmdeploy) - Apache 2.0 License)\n*   **Notebook:** [https://www.kaggle.com/code/stuveee/aimo-lmdeploy](https://www.kaggle.com/code/stuveee/aimo-lmdeploy)\n*   **Key References:** [https://www.kaggle.com/code/yekenot/aimo-2-deepseek-r1-distill-qwen-7b-awq](https://www.kaggle.com/code/yekenot/aimo-2-deepseek-r1-distill-qwen-7b-awq) (public notebook of Vladimir Demidov)\n*   **E2E handler for HF Endpoints:** https://huggingface.co/usernameeeeeeee/r1-distill-14b-awq-casperhansen-e2e-solution-handler\n* **Computational Resources (to reach the winning submission):** Kaggle's L4x4 GPU (15h/week)\n\n## Overview\n\nCompared to Vladimir Demidov's public notebook, I utilized the 14B-AWQ version of the DeepSeek-R1 Distill-Qwen model and implemented inference using lmdeploy, resulting in a 28% throughput gain over vllm. I learned these from the public model and discussion shared by the imagination-research team – whose insights were greatly appreciated.\n\nI attribute my 5th place finish largely to fortunate circumstances, as a near identical submission achieved a public score of only 23. I share this outcome with those who may have more contributions or developed stronger models, yet did not experience the same favorable results. I hope everyone has the opportunity to benefit from a similar stroke of luck in future events.\n\nFinally, I am also sharing a simulation technique applied during this competition, which reduces evaluation compute from O(N) to O(1). To avoid potential submission waste or a slight performance downgrade, I directly adopted answer extraction/voting codes and prompts from Vladimir Demidov's notebook (though I had my own version). I am very grateful for the original author(s) for their work.\n\n\n\n## Throughput\n\n\nCompared to vllm, lmdeploy increases the throughput by 28% in the 14b-awq setting.\n\n\n|||lmdeploy|sglang|vllm 0.7.2|||||||||\n| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n|14b-awq bs 9 seqlen 13500|Question Time| 400s|462s|511s|\n||Throughput|304 token/s | 263 tokens/s|238 tokens/s|\n|32b-awq bs 9 seqlen 9000|Question Time| 355s|374s|396s|\n||Throughput|228 token/s | 193 tokens/s|183 tokens/s|\n|7b-awq bs 32 seqlen 13500|Question Time| 403s|391s|505s|\n||Throughput|1073 token/s | 1103 tokens/s|856 tokens/s|\n\n\n* Throughput testing code: https://www.kaggle.com/code/stuveee/aimo2-throughput-sglang-lmdeploy-vllm\n\n\n* I gave up on vllm engine v1 during the competition because I couldn't reproduce Vladimir Demidov's score on public lb with engine v1 and there were also accuracy downgrade problems reported in the forum. (Later, it seemed that overfitting was the actual cause.)\n\n* note: according to team imagination-research's and tascj's great solution writeups, using int8 kv quantization can further enhance throughput without sacrificing accuracy.\n\n\n\n\n## Details and Strategies\n\n\n<!-- **Running details:** -->\n### Running details:\n\n* temperature: 0.9\n* top_p: 0.9\n* min_p: 0.05\n* stop_words: ['&lt;&#x2F;think&gt;']\n* batchsize: 9\n* seqlen: 13500\n\n### Strategies:\n\n* To avoid complexity, I use the same batchsize and cutoff length for all questions, just to ensure the entire run to complete in about 4.5~4.7h.\n\n* For each question, 9 requests run concurrently, and cutoff at seqlen 13500. Majority vote is applied to get the answer.\n\n* Note: a question-level early stop strategy saves about 4.5~9% tokens without losing accuracy (see next section). However, it might bring bugs and implementing it in lmdeploy turbomind seemed effort consuming during the competition, so I didn't apply it.\n\n\n## Simulations\n\n### Overview:\n\nDoing simulations can help saving compute resource from O(N) to O(1) by alternating the evaluation steps. It helped me to save a lot of submissions and compute resources during the competition.\n\nVanilla Evaluation:\n``` markdown\nFor each new scheme:\n    Use llm to generate sufficient samples of this scheme\n    Obtain evaluation result\n```\n\nSimulation:\n``` markdown\nUse llm to generate sufficient samples as the 'groundtruth' \nFor each new scheme:\n    Sample from the 'groundtruth' the outputs of this scheme (until the evaluation result converges)\n    Obtain evaluation result\n```\n\nNote that step 1 of simulation only needs to be conducted once, and there is no need to generate new outputs when evaluating new schemes. Also, more samples lead to a more accurate 'groundtruth'.\n\n\n\ncode: https://www.kaggle.com/code/stuveee/aimo2-simulation\n\n\nI conducted simulations for the purposes including:\n* grid search - batchsize & seqlen\n* grid search - temperature\n* estimate early stop benefits and losses\n\n\n## Grid Search - Batchsize & Seqlen:\n\nI empirically used max_question_time = 410s to estimate the seqlen and batchsize that ensures the entire run to finish in 4.5~4.7h, resulting in:\n|Batchsize|5|6|7|8|9|10|11|12|13|14|15|16|\n|---|---|---|---|---|---|---|---|---|---|---|---|---|\n|seqlen|20000|17000|15500|14500|13800|13300|12800|12200|11600|11100|10600|10200|\n\n\n\n* The simulation runs show that the optimal (batchsize, seqlen) is at (10, 13300) or (9, 13800).\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F9089026a7616f70127aa745c9c533bbb%2Fimage-14.png?generation=1745164795971663&alt=media)\n\n\n### Grid Search - Temperature:\n\n* Temperature 0.9 seems to have an observable advantage over temperature 0.8 for the 14b model:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2Fc34fb7d42207f0867510bc34f098ad69%2Fimage-15.png?generation=1745164761238215&alt=media)\n\n* In the meantime, temperature 0.85/0.95 do not seem better than 0.9:\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F0ef08ba151431a6433aedd6206417a40%2Fimage-16.png?generation=1745164883466768&alt=media)\n\n\n\n\n### Estimate Early Stop Benefits and Losses:\n\n\n* According to the simulation, at batchsize 9, a radical early stop strategy saves about 9% tokens, while a conservative strategy saves about 4.5%. Both the radical strategy and the conservative strategy have no accuracy loss when batchsize < 12.\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2Faea29449ae85ce167a6f3ecc6393392f%2Fimage-11.png?generation=1745164981705719&alt=media)\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F8ecc3aa403e71d259834161dbe44269f%2Fimage-17.png?generation=1745164842429171&alt=media)\n\nDetails of the strategies are as follows:\n* conservative\n    * stop when: running_requests + 2nd_most_answer <= 1st_most_answer\n* radical\n    * In addition, stop when: 1st_most_answer >= current_answers * (80% - (current_answers - 5) / (batchsize - 5) * 30%)\n    * i.e., linearly interpolate between:\n        * 4 consistent answers when 5 are obtained\n        * 50% consistent answers when all obtained\n\n\n## Failed Attempts\n\n### AWQ enhancement\n\n**groupsize 128 -> 32:** not supported by lmdeploy\n\n**customized AWQ:**\n1. calib_data: \n    * mit-han-lab/pile-val-backup -> selective samples from lightr1-stage2.json (I appreciate LightR1 team for their work), question + solution\n\n2. max_calib_data_seqlen: \n    * 512 -> 20000\n\n3. increasing sample num\n\n&nbsp;\n  Note: though the original AWQ paper shows that AWQ is robust to and don't need a large scale of calibration data, I still made an attempt.\n\n  ![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F2988556%2F58aee13b07eb3405e32fdb082952597b%2Fimage-19.png?generation=1745164814021926&alt=media)\n\n  The AIME25 result shows that 14b-awqv2 (i.e., customized AWQ) with 8 calibration samples performs better than 14b-awq-casperhansen. However, it couldn't outperform 14b-awq-casperhansen in my few submission attempts.\n\n\n\n### SFT\nI failed to conduct SFT because the sequence lengths for reasoning tasks were too large, and there was not enough GPU memory to fit, causing GPU OOMs even with lora.\n\n\n\n### failure of reproducing the public notebook\nI could not reproduce the score of Vladimir Demidov's notebook in my own code. I spent 20 submissions, bisected the code differences, and ended up finding that either change below leads to a score downgrade from 23~26 to 18~21:\n\n1. merely changing vllm engine from v0 to v1\n2. merely using vllm-0.6.3.post1 engine v0 without seed\n\n\n\n\n## Appreciation\n\nFinally, I would like to once again thank XTX Markets and Kaggle for hosting this wonderful competition, and to all the participants for their incredible effort and dedication. I am also deeply grateful to everyone who supported me throughout this journey. Their encouragement was truly invaluable.",
      "votes": 17
    },
    {
      "id": 3183960,
      "postDate": "2025-04-21T13:25:47.487Z",
      "content": "<p>Good Work By the way. <br>\nJust wanted to ask if you find any good solution to this, please add it in the op. </p>\n<blockquote>\n  <p>I failed to conduct SFT because the sequence lengths for reasoning tasks were too large, and there was not enough GPU memory to fit, causing GPU OOMs even with lora.</p>\n</blockquote>",
      "rawMarkdown": "Good Work By the way. \nJust wanted to ask if you find any good solution to this, please add it in the op. \n\n>I failed to conduct SFT because the sequence lengths for reasoning tasks were too large, and there was not enough GPU memory to fit, causing GPU OOMs even with lora.",
      "replies": [
        {
          "id": 3184095,
          "postDate": "2025-04-21T16:32:39.303Z",
          "content": "<hr>\n<p>Update: </p>\n<ul>\n<li><p><strong>TLDR</strong>:</p>\n<ul>\n<li><p><strong>Solutions to reduce activation memory for long sequence training</strong>:</p>\n<ul>\n<li>(1) MLA + recompute activation</li>\n<li>(2) activation offloading to RAM, may reduce offload overhead to 0 by pin memory.</li></ul></li>\n<li><p><strong>14B full SFT</strong>: Model + Gradient + Optimizer States &gt; 200G, a large server is needed. </p></li>\n<li><p><strong>14B LoRA</strong>: (no guaranteed result)</p>\n<ul>\n<li>A100 40G:<ul>\n<li>implement either or both of solution (1) and (2)</li></ul></li>\n<li>L4x4: <ul>\n<li>Try a training framework supports LoRA + Model Parallelism. Possible options:<ul>\n<li>NeMo-Megatron</li>\n<li>DeepSpeed</li></ul></li></ul></li></ul></li></ul></li>\n</ul>\n\n<p>&nbsp;</p>\n<ul>\n<li>I tried 14B LoRA with Llamafactory and 40GB VRAM:</li>\n</ul>\n<table>\n<thead>\n<tr>\n<th>seqlen</th>\n<th>0 (before forward)</th>\n<th>2000</th>\n<th>5000</th>\n<th>10000</th>\n<th>20000</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>memory (GB)</td>\n<td>30.4</td>\n<td>31.0</td>\n<td>33.1</td>\n<td>37.1</td>\n<td>OOM</td>\n</tr>\n</tbody>\n</table>\n<p>&nbsp;<br>\nAlso see the bold part below for the updated approach.</p>\n<hr>\n<p>Thank you for your comment!</p>\n<p>For 14B with LoRA, I just did a theoretical VRAM calculation:</p>\n<ul>\n<li>Parameters (16-bit): ~28GB</li>\n<li>Optimizer/Gradient States: ~1GB</li>\n<li>Activations (with gradient checkpointing, seqlen=20000, batchsize=1): ~10.4GB<br>\n<br>\n(seqlen * 16/8 * (intermidiate_size + hidden_size * num_layers) / 1,000,000,000 = 20000 * 16 / 8 * (13824 + 5120 * 48) / 1,000,000,000 = 10.4)</li>\n</ul>\n<p>Total is theoretically around  39.4G,  which is not likely to fit into a 40GB A100 considering other overheads omitted in the compute. <strong>However, I believe using MLA can reduce the activation memory to &lt; 3G. Another approach is to offload activations to RAM, and I guess if pin memory is used smoothly, the offload process might have 0 overhead.</strong></p>\n<p>Kaggle's L4x4 VRAM should be sufficient in aggregate, but successfully utilizing it requires a training framework that supports LoRA combined with model parallelism. I guess NeMo-Megatron or DeepSpeed might work?</p>\n<p>Furthermore, I haven't encountered reports of LoRA alone achieving strong performance on reasoning tasks requiring such long sequences.</p>\n<p>For 14B full SFT, the parameter, gradient, and optimizer states alone sum to roughly 200GB, making it infeasible without a larger server.</p>",
          "rawMarkdown": "---\nUpdate: \n* **TLDR**:\n\n  * **Solutions to reduce activation memory for long sequence training**:\n      * (1) MLA + recompute activation\n      * (2) activation offloading to RAM, may reduce offload overhead to 0 by pin memory.\n\n  * **14B full SFT**: Model + Gradient + Optimizer States > 200G, a large server is needed. \n  * **14B LoRA**: (no guaranteed result)\n      * A100 40G:\n          * implement either or both of solution (1) and (2)\n      * L4x4: \n          * Try a training framework supports LoRA + Model Parallelism. Possible options:\n              * NeMo-Megatron\n              * DeepSpeed\n<!--       * (1) [MLA + recompute activation](https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/training/arguments.py#L1594C26-L1594C37) -->\n&nbsp;\n\n* I tried 14B LoRA with Llamafactory and 40GB VRAM:\n\n|seqlen|0 (before forward)|2000|5000|10000|20000|\n|---|---|---|---|---|---|\n|memory (GB)|30.4|31.0|33.1|37.1|OOM|\n\n&nbsp;\nAlso see the bold part below for the updated approach.\n\n---\n\n\nThank you for your comment!\n\nFor 14B with LoRA, I just did a theoretical VRAM calculation:\n\n* Parameters (16-bit): ~28GB\n* Optimizer/Gradient States: ~1GB\n* Activations (with gradient checkpointing, seqlen=20000, batchsize=1):~~ ~3.8GB~~ ~10.4GB\n~~(seqlen * intermidiate_size * 16/8 * sqrt(num_layers) / 1,000,000,000 = 20000 * 13824 * 16/8 * sqrt(48) / 1,000,000,000 = 3.8)~~\n(seqlen * 16/8 * (intermidiate_size + hidden_size * num_layers) / 1,000,000,000 = 20000 * 16 / 8 * (13824 + 5120 * 48) / 1,000,000,000 = 10.4)\n\nTotal is theoretically around ~~~33GB (not sure if there is any mistake)~~ 39.4G, ~~which might fit on a 40GB A100.~~ which is not likely to fit into a 40GB A100 considering other overheads omitted in the compute. **However, I believe using MLA can reduce the activation memory to < 3G. Another approach is to offload activations to RAM, and I guess if pin memory is used smoothly, the offload process might have 0 overhead.**\n\n\n\nKaggle's L4x4 VRAM should be sufficient in aggregate, but successfully utilizing it requires a training framework that supports LoRA combined with model parallelism. I guess NeMo-Megatron or DeepSpeed might work?\n\nFurthermore, I haven't encountered reports of LoRA alone achieving strong performance on reasoning tasks requiring such long sequences.\n\nFor 14B full SFT, the parameter, gradient, and optimizer states alone sum to roughly 200GB, making it infeasible without a larger server.",
          "votes": 3,
          "replies": [
            {
              "id": 3184925,
              "postDate": "2025-04-22T16:34:03.823Z",
              "content": "<p>DeepSpeed is a strong candidate, as it handles LoRA and model parallelism well, especially with ZeRO Stage 3 for memory optimization. NeMo-Megatron could also work but might require more configuration for LoRA-specific tasks. Hugging Face’s Accelerate with FSDP is another option to explore for distributed training.On LoRA’s performance for long-sequence reasoning tasks, your skepticism is warranted. LoRA tends to underperform on complex reasoning with extended contexts compared to full fine-tuning, as it only updates low-rank adapters. There’s limited evidence of LoRA excelling in such scenarios, especially at this scale, so you might need to experiment or combine it with techniques like prompt tuning or sparse attention.</p>",
              "rawMarkdown": "DeepSpeed is a strong candidate, as it handles LoRA and model parallelism well, especially with ZeRO Stage 3 for memory optimization. NeMo-Megatron could also work but might require more configuration for LoRA-specific tasks. Hugging Face’s Accelerate with FSDP is another option to explore for distributed training.On LoRA’s performance for long-sequence reasoning tasks, your skepticism is warranted. LoRA tends to underperform on complex reasoning with extended contexts compared to full fine-tuning, as it only updates low-rank adapters. There’s limited evidence of LoRA excelling in such scenarios, especially at this scale, so you might need to experiment or combine it with techniques like prompt tuning or sparse attention."
            },
            {
              "id": 3185277,
              "postDate": "2025-04-23T04:47:05.390Z",
              "rawMarkdown": "",
              "isDeleted": true
            }
          ]
        }
      ]
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-20T06:40:46Z",
  "competition_id": 86023,
  "competition_slug": "ai-mathematical-olympiad-progress-prize-2",
  "team_id": 12781901,
  "solution_url": "/competitions/ai-mathematical-olympiad-progress-prize-2/writeups/usernam-5th-place-solution"
}