<script data-pm-proxy="intercept"></script><?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[Maxime Labonne]]></title><description><![CDATA[Technical deep dives and analyses on LLMs and post-training.]]></description><link>https://maximelabonne.substack.com</link><image><url>https://substackcdn.com/image/fetch/$s_!ytBE!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F62c15ee1-2bcd-4f98-a38c-6f4c61b89c3a_657x657.png</url><title>Maxime Labonne</title><link>https://maximelabonne.substack.com</link></image><generator>Substack</generator><lastBuildDate>Wed, 02 Sep 2026 02:26:05 GMT</lastBuildDate><atom:link href="/__u/maximelabonne.substack.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Maxime Labonne]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[maximelabonne@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[maximelabonne@substack.com]]></itunes:email><itunes:name><![CDATA[Maxime Labonne]]></itunes:name></itunes:owner><itunes:author><![CDATA[Maxime Labonne]]></itunes:author><googleplay:owner><![CDATA[maximelabonne@substack.com]]></googleplay:owner><googleplay:email><![CDATA[maximelabonne@substack.com]]></googleplay:email><googleplay:author><![CDATA[Maxime Labonne]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The State of the Open Frontier]]></title><description><![CDATA[Tracking the gap between open and closed models at the frontier]]></description><link>https://maximelabonne.substack.com/p/the-state-of-the-open-frontier</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/the-state-of-the-open-frontier</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 06 Jul 2026 08:42:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Xvby!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Xvby!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 424w, /__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 848w, /__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Xvby!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:928371,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/201523304?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 424w, /__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 848w, /__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Xvby!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37e8617a-5322-4062-b4ba-8448173af1f7_1920x1080.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><blockquote><p><em>Updated July 28, 2026: Kimi K3 replaces Kimi K2.6 and takes the open lead</em></p></blockquote><p>If closed models like Claude and GPT are more performant, why should you use open models at all? The first reason is <strong>cost</strong>: leading open models now deliver near-frontier intelligence at a fraction of the cost of closed-API models. For everyday, high-volume work, they offer a <strong>better tradeoff between price and intelligence</strong>.</p><p>The second reason is <strong>control</strong>. Two recent decisions show the risk of relying on a closed model: Anthropic restricted Mythos to trusted partners, and the US government pulled Fable 5 from the market. An API model can be deprecated, rerouted, or pulled away from you. One that you host yourself is <strong>stable, can be fine-tuned, and doesn&#8217;t leak your data</strong>.</p><p>This article analyzes the seven strongest open models and tracks how far they trail the closed frontier.</p><div class="callout-block" data-callout="true"><h4>Summary</h4><p>&#8226; <strong>Six of the seven best open models are Chinese</strong>, and the US entry trails the leaders by a large gap.</p><p>&#8226; <strong>Everyone converged on sparse MoE</strong>, while attention went the other way: no two models share a design.</p><p>&#8226; <strong>On-policy distillation</strong> is the new standard for post-training, either replacing or complementing reinforcement learning.</p></div><h2>The frontier at a glance</h2><p>Across 2026, open models nearly caught up to the closed frontier, then fell behind as the closed labs released stronger models. GLM-5.2 has now closed most of that gap again. Kimi K3 has now pulled them back to within three points.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!NYZJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 424w, /__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 848w, /__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 1272w, /__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!NYZJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png" width="1456" height="1046" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1046,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:185846,&quot;alt&quot;:&quot;Frontier gap over time&quot;,&quot;title&quot;:&quot;Frontier gap over time&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Frontier gap over time" title="Frontier gap over time" srcset="/__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 424w, /__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 848w, /__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 1272w, /__u/substackcdn.com/image/fetch/$s_!NYZJ!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff9958dc4-a754-478f-ba8b-e18fb3f2a9d4_2384x1713.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On the <a href="https://artificialanalysis.ai/">Artificial Analysis Intelligence Index</a>, <strong>Kimi K3 leads all open models</strong> at 57, six points above GLM-5.2 (51) and 19 above the best US open model, <a href="/__u/maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation">Nemotron 3 Ultra</a> (38). Only Anthropic&#8217;s Fable 5 (60) and OpenAI&#8217;s GPT-5.6 Sol (59) score higher, and both are closed.</p><p>Other evaluations point in the same direction. <a href="https://www.vals.ai/">Vals AI</a> scores domain-specific work (legal, finance, tax) on private test sets, and <a href="https://lmarena.ai/">LMArena</a> ranks models by human preference in head-to-head chat. <strong>Kimi K3 leads all three</strong>, but each ranks the models below it differently.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BwiH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 424w, /__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 848w, /__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BwiH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png" width="1456" height="639" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:639,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:71652,&quot;alt&quot;:&quot;Multi-source standings&quot;,&quot;title&quot;:&quot;Multi-source standings&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Multi-source standings" title="Multi-source standings" srcset="/__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 424w, /__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 848w, /__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BwiH!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F575b58dc-fff1-42c3-8421-ce2020fda25a_1520x667.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>However, closed models still keep a clear edge on real-world agentic coding tasks. On benchmarks like SWE-Bench Pro and long, real-world agentic coding tasks that Claude Code and Codex run, <strong>closed models are still ahead</strong>.</p><h2>The models</h2><p>Every model here is a <strong>sparse Mixture of Experts</strong> (MoE). Six of the seven come from Chinese labs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!K3aA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 424w, /__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 848w, /__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 1272w, /__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!K3aA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png" width="1456" height="703" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:703,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:144511,&quot;alt&quot;:&quot;Master table&quot;,&quot;title&quot;:&quot;Master table&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Master table" title="Master table" srcset="/__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 424w, /__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 848w, /__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 1272w, /__u/substackcdn.com/image/fetch/$s_!K3aA!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa11ce85b-69b3-459f-aba6-09dc434f878d_1840x889.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Every family here shipped its current generation within the last six months.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!YPme!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 424w, /__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 848w, /__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!YPme!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png" width="1456" height="686" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:686,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:110377,&quot;alt&quot;:&quot;Timeline&quot;,&quot;title&quot;:&quot;Timeline&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Timeline" title="Timeline" srcset="/__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 424w, /__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 848w, /__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YPme!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc406b1db-4117-4106-b1ba-206abe38bf51_2672x1259.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Kimi K3</strong> (Moonshot AI, 2.8T total, 104B active; <a href="https://github.com/MoonshotAI/Kimi-K3">technical report</a>) is the strongest open alternative to Claude and GPT today, and <strong>the first open model at 3T scale</strong>, nearly double the next largest here (DeepSeek-V4 Pro, 1.6T). It also reverses Moonshot&#8217;s own design philosophy: K2.6 ran the most conservative attention stack of the seven, and K3 runs the most aggressive. Two costs come with it. Its API price is five times K2.6&#8217;s, and its calibration got worse: Artificial Analysis measures its hallucination rate rising from 39% to 51% while its accuracy climbed from 33% to 46%, so K3 buys correct answers by guessing more often.</p><p><strong>GLM-5.2</strong> (Z.ai, 744B total, 40B active; <a href="/__u/maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company">my GLM-5 article</a>) held the open lead for five weeks and remains the better buy for most work. It tops SWE-Bench Pro, has a usable 1M-token context, and costs <strong>less than a quarter</strong> of what K3 does for six index points less.</p><p><strong>MiniMax-M3</strong> (MiniMax, 428B total, 23B active, 1M context; <a href="/__u/maximelabonne.substack.com/p/minimax-m25-the-1hour-frontier-model">my M2.5 article</a>) replaced M2.7 just eight weeks after it shipped. It swapped M2.7&#8217;s full attention for <strong>MSA, a new sparse attention mechanism</strong>, and added native image and video input. Its real edge is price: M3 runs at some of the lowest costs on the frontier.</p><p><strong>DeepSeek-V4 Pro</strong> (DeepSeek, 1.6T total, 49B active; <a href="/__u/maximelabonne.substack.com/p/deepseek-v4">my DeepSeek-V4 article</a>) is <strong>architected around million-token serving</strong> and consolidates its post-training via distillation alone. It is the cheapest model here, at roughly 4% of K3&#8217;s blended price. Its clearest weakness is calibration: on hallucination tests, it guesses on questions it cannot answer instead of declining them.</p><p><strong>MiMo-V2.5-Pro</strong> (Xiaomi, 1.02T total, 42B active) is the fastest climb on this list. Xiaomi launched its Core AI group in April 2025 and hired Luo Fuli, a core DeepSeek-V2 developer, to lead MiMo. They went from a small first model to a frontier-scale one in about a year. It is assembled largely from <strong>published components</strong>, and a June paper documents Xiaomi&#8217;s <a href="https://arxiv.org/abs/2606.30406">multi-teacher on-policy distillation</a>.</p><p><strong>Nemotron 3 Ultra</strong> (Nvidia, 550B total, 55B active; <a href="/__u/maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation">my Nemotron 3 Ultra article</a>) is the best US open model, <strong>co-designed with the hardware</strong> its maker sells. It serves several times faster than its Chinese peers but trails them in quality by the widest gap on this list, due to its design tuned for throughput.</p><p><strong>Qwen3.5-397B-A17B</strong> (Alibaba, 397B total, 17B active; <a href="/__u/maximelabonne.substack.com/p/qwen35-nobody-agrees-on-attention">my Qwen3.5 article</a>) was the <strong>first production test of linear attention at frontier scale</strong>, a bet K3 has since made seven times larger, and it is the only model here under a plain Apache-2.0 license. It is Alibaba&#8217;s strongest open model, but not its strongest model: the more capable Qwen Max line stays closed.</p><h2>Architecture</h2><p>Everyone agrees on the MoE backbone, but nobody agrees on attention. Which design wins for long context processing is still <strong>a different answer per lab</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BRW6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 424w, /__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 848w, /__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BRW6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png" width="1456" height="1492" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1492,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:398669,&quot;alt&quot;:&quot;Taxonomy&quot;,&quot;title&quot;:&quot;Taxonomy&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Taxonomy" title="Taxonomy" srcset="/__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 424w, /__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 848w, /__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BRW6!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F18b85367-ed96-4b57-bf52-e36fa3705df1_3791x3886.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>One camp stays entirely on attention and shrinks the cache rather than replacing it, which it does three ways:</p><ul><li><p>The first <strong>compresses the cache</strong>. DeepSeek-V4 moved to <strong>compressed hybrids</strong> (CSA and HCA) built for very long context, with the most aggressive cache reduction in the field.</p></li><li><p>The second keeps only <strong>selected blocks</strong> of the cache per token. GLM-5 stacked <a href="https://api-docs.deepseek.com/news/news250929">DeepSeek Sparse Attention</a> on MLA, and GLM-5.2 added <strong>IndexShare</strong> to reuse the sparse-attention indexer every fourth layer. After M1&#8217;s Lightning Attention and M2&#8217;s full attention, M3 landed on <strong>Minimax Sparse Attention</strong>. It scores the cache in blocks with a cheap index branch and lets each query read only its top-ranked ones.</p></li><li><p>The third route is <strong>local-global attention</strong>. MiMo runs sliding-window attention over GQA at a 6:1 ratio, so most layers attend only to a nearby window.</p></li></ul><p>The other camp replaces most attention layers with a cheaper <strong>sequence mixer</strong>, whose cost grows only weakly with sequence length:</p><ul><li><p>Kimi K3 is the newest and largest defector to it, and it went further than anyone: <strong>69 of its 93 layers are linear</strong>, with a Gated MLA layer closing every block of four to restore global attention. Its mixer is <strong>Kimi Delta Attention</strong>, a channel-wise-gated refinement of the delta rule that Moonshot introduced in <a href="https://arxiv.org/abs/2510.26692">Kimi Linear</a> in October 2025, which itself refines <a href="https://arxiv.org/abs/2412.06464">Gated DeltaNet</a>.</p></li><li><p>Qwen interleaves Gated DeltaNet with full attention at the same 3:1 ratio.</p></li><li><p>Nemotron pairs <a href="https://arxiv.org/abs/2405.21060">Mamba-2</a> with thin GQA layers.</p></li></ul><p>Sparsity varies just as much. The number to compare is <strong>active parameters</strong>, i.e., how many of a model&#8217;s parameters actually run on each token. That now ranges from Qwen3.5&#8217;s 17B to K3&#8217;s 104B, a <strong>6x spread</strong> among models within 23 index points. Most use the <a href="https://arxiv.org/abs/2401.06066">DeepSeekMoE</a> layout. The structural departure is <a href="https://arxiv.org/abs/2601.18089">LatentMoE</a>, which Nvidia published in January, compressing each expert into a narrow latent space so a model can hold many more of them at the same active-parameter cost. K3 is its <strong>first adoption outside Nvidia</strong>.</p><p>No design has won, and they are all making the same bet: <strong>trade some recall for cheaper long-context capacity</strong>. A sequence mixer is the cheapest, with a constant-size state per layer, but it recalls earlier tokens poorly. This is why Kimi, Qwen, and Nemotron all pair it with periodic full-attention layers to compensate, which makes them hybrids. The compression and selection designs (MLA, DSA, MSA) give up less recall, but their cache still grows with the input, while sliding-window attention caps it at a fixed window.</p><h2>Pre-training</h2><p>Few labs document pre-training in depth, and the choices they do disclose already diverge.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!JL_N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 424w, /__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 848w, /__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!JL_N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png" width="1456" height="712" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:712,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:162528,&quot;alt&quot;:&quot;Pre-training&quot;,&quot;title&quot;:&quot;Pre-training&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Pre-training" title="Pre-training" srcset="/__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 424w, /__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 848w, /__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JL_N!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F052d765c-c05e-4bc8-aa80-487c043d2090_1720x841.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Of the four labs that disclose a token budget, Ultra is the low outlier at <strong>20T, five trillion short of plan</strong>, after its run diverged twice. Long context now splits on method rather than reach, since six of the seven ship 1M. V4 ramped its sequence length from 4K to 1M during the run and MiMo trained natively to 1M, while K3 grew its window in four stages, 8K to 64K during pre-training and 256K to 1M during cooldown.</p><p>Precision is where the labs are still experimenting. Ultra is the largest model pre-trained in <strong>NVFP4</strong> (4-bit), and it paid for it: two runs diverged, one traced to FP4 interacting with the MTP heads, and one never explained. Both DeepSeek-V4 and K3 took the conservative route instead, training in <a href="https://arxiv.org/abs/2412.19437">FP8</a> and reaching 4-bit only through <strong>quantization-aware training</strong> afterwards. The <strong>optimizer has converged on</strong> <a href="https://kellerjordan.github.io/posts/muon/">Muon</a>: Moonshot proved it at a trillion parameters on K2, adding a stabilizer called <a href="https://moonshotai.github.io/Kimi-K2/">QK-Clip</a>, and K3 now orthogonalizes each attention head&#8217;s momentum separately so a few large heads stop dominating the shared update. DeepSeek-V4 adopted Muon but dropped QK-Clip because its RMSNorm placement already keeps training stable.</p><p>Hardware is the murkiest of these choices. Every model here <strong>most likely trained on Nvidia</strong>. DeepSeek&#8217;s attempt to migrate to Huawei Ascend failed in mid-2025 and cost months, per <a href="https://www.chinatalk.media/p/deepseek-v4">ChinaTalk</a>, which shows how hard a full Ascend pre-training run still is. Z.ai is the only lab here on the <a href="https://www.scmp.com/tech/tech-war/article/3295002/tech-war-us-adds-chinese-ai-unicorn-zhipu-trade-blacklist-bidens-exit">US Entity List</a> (added January 2025), which cut it off from advanced Nvidia chips, so GLM-5.2 was widely rumored to have trained on <a href="https://lushbinary.com/blog/glm-5-developer-guide-zhipu-ai-huawei-ascend-open-weight/">Huawei Ascend</a>. Z.ai never confirmed that, so Nvidia stays the most likely. The one confirmed frontier-scale run off Nvidia is Meituan&#8217;s LongCat-2.0, trained on roughly <a href="https://www.scmp.com/tech/tech-trends/article/3358854/china-debuts-biggest-ai-model-trained-local-chips-meituan-releases-longcat-20">50,000 domestic ASICs</a>. It shows the Nvidia dependency is only starting to loosen.</p><h2>Post-training</h2><p>Post-training is where the training pipelines diverge the most. The main trend is the wide adoption of <strong>multi-domain on-policy distillation</strong> (MOPD). It consists of training a set of domain specialists, then distilling them into a single student on the student&#8217;s own outputs. It is doing work the reinforcement learning stage used to do, either replacing that stage or adding to it. Four of the seven now run it, and Kimi K3 is the newest convert: Moonshot&#8217;s last generation ran a conventional RL pipeline.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!rWb_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 424w, /__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 848w, /__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!rWb_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png" width="1456" height="1497" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1497,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:182693,&quot;alt&quot;:&quot;The MOPD pipeline across Kimi K3, DeepSeek-V4, MiMo, and Nvidia&quot;,&quot;title&quot;:&quot;The MOPD pipeline across Kimi K3, DeepSeek-V4, MiMo, and Nvidia&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The MOPD pipeline across Kimi K3, DeepSeek-V4, MiMo, and Nvidia" title="The MOPD pipeline across Kimi K3, DeepSeek-V4, MiMo, and Nvidia" srcset="/__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 424w, /__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 848w, /__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 1272w, /__u/substackcdn.com/image/fetch/$s_!rWb_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe7f3b1ca-55cf-4e8e-ac49-667a1b765801_2200x2262.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Kimi K3, <a href="/__u/maximelabonne.substack.com/p/deepseek-v4">DeepSeek-V4</a>, and <a href="https://arxiv.org/abs/2606.30406">Xiaomi&#8217;s MiMo</a> <strong>use it in place of the student&#8217;s RL</strong>: they train domain specialists, then distill those teachers into an SFT student, with no RL on the student itself. The way they build these specialists differs, though. DeepSeek trains each specialist from the base model with both SFT and RL. Xiaomi initializes its specialists from the SFT checkpoint and only uses RL, keeping teachers and student close in policy. <a href="/__u/maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation">Nvidia</a> <strong>adds distillation on top of RL</strong>: it trains the student with SFT and RL first, then distills the specialists to push past the plateau RL hit on its own. Distillation only <strong>amplifies what the base can already do</strong>, and it is not cheap, since it requires training a stack of specialist teachers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!r_Eh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 424w, /__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 848w, /__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 1272w, /__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!r_Eh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png" width="1456" height="837" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:837,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:78241,&quot;alt&quot;:&quot;The multi-stage RL pipeline across GLM-5.2, MiniMax, and Qwen&quot;,&quot;title&quot;:&quot;The multi-stage RL pipeline across GLM-5.2, MiniMax, and Qwen&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The multi-stage RL pipeline across GLM-5.2, MiniMax, and Qwen" title="The multi-stage RL pipeline across GLM-5.2, MiniMax, and Qwen" srcset="/__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 424w, /__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 848w, /__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 1272w, /__u/substackcdn.com/image/fetch/$s_!r_Eh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2092c374-bd01-4a6f-b4a6-cd0fcd2845a4_2018x1160.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The labs that skip distillation run a <strong>long, multi-stage RL pipeline</strong> instead: SFT, RL with verifiable rewards, agentic RL against live software repos, terminals, and browsers, then preference tuning on top. This is the path <a href="/__u/maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company">GLM-5.2</a>, <a href="/__u/maximelabonne.substack.com/p/minimax-m25-the-1hour-frontier-model">MiniMax</a>, and <a href="/__u/maximelabonne.substack.com/p/qwen35-nobody-agrees-on-attention">Qwen</a> take. With agentic RL, the bottleneck is generation, not the gradient step, since a few very long rollouts stall the whole batch. That is why these labs build asynchronous RL systems, like MiniMax&#8217;s Forge, that decouple rollout generation from training so the accelerators never idle on the slowest trajectory. GLM is the partial exception: it runs the same RL pipeline, then adds a final distillation step that uses each earlier stage&#8217;s own checkpoint as the teacher, so the last stage does not overwrite the skills the earlier ones learned.</p><h2>The economics of open models</h2><p>Open frontier models are much cheaper than closed-source ones, but it also means the labs that make them profit little from inference alone.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!bmGh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 424w, /__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 848w, /__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 1272w, /__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!bmGh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png" width="1456" height="1039" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1039,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:130252,&quot;alt&quot;:&quot;Price vs. intelligence&quot;,&quot;title&quot;:&quot;Price vs. intelligence&quot;,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/208708169?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Price vs. intelligence" title="Price vs. intelligence" srcset="/__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 424w, /__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 848w, /__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 1272w, /__u/substackcdn.com/image/fetch/$s_!bmGh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff33b99b4-7689-4d2a-9ba0-c9e1b4033725_1835x1309.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The rule holds because of competition, not efficiency. Anyone can serve open weights, so dozens of providers drive the price of these models <strong>down to roughly the cost of the GPUs and electricity</strong>. A closed model has one seller, who charges for the value it delivers instead.</p><p>The catch for the lab is that it is just another provider, with limited cost advantage over Together or Fireworks when serving the same checkpoint. <strong>Open-sourcing a frontier model means giving up exclusive inference revenue</strong>, so the question is what each lab sells instead.</p><p>Two sell the <strong>complement</strong>. Nvidia sells GPUs, and Alibaba sells cloud services, so a cheap, ubiquitous model only drives demand for what they charge for. Three sell a <strong>differentiated</strong> <strong>service</strong> based on a hosted API tuned for reliability and support: MiniMax, Moonshot, and Z.ai. Alibaba also keeps a stronger model <strong>closed</strong>, the Qwen Max line above open Qwen3.5. And two sell only (publicly) sell model inference: DeepSeek and Xiaomi open-source it as a strategic bet.</p><p>A frontier run can cost <a href="https://arxiv.org/abs/2405.21015">over a hundred million dollars</a>, and open weights let anyone serve them at commodity margins. The labs that can keep going are the ones with a business the model feeds (Nvidia, Alibaba) or a backer that does not need it to earn (DeepSeek's High-Flyer fund, Xiaomi's phone business). The pure plays take the real risk: MiniMax, Moonshot, and Z.ai are betting that giving the weights away buys <strong>enough API and enterprise business to fund the next model</strong>.</p><h2>Where the frontier moves next</h2><p>To conclude, here is a list of open questions worth watching:</p><ol><li><p><strong>Silicon</strong>: LongCat-2.0 was trained on domestic Chinese hardware. Are other Chinese labs going to make the switch this year?</p></li><li><p><strong>Attention</strong>: the field keeps splitting on this. Will one design become the standard, or does the split hold?</p></li><li><p><strong>FP4 training</strong>: despite its theoretical advantages, stability and performance issues make FP4 difficult to justify. Is it going to become a new standard for large runs?</p></li><li><p><strong>Open publishing</strong>: competitors now adopt a new technique within a single release cycle. Are we going to see less and less open research and detailed reports?</p></li></ol><h3>Reading list</h3><ul><li><p><a href="/__u/maximelabonne.substack.com/p/deepseek-v4">DeepSeek V4: ten teachers, one student</a>: the consolidation recipe in full.</p></li><li><p><a href="/__u/maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation">Nemotron 3 Ultra: what distillation can't fix</a>: the recovery ceiling, measured.</p></li><li><p><a href="/__u/maximelabonne.substack.com/p/qwen35-nobody-agrees-on-attention">Qwen3.5: nobody agrees on attention</a>: the architecture split this post extends.</p></li><li><p><a href="/__u/maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company">GLM-5: China's first public AI company</a>: the lab behind the Ascend run.</p></li><li><p><a href="/__u/maximelabonne.substack.com/p/kimi-k25-still-worth-it-after-two">Kimi K2.5: still worth it after two</a>: the Moonshot lineage behind K2.6.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[DeepSeek V4: ten teachers, one student]]></title><description><![CDATA[On-policy distillation replaced the RL stage]]></description><link>https://maximelabonne.substack.com/p/deepseek-v4-ten-teachers-one-student</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/deepseek-v4-ten-teachers-one-student</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Thu, 11 Jun 2026 11:09:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!QSEt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!QSEt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 424w, /__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 848w, /__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 1272w, /__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!QSEt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2337369,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 424w, /__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 848w, /__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 1272w, /__u/substackcdn.com/image/fetch/$s_!QSEt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8b8c1b2-01c9-46b2-9160-cde72a949af7_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>DeepSeek shipped V4 on April 24th, 2026, in two open-weight sizes: the 1.6-trillion-parameter <strong>Pro</strong> and the 284-billion-parameter <strong>Flash</strong>, both MIT-licensed with a million-token context window. The release put DeepSeek back among the leading open-weight labs after a long quiet stretch where Kimi, Qwen, and GLM did most of the talking. The pitch is <strong>efficiency rather than raw scale</strong>, built on a hybrid attention design that makes long context cheap to serve.</p><p>The architecture earns a look, and the post-training breaks more new ground: V4 drops the mixed reinforcement learning stage that consolidated V3.2 and replaces it with <strong>on-policy distillation</strong> from a panel of specialist teachers.</p><p>Two things matter more than the launch benchmarks: which variant people actually run, and <strong>where V4 falls down</strong>.</p><h2>Architecture</h2><p>V4 keeps the <a href="https://arxiv.org/abs/2401.06066">DeepSeekMoE</a> layout and Multi-Token Prediction objective from V3. The new work is in <strong>three places</strong>: the attention, the residuals, and the optimizer. Pro and Flash run the same design at two scales.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!EIs6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 424w, /__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 848w, /__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 1272w, /__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!EIs6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png" width="1456" height="632" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/be1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:632,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:77532,&quot;alt&quot;:&quot;The DeepSeek V4 family against its predecessor. Efficiency figures are single-token inference FLOPs and KV cache at a 1M-token context, with V3.2 as the 100% baseline.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The DeepSeek V4 family against its predecessor. Efficiency figures are single-token inference FLOPs and KV cache at a 1M-token context, with V3.2 as the 100% baseline." title="The DeepSeek V4 family against its predecessor. Efficiency figures are single-token inference FLOPs and KV cache at a 1M-token context, with V3.2 as the 100% baseline." srcset="/__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 424w, /__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 848w, /__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 1272w, /__u/substackcdn.com/image/fetch/$s_!EIs6!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbe1cadb5-70be-48e3-bffd-d92420b36444_1520x660.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The <strong>hybrid attention</strong> is the real change. At a million tokens, attention is the bottleneck: every new token reads a KV cache that grows with the whole context. V4's answer is two layer types that shrink that cache by merging runs of consecutive tokens into single, compressed entries. They differ in how hard they compress and what they read back.</p><p><strong>Compressed Sparse Attention (CSA)</strong> compresses gently and reads selectively. It folds a few tokens into each entry, then runs <a href="https://api-docs.deepseek.com/news/news250929">DeepSeek Sparse Attention</a> on the result, so that a query attends only to the top-k compressed entries that an indexer scores as relevant. <strong>Heavily Compressed Attention (HCA)</strong> makes the opposite trade: it packs far more tokens into each entry, then attends to all of them with no selection step. In effect, CSA layers retrieve the specific passages a query needs, while HCA layers keep a cheap, blurry view of the whole context, so whatever the indexer misses is degraded rather than gone. Both add a sliding window over the most recent raw tokens, because a query can't see inside its own compressed block and the nearest tokens matter most.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!X0EO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 424w, /__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 848w, /__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 1272w, /__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!X0EO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png" width="1326" height="651" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:651,&quot;width&quot;:1326,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:85887,&quot;alt&quot;:&quot;CSA in detail: a token-level compressor shrinks the KV stream, a lightning indexer scores the compressed entries, and only the top-k reach the attention alongside the sliding-window entries. HCA keeps the compressor (set much harder) and the window, and drops the indexer.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="CSA in detail: a token-level compressor shrinks the KV stream, a lightning indexer scores the compressed entries, and only the top-k reach the attention alongside the sliding-window entries. HCA keeps the compressor (set much harder) and the window, and drops the indexer." title="CSA in detail: a token-level compressor shrinks the KV stream, a lightning indexer scores the compressed entries, and only the top-k reach the attention alongside the sliding-window entries. HCA keeps the compressor (set much harder) and the window, and drops the indexer." srcset="/__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 424w, /__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 848w, /__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 1272w, /__u/substackcdn.com/image/fetch/$s_!X0EO!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71e2ba55-7a3c-42c8-a8eb-90e8388ab66c_1326x651.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Interleaving the two is what makes a million tokens tractable, and the report puts the KV cache at <strong>2% of a standard BF16 GQA baseline</strong> at 1M. The whole field is improvising here, which I covered in <a href="/__u/maximelabonne.substack.com/p/qwen35-nobody-agrees-on-attention">Qwen3.5</a>: <a href="/__u/maximelabonne.substack.com/p/kimi-k25-still-worth-it-after-two">Kimi K2.6</a> keeps plain MLA, <a href="/__u/maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company">GLM-5.1</a> stacks DSA on MLA, Qwen3.5 interleaves Gated DeltaNet with full attention, and <a href="/__u/maximelabonne.substack.com/p/minimax-m25-the-1hour-frontier-model">MiniMax</a> reverted to dense attention. V4 is one more distinct answer, and <strong>the one most tuned for raw context length</strong>.</p><p>The other two changes are borrowed, and worth naming as such. <strong>Manifold-Constrained Hyper-Connections (mHC)</strong> extend ByteDance's <a href="https://arxiv.org/abs/2409.19606">Hyper-Connections</a> by projecting the residual mix onto doubly stochastic matrices with Sinkhorn-Knopp, which bounds the spectral norm and keeps deep stacks stable. And V4 trains on the <a href="https://kellerjordan.github.io/posts/muon/">Muon optimizer</a> instead of AdamW. Muon at this scale is <strong>Moonshot's move</strong>, proven on the trillion-parameter Kimi K2. The telling divergence is that Moonshot needed <a href="https://moonshotai.github.io/Kimi-K2/">QK-Clip</a> to stop attention logits from exploding under Muon, while DeepSeek drops it because the RMSNorm it already applies to queries and compressed KV entries does the same job.</p><p>One number jumped out at me. V4-Pro activates <strong>49B parameters per token</strong>, the highest of any leading open-weight model: Kimi K2.6 fires 32B, GLM-5.1 40B, Qwen3.5 17B, MiniMax-M2.7 just 10B. Active parameters are the compute you pay on every single token, which is why the trend everywhere else is to shrink them. DeepSeek runs the trade in reverse. The hybrid attention cuts so much of the long-context bill that Pro can afford to activate more experts per token, buying back the capabilities the sparser models give up, and still come out almost 4x cheaper than V3.2 in FLOPs at 1M. Everyone else economizes on the experts, but V4 economizes on the attention and spends the savings.</p><h2>Pre-training</h2><p>Pre-training is the least surprising part. DeepSeek trained Flash on <strong>32T tokens</strong> and Pro on <strong>33T</strong>, a refreshed corpus that filters out machine-generated web text and leans harder on math, code, and long documents, with the sequence length ramped from 4K to 1M during the run. Before any post-training, Pro-Base already beats V3.2-Base almost everywhere, and Flash-Base wins most benchmarks on a third of the active parameters, ceding only some code and math rows.</p><p>The detail the model card omits is the hardware. Per <a href="https://www.chinatalk.media/p/deepseek-v4">ChinaTalk</a> and the Chinese tech outlet 36Kr, V4 was trained on Nvidia Hopper after a mid-2025 training failure during an attempted migration to Huawei Ascend. That failure says <strong>domestic silicon still can't carry a frontier-scale training run</strong>, and the detour back to Nvidia cost DeepSeek months. What DeepSeek did ship is native MXFP4 weights and a TileLang kernel layer, which let the model run inference on domestic Ascend, Cambricon, and Biren chips it was never trained on.</p><h2>Post-training</h2><p>V4's post-training is a clean two-stage design: train a panel of domain specialists, then distill them into one model.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!EmAm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 424w, /__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 848w, /__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 1272w, /__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!EmAm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png" width="1456" height="181" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:181,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:71058,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 424w, /__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 848w, /__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 1272w, /__u/substackcdn.com/image/fetch/$s_!EmAm!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bc67709-7e7c-40cb-be54-3e3b8c94f0b0_3409x424.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Stage one trains the teachers.</strong> DeepSeek forks the base into separate specialists for math, code, agentic tasks, and instruction following, each taken through SFT and then RL with <a href="https://arxiv.org/abs/2402.03300">GRPO</a>. The ingredients are standard, but running a <strong>full, separate RL pipeline per domain</strong> is not, and it is the expensive half of the recipe. Two choices stand out:</p><ul><li><p><strong>Every specialist still starts with SFT.</strong> Last year, DeepSeek itself tried to skip this stage with <a href="https://arxiv.org/abs/2501.12948">R1-Zero</a>, bootstrapping reasoning with RL alone, straight from the base model. Two generations later, they gave up on this idea, and SFT is still the backbone of the pipeline.</p></li><li><p><strong>The reward model is the actor.</strong> Where a rule check can grade the task, it does. Everywhere else, DeepSeek trains no separate reward model: the specialist itself learns to judge, scoring rubric-guided trajectories in the same GRPO run that trains it to answer. The report claims a minimal set of human annotations suffices, because the model's own reasoning carries the grading.</p></li></ul><p><strong>Stage two consolidates them.</strong> Instead of one more multi-domain RL phase to merge those skills, the way V3.2 did, V4 distills every specialist into a single student. The student generates its own rollouts, more than ten teachers score them, and it minimizes a weighted reverse-KL against the teacher distributions on its own outputs.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!3b9S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 424w, /__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 848w, /__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!3b9S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png" width="1456" height="167" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:167,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:59292,&quot;alt&quot;:&quot;On-policy distillation: the student generates a rollout, the teachers grade every token against their full distribution, and the reverse-KL drives the next update.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="On-policy distillation: the student generates a rollout, the teachers grade every token against their full distribution, and the reverse-KL drives the next update." title="On-policy distillation: the student generates a rollout, the teachers grade every token against their full distribution, and the reverse-KL drives the next update." srcset="/__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 424w, /__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 848w, /__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3b9S!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd3bf45b-cbbc-4a62-a662-7dbd0e6f4421_3485x399.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>None of that framing is DeepSeek's. Reverse-KL distillation on the student's own samples is <a href="https://arxiv.org/abs/2306.13649">GKD</a>, from Agarwal et al. in 2023, and the report credits its on-policy form to <a href="https://thinkingmachines.ai/blog/on-policy-distillation/">Thinking Machines</a>, which used it last October to rebuild Qwen3's reasoning cheaply. The multi-teacher, multi-domain version is also used by <a href="/__u/maximelabonne.substack.com/p/nemotron-cascade-2-on-policy-distillation">Nvidia's Nemotron Cascade 2</a> as MOPD. <strong>DeepSeek's contribution is the engineering that makes it cheap at this scale.</strong></p><p>That engineering is <strong>full-vocabulary logit distillation</strong>. Most on-policy distillation, including the Thinking Machines recipe, scores only the token the student sampled, a cheap but noisy per-token reverse-KL that the report rejects for that reason. V4 matches the entire teacher distribution at every position instead, which is denser and more stable but should be impossible to store. The trick is to keep the gradient dense without ever materializing the logits:</p><ol><li><p><strong>Cache only each teacher's last-layer hidden states</strong>, then rebuild the full logits on the fly through that teacher's prediction head.</p></li><li><p><strong>Order training samples by teacher index</strong>, so only one teacher head is resident in memory at a time.</p></li><li><p><strong>Compute the exact KL with a custom TileLang kernel.</strong></p></li></ol><p>That scheduling is what turns a textbook objective into something you can run with a dozen trillion-parameter teachers.</p><p>Nvidia's MOPD releases put the same ingredients in a different place. In Cascade 2 and again in <a href="/__u/maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation">Nemotron 3 Ultra</a>, the student is a generalist that already went through a multi-domain RL stage, so distillation arrives <strong>on top of RL</strong> as a consolidation layer, grading one sampled token at a time. V4 hands the entire consolidation to distillation, with no unified RL before or after. That choice is what forces the dense loss: a sampled-token signal can transfer deltas onto an RL-trained student, but it is too noisy to carry the merge alone.</p><p>DeepSeek's argument for cutting the RL stage is <strong>interference</strong>. A single multi-domain reward mixture invites reward hacking and capability drift, and Nvidia saw the cost directly: Nemotron 3 Ultra's mixed RL stage plateaued, with more than a dozen environments leaving each domain too little signal per batch. Specialists trained to convergence dodge that fight, and the reasoning-effort modes come almost for free because the teacher pool already spans them.</p><p>Nvidia's stacking has its own logic, though. On-policy distillation only grades the student's own rollouts, so a student that has already been through RL <strong>samples stronger rollouts</strong> for the teachers to refine. Keeping RL in the pipeline also means some stage optimizes the model <strong>directly against a reward</strong>, while V4's student only ever matches teacher distributions, a gap worth remembering when the benchmarks get to calibration. V4 and Nemotron 3 Ultra both pay for ten-plus specialist pipelines either way, so the choice is really about where the consolidation risk sits, and neither lab has run the ablation that would settle it.</p><h2>Benchmarks</h2><p>DeepSeek's own numbers put V4-Pro at maximum effort against the closed and open frontier.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Kr5H!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 424w, /__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 848w, /__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Kr5H!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png" width="1456" height="564" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:564,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:112685,&quot;alt&quot;:&quot;DeepSeek's reported results at maximum reasoning effort. Best in each row is bold; an em dash means the model wasn't run on that benchmark.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="DeepSeek's reported results at maximum reasoning effort. Best in each row is bold; an em dash means the model wasn't run on that benchmark." title="DeepSeek's reported results at maximum reasoning effort. Best in each row is bold; an em dash means the model wasn't run on that benchmark." srcset="/__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 424w, /__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 848w, /__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Kr5H!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdec19ba6-6b06-41e4-ba48-87839668f860_2000x775.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>V4-Pro is <strong>competitive but not dominant</strong>. It leads on LiveCodeBench, sits mid-pack on knowledge and reasoning, and trails Gemini 3.1 Pro badly on SimpleQA-Verified, a factuality test. Its agentic GDPval-AA score is the best of any open-weight model, behind only the closed GPT-5.4 and Opus 4.6.</p><p>Artificial Analysis has since run V4 independently.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!q6Vv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 424w, /__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 848w, /__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 1272w, /__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!q6Vv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png" width="1456" height="439" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:439,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:65291,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200949224?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 424w, /__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 848w, /__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 1272w, /__u/substackcdn.com/image/fetch/$s_!q6Vv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F75892430-53e8-4f3d-bf12-aa5dbb064833_1520x458.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Their composite index puts V4-Pro at <strong>52, just behind the joint open leaders Kimi K2.6 and MiMo-V2.5-Pro at 54</strong>. Flash lands around Claude Sonnet 4.6's level for a fraction of the price.</p><p>The recurring weakness is factuality. On their AA-Omniscience, which scores whether a model declines or guesses when it doesn't know the answer, V4 guesses <strong>94% of the time (Pro) and 96% (Flash)</strong>, against 39% for Kimi K2.6 and 34% for MiniMax-M2.7. It is one benchmark, but it tracks both <a href="https://www.digitalapplied.com/blog/ai-model-hallucination-rate-benchmarks-2026-study">independent factuality tests</a> and the long-running complaint that DeepSeek's reasoning models trade caution for fluency.</p><p>Against closed models, the gap is concrete. On DeepSeek's own R&amp;D coding benchmark, V4-Pro-Max passes <strong>67% to 80% for Claude Opus 4.6 in thinking mode</strong>, and the report concedes V4 trails the frontier by three to six months.</p><p>Verbosity is the other catch. V4 Pro burns <strong>190M output tokens</strong> to finish the Intelligence Index and Flash burns 240M, among the most of any model tested, so the cheap per-token price buys a lot of tokens. The effective cost gap to a closed model is smaller than the sticker, though Pro still runs the full index for about <strong>a quarter of what Claude Opus 4.7 costs</strong>.</p><p>Reception split along the Pro/Flash line. <strong>Flash is the one that won traffic.</strong> On OpenRouter it climbed to roughly <strong>3.64 trillion tokens a week</strong> and briefly out-consumed Claude, before Tencent's <a href="https://minimaxir.com/2026/05/openrouter-hy3/">Hy3 preview</a> took the top. The cheapest providers list it near $0.10 in and $0.20 out. Pro drew the more measured takes, an "<a href="https://news.ycombinator.com/item?id=47977026">almost on the frontier</a>" thread and early endpoint instability that has since settled.</p><h2>The bigger picture</h2><p>V4 reads as the start of what <a href="https://www.chinatalk.media/p/deepseek-v4">ChinaTalk</a> calls a <strong>post-DeepSeek era</strong>. The model is excellent, yet DeepSeek concedes it is months behind the frontier, a strange thing to write about the lab that defined the open-weight conversation a year ago. The slip is mostly not technical: DeepSeek lost core researchers to Tencent, ByteDance, and Xiaomi, ByteDance's Doubao took the consumer market while DeepSeek stayed in research mode, and the chip migration cost it a run. The funding gap behind all of that is structural and won't close on benchmark wins.</p><p>What will outlast the news cycle is the recipe. <strong>Multi-teacher on-policy distillation at trillion-parameter scale</strong> is the strongest sign yet that specialize-then-consolidate is becoming the default shape of frontier post-training. DeepSeek is plain that the rest is debt: it calls the architecture complex and kept tricks it doesn't fully understand to de-risk the run. The open question is whether the next lab to run this pipeline can fix the calibration hole. Either way, pushing a 1.6T model through a new optimizer and a ten-teacher distillation run is a serious piece of work, and the team did it while the ground moved under them.</p><div><hr></div><h3>Resources</h3><ul><li><p><strong>Technical report</strong>: <a href="https://huggingface.co/collections/deepseek-ai/deepseek-v4">DeepSeek-V4</a></p></li><li><p><strong>Hugging Face</strong>: <a href="https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro">DeepSeek-V4-Pro</a>, <a href="https://huggingface.co/deepseek-ai/DeepSeek-V4-Flash">DeepSeek-V4-Flash</a></p></li><li><p><strong>Artificial Analysis</strong>: <a href="https://artificialanalysis.ai/models/deepseek-v4-pro">DeepSeek V4 Pro</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Nemotron 3 Ultra: what distillation can't fix]]></title><description><![CDATA[Ten specialist teachers distilled into one open 550B model]]></description><link>https://maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/nemotron-3-ultra-what-distillation</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 08 Jun 2026 09:00:27 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!uJVo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!uJVo!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 424w, /__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 848w, /__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!uJVo!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:728386,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 424w, /__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 848w, /__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uJVo!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b69d46d-e3b4-4f7a-aff3-f1df21d4b8e3_1672x941.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On June 4, 2026, Nvidia closed out its Nemotron 3 lineup with <strong>Nemotron 3 Ultra</strong>, a 550B-parameter MoE with 55B active and fully open weights. It is the most intelligent open-weight model from a US lab, <strong>but it still trails the Chinese open frontier</strong> led by Kimi K2.6.</p><p>Nvidia's pitch is not the highest benchmark scores, but <strong>the highest throughput on long-running agentic workloads</strong>. Let's walk through the recipe and poke at the inference numbers behind that claim.</p><h2>Architecture</h2><p>Ultra is the biggest of the three Nemotron 3 models. All three are MoEs that pair <a href="https://arxiv.org/abs/2405.21060">Mamba-2</a> layers, which run in linear time with no growing KV cache, with a thin set of attention layers for exact recall.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!P9NM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 424w, /__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 848w, /__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!P9NM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png" width="1456" height="602" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/baf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:602,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60321,&quot;alt&quot;:&quot;The Nemotron 3 family, from 30B to 550B.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The Nemotron 3 family, from 30B to 550B." title="The Nemotron 3 family, from 30B to 550B." srcset="/__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 424w, /__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 848w, /__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P9NM!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbaf0f2fa-1075-4b99-ae68-f73b8011f7f3_1520x628.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The one constant worth noting is sparsity: <strong>all three keep about 90% of their weights idle per token</strong>, even as total parameters grow 17x. The hybrid backbone is otherwise standard, the same linear-time-plus-attention mix Liquid, MiniMax, and Qwen use. Two blocks are more particular:</p><ul><li><p><strong>LatentMoE</strong> (<a href="https://arxiv.org/abs/2601.18089">paper</a>): compresses the expert dimension about 4x, which lets Nvidia run <strong>512 experts with 22 active</strong> per token at normal cost. Nano skips it for a conventional 128-expert, top-6 setup.</p></li><li><p><strong>Multi-Token Prediction (MTP)</strong>: two tied heads predict ahead, baking the speculative-decoding drafter into the weights. DeepSeek introduced MTP in V3, and Nvidia ties the two heads so the drafter stays aligned with the model.</p></li></ul><p>Laid side by side, the family is one recipe instantiated at three different lengths:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!v3O4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 424w, /__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 848w, /__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 1272w, /__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!v3O4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png" width="1456" height="926" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:926,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:102699,&quot;alt&quot;:&quot;Layer patterns across the family, at increasing depth.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Layer patterns across the family, at increasing depth." title="Layer patterns across the family, at increasing depth." srcset="/__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 424w, /__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 848w, /__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 1272w, /__u/substackcdn.com/image/fetch/$s_!v3O4!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd88e3691-5510-4fd2-b7eb-e1cca8773731_1548x985.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>Pre-training</h2><p>Ultra is the <strong>largest model pretrained end-to-end in NVFP4</strong>, Nvidia's 4-bit float format. The recipe is Super's, scaled up: keep the most sensitive tensors in higher precision and run the rest in FP4.</p><p>What surprised me most is the token budget. <strong>Ultra trained on only 20T tokens, fewer than the 25T behind both Nano and Super.</strong> Normally the biggest model gets the most data, not the least. Nvidia cut the run short because, by its own account, it diverged twice:</p><ul><li><p><strong>Around 8T tokens</strong>, a throughput tweak that moved the output layer's gradient accumulation to BF16 quietly zeroed out the MTP heads' contribution, and the MTP loss spiked before the main loss showed anything. Reverting to FP32 fixed it.</p></li><li><p><strong>Around 16T tokens</strong>, a second divergence Nvidia never root-caused. They annealed the learning rate early and stopped at 20T instead of the planned horizon. The report links it to dead experts and a ballooning residual stream, but only by correlation.</p></li></ul><p>The curves show the call. The original run (orange) spikes near 16T, the early-annealed runs keep dropping, and the 20T version (red) is the one Nvidia shipped.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!_4wv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 424w, /__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 848w, /__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 1272w, /__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!_4wv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png" width="1456" height="543" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/70eb450a-372e-4655-868d-4f0401933af5_1548x577.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:543,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:102560,&quot;alt&quot;:&quot;Training and validation loss. The original run (orange) spikes near 16T, and the 20T annealed run (red) is the one that shipped.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Training and validation loss. The original run (orange) spikes near 16T, and the 20T annealed run (red) is the one that shipped." title="Training and validation loss. The original run (orange) spikes near 16T, and the 20T annealed run (red) is the one that shipped." srcset="/__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 424w, /__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 848w, /__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 1272w, /__u/substackcdn.com/image/fetch/$s_!_4wv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70eb450a-372e-4655-868d-4f0401933af5_1548x577.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>NVFP4 pretraining is <strong>still experimental at this scale</strong>. The run diverged twice; Nvidia never explained the second one, and the instability cost Ultra a fifth of its planned tokens. FP4 buys inference throughput, but it still adds real training risk.</p><h2>Post-training</h2><p>Post-training runs in four stages: a base model, supervised fine-tuning, reinforcement learning, then several rounds of distillation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!9H6q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 424w, /__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 848w, /__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 1272w, /__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!9H6q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png" width="1456" height="673" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:673,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:106520,&quot;alt&quot;:&quot;The post-training pipeline, from the base model to the final Ultra.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The post-training pipeline, from the base model to the final Ultra." title="The post-training pipeline, from the base model to the final Ultra." srcset="/__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 424w, /__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 848w, /__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 1272w, /__u/substackcdn.com/image/fetch/$s_!9H6q!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8a65a30-7908-4623-b2cb-2194f7bf584b_1572x727.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The first two stages are routine. <strong>SFT</strong> is multi-domain and keeps the shared-weight MTP objective. <strong>RLVR</strong> then runs a single reinforcement-learning stage with verifiable rewards across every domain at once: agentic, reasoning, chat, safety, and long context, producing one generalist checkpoint. That generalist plateaus because, with more than a dozen environments mixed together, each domain gets too little signal per batch.</p><p>To get past that, Nvidia also trains <strong>more than ten domain specialists</strong>, each a separate model tuned hard on one area: SWE, terminal use, search, safety, and so on, through its own SFT and RL. These specialists are the teachers, and the generalist is the student.</p><p>It merges them with <strong>on-policy distillation</strong> (<a href="https://arxiv.org/abs/2306.13649">GKD</a>, 2023), where the student generates its own rollouts and each teacher grades them token by token. Nvidia runs this over two iterations, with a brief warm-up SFT first so the student's rollouts stay on the teachers' distribution. The first round distills the specialists into an interim model, the second reuses them plus a fresh batch to produce the final Ultra. Nvidia calls it <strong>Multi-teacher On-Policy Distillation (MOPD)<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!6znt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 424w, /__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 848w, /__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 1272w, /__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!6znt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png" width="1456" height="878" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:878,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:228210,&quot;alt&quot;:&quot;The two MOPD iterations: specialist teachers distilled into the student, then a second round into the final model.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="The two MOPD iterations: specialist teachers distilled into the student, then a second round into the final model." title="The two MOPD iterations: specialist teachers distilled into the student, then a second round into the final model." srcset="/__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 424w, /__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 848w, /__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 1272w, /__u/substackcdn.com/image/fetch/$s_!6znt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F95cca501-f32e-4e31-b8b4-c6264299ea20_1931x1164.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The contrast with DeepSeek-V4 is the interesting part. DeepSeek dropped its RL stage and replaced it with multi-teacher distillation. Nvidia keeps RL and stacks MOPD on top. <strong>DeepSeek treats distillation as a replacement for RL, Nvidia treats it as a consolidation layer that RL feeds into.</strong></p><p>The payoff is lopsided. Recovery runs from over 170% on Terminal Bench, where the student beats its teacher, down to 17% on HLE. Execution and tool-use recover almost fully, and hard reasoning barely moves.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!qpV8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 424w, /__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 848w, /__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!qpV8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png" width="1456" height="1123" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1123,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:151359,&quot;alt&quot;:&quot;MOPD recovery by task, sorted high to low: execution recovers almost fully, hard reasoning barely moves.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="MOPD recovery by task, sorted high to low: execution recovers almost fully, hard reasoning barely moves." title="MOPD recovery by task, sorted high to low: execution recovers almost fully, hard reasoning barely moves." srcset="/__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 424w, /__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 848w, /__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qpV8!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F36986e86-2aa2-45dc-b84d-62074380eecd_1520x1172.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Nvidia is precise about why the reasoning gap stays open. Its reasoning teacher gained its edge from extra SFT and RL on a DeepSeek-V4-Pro reasoning mixture the student never saw, so the teacher's reasoning paths fall outside what the student samples. On-policy distillation only grades the student's own rollouts, so it cannot transfer a skill the student never produces. <strong>It amplifies reasoning the student can already reach, not reasoning beyond it.</strong></p><p>The same pattern shows up elsewhere. <a href="https://thinkingmachines.ai/blog/on-policy-distillation/">Thinking Machines</a> lifted a Qwen3-8B from 60 to 70 on AIME with this method, because that student could already reach AIME-level traces, and DeepSeek-V4 reasons well because its base could. My read is that the lever is the base. Ultra, undertrained by 5T tokens, does not reach far enough on the hardest problems, which is why HLE barely moves.</p><h2>Benchmarks</h2><p>Nvidia's own table and Artificial Analysis agree on where Ultra stands. The Nvidia table has it among the best open models on agentic and long-context work, and behind DeepSeek-V4 and Kimi on hard reasoning like HLE and GPQA.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ynhU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 424w, /__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 848w, /__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ynhU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png" width="1456" height="1163" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1163,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:144973,&quot;alt&quot;:&quot;Nemotron 3 Ultra vs the open frontier. The top score in each row is bold.&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Nemotron 3 Ultra vs the open frontier. The top score in each row is bold." title="Nemotron 3 Ultra vs the open frontier. The top score in each row is bold." srcset="/__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 424w, /__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 848w, /__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ynhU!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17901e28-dc5f-48ba-99e1-576ff5fb814c_1520x1214.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Read down the columns, and the problem is hard to miss. <strong>Ultra holds the top score in only one of eleven benchmarks</strong> (RULER at 1M), and a Chinese model, usually Kimi, takes most of the rest. For a 550B flagship measured against models its own size and smaller, that is a thin result.</p><p><a href="https://artificialanalysis.ai/models/nvidia-nemotron-3-ultra-550b-a55b">Artificial Analysis</a> breaks it down the same way. Ultra leads on instruction-following, professional tasks, and long context, and falls behind on coding and long-horizon planning, exactly where <strong>Kimi K2.6 and GLM-5.1 keep their edge</strong>. On the Intelligence Index, it&#8217;s the top US open model, but it lands about six points behind Kimi K2.6, a real gap on a 100-point scale.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!gnGq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 424w, /__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 848w, /__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!gnGq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png" width="1456" height="444" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:46430,&quot;alt&quot;:&quot;Artificial Analysis Intelligence Index: Ultra (green) leads US open models but trails the Chinese frontier (red).&quot;,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/200733460?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Artificial Analysis Intelligence Index: Ultra (green) leads US open models but trails the Chinese frontier (red)." title="Artificial Analysis Intelligence Index: Ultra (green) leads US open models but trails the Chinese frontier (red)." srcset="/__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 424w, /__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 848w, /__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gnGq!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1481a608-7ae5-4e48-8b2e-38013d0084f3_1520x464.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>None of this is a surprise after the post-training section. The place MOPD gained the least, hard reasoning, is exactly where Ultra falls short, so the category split here just echoes the recovery numbers.</p><p>Speed is the one axis where Ultra clearly wins. A pre-release DeepInfra endpoint ran it above <strong>300 tokens per second</strong>, against the 50 to 100 typical of comparable Chinese models. Nvidia's own "up to 6x" is shakier. It is 5.9x against Kimi but only 1.6x against Qwen, the one rival with a similarly lean active path, and it was timed on Nvidia's own stack against rivals on vLLM. As <a href="https://www.implicator.ai/nvidias-nemotron-3-ultra-leads-us-open-models-but-trails-chinas-kimi-k2-6/">implicator.ai</a> put it, these are "Nvidia's own numbers, against rivals Nvidia chose." The lead seems real, but the exact multiple might not hold in practice.</p><h2>The bigger picture</h2><p>Nvidia barely needs Ultra to win. It sells the silicon nearly every frontier model trains and runs on, so trailing Kimi costs it little. The real risk is not a better Chinese model, but a better Chinese chip. DeepSeek-V4 already trains and serves on <a href="https://www.trendforce.com/news/2026/04/29/news-huawei-ascend-cambricon-and-hygon-completed-day-0-adaptation-to-deepseek-v4/">Huawei Ascend</a>, and as more Chinese labs move off Nvidia, the moat Ultra quietly defends erodes.</p><p>None of this takes away from the work. A stable 550B run in 4-bit, a ten-teacher distillation pipeline, and fully open weights are hard to land. Congratulations to the team that shipped it!</p><div><hr></div><h3>Resources</h3><ul><li><p><strong>Technical report</strong>: <a href="https://research.nvidia.com/labs/nemotron/Nemotron-3-Ultra/">Nemotron 3 Ultra: Open, Efficient MoE Hybrid Mamba-Transformer for Agentic Reasoning</a></p></li><li><p><strong>Hugging Face</strong>: <a href="https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-BF16">BF16</a> and <a href="https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Ultra-550B-A55B-NVFP4">NVFP4</a></p></li><li><p><strong>Recipes &amp; data</strong>: <a href="https://github.com/NVIDIA-NeMo/Nemotron">github.com/NVIDIA-NeMo/Nemotron</a></p></li></ul><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>Funnily enough, <a href="/__u/maximelabonne.substack.com/p/nemotron-cascade-2-on-policy-distillation">Nemotron Cascade 2</a> already employed the acronym &#8220;MOPD&#8221; to talk about Multi-<em>domain</em> On-Policy Distillation instead of Multi-<em>teacher</em> On-Policy Distillation.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Nemotron Cascade 2: On-policy distillation is back!]]></title><description><![CDATA[Multi-domain On-Policy Distillation, open datasets, and gold medals]]></description><link>https://maximelabonne.substack.com/p/nemotron-cascade-2-on-policy-distillation</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/nemotron-cascade-2-on-policy-distillation</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 23 Mar 2026 09:22:39 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Vymt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Vymt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 424w, /__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 848w, /__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Vymt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:971,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2735472,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/191776807?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 424w, /__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 848w, /__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Vymt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1762ee15-dc03-4484-868f-d06ec0d3f250_1536x1024.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On March 19th, 2026, Nvidia dropped <a href="https://research.nvidia.com/labs/nemotron/nemotron-cascade-2/">Nemotron-Cascade 2</a>, a <strong>30B MoE model with  3B activated parameters</strong> that achieves gold-medal performance on the 2025 International Mathematical Olympiad (IMO), the International Olympiad in Informatics (IOI), and the ICPC World Finals. This was previously achieved by DeepSeek-V3.2-Speciale at 671B-A37B, a model with 20x more parameters.</p><p>The most interesting part of this release isn&#8217;t the headline benchmarks, but the open post-training recipe. Nvidia open-sourced the model weights, as well as the <strong>SFT and RL datasets</strong>. Let&#8217;s analyze the technical details shared in the technical report.</p><h2>What is Nemotron Cascade 2?</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!dIeZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 424w, /__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 848w, /__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 1272w, /__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!dIeZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png" width="1456" height="757" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:757,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:418253,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/191776807?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 424w, /__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 848w, /__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 1272w, /__u/substackcdn.com/image/fetch/$s_!dIeZ!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a3de1b7-7684-454d-ac8c-60a3d849239d_2680x1394.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Nemotron-Cascade 2 is post-trained from <a href="https://huggingface.co/nvidia/Nemotron-3-Nano-30B-A3B-Base">Nemotron-3-Nano-30B-A3B-Base</a>, Nvidia Mamba2-Transformer hybrid MoE base model that shipped in December 2025. Same base, same architecture: the only difference between Cascade 2 and the original Nemotron-3-Nano instruct model is the <strong>post-training pipeline</strong>. Both models start from the same checkpoint, but Cascade 2 outperforms Nano on nearly every benchmark. Internal competition looks fierce at Nvidia!</p><p>Cascade 2 is a direct competitor to Qwen3.5-35B-A3B. It also operates in two modes: thinking (reasoning traces inside <code>&lt;think&gt;</code> tags) and instruct (a prepended empty <code>&lt;think&gt;&lt;/think&gt;</code> block suppresses chain-of-thought).</p><p>Cascade 2 outperforms Qwen3.5-35B-A3B and the larger Nemotron-3-Super-120B-A12B across reported math, code reasoning, alignment, and instruction following benchmarks:</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/WlhLc/3/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e9994203-4553-4362-ad06-7c7237a0d697_1220x2536.png&quot;,&quot;thumbnail_url_full&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eacb6cd2-a52e-4c37-99b7-3d4304f84938_1220x2536.png&quot;,&quot;height&quot;:1286,&quot;title&quot;:&quot;Created with Datawrapper&quot;,&quot;description&quot;:&quot;&quot;,&quot;belowTheFold&quot;:false}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/WlhLc/3/" width="730" height="1286" frameborder="0" scrolling="no"></iframe><script type="text/javascript">!function(){"use strict";window.addEventListener("message",(function(e){if(void 0!==e.data["datawrapper-height"]){var t=document.querySelectorAll("iframe");for(var a in e.data["datawrapper-height"])for(var r=0;r<t.length;r++){if(t[r].contentWindow===e.source)t[r].style.height=e.data["datawrapper-height"][a]+"px"}}}))}();</script></div><p><em>&#8224; Numbers in brackets refers to Tool-Integrated Reasoning (TIR) results.<br>&#8225; Official numbers when available, otherwise evaluated using the recommended settings.</em></p><p>The competition results look great: 35/42 on IMO 2025 (gold), 439.28/600 on IOI 2025 (gold), 10/12 on ICPC World Finals (gold). But Qwen3.5-35B-A3B significantly <strong>outperforms on knowledge-intensive benchmarks</strong>, like MMLU-Pro (85.3 vs 79.8), GPQA-Diamond (84.2 vs 76.1), HLE (22.4 vs 17.7), as well as <strong>agentic tasks</strong> like SWE Verified (69.2 vs 50.2), Terminal Bench 2.0 (40.5 vs 21.1), Tau-2 Bench (81.2 vs 58.9).</p><p>Cascade 2 is clearly optimized for math and code reasoning at the expense of breadth on knowledge and agentic tasks. Nvidia acknowledges this directly in the paper, pointing to stronger pre-training and agentic RL as future priorities.</p><h2>Supervised Fine-Tuning</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!20fT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 424w, /__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 848w, /__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 1272w, /__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!20fT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png" width="1456" height="462" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/65beee05-df82-4456-9205-a74fbc709313_2586x820.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:462,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150114,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/191776807?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 424w, /__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 848w, /__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 1272w, /__u/substackcdn.com/image/fetch/$s_!20fT!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F65beee05-df82-4456-9205-a74fbc709313_2586x820.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The pipeline has two major phases: SFT, then Cascade RL with a new addition called <strong>Multi-domain On-Policy Distillation</strong> (MOPD).</p><p>The SFT stage is a single-stage training run with 15.9M samples packed into 256K token sequences, converging after about 1.5 epochs. Here are the most interesting domains:</p><ul><li><p><strong>Math</strong>: 1.8M tool-calling samples + 2.6M non-tool samples for competition math, generated by DeepSeek-V3.2 and DeepSeek-V3.2-Speciale. Plus 816K proof generation/verification samples.</p></li><li><p><strong>Code reasoning</strong>: ~165K unique prompts from Codeforces, AtCoder, AIZU, CodeChef, deduplicated via I/O fingerprinting and n-gram analysis (removing ~24.2% redundancy). Responses by gpt-oss-120b. Final dataset: 1.9M Python traces + 1.0M C++14 traces + 1.3M Python tool-calling traces.</p></li><li><p><strong>SWE</strong>: 125K agentic + 389K agentless samples. They found that combining agentless and agentic data helps both scaffolds: pass@1 goes from 48.9 to 49.9 and pass@4 from 62.8 to 65.2 on SWE-bench Verified via OpenHands.</p></li><li><p><strong>General chat</strong>: 4.9M reasoning-on + 372K reasoning-off samples, plus 700K multi-turn conversations synthesized by having two gpt-oss-120b instances role-play user and assistant.</p></li><li><p><strong>Terminal agent</strong>: 490K samples using the Terminus 2 framework with Docker-based execution loops.</p></li></ul><p>To sum up, Nvidia uses three main teacher models: gpt-oss-120b for most code and general tasks, DeepSeek-V3.2/Speciale for math, Qwen3-235B variants for chat and tool calling.</p><h2>Cascade Reinforcement Learning</h2><p>The core idea from Nemotron-Cascade 1 carries forward: instead of blending prompts from every domain into a single RL run (the DeepSeek-R1/Qwen3 approach), you train <strong>RL stages sequentially</strong>, one domain at a time.</p><p>This is also something we&#8217;ve <a href="https://www.liquid.ai/blog/lfm2-5-1-2b-thinking-on-device-reasoning-under-1gb">successfully implemented at Liquid</a> last year. The benefits are threefold: (1) resistance to catastrophic forgetting, (2) domain-specific hyperparameter tuning, and (3) compute savings from homogeneous batches within the same domain.</p><p>The Cascade 2 pipeline runs in this order:</p><ol><li><p><strong>IF-RL</strong> (Instruction Following) for ~180 steps</p></li><li><p><strong>Multi-domain RL</strong> (MCQA, tool calling, structured output) for ~70 steps</p></li><li><p><strong>Multi-domain On-Policy Distillation (MOPD)</strong> for ~40-50 steps</p></li><li><p><strong>RLHF</strong> (human preference via GenRM) for ~30 steps</p></li><li><p><strong>Long-context RL</strong> (32K input, 49K max sequence) for ~30 steps</p></li><li><p><strong>Code RL</strong> (competitive programming, binary rewards)</p></li><li><p><strong>SWE RL</strong> (agentless + agentic) for ~40-50 steps</p></li></ol><p>The ordering changed from Cascade 1: IF-RL is now first (it used to come after RLHF) because they discovered that <strong>IF-RL hurts human alignment</strong>, but subsequent RLHF can recover that regression. This is in line with our own training process at Liquid, where IF training is always the first stage.</p><p>Throughout all stages, they use GRPO with strict on-policy training (importance ratio always 1.0) and <strong>no KL divergence term</strong>. This reduces the GRPO objective to standard REINFORCE with group-normalized rewards and token-level loss. The one exception: RLHF uses a small KL coefficient of 0.03 to preserve capabilities from other domains.</p><h2>Multi-domain On-Policy Distillation</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Fvzd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 424w, /__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 848w, /__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Fvzd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png" width="1456" height="525" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:525,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:282098,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/191776807?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 424w, /__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 848w, /__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Fvzd!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2593120-6c51-4edf-92c0-3170b87dfb15_2576x928.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Multi-domain On-Policy Distillation</strong> is the headline technical contribution. Even with careful cascade ordering, you still see capability drift across benchmarks. Some RL stages (particularly code RL) reduce model entropy and shorten reasoning traces, which hurts math. RLHF trades off against instruction following.</p><p>The solution: take the best checkpoint from each domain (the &#8220;teacher&#8221;) and <strong>distill on-policy into a single student</strong>. The teachers all come from within the Cascade RL pipeline itself , i.e., they share the same SFT initialization, same tokenizer, same vocabulary. No external models needed.</p><p>The MOPD objective defines a token-level distillation advantage:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;a_t^{MOPD} = \\log \\pi^{domain_i}(y_t | s_t) - \\log \\pi^{train}(y_t | s_t).&quot;,&quot;id&quot;:&quot;YJPFJCDAJZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>This is positive when the domain teacher is more confident than the current student on a given token. Because it&#8217;s token-level rather than sequence-level (like GRPO), it provides <strong>much denser gradients</strong>.</p><p>The practical setup uses three domain teachers: (1) the <strong>SFT checkpoint</strong> as the math teacher (SFT data quality is strong enough), (2) an <strong>RLHF checkpoint</strong>, and (3) the <strong>post-IF-RL + multi-domain-RL checkpoint</strong>. They sample prompts from the corresponding domain data pools and use truncated importance weighting with bounds [0.5, 2.0] to handle train-inference mismatch.</p><p>Code RL is particularly interesting: it uses an <strong>aggressively filtered set</strong> of only 3.5K prompts, removing anything that gpt-oss-120b solved correctly in all 8/8 rollouts. Only hard problems with strong test cases remain. The max response length is 118K tokens (up significantly from Cascade 1), with 16 rollouts per sample. Strict binary rewards, no partial credit, which are explicitly avoided to prevent reward hacking.</p><h2>The bigger picture</h2><p>Nvidia is explicitly pushing "intelligence density" as the metric that matters, i.e., task-level competence per active parameter. This also confirms a trend we've been tracking: <strong>post-training is becoming the dominant lever for model capability</strong>. The base model here is the same one that ships as Nemotron-3-Nano. The entire performance delta comes from SFT data curation, RL pipeline design, and MOPD.</p><p>But Nvidia&#8217;s relative weakness on agentic benchmarks (Tau-2 Bench: 58.9 vs Qwen&#8217;s 81.2, Terminal Bench 2.0: 21.1 vs 40.5) suggests that Cascade RL, while excellent for verifiable reasoning tasks, <strong>hasn&#8217;t yet cracked agentic capabilities at the same level</strong>. The gap on knowledge-heavy benchmarks (MMLU-Pro, GPQA) also points to pre-training limitations that no amount of post-training can fully overcome.</p><h2>What&#8217;s next</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!C6ml!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 424w, /__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 848w, /__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 1272w, /__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!C6ml!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png" width="640" height="356" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:356,&quot;width&quot;:640,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;r/LocalLLaMA - NVIDIA 2026 Conference LIVE. New Base model coming!&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="r/LocalLLaMA - NVIDIA 2026 Conference LIVE. New Base model coming!" title="r/LocalLLaMA - NVIDIA 2026 Conference LIVE. New Base model coming!" srcset="/__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 424w, /__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 848w, /__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 1272w, /__u/substackcdn.com/image/fetch/$s_!C6ml!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4caa2b0-a04f-47b5-af9c-2bd313c082e7_640x356.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>As predicted in <a href="/__u/substack.com/home/post/p-190644522">our previous article</a>, Nvidia officially announced <strong>Nemotron 3 Ultra</strong>. But, more interestingly, they also announced the <a href="https://nvidianews.nvidia.com/news/nvidia-launches-nemotron-coalition-of-leading-global-ai-labs-to-advance-open-frontier-models">Nemotron Coalition</a>, a collaboration to produce <strong>open frontier LLMs</strong>. The Cursor/Kimi K2.5 drama from the same week (where Composer 2 turned out to be Kimi K2.5 with RL on top) just reinforces the point: <strong>base models are commodities now, post-training is the differentiator</strong>, and Nvidia wants to be the platform everyone post-trains on<strong>.</strong></p><p><strong>Links:</strong></p><ul><li><p><a href="https://research.nvidia.com/labs/nemotron/files/Nemotron-Cascade-2.pdf">Technical report (PDF)</a></p></li><li><p><a href="https://huggingface.co/nvidia/Nemotron-Cascade-2-30B-A3B">Model weights (HuggingFace)</a></p></li><li><p><a href="https://huggingface.co/collections/nvidia/nemotron-cascade-2">Training data collection</a></p></li><li><p><a href="https://research.nvidia.com/labs/nemotron/nemotron-cascade-2/">NVIDIA project page</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Nemotron 3 Super: NVIDIA's gpt-oss killer?]]></title><description><![CDATA[120B parameters, 12B active, 512 experts, and 25 trillion tokens of NVFP4 pretraining]]></description><link>https://maximelabonne.substack.com/p/nemotron-3-super-nvidias-gpt-oss</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/nemotron-3-super-nvidias-gpt-oss</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Thu, 12 Mar 2026 11:53:03 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Jrs1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Jrs1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 424w, /__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 848w, /__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Jrs1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1850358,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 424w, /__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 848w, /__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Jrs1!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4909e684-bf23-456a-932a-c36c1a274b6c_1470x827.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On March 11th, 2026, NVIDIA released <a href="https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16">Nemotron 3 Super</a>, the second model in the Nemotron 3 family following <a href="https://developer.nvidia.com/blog/inside-nvidia-nemotron-3-techniques-tools-and-data-that-make-it-efficient-and-accurate/">Nano's December debut</a>. Super is a 120B total / 12B active parameter hybrid Mamba-Transformer MoE model, and it brings several features: <strong>LatentMoE</strong>, <strong>native NVFP4 pretraining</strong>, and <strong>multi-token prediction with shared-weight heads</strong>. They released not only model weights, but also datasets and training recipes, which makes it particularly interesting to analyze.</p><p>With this release, NVIDIA&#8217;s goal is to <strong>match gpt-oss-120b and Qwen3.5-122B-A10B</strong> on accuracy and deliver higher inference throughput. In practice, they claim 2.2x throughput over gpt-oss-120b on an 8k input / 64k output workload.</p><h2>Architecture</h2><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4LP6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 424w, /__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 848w, /__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4LP6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png" width="1381" height="289" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:289,&quot;width&quot;:1381,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:54881,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 424w, /__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 848w, /__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4LP6!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff5485e6c-1051-447d-9f7b-75bc38f3ac77_1381x289.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>Super adopts a <strong>hybrid Mamba-2/GQA architecture with 88 layers</strong>. In comparison, gpt-oss-20b uses Grouped Multi-Query Attention with 36 layers, and Qwen3.5-122B-A10B is a Gated Delta Network hybrid with 48 layers. In the Super architecture, Mamba-2 blocks handle the majority of sequence processing (linear-time complexity, constant memory during generation), while attention layers are inserted at strategic intervals as "global anchors" for precise associative recall.</p><p>The most interesting contribution here is <a href="https://arxiv.org/abs/2601.18089">LatentMoE</a> (Elango et al., 2026). Standard MoE designs route tokens from the model's full hidden dimension directly to experts. LatentMoE wraps the routed expert path with <strong>two shared linear projections</strong>: a down-projection from the hidden dimension <em>d</em> = 4096 to a latent dimension <em>l</em> = 1024, then expert computation happens entirely in this compressed space, and results get projected back up.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!84b2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 424w, /__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 848w, /__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 1272w, /__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!84b2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png" width="660" height="414.33878157503716" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:845,&quot;width&quot;:1346,&quot;resizeWidth&quot;:660,&quot;bytes&quot;:207319,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 424w, /__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 848w, /__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 1272w, /__u/substackcdn.com/image/fetch/$s_!84b2!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b50edde-8789-48e8-b9b4-e61407d7d680_1346x845.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The key insight is that reducing the expert dimension by a factor of <em>d/l</em> = 4 lets you reinvest those savings into both more total experts and higher top-k. Nemotron 3 Super runs <strong>512 total experts with top-22 routing</strong>, while standard MoE designs typically use 128 experts with top-6 or top-8. You get 4x the expert count and roughly 4x the active experts, at approximately the same compute and communication cost.</p><p>Why does this matter?</p><ul><li><p>In latency-sensitive inference, MoE is dominated by the <strong>memory bandwidth</strong> cost of reading expert weights.</p></li><li><p>In throughput-oriented serving, it&#8217;s dominated by <strong>all-to-all routing communication</strong>.</p></li></ul><p>LatentMoE reduces <em>both</em> bottlenecks by operating in the compressed space. The technical report includes ablations showing LatentMoE consistently outperforms standard MoE across code, math, and commonsense benchmarks at matched parameter and FLOP budgets.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!xHxb!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 424w, /__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 848w, /__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 1272w, /__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!xHxb!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png" width="712" height="314.9230769230769" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:644,&quot;width&quot;:1456,&quot;resizeWidth&quot;:712,&quot;bytes&quot;:234342,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 424w, /__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 848w, /__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 1272w, /__u/substackcdn.com/image/fetch/$s_!xHxb!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc5c0347e-8332-41f2-9f3c-48277d7039a1_1492x660.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Super includes 2 <strong>Multi-Token Prediction</strong> (MTP) layers that predict multiple future tokens from each position. Concretely, this provides <strong>native speculative decoding</strong> without needing a separate draft model.</p><p>The design choice that stands out is the <strong>shared-weight formulation</strong> across prediction heads. Standard MTP implementations use independent heads for each offset (e.g., one head for token n+2, another for n+3). This works fine during training but limits speculative decoding to at most N draft tokens, and degrades when you try to reuse a fixed-offset head autoregressively because of the training-inference distribution mismatch.</p><p>By sharing parameters, the heads <strong>see multiple offsets during training</strong>, which regularizes them into a more robust drafting model. The technical report shows an average acceptance length of 3.45 tokens on SPEED-Bench (draft length of 7), beating DeepSeek-R1 (2.70) and slightly edging out Qwen3-Next (3.33).</p><h2>Pre-training</h2><p><strong>Nemotron 3 Super is pretrained natively in NVFP4</strong> (NVIDIA's 4-bit floating-point format) for the entire 25T token run. Note that gpt-oss was already pre-trained in 4-bit precision, but using MXFP4, a lower-accuracy alternative.</p><p>NVFP4 is a narrow format that requires careful handling of numerical stability. The technical report is transparent about the challenges: they observed <strong>growing zero-valued weight gradients</strong> (reaching 7% of total parameters by end of pretraining), caused by NVFP4 underflowing already-small gradient values to zero.</p><p>NVIDIA investigated whether &#8220;healing&#8221; by switching to higher precision (MXFP8) before learning rate annealing would help. Their ablation showed the switch <strong>improved loss trajectory but yielded no downstream accuracy gains</strong>. So the final model is pure NVFP4 for the full token horizon. That&#8217;s a strong statement about the viability of low-precision pretraining at scale.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!unjR!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 424w, /__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 848w, /__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 1272w, /__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!unjR!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png" width="1456" height="482" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:482,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158703,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 424w, /__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 848w, /__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 1272w, /__u/substackcdn.com/image/fetch/$s_!unjR!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa06ada97-a454-4059-8a91-cda2a2645f2b_1468x486.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The pretraining corpus includes:</p><ul><li><p><strong>Two-phase structure</strong>: Phase 1 (80%, 20T tokens) focused on diversity and coverage; Phase 2 (20%, 5T tokens) focused on high-quality data</p></li><li><p><strong>Synthetic code datasets</strong>: ~15M Python problem-solution pairs generated and cleaned via gpt-oss models</p></li><li><p><strong>Synthetic formal logic, economics, and MCQ datasets</strong> generated using Qwen3-235B and DeepSeek-V3 for verification</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4GmL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 424w, /__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 848w, /__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4GmL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png" width="1456" height="425" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:425,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:105127,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 424w, /__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 848w, /__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4GmL!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1f264fc-b743-4e9f-8d29-0d4c333baaad_1636x478.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>During the stable phase of their Warmup-Stable-Decay (WSD) learning rate schedule, the constant learning rate makes individual checkpoint benchmarks <strong>noisy from step to step</strong>. Rather than running expensive dedicated LR decay branches just to gauge model quality, NVIDIA applies offline checkpoint merging (weighted averaging over a sliding window of recent checkpoints) to produce cleaner readouts.</p><p>Following the <a href="https://arxiv.org/abs/2507.17634">WSM framework</a> (Tian et al., 2025), which establishes a formal connection between LR decay and model merging, they use a minus-sqrt decay emulation to compute merge coefficients. The results are striking: across a suite of 12 benchmarks, the best merge consistently outperforms the corresponding raw trained checkpoint by 2-4 points. NVIDIA estimates this technique saved roughly 4T tokens of compute by avoiding dedicated decay runs needed purely for quality assessment.</p><h2>Post-Training</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!VP1l!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 424w, /__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 848w, /__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 1272w, /__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!VP1l!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png" width="1444" height="453" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:453,&quot;width&quot;:1444,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:87504,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 424w, /__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 848w, /__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 1272w, /__u/substackcdn.com/image/fetch/$s_!VP1l!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4f224c8-f7cb-46b6-86b2-b878b022ee9c_1444x453.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Super is SFTed on <strong>~7 million samples</strong> from a broader corpus of <strong>40 million</strong>, covering reasoning, instruction following, coding, safety, and multi-step agentic tasks. The SFT data explicitly trains the model for <strong>reasoning ON/OFF modes</strong> via the chat template.</p><p>Interestingly, they introduce a two-stage SFT loss function. Stage 1 corresponds to the standard approach (token-level average), where long conversations dominate the gradient signal. Stage 2 <strong>normalizes each conversation&#8217;s loss and then averages equally across the batch</strong>. This prevents shorter responses from being drowned out by long reasoning traces. It&#8217;s probably particularly important with the reasoning ON/OFF modes.</p><p>After SFT, NVIDIA runs RL across <strong>21 distinct environments </strong>drawn from <strong>37 datasets</strong>, generating approximately <strong>1.2 million environment rollouts</strong>. The environments span a diverse set of tasks: math, code, STEM, instruction following, safety, long context, agentic tool use, and reasoning gym. The training uses a very traditional GRPO with importance sampling to handle discrepancies between the training and rollout policies.</p><p>This is followed by a specific SWE stage focusing on agentic coding capabilities to autonomously solve GitHub issues. They use OpenHands as an agentic harness, which allows them to directly train on the tool formats expected by Claude Code and Codex.</p><p>After this, a separate RLHF stage refines conversational quality. NVIDIA trained a <strong>generative reward model (GenRM)</strong> by running GRPO on <a href="https://huggingface.co/nvidia/Qwen3-Nemotron-235B-A22B-GenRM-2603">Qwen3-Nemotron-235B-A22B</a> on a combination of Helpsteer 3 and lmarena-140k. Given a conversation history, a new user query, and two candidate assistant responses, the GenRM reasons explicitly about the strengths and weaknesses of each response, produces individual helpfulness scores, and generates a ranking.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!fT-_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 424w, /__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 848w, /__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!fT-_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png" width="966" height="367" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:367,&quot;width&quot;:966,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:60576,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/190644522?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 424w, /__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 848w, /__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fT-_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F126403c3-7a86-4102-8526-aa343d5f7e84_966x367.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On benchmarks, Qwen3.5-122B generally leads on raw accuracy, particularly on knowledge-heavy and agentic benchmarks. gpt-oss-120b edges ahead on some math and coding tasks. Nemotron 3 Super wins on HMMT Feb25 math and long-context retrieval, and holds competitive across the board. This is slightly underwhelming, but Super is also significantly faster than both models, even though the comparison with Qwen3.5 in BF16 is unfair.</p><p><a href="https://artificialanalysis.ai/models/nvidia-nemotron-3-super-120b-a12b">Artificial Analysis</a> independently confirms strong throughput numbers: ~478 tokens/second across providers, with 0.56s time to first token. Though they also flag the model as insanely verbose, generating 110M tokens during their evaluation suite versus an average of 7.3M. This extreme level of verbosity could erase most of the throughput gains in practice: gpt-oss-120b in high effort mode generates 77M tokens, and Qwen3.5-122B in reasoning mode produces 91M tokens.</p><h2>What&#8217;s Next</h2><p>Nemotron 3 Ultra (~500B parameters) is still expected. Given the LatentMoE scaling properties and the NVFP4 pretraining recipe, Ultra should be interesting. It would also directly compete with frontier Chinese MoEs and give us a good understanding of NVIDIA&#8217;s internal capabilities.</p><p><strong>Links:</strong></p><ul><li><p><a href="https://research.nvidia.com/labs/nemotron/files/NVIDIA-Nemotron-3-Super-Technical-Report.pdf">Nemotron 3 Super Technical Report (PDF)</a></p></li><li><p><a href="https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-BF16">Model Weights (BF16)</a> | <a href="https://huggingface.co/nvidia/NVIDIA-Nemotron-3-Super-120B-A12B-FP8">FP8</a></p></li><li><p><a href="https://developer.nvidia.com/blog/introducing-nemotron-3-super-an-open-hybrid-mamba-transformer-moe-for-agentic-reasoning/">NVIDIA Blog Post</a></p></li><li><p><a href="https://arxiv.org/abs/2601.18089">LatentMoE Paper</a></p></li><li><p><a href="https://github.com/NVIDIA-NeMo/Nemotron/tree/main/usage-cookbook/Nemotron-3-Super">Deployment Cookbooks (GitHub)</a></p></li><li><p><a href="https://huggingface.co/collections/nvidia/nemotron-pre-training-datasets">Pre-training Datasets</a> | <a href="https://huggingface.co/collections/nvidia/nemotron-post-training-v3">Post-training Datasets</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Kimi K2.5: Still Worth It After Two Weeks?]]></title><description><![CDATA[Agent swarm and early fusion for better vision capabilities]]></description><link>https://maximelabonne.substack.com/p/kimi-k25-still-worth-it-after-two</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/kimi-k25-still-worth-it-after-two</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Thu, 19 Feb 2026 10:26:54 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!2qPi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!2qPi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 424w, /__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 848w, /__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!2qPi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2309894,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188072694?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 424w, /__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 848w, /__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2qPi!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F71755614-a395-4e28-8761-b32c0f2069e0_1536x864.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Beijing-based Moonshot AI released <strong>Kimi K2.5</strong> on January 27, 2026. Beyond traditional claims on benchmarks like HLE (50.2% with tools), coding, and vision, this release introduced the idea of &#8220;Agent Swarm&#8221;. Two weeks in, I wanted to revisit Kimi K2.5 and compare it with other recent releases like GLM-5, MiniMax-M2.5, and Qwen3.5.</p><h2>What K2.5 Actually Is</h2><p>Kimi K2.5 is one of the largest open-weight models with 1.04 trillion parameters and 32B activated parameters per token. This is significantly bigger than MiniMax-M2.5 (230B-A10B), Qwen3.5 (397B-A17B), and GLM-5 (1T-32B). It uses 384 experts with 8 activated per token, MLA attention, SwiGLU activation, and a 256K context window. The architecture is identical to Kimi K2, which shipped back in mid-2025.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!lNSj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 424w, /__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 848w, /__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!lNSj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png" width="1456" height="460" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:460,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:148692,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188072694?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 424w, /__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 848w, /__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lNSj!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78ed0b61-3a32-4fe2-a2ed-b5e8d2e9607a_1496x473.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>What&#8217;s new is the training. K2 was originally pre-trained on 15T text-only tokens. K2.5 then continues from a near-end K2 checkpoint over an additional <strong>~15T mixed visual and text tokens</strong>, plus ~1T for ViT training and ~700B for long-context mid-training (see <a href="https://arxiv.org/abs/2602.02276">tech report</a>). If the numbers don&#8217;t overlap, that&#8217;s roughly <strong>32T tokens </strong>across the full pipeline (vs. 28.5T tokens for the text-only GLM-5 &#8212; Qwen3.5 and MiniMax-2.5 haven&#8217;t released any numbers).</p><p>The vision encoder is MoonViT-3D, a 400M parameter native-resolution ViT based on SigLIP-SO-400M, with a NaViT packing strategy that handles variable-resolution images. For video, consecutive frames are grouped in fours and temporally pooled, achieving 4x compression. Qwen3.5 also used early fusion with a different strategy. Late fusion seems dead for frontier models.</p><p>The model ships in native INT4 precision (~595GB), not FP8/BF16. Moonshot used quantization-aware training during post-training to achieve this. <a href="https://huggingface.co/unsloth/Kimi-K2.5-GGUF">Unsloth&#8217;s dynamic 1.8-bit quant</a> brings it down to ~240GB, runnable on a single 24GB GPU with sufficient RAM offloading at ~10 tokens/sec.</p><h2>Agent Swarm</h2><p>Before we get to the benchmarks, I want to talk about the most technically interesting part of this release: <strong>Agent Swarm</strong>. And, specifically, the <strong>Parallel-Agent Reinforcement Learning (PARL)</strong> framework that powers it.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!RLP1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 424w, /__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 848w, /__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 1272w, /__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!RLP1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png" width="1456" height="788" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:788,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 424w, /__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 848w, /__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 1272w, /__u/substackcdn.com/image/fetch/$s_!RLP1!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9bba2f28-7fbe-4c2a-a6ce-e3ffe22f9c24_3622x1960.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The core idea is that, instead of executing agent tasks sequentially (tool call, observe result, reason, next tool call, etc.), K2.5 learns to decompose problems into parallelizable subtasks and delegates them to sub-agents. The orchestrator is trainable, but the sub-agents are frozen copies of intermediate policy checkpoints. Only the orchestrator&#8217;s parameters get updated via RL.</p><p>This is designed this way because an end-to-end co-optimization of the orchestrator and sub-agents would create a <strong>credit assignment nightmare</strong>. In other words, if the final answer is wrong, is it the orchestrator&#8217;s fault for bad delegation, or the sub-agent&#8217;s fault for bad execution?</p><p>The training had to solve two emergent failure modes: <strong>serial collapse</strong> (the orchestrator defaults to safe sequential execution) and <strong>spurious parallelism</strong> (it spams sub-agent creation to game metrics without meaningful decomposition). Auxiliary reward terms push past both early in training, then anneal to zero so the final policy optimizes purely for task success.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!onrH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 424w, /__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 848w, /__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 1272w, /__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!onrH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png" width="997" height="292" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:292,&quot;width&quot;:997,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 424w, /__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 848w, /__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 1272w, /__u/substackcdn.com/image/fetch/$s_!onrH!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe36a8975-2d5a-4b40-b477-bf70d81e4c41_997x292.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>According to Moonshot AI, BrowseComp jumps from 60.6% (single agent) to <strong>78.4%</strong> (swarm), WideSearch F1 from 72.7% to 79.0%, and execution time drops 3-4.5x on suitable tasks. However, for comparison, Qwen3.5 reports a BrowseComp score of 78.6 using the same discard-all strategy as K2.5, but without a swarm mechanism. To my knowledge, this is the first time an open-weight model has been <em>trained</em> to parallelize agentic work rather than having it imposed by external scaffolding. Exciting stuff!</p><h2>Benchmarks</h2><p>Moonshot&#8217;s reported numbers are competitive. Here&#8217;s the context that matters.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!R98A!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 424w, /__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 848w, /__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 1272w, /__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!R98A!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png" width="1456" height="801" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/df8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:801,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 424w, /__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 848w, /__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 1272w, /__u/substackcdn.com/image/fetch/$s_!R98A!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf8575fb-a192-401e-954b-b3915b0809b3_3786x2082.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Where K2.5 leads (among all models, including proprietary):</strong> HLE-Full with tools (50.2% vs. GPT-5.2&#8217;s 45.5%), BrowseComp with swarm (78.4%), OCRBench (92.3%), MathVista (90.1%), InfoVQA (92.6%). Note that MiniMax M2.5 reports 76.3% for BrowseComp without any swarm mechanism.</p><p><strong>Where K2.5 is competitive but behind frontier:</strong> AIME 2025 (96.1% vs. GPT-5.2&#8217;s 100%), SWE-Bench Verified (76.8% vs. Claude Opus 4.5&#8217;s 80.9%, MiniMax M2.5&#8217;s 80.2%, Qwen3.5&#8217;s 76.4%), GPQA-Diamond (87.6% vs. GPT-5.2&#8217;s 92.4% and Qwen3.5&#8217;s 88.4%), Terminal-Bench 2.0 (50.8% vs. Claude&#8217;s 59.3%).</p><p><strong>Where K2.5 shows clear gaps:</strong> WeirdML (46% vs. 72% for GPT-5.2) is telling. On Artificial Analysis&#8217;s AA-Omniscience knowledge index, K2.5 scores -11 (correct minus incorrect), meaning it hallucinates more than other frontier models. Claude Opus 4.5 scores +10, Gemini 3 Pro scores +13.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!wJOh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 424w, /__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 848w, /__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 1272w, /__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!wJOh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png" width="1456" height="391" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:391,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:741174,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188072694?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 424w, /__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 848w, /__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 1272w, /__u/substackcdn.com/image/fetch/$s_!wJOh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8012004b-e280-42bd-b5bf-e006be8bc319_6012x1616.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Kimi K2.5 was also the open-weight model with the high Intelligence Index on Artificial Analysis before the release of GLM-5. It still leads compared to Qwen3.5 and MiniMax-M2.5, which are smaller models. Note that it doesn&#8217;t mean that GLM-5 is necessarily superior (and vice-versa): many details get ironed out with these streamlined benchmarks, and features like Agent Swarm are not properly taken into account.</p><h2>Community Feedback</h2><p>Two weeks of community usage provide a good picture of the model&#8217;s real impact.</p><p><strong>Coding:</strong> K2.5 is legitimately strong, especially for front-end work and visual-to-code tasks. <a href="https://blog.kilo.ai/p/what-we-learned-from-a-week-of-free">Kilo Code reports</a> it rapidly climbed to top-performer status for architectural planning. Multiple developers on r/LocalLLaMA report building complete projects at ~1/8th the cost of Opus. But the pattern in skeptical reviews is consistent: K2.5 often generates verbose, over-engineered code on the first pass, then simplifies when asked. Opus and Codex tend to get it right the first time.</p><p><strong>Agent Swarm:</strong> Impressive when it works. Users report effective parallel web research and multi-niche data collection. But follow-up editing of swarm outputs is painful, and sub-agents can drift into inconsistent definitions for shared concepts. The spreadsheet use case (compiling data across rows) exposed this: every agent used slightly different column definitions.</p><p><strong>Vision:</strong> The first open-weight model where vision feels genuinely competitive. Nathan Labenz tested it on a scanned document transcription task where Chinese models historically lagged, and K2.5 matched Gemini 3 level. Qwen3.5 also makes a strong play here: 90.3 on MathVista, 85.0 on MMMU, and native UI screenshot understanding with element detection. Creative writing and personality, on the other hand, are clearly behind Opus. And multiple users discovered K2.5 sometimes identifies itself as Claude, a strong signal about training data provenance.</p><h2>The Bigger Picture</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!K3vh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 424w, /__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 848w, /__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 1272w, /__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!K3vh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png" width="1456" height="421" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:421,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:846672,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188072694?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 424w, /__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 848w, /__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 1272w, /__u/substackcdn.com/image/fetch/$s_!K3vh!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe48963a7-5d14-4da4-9517-7794f732871f_6008x1736.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Verbosity and cost.</strong> When Artificial Analysis evaluated K2.5, the model generated 89 million output tokens. The median for comparable models is 14 million. At $0.60/$3.00 per million input/output tokens, the per-token price looks cheap, but when the model produces 6x more tokens per task, effective costs still spike. Kilo Code&#8217;s week-long free trial confirmed this: usage surged past 50B tokens/day, and they concluded the model&#8217;s verbosity dilutes the savings from input caching. This is the main issue with this model.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!FGPY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 424w, /__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 848w, /__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!FGPY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png" width="1223" height="307" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:307,&quot;width&quot;:1223,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:94118,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188072694?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 424w, /__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 848w, /__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FGPY!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7261e4a9-bf7a-4f99-b348-0b73a4ba86bb_1223x307.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Multimodal training insights.</strong> The technical report contains a finding worth highlighting for anyone building multimodal models. Given a fixed vision-text token budget, early fusion with a low vision ratio (10% vision from the start) outperformed late fusion with a high ratio (50% vision injected at the 80% mark) across every metric. Moonshot also introduces &#8220;zero-vision SFT,&#8221; where text-only fine-tuning activates visual reasoning capabilities, and visual RL actually <em>improved</em> text-only benchmarks (MMLU-Pro: 84.7% to 86.4%, GPQA-Diamond: 84.3% to 86.4%). This bidirectional transfer validates the native multimodal approach.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!nckO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 424w, /__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 848w, /__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 1272w, /__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!nckO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png" width="1456" height="264" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:264,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:73070,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188072694?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 424w, /__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 848w, /__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 1272w, /__u/substackcdn.com/image/fetch/$s_!nckO!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F41cb7c3f-8618-4556-90b1-f1b882d33ecd_1473x267.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Geopolitics and sustainability.</strong> K2.5 was trained on hardware constrained by US export controls, and it&#8217;s competitive with models from labs that have unconstrained chip access. Moonshot raised at a $4.8 billion valuation and is clearly spending that capital on user acquisition: the free tier is generous, Agent Swarm beta comes with free credits. The pricing is almost certainly not sustainable long-term. The license is Modified MIT, commercially free for companies under 100M MAU.</p><p><strong>Deployment.</strong> Running K2.5 locally requires serious hardware: ~595GB at native INT4, with Unsloth&#8217;s 2-bit quant (375GB) as the practical sweet spot. On a single 24GB GPU with 256GB+ RAM, expect ~10 tokens/sec. The model works with vLLM, SGLang, and KTransformers, though the r/LocalLLaMA AMA surfaced rough edges with <code>&lt;think&gt;</code> tag parsing on some backends. Vision support in GGUF/llama.cpp is not yet available. For API users, 8 providers serve K2.5, with Fireworks leading on speed (283 t/s), DeepInfra on price ($0.90 blended), and Baseten on raw throughput (336 t/s).</p><h2>What&#8217;s Next</h2><p>K2.5 is a solid open-weight model with strong vision capabilities, but verbosity can be an issue for real-world usage. Because competition is particularly fierce at this range, it&#8217;s better to experiment with different options for your particular use cases.</p><p>The part I'd watch most closely is whether PARL generalizes. Whether that transfers to arbitrary real-world workflows or mainly helps on embarrassingly parallel research tasks is still open. &#175;\_(&#12484;)_/&#175;</p><p><strong>Quick links:</strong></p><ul><li><p>Weights: <a href="https://huggingface.co/moonshotai/Kimi-K2.5">huggingface.co/moonshotai/Kimi-K2.5</a></p></li><li><p>Technical report: <a href="https://arxiv.org/pdf/2602.02276">arxiv.org/pdf/2602.02276</a></p></li><li><p>Blog post: <a href="https://www.kimi.com/blog/kimi-k2-5.html">kimi.com/blog/kimi-k2-5.html</a></p></li><li><p>API: <a href="https://platform.moonshot.ai/">platform.moonshot.ai</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Qwen3.5: Nobody Agrees on Attention Anymore]]></title><description><![CDATA[Bigger than MiniMax-M2.5, sparser than GLM-5, as good as Kimi K2.5?]]></description><link>https://maximelabonne.substack.com/p/qwen35-nobody-agrees-on-attention</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/qwen35-nobody-agrees-on-attention</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 16 Feb 2026 17:49:53 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!n8yq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!n8yq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 424w, /__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 848w, /__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 1272w, /__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!n8yq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png" width="1456" height="843" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/86a23dac-a464-431d-95e0-814229691b4e_1536x889.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:843,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2383812,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188133649?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 424w, /__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 848w, /__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 1272w, /__u/substackcdn.com/image/fetch/$s_!n8yq!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86a23dac-a464-431d-95e0-814229691b4e_1536x889.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On February 16th, 2026, Alibaba's Qwen team released <strong>Qwen3.5-397B-A17B</strong>, their next-generation foundation model. If you're getting a sense of d&#233;j&#224; vu from the holiday timing, you should be. GLM-5 shipped on February 11th. MiniMax M2.5 landed the same day. Kimi K2.5 arrived on January 27th. And now Qwen3.5 closes out the pre-holiday window. Let&#8217;s see how it compares with the other releases.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Tuky!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 424w, /__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 848w, /__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Tuky!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png" width="1456" height="941" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:941,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 424w, /__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 848w, /__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Tuky!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbffcc1ce-f7f4-4a4a-ac49-63c67d7c2467_17277x11171.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>What Qwen3.5 Actually Is</h2><p>Qwen3.5-397B-A17B is a 397 billion parameter Mixture-of-Experts model with only 17 billion active parameters per token. The hosted API version is called Qwen3.5-Plus, and it ships with a 1M context window, built-in tools, and adaptive tool use out of the box.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!mxxw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 424w, /__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 848w, /__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 1272w, /__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!mxxw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png" width="440" height="468.7087912087912" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1551,&quot;width&quot;:1456,&quot;resizeWidth&quot;:440,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 424w, /__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 848w, /__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 1272w, /__u/substackcdn.com/image/fetch/$s_!mxxw!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab472d4b-0eb7-4df3-8d40-d4eed541a8ae_2204x2348.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The key innovations stack up like this:</p><p><strong>Hybrid Attention Architecture.</strong> This is the big architectural bet. Qwen3.5 builds on the Qwen3-Next lineage, combining Gated Delta Networks (a linear attention variant) with sparse Mixture-of-Experts. The model alternates between Gated DeltaNet layers (linear attention) and full attention layers in roughly a 3:1 ratio. <a href="https://magazine.sebastianraschka.com/i/168650848/12-qwen3-next">Sebastian Raschka has an excellent write-up</a> on how this works, but the short version is: three out of every four transformer blocks use linear attention (which scales near-linearly with sequence length), and every fourth block uses standard full attention. The result is a model that can process long contexts more efficiently than full attention.</p><p>The Gated DeltaNet mechanism itself draws from the &#8220;<a href="https://arxiv.org/abs/2412.06464">Gated Delta Networks: Improving Mamba2 with Delta Rule</a>&#8221; paper. It combines Mamba2&#8217;s gated decay mechanism with a delta rule for updating hidden states. The gated attention output gating helps eliminate attention sinks and massive activations, improving training stability at scale.</p><p><strong>Scalable RL at Agent Scale.</strong> Qwen3.5 was trained with reinforcement learning scaled across what the team describes as "million-agent environments with progressively complex task distributions." This follows the trend we've seen from MiniMax's Forge and Zhipu's Slime: asynchronous RL infrastructure designed to handle the long-horizon, multi-step nature of agentic tasks. The details here are sparse in the initial release, but the emphasis on "robust real-world adaptability" suggests they've invested heavily in environment diversity during RL post-training.</p><p><strong>Unified Vision-Language Foundation.</strong> Unlike Qwen3, which had separate text and vision model lines (Qwen3 and Qwen3-VL), Qwen3.5 is natively multimodal from the ground up. Early fusion training on multimodal tokens means the model doesn&#8217;t need a separate vision adapter. The team claims cross-generational parity with Qwen3 on text tasks while outperforming Qwen3-VL on visual understanding.</p><p><strong>201 Languages.</strong> Expanded from Qwen3&#8217;s 119 to 201 languages and dialects. This is the broadest language coverage of any open model I&#8217;m aware of. Note that Qwen tends to be very generous with its definition of &#8220;language support,&#8221; and quality is not guaranteed for low-resource languages.</p><h2>Attention &amp; Sparsity</h2><p>Efficient attention mechanisms and increased sparsity are two common trends with recent releases. While DeepSeek pioneered this field, every major Chinese lab has its own take on how to handle attention.</p><p>Qwen3-Next uses a 3:1 hybrid attention layout in which most layers use <strong>Gated DeltaNet</strong> (linear attention) and the remaining layers use <strong>Gated Attention</strong> (full/softmax-style attention). Kimi K2.5 and GLM-5 both use <strong>Multi-head Latent Attention (</strong>MLA<strong>)</strong>, but GLM-5 also integrates <strong>DeepSeek Sparse Attention (</strong>DSA<strong>)</strong> to induce token-level sparsity on top of it. Finally, MiniMax-M2.5 is the only full attention model (see <a href="https://www.minimax.io/news/why-did-m2-end-up-as-a-full-attention-model">this article</a>) with <strong>Multi-Head Attention (</strong>MHA<strong>)</strong> for reliability purposes.</p><p>The active parameter count is also worth zooming in on. At 17B active, Qwen3.5 is a lot sparser than Qwen3-235B-A22B, but in line with other recent releases:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!h7nG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 424w, /__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 848w, /__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 1272w, /__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!h7nG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png" width="552" height="270.00685714285714" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:428,&quot;width&quot;:875,&quot;resizeWidth&quot;:552,&quot;bytes&quot;:43515,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188133649?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 424w, /__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 848w, /__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 1272w, /__u/substackcdn.com/image/fetch/$s_!h7nG!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca44aac-39ac-41c1-b0cd-2dd38ad75c25_875x428.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Notably, MiniMax M2.5 has the smallest active parameter count at 10B and the same activation ratio as Qwen3.5. Kimi K2.5 is even sparser but also significantly bigger with 1T total parameters.</p><h2>Benchmarks</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4enI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 424w, /__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 848w, /__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4enI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png" width="595" height="249.16475972540044" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:366,&quot;width&quot;:874,&quot;resizeWidth&quot;:595,&quot;bytes&quot;:52878,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188133649?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 424w, /__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 848w, /__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4enI!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F805fa8e6-12dc-43b9-b27c-7a874bca86fc_874x366.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Reasoning and Math.</strong> Qwen3.5 scores 91.3 on AIME 2026 and 94.8 on HMMT Feb 25, which is competitive but below the best-performing models (GPT-5.2 hits 96.7 on AIME 2026, Claude 93.3). Math capabilities are solid but far from dominant.</p><p><strong>Knowledge and Instruction Following.</strong> On IFBench, it scores 76.5, beating every model in the comparison, including GPT-5.2 (75.4) and blowing past Claude (58.0). MultiChallenge tells the same story: 67.6 vs. GPT-5.2&#8217;s 57.9 and Claude&#8217;s 54.2. The model seems exceptionally good at following complex instructions but to be confirmed with real-world testing.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!TYox!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 424w, /__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 848w, /__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!TYox!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png" width="594" height="218.34246575342465" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:322,&quot;width&quot;:876,&quot;resizeWidth&quot;:594,&quot;bytes&quot;:47694,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/188133649?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 424w, /__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 848w, /__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TYox!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff2a2bfdb-356c-403a-85a6-3095ffa8bb2c_876x322.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Agents.</strong> The agentic benchmarks paint an interesting picture. Qwen3.5 scores 86.7 on Tau2-Bench, second only to Claude (91.6). On MCPMark, it hits 46.1 vs. GPT-5.2&#8217;s 57.5 and Claude&#8217;s 42.3. On BrowseComp, Qwen3.5 reports two numbers depending on strategy: 69.0 with simple context-folding, and 78.6 using the same discard-all strategy as DeepSeek-V3.2 and K2.5. The BrowseComp split is worth noting because it highlights how much agentic benchmark scores depend on scaffolding choices, not just raw model capability.</p><p><strong>Coding.</strong> Qwen3.5 scores 76.4 on SWE-bench Verified, essentially level with K2.5 (76.8) and Gemini 3 Pro (76.2), but behind GPT-5.2 (80.0) and Claude (80.9). On SWE-bench Multilingual, it does better at 72.0, matching GPT-5.2. SecCodeBench is a strong suit: 68.3, tied with GPT-5.2 (68.7) and Claude (68.6).</p><p><strong>Vision.</strong> As a natively multimodal model, Qwen3.5 excels here. It scores 85.0 on MMMU (up from Qwen3-VL&#8217;s 80.6!), 88.6 on MathVision (ahead of Gemini 3 Pro&#8217;s 86.6), and 90.8 on OmniDocBench. The visual agent results are solid too: 62.2 on OSWorld-Verified and 66.8 on AndroidWorld. The ZEROBench result of 12 (vs. 10 for Gemini and 9 for GPT-5.2) is notable given the extreme difficulty of this benchmark.</p><p>Qwen3.5 is not the best at any single category, but it's remarkably well-rounded and leads on instruction following. It significantly outperforms its own Qwen3-Max-Thinking across the board despite being much smaller (397B vs 1T+).</p><h2>The Bigger Picture</h2><p><strong>The attention mechanism is the new battleground.</strong> A year ago, the question was &#8220;MoE or dense?&#8221; That&#8217;s settled (and we might thank Llama-3.1-405B for this). Now the divergence is in how you handle attention. DeepSeek&#8217;s fingerprints are everywhere (MLA in K2.5 and GLM-5, DSA in GLM-5), but the Gated DeltaNet hybrid from Qwen3.5 (and initiated in Qwen3-Next) offers a new direction.</p><p><strong>The benchmark landscape has shifted to match agentic workloads.</strong> All four releases target agentic tasks. The models are evaluated on SWE-bench, BrowseComp, HLE with tools, TAU2-Bench, and MCPMark. The era of chatbot benchmarks as the primary evaluation axis is over. Qwen3.5&#8217;s BrowseComp split (69.0 vs. 78.6 depending on strategy) is a reminder that agentic scores are increasingly a function of scaffolding and context management, not just raw intelligence.</p><h2>What&#8217;s Next</h2><p>The fact that Qwen3.5 ships only the 397B-A17B size on day one (&#8221;more sizes are coming&#8221;) suggests we&#8217;ll see a family rollout similar to Qwen3. It&#8217;ll be interesting to see if smaller variants also adopt the hybrid DeltaNet architecture. For this release, it feels like Qwen3-Next previewed this direction (back in September), but Qwen3.5 is the production-scale validation.</p><p><strong>Quick links:</strong></p><ul><li><p>Model weights: <a href="https://huggingface.co/Qwen/Qwen3.5-397B-A17B">https://huggingface.co/Qwen/Qwen3.5-397B-A17B</a></p></li><li><p>GitHub: <a href="https://github.com/QwenLM/Qwen3.5">https://github.com/QwenLM/Qwen3.5</a></p></li><li><p>Blog: <a href="https://qwen.ai/blog?id=qwen3.5">https://qwen.ai/blog?id=qwen3.5</a></p></li></ul>]]></content:encoded></item><item><title><![CDATA[MiniMax-M2.5: The $1/hour Frontier Model]]></title><description><![CDATA[Cheap agentic AI for productivity workflows]]></description><link>https://maximelabonne.substack.com/p/minimax-m25-the-1hour-frontier-model</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/minimax-m25-the-1hour-frontier-model</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Fri, 13 Feb 2026 12:31:38 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!p368!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!p368!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 424w, /__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 848w, /__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 1272w, /__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!p368!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:2246995,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/187850795?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 424w, /__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 848w, /__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 1272w, /__u/substackcdn.com/image/fetch/$s_!p368!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F29a3118c-dc4d-4fc7-a407-0c1ca6b0ceac_1536x864.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On February 12th, 2026, barely a month after its Hong Kong IPO, Shanghai-based MiniMax dropped M2.5. The headline numbers: <strong>80.2% SWE-Bench Verified</strong>, <strong>51.3% Multi-SWE-Bench</strong> (first place), <strong>76.3% BrowseComp</strong>. These are numbers that sit within a percentage point of Claude Opus 4.6 and ahead of GPT-5.2 on several agentic benchmarks. Even more interestingly to me, the model costs roughly <strong>$1 per hour of continuous operation</strong> at 100 tokens per second.</p><p>The striking part of this release is the combination: this is a 230B MoE model with only 10B active parameters, trained primarily through large-scale reinforcement learning across 200,000+ real-world environments. It handles not just code but full office productivity workflows (Word, Excel, PowerPoint).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!aoF9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 424w, /__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 848w, /__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 1272w, /__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!aoF9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png" width="1456" height="777" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0817df16-e91e-4558-8116-e2267911c30c_1501x801.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:777,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 424w, /__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 848w, /__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 1272w, /__u/substackcdn.com/image/fetch/$s_!aoF9!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0817df16-e91e-4558-8116-e2267911c30c_1501x801.png 1456w" sizes="100vw"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><h2>What M2.5 Actually Is</h2><p>MiniMax-M2.5 is an iterative improvement on the M2 family, which launched in late October 2025. The architecture is unchanged from M2: a Mixture-of-Experts model with <strong>230 billion total parameters and 10 billion active</strong> per forward pass. For context, this active parameter count is tiny compared to what you&#8217;d expect from a frontier-competitive model:</p><ul><li><p>GLM-5 has <strong>744B</strong> parameters and <strong>40B</strong> active</p></li><li><p>DeepSeek V3/R1 has <strong>685B</strong> parameters and <strong>37B</strong> active</p></li><li><p>Not frontier, but as reference Qwen3-235B has <strong>235B</strong> parameters and <strong>22B</strong> active</p></li></ul><p>The model comes in two API variants:</p><ul><li><p><strong>M2.5-Lightning</strong>: 100 tokens per second, $0.30/M input, $2.40/M output</p></li><li><p><strong>M2.5 Standard</strong>: 50 tokens per second, $0.15/M input, $1.20/M output</p></li></ul><p>The Lightning version is roughly 2x the throughput of other frontier models. The Standard version is extremely cheap. To put the pricing in perspective: Claude Opus 4.6 charges $5/M input and $25/M output tokens. Even <strong><a href="/__u/maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company">GLM-5 that was just released </a></strong>is priced at $1/M input and $3.20/M output tokens, which makes it several times more expensive.</p><p>If you want to run it locally, the recommendation is vLLM or SGLang. With only 10B active parameters, the inference footprint is remarkably manageable for a model at this capability level.</p><h3>Benchmarks</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!nJPN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 424w, /__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 848w, /__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 1272w, /__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!nJPN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png" width="1257" height="732" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:732,&quot;width&quot;:1257,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 424w, /__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 848w, /__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 1272w, /__u/substackcdn.com/image/fetch/$s_!nJPN!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7994da95-2843-41fb-bd5b-238b82ba310d_1257x732.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>A few things stand out. The <strong>Multi-SWE-Bench</strong> score of 51.3% is actually first place, ahead of Opus 4.6&#8217;s 50.3%. Multi-SWE-Bench tests multilingual coding tasks, and M2.5 was trained on 10+ languages (Python, Go, C, C++, TypeScript, Rust, Kotlin, Java, JavaScript, PHP, Lua, Dart, Ruby). This is not a Python-only model, my C++/Rust friends will be happy.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!TD6T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 424w, /__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 848w, /__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!TD6T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png" width="1267" height="777" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:777,&quot;width&quot;:1267,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 424w, /__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 848w, /__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TD6T!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b204368-cfe7-4620-bf54-b139cbc52857_1267x777.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>The <strong>BFCL multi-turn</strong> score is quite an interesting number. First, it&#8217;s quite cheeky to only report the multi-turn split and nothing else. At 76.8% on multi-turn function calling, M2.5 leads Opus 4.6 by over 13 percentage points. It also shows immense progress in terms of multi-turn tool use compared to MiniMax M2.1 (+39.4 points).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!UsLi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!UsLi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg" width="1280" height="785" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:785,&quot;width&quot;:1280,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!UsLi!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb602ccc7-6523-4a62-bc89-44607aa241b8_1280x785.jpeg 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>And then there&#8217;s the independent evaluation from <strong>OpenHands</strong> (the open-source coding agent platform). Their OpenHands Index placed M2.5 4th overall, behind only Claude Opus 4.6, Claude Opus 4.5, and GPT-5.2 Codex. Graham Neubig noted the model performed particularly well on long-running tasks like developing apps from scratch, an area where smaller models have historically struggled.</p><h2>Forge Reinforcement Learning</h2><p>What&#8217;s technically interesting about M2.5 is <em>how</em> MiniMax got here. The answer is large-scale reinforcement learning, and specifically their in-house framework called <strong>Forge</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!7Tnz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 424w, /__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 848w, /__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!7Tnz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png" width="1074" height="786" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:786,&quot;width&quot;:1074,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="/__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 424w, /__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 848w, /__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7Tnz!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6cfbc3d-453a-4363-9fec-afd78777110c_1074x786.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Forge is what MiniMax calls an &#8220;agent-native RL framework.&#8221; The key design decision is a decoupling layer between the training/inference engine and the agent scaffolding. This means MiniMax can plug any agent framework (Claude Code, Droid, OpenCode, custom harnesses) into the RL training loop, and the model learns to generalize across scaffolds rather than overfitting to one particular tool interface. MiniMax trained across <strong>200,000+ real-world environments</strong> and in multiple domains, including, interestingly, their own company&#8217;s internal tasks.</p><p>To get the RL to scale, MiniMax used three key innovations:</p><ol><li><p><strong>CISPO (Clipped Importance Sampling Policy Optimization)</strong>: Their custom RL algorithm, first proposed in the M1 paper. Rather than clipping token updates like PPO/GRPO, CISPO clips the importance sampling weights. The result is that all tokens contribute to gradient computations, even low-probability ones that are often crucial for maintaining entropy and enabling scalable RL. In controlled experiments on Qwen2.5-32B, CISPO achieved a 2x speedup compared to DAPO (ByteDance&#8217;s recent RL algorithm).</p></li><li><p><strong>Asynchronous scheduling + tree-structured sample merging</strong>: To keep GPU utilization high during the inherently sequential nature of agent rollouts, they optimized the balance between throughput and sample off-policyness. They claim it achieves approximately a 40x training speedup over naive approaches.</p></li><li><p><strong>Process rewards for credit assignment</strong>: Long agent trajectories make credit assignment extremely difficult. If a coding agent takes 50 steps to solve a bug, which steps were actually helpful? MiniMax introduced process-level rewards to monitor generation quality throughout the trajectory, and also directly estimated real-world task completion time as a reward signal, pushing the model toward faster solutions.</p></li></ol><p>MiniMax engineer Olive Song noted on <strong><a href="https://www.linkedin.com/in/alex-volkov-?miniProfileUrn=urn%3Ali%3Afs_miniProfile%3AACoAAAPqfkkB95PruxCmgSFCvso-EFEpT4EnqH4">Alex Volkov</a></strong>&#8216;s ThursdAI podcast that the entire M2.5 training period was about two months. For reference, the M1 reasoning model&#8217;s full RL training on 512 H800s completed in just three weeks at a rental cost of $534,700. The M2 series uses the smaller 230B MoE architecture (M1 was 456B with 45.9B active), so the compute requirements are even more favorable.</p><h2>The Bigger Picture</h2><p>MiniMax made a few interesting design choices that deserve a highlight.</p><p><strong>Emergent spec-writing behavior.</strong> MiniMax notes that M2.5 has learned to proactively plan before writing code, decomposing a project before starting implementation. This is consistent with what we&#8217;ve seen in other top coding models. When they&#8217;re trained in environments that reward end-to-end task completion, they develop strategic planning behaviors. The model learns that spending tokens on upfront planning saves tokens and reduces errors downstream. This directly translates into token efficiency. On SWE-Bench Verified, M2.5 consumed an average of 3.52M tokens per task versus M2.1&#8217;s 3.72M tokens.</p><p><strong>Office productivity.</strong> Beyond code, manipulating Office documents becomes a key feature for frontier models. MiniMax clearly targets this space and developed an internal GDPval-MM benchmark (pairwise LLM-as-judge evaluation of trajectory quality). They claim that M2.5 achieved a <strong>59.0% average win rate</strong> against mainstream models. They also develop MiniMax Agent, their consumer-facing agentic platform where users have built over 10,000 &#8220;Experts&#8221; (specialized agent configurations).</p><p><strong>Cost.</strong> This is the most interesting bit to me here. MiniMax is still not Opus 4.6-level, but it frames M2.5 as the most cost-efficient alternative. The blog post even states that &#8220;you can have four M2.5 instances running continuously for an entire year for $10,000.&#8221; Honestly, I don&#8217;t think the experience is consistent enough for production workloads. Early reports from OpenHands suggest the model is strong but occasionally sloppy (wrong branch pushes, missed formatting instructions). However, it shows a clear and achievable path a few generations down the line.</p><h2>What&#8217;s Next</h2><p>MiniMax promised a more detailed technical blog post on the Forge framework and their RL scaling laws. That&#8217;s what I&#8217;m most interested about: does performance scale linearly with the number of environments, or are there diminishing returns?</p><p>Another question I have in mind is whether the M2 series&#8217; rapid improvement is driven by catching up to others, or whether they are genuinely pushing the frontier on agentic RL. It feels like competition is extremely tough in terms of coding, but GDPval and office productivity might be a good approach to building differentiating capabilities.</p><p><strong>Quick links:</strong></p><ul><li><p>Official announcement: <strong><a href="https://www.minimax.io/news/minimax-m25">https://www.minimax.io/news/minimax-m25</a></strong></p></li><li><p>API access: <strong><a href="https://platform.minimax.io/docs/guides/text-generation">https://platform.minimax.io/docs/guides/text-generation</a></strong></p></li><li><p>MiniMax Agent: <strong><a href="https://agent.minimax.io/">https://agent.minimax.io</a></strong></p></li><li><p>OpenHands evaluation: <strong><a href="https://openhands.dev/blog/minimax-m2-5-open-weights-models-catch-up-to-claude">https://openhands.dev/blog/minimax-m2-5-open-weights-models-catch-up-to-claude</a></strong></p></li><li><p>M2.5 weights (Hugging Face): <strong><a href="https://huggingface.co/MiniMaxAI/MiniMax-M2.5">https://huggingface.co/MiniMaxAI/MiniMax-M2.5</a></strong></p></li><li><p>OpenRouter: <strong><a href="https://openrouter.ai/minimax">https://openrouter.ai/minimax</a></strong></p></li><li><p>CISPO paper (MiniMax-M1): <strong><a href="https://arxiv.org/abs/2506.13585">https://arxiv.org/abs/2506.13585</a></strong></p></li></ul>]]></content:encoded></item><item><title><![CDATA[GLM-5: China's First Public AI Company Ships a Frontier Model]]></title><description><![CDATA[Updated with the GLM-5 technical report!]]></description><link>https://maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/glm-5-chinas-first-public-ai-company</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Thu, 12 Feb 2026 17:48:37 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!KJuf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!KJuf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 424w, /__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 848w, /__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 1272w, /__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!KJuf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png" width="1456" height="819" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/623518a9-458b-4877-a0eb-442521747c1e_1536x864.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:819,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1979452,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/187768487?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 424w, /__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 848w, /__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 1272w, /__u/substackcdn.com/image/fetch/$s_!KJuf!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F623518a9-458b-4877-a0eb-442521747c1e_1536x864.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><blockquote><p><em>Updated February 18th, 2026: This article has been revised to include additional technical details from the <a href="https://arxiv.org/abs/2602.15763">GLM-5 technical report</a>, &#8220;GLM-5: from Vibe Coding to Agentic Engineering.&#8221;</em></p></blockquote><p>On February 11th, 2026, just days before the Lunar New Year, Z.ai officially released GLM-5, its new frontier large language model.</p><p>First, congrats to the Z.ai team on a strong release. GLM-5 was the new <strong>#1 open-weight model on Artificial Analysis</strong> and hit <strong>#1 among open models on LMArena&#8217;s Text Arena</strong> (score 1452, #11 overall) at the time of its release. It scores 77.8% on SWE-bench Verified, 92.7% on AIME 2026, 86.0% on GPQA-Diamond, and leads open-source models on BrowseComp, Vending Bench 2, and MCP-Atlas.</p><h2>What GLM-5 Actually Is</h2><p>GLM-5 is a <strong>744B-parameter Mixture-of-Experts model with 40B active parameters</strong> per token. That&#8217;s roughly a 2x scale-up from GLM-4.5 (355B total, 32B active). GLM-5 uses 256 experts per MoE layer with 8 activated per token (5.9% sparsity), and reduces its layer count to 80 compared to GLM-4.5 to minimize expert parallelism communication overhead. Pre-training data went from 23T to 28.5T tokens.</p><p>On the attention side, GLM-5 layers <strong>DeepSeek Sparse Attention</strong> (DSA) on top of <strong>MLA</strong> via continued pre-training. The tech report ablates alternatives, including sliding window attention, Gated DeltaNet, and SimpleGDN, but all showed accuracy gaps on long-context retrieval tasks. DSA avoids this tradeoff: its dynamic indexer achieves token-level sparsity without discarding long-range dependencies, cutting attention compute by roughly 1.5-2x for long sequences. </p><p>According to <strong><a href="https://www.reuters.com/technology/chinas-ai-startup-zhipu-releases-new-flagship-model-glm-5-2026-02-11/">Reuters</a></strong>, GLM-5 was trained entirely on Huawei Ascend chips using the MindSpore framework, with zero dependency on NVIDIA hardware. This hasn&#8217;t been confirmed by Z.ai, which has been on the U.S. Entity List since January 2025, which bans access to H100/H200 GPUs.</p><h2>Training Pipeline</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!bZv_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 424w, /__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 848w, /__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 1272w, /__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!bZv_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png" width="598" height="338.8392857142857" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:825,&quot;width&quot;:1456,&quot;resizeWidth&quot;:598,&quot;bytes&quot;:172714,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:&quot;https://maximelabonne.substack.com/i/187768487?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 424w, /__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 848w, /__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 1272w, /__u/substackcdn.com/image/fetch/$s_!bZv_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b4bebf9-08a2-43e1-b507-289e112a6f93_1585x898.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p><strong>Pre-training</strong> started with a 27T token corpus in two stages: general, then code and reasoning. They refined their data selection by introducing a DCLM classifier based on sentence embeddings to identify high-quality data, plus a &#8220;World Knowledge classifier&#8221; trained on Wikipedia entries and LLM-labeled data to extract valuable information from otherwise medium-low quality sources. They also expanded the code corpus with refreshed snapshots from major code hosting platforms, resulting in a 28% increase in deduplicated unique code tokens.</p><p><strong>Mid-training</strong> is where they progressively extended context length from 4K to 200K tokens. The focus here was specifically on long-context agentic data to ensure stability in complex workflows. It&#8217;s designed to prepare the model for the kind of long-horizon tasks that are common for agentic use cases.</p><p><strong>Post-training</strong> begins with SFT, which significantly scales up agentic and coding data compared to GLM-4.5 and extends the max context to 202,752 tokens. The key innovation is three thinking modes: Interleaved Thinking (think before every response and tool call), Preserved Thinking (retain all thinking blocks across turns to avoid re-deriving reasoning, critical for long-horizon coding agents), and Turn-level Thinking (per-turn on/off control to trade latency for accuracy). SFT also masks erroneous segments in agent trajectories, so the model learns error correction without reinforcing mistakes.</p><p>A sequential Reinforcement Learning pipeline is applied on top of the SFT checkpoint:</p><ol><li><p><strong>Reasoning RL</strong>: Mixed-domain training across math, science, code, and tool-integrated reasoning. They use GRPO with the <a href="https://ringtech.notion.site/icepop">IcePop technique</a> to address the mismatch between training and inference distributions. To speed up training, they also removed KL regularization.</p></li><li><p><strong>Agentic RL</strong>: Fully asynchronous, decoupled framework where inference and training engines run on separate GPUs. This is necessary because synchronous RL has massive GPU idle time during long-horizon agent rollouts (coding tasks, search tasks). A central Multi-Task Rollout Orchestrator manages 1k+ concurrent rollouts across heterogeneous tasks. To handle the off-policy issue introduced by asynchrony (different trajectories generated by different model versions), they use Direct Double-sided Importance Sampling with token-level clipping, and drop stale samples whose rollout version lags too far behind the current policy.</p></li><li><p><strong>General RL</strong>: Human-style alignment with a hybrid reward system combining rule-based rewards, outcome reward models (ORMs), and generative reward models (GRMs). They also inject expert human-written responses as stylistic anchors to avoid converging to &#8220;model-like&#8221; verbose patterns.</p></li></ol><p>Crucially, they used <strong>On-Policy Cross-Stage Distillation</strong> as a final stage to prevent catastrophic forgetting. The checkpoints from each preceding stage (SFT, Reasoning RL, General RL) serve as teacher models, and the advantage signal is computed directly from the gap between teacher and student logits rather than from sampled rewards. I would&#8217;ve used <strong>model merging</strong> instead to address this problem, but this technique isn&#8217;t mentioned in the paper.</p><h2>Benchmarks</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!v8Rr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 424w, /__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 848w, /__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 1272w, /__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!v8Rr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png" width="1050" height="1000" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1000,&quot;width&quot;:1050,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="/__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 424w, /__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 848w, /__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 1272w, /__u/substackcdn.com/image/fetch/$s_!v8Rr!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc42071b7-ad4c-440d-94fb-c2817b56135a_1050x1000.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Among self-reported benchmarks, the SWE-bench number is the headline. At 77.8%, GLM-5 beats Gemini 3 Pro (76.2%) and GPT-5.2 (75.4%) but still trails Claude Opus 4.5 (80.9%). Note that they didn&#8217;t compare themselves with the more recent Opus 4.6 and GPT-5.3-Codex. The report also shows 73.3% on SWE-bench Multilingual and 56.2% on Terminal-Bench 2.0, evaluated in Claude Code 2.1.14 with think mode enabled.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!volB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 424w, /__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 848w, /__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 1272w, /__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!volB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png" width="1456" height="996" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:996,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="/__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 424w, /__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 848w, /__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 1272w, /__u/substackcdn.com/image/fetch/$s_!volB!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9f5c9b36-d824-4751-9d07-4ec86d21a5fe_1462x1000.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p>On their internal CC-Bench-V2 suite, GLM-5 hits a 98% frontend build success rate and 74.8% end-to-end correctness, which represents a 26% improvement over GLM-4.7 on frontend tasks. They&#8217;re framing this as the shift from &#8220;vibe coding&#8221; to &#8220;agentic engineering,&#8221; and the Vending Bench 2 result (where the model runs a simulated vending machine business over a full year) supports that framing. Long-horizon planning seems significantly improved compared to GLM-4.7.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!aq4i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 424w, /__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 848w, /__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 1272w, /__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!aq4i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png" width="1456" height="418" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:418,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="/__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 424w, /__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 848w, /__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 1272w, /__u/substackcdn.com/image/fetch/$s_!aq4i!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F31ca3b36-2df5-4ef6-9c60-8cc2ef559bb7_2019x579.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p>One interesting data point from Artificial Analysis: GLM-5 achieved a score of -1 on the AA-Omniscience Index, a 35-point improvement over its predecessor. This means GLM-5 leads the industry in &#8220;knowing when to say I don&#8217;t know&#8221; rather than hallucinating. Hallucinations are a very 2023 problem, but it&#8217;s still a concrete improvement for production deployment.</p><h2>The Pony Alpha Saga</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Cyiu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 424w, /__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 848w, /__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Cyiu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png" width="1288" height="551" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:551,&quot;width&quot;:1288,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="/__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 424w, /__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 848w, /__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Cyiu!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b21057b-0f11-49e1-8793-825466e441c1_1288x551.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p>The backstory here is too good to skip. On February 6th, OpenRouter quietly launched &#8220;Pony Alpha&#8221; as a stealth model with no attribution, zero cost, and a 200K context window. It processed over 40 billion tokens on its first day. The community immediately started speculating. Was it DeepSeek V4? Grok 4.2? A Claude variant?</p><p>The evidence quickly pointed to Zhipu. The model self-identified as GLM under certain prompts. The output style matched the GLM series. And the timing aligned perfectly with Zhipu&#8217;s pre-announced GLM-5 release window around Spring Festival. Some people even caught the zodiac connection: 2026 is the Year of the Horse.</p><p>OpenRouter has a history of these stealth drops. Quasar Alpha turned out to be GPT-4.1. Sherlock Alpha was Grok 4.1 Fast. Pony Alpha was GLM-5 getting a live stress test with real users before the official launch. This is a good move since you get genuine usage data and community feedback without the hype cycle distorting everything.</p><h2>Pricing and Accessibility</h2><p>The official GLM-5 API is priced at $1.00 per million input tokens and $3.20 per million output tokens. That&#8217;s approximately 5x cheaper on input and nearly 8x cheaper on output compared to Claude Opus 4.6 ($5/$25). Despite that, it is still quite pricey compared to previous versions and other Chinese MoEs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ZWeB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ZWeB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png" width="691" height="363" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:363,&quot;width&quot;:691,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Article content&quot;,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="Article content" title="Article content" srcset="/__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZWeB!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3734eda2-62ad-4a26-8ff8-0dc60ff6fb96_691x363.png 1456w" sizes="100vw" loading="lazy"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a><figcaption class="image-caption"></figcaption></figure></div><p><strong><a href="https://www.linkedin.com/company/zdotai/">Z.ai</a></strong> also offers a GLM Coding Plan, which is their answer to Anthropic&#8217;s Claude Code. They actually hiked the price by 30% this week to capitalize on demand, and their Hong Kong-listed stock surged 34% on the day of release.</p><p>With 744B parameters, GLM-5 is mostly an API model. If you want to deploy it, you&#8217;ll need at least 8 H200s (or H20s) for FP8 inference. Because of the infrastructure budget it requires, it makes little sense for most teams and companies. I saw an HN discussion with people debating whether you could run this on 2x M4 Ultra Macs with 512GB unified memory each. The answer is &#8220;technically yes, but practically painful.&#8221; This is an API model for 99% of users.</p><h2>The Bigger Picture</h2><p>GLM-5 drops at an inflection point for Zhipu and for the Chinese AI ecosystem more broadly. A few things worth noting:</p><p><strong>Zhipu just became the world&#8217;s first publicly traded foundation model company.</strong> Their Hong Kong IPO on January 8th raised $558 million at a $7.1 billion valuation. Meanwhile, OpenAI and Anthropic are still private. That&#8217;s a structural difference in how frontier AI companies are funded and governed.</p><p><strong>DeepSeek leads the architecture game.</strong> GLM-5 adopted DeepSeek Sparse Attention and was already using their training recipes. This is a strong signal that DeepSeek still has a significant technical lead in terms of model architecture.</p><h2>What&#8217;s Missing</h2><p>I just wanted to note a few issues with GLM-5:</p><p><strong>GLM-5 is text-only.</strong> No native multimodal support. Kimi K2.5 from Moonshot AI offers multimodal capabilities that GLM-5 lacks. This matters increasingly as the industry moves toward unified architectures.</p><p><strong>Early adopters report that while benchmarks are strong, "situational awareness" lags behind Claude.</strong> The vibe test results are mixed. It's a strong executioner but perhaps not as thoughtful a collaborator.</p><p><strong>Many people flagged questions about benchmark methodology. </strong>It&#8217;s a good sign that the community reads leaderboard claims with a more technical lens these days, and some of the numbers in the official docs raised eyebrows. More independent testing is needed.</p><h2>What&#8217;s Next</h2><p>GLM-5 is the strongest open-weight model released to date for coding and agentic tasks, and it does this on domestic Chinese hardware under U.S. sanctions. Those are two separate statements, and both are significant.</p><p><strong>Quick links:</strong></p><ul><li><p>Model weights: <strong><a href="http://huggingface.co/zai-org/GLM-5">huggingface.co/zai-org/GLM-5</a></strong></p></li><li><p>Tech report: <strong><a href="https://arxiv.org/abs/2602.15763">https://arxiv.org/abs/2602.15763</a></strong></p></li><li><p>API: <strong><a href="http://chat.z.ai/">chat.z.ai</a></strong></p></li><li><p>OpenRouter: <strong><a href="http://openrouter.ai/z-ai/glm-5">openrouter.ai/z-ai/glm-5</a></strong></p></li><li><p>GitHub: <strong><a href="http://github.com/zai-org/GLM-5">github.com/zai-org/GLM-5</a></strong></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Uncensor any LLM with abliteration]]></title><description><![CDATA[Fine-tuning without retraining]]></description><link>https://maximelabonne.substack.com/p/uncensor-any-llm-with-abliteration-d30148b7d43e</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/uncensor-any-llm-with-abliteration-d30148b7d43e</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Wed, 12 Jun 2024 18:09:26 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/061ddefb-b4a2-4eb7-a148-040b7976fdc9_800x450.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!P_Ug!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!P_Ug!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P_Ug!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff875d5e4-c782-4a09-91ad-b638b5f819f0_800x450.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>The third generation of Llama models provided fine-tunes (Instruct) versions that excel in understanding and following instructions. However, these models are heavily censored, designed to refuse requests seen as harmful with responses such as &#8220;As an AI assistant, I cannot help you.&#8221; While this safety feature is crucial for preventing misuse, it limits the model&#8217;s flexibility and responsiveness.</p><p>In this article, we will explore a technique called &#8220;abliteration&#8221; that can uncensor any LLM without retraining. This technique effectively removes the model&#8217;s built-in refusal mechanism, allowing it to respond to all types of prompts.</p><p>The code is available on <a href="https://colab.research.google.com/drive/1VYm3hOcvCpbGiqKZb141gJwjdmmCcVpR?usp=sharing">Google Colab</a> and in the <a href="https://github.com/mlabonne/llm-course">LLM Course</a> on GitHub. Special thanks to FailSpy for proofreading this article.</p><h3>&#9986;&#65039; What is abliteration?</h3><p>Modern LLMs are fine-tuned for safety and instruction-following, meaning they are trained to refuse harmful requests. In their <a href="https://www.lesswrong.com/posts/jGuXSZgv6qfdhMCuJ/refusal-in-llms-is-mediated-by-a-single-direction">blog post</a>, Arditi et al. have shown that this refusal behavior is mediated by a specific direction in the model&#8217;s residual stream. If we prevent the model from representing this direction, it <strong>loses its ability to refuse requests</strong>. Conversely, adding this direction artificially can cause the model to refuse even harmless requests.</p><p>In the traditional decoder-only Llama-like architecture, there are three residual streams we can target: at the start of each block (&#8220;pre&#8221;), between the attention and MLP layers (&#8220;mid&#8221;), and after the MLP (&#8220;post&#8221;). The following figure illustrates the location of each residual stream.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!HjDt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 424w, /__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 848w, /__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!HjDt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 424w, /__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 848w, /__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 1272w, /__u/substackcdn.com/image/fetch/$s_!HjDt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4f768cf0-d95c-43d9-8c3a-24bdfe5d8197_800x306.png 1456w" sizes="100vw"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>To uncensor an LLM, we first need to identify the &#8220;refusal direction&#8221; within the model. This process involves a few technical steps:</p><ol><li><p><strong>Data Collection</strong>: Run the model on a set of harmful instructions and a set of harmless instructions, recording the residual stream activations at the last token position for each.</p></li><li><p><strong>Mean difference</strong>: Calculate the mean difference between the activations of harmful and harmless instructions. This gives us a vector representing the &#8220;refusal direction&#8221; for each layer of the model.</p></li><li><p><strong>Selection</strong>: Normalize these vectors and evaluate them to select the single best &#8220;refusal direction.&#8221;</p></li></ol><p>Once we have identified the refusal direction, we can &#8220;ablate&#8221; it, effectively removing the model&#8217;s ability to represent this feature. This can be done through an <strong>inference-time intervention</strong> or permanently with <strong>weight orthogonalization</strong>.</p><p>Let&#8217;s talk about inference-time intervention first. For every component that writes to the residual stream (such as an attention head), we calculate the projection of its output onto the refusal direction and subtract this projection. This subtraction is applied at every token and every layer, ensuring that the model never represents the refusal direction.</p><p>On the other hand, weight orthogonalization involves modifying the model weights directly. By orthogonalizing the component weights with respect to the refusal direction, it prevents the model from writing to this direction altogether. This is achieved by adjusting the matrices that write to the residual stream, ensuring they do not contribute to the refusal direction.</p><p>In the next section, we will implement abliteration with weight orthogonalization.</p><h3>&#128187; Implementation</h3><p>The following implementation of abliteration is based on <a href="https://huggingface.co/failspy/llama-3-70B-Instruct-abliterated/blob/main/ortho_cookbook.ipynb">FailSpy&#8217;s notebook</a>, which is itself based on the original authors&#8217; <a href="https://colab.research.google.com/drive/1a-aQvKC9avdZpdyBn4jgRQFObTPy1JZw?usp=sharing">notebook</a>. I mostly adapted and simplified it to make it easier to understand. This section is quite code-heavy so you can see what is going on, but you can use FailSpy&#8217;s <a href="https://github.com/FailSpy/abliterator">abliterator library</a> if you&#8217;re less interested in the technical details (also check his <a href="https://huggingface.co/collections/failspy/abliterated-v3-664a8ad0db255eefa7d0012b">collection of abliterated models</a> on Hugging Face).</p><p>The code relies on the excellent <a href="https://github.com/TransformerLensOrg/TransformerLens">TransformerLens</a> library (formerly known as EasyTransformer) to do the heavy lifting. It is designed for mechanistic interpretability and is used here to intervene on activations. Thanks to Neel Nanda and Joseph Bloom for creating and maintaining this library.</p><p>First, let&#8217;s install the necessary packages and import them. All these steps are available in this <a href="https://colab.research.google.com/drive/1VYm3hOcvCpbGiqKZb141gJwjdmmCcVpR?usp=sharing">Google Colab notebook</a>.</p><pre><code>!pip install transformers transformers_stream_generator tiktoken transformer_lens einops jaxtyping

import torch
import functools
import einops
import gc

from datasets import load_dataset
from tqdm import tqdm
from torch import Tensor
from typing import List
from transformer_lens import HookedTransformer, utils
from transformer_lens.hook_points import HookPoint
from transformers import AutoModelForCausalLM, AutoTokenizer
from jaxtyping import Float, Int
from collections import defaultdict

# Turn automatic differentiation off to save GPU memory (credit: Undi95)
torch.set_grad_enabled(False)</code></pre><p>We need two datasets: one containing harmless instructions, and one containing harmful instructions. We&#8217;ll use <a href="https://huggingface.co/datasets/tatsu-lab/alpaca">tatsu-lab/alpaca</a> as well as data from <a href="https://github.com/llm-attacks/llm-attacks">llm-attacks</a>. To make things easier, I repackaged them in two Hugging Face datasets: <a href="https://huggingface.co/datasets/harmless_behaviors">mlabonne/harmless_behaviors</a> and <a href="https://huggingface.co/datasets/mlabonne/harmful_behaviors">mlabonne/harmful_behaviors</a>. That way, you can easily replace them with your own datasets.</p><p>We will load the instructions and reformat them into a list of dictionaries with &#8220;role&#8221; and &#8220;content&#8221; keys. This makes it compatible with the <code>apply_chat_tokenizer()</code> method, which we will use to follow Llama 3's chat template.</p><pre><code>def reformat_texts(texts):
    return [[{"role": "user", "content": text}] for text in texts]

# Get harmful and harmless datasets
def get_harmful_instructions():
    dataset = load_dataset('mlabonne/harmful_behaviors')
    return reformat_texts(dataset['train']['text']), reformat_texts(dataset['test']['text'])

def get_harmless_instructions():
    dataset = load_dataset('mlabonne/harmless_alpaca')
    return reformat_texts(dataset['train']['text']), reformat_texts(dataset['test']['text'])

harmful_inst_train, harmful_inst_test = get_harmful_instructions()
harmless_inst_train, harmless_inst_test = get_harmless_instructions()</code></pre><p>Now that we have our datasets, we can load the model we want to abliterate. Unfortunately, you can&#8217;t directly load a custom model using <code>HookedTransformer</code>. Here, I use a trick described in FailSpy's notebook to download a custom model and rename it as <a href="https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct">meta-llama/Meta-Llama-3-8B-Instruct</a>. Load in <code>torch.float16</code> format if your GPU is not compatible with BF16.</p><p>In this example, we&#8217;ll use <a href="https://huggingface.co/mlabonne/Daredevil-8B">mlabonne/Daredevil-8B</a>, a mega-merge created with DARE TIES (see my article about <a href="https://huggingface.co/blog/mlabonne/merge-models">model merging</a>) that has the highest MMLU score on the Open LLM Leaderboard in the 8B category.</p><pre><code>MODEL_ID = "mlabonne/Daredevil-8B"
MODEL_TYPE = "meta-llama/Meta-Llama-3-8B-Instruct"

# Download and load model
!git clone https://huggingface.co/{MODEL_ID} {MODEL_TYPE}

# Load model and tokenizer
model = HookedTransformer.from_pretrained_no_processing(
    MODEL_TYPE,
    local_files_only=True,
    dtype=torch.bfloat16,
    default_padding_side='left'
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_TYPE)
tokenizer.padding_side = 'left'
tokenizer.pad_token = tokenizer.eos_token</code></pre><p>We can now tokenize our datasets. We&#8217;re using the same number of samples for both harmless and harmful instructions. Note that a high number of samples can use all the RAM/VRAM, which is why I&#8217;m limiting it to 256 here.</p><pre><code>def tokenize_instructions(tokenizer, instructions):
    return tokenizer.apply_chat_template(
        instructions,
        padding=True,
        truncation=False,
        return_tensors="pt",
        return_dict=True,
        add_generation_prompt=True,
    ).input_ids

n_inst_train = min(256, len(harmful_inst_train), len(harmless_inst_train))

# Tokenize datasets
harmful_tokens = tokenize_instructions(
    tokenizer,
    instructions=harmful_inst_train[:n_inst_train],
)
harmless_tokens = tokenize_instructions(
    tokenizer,
    instructions=harmless_inst_train[:n_inst_train],
)</code></pre><p>Everything is set up, we can now implement the first step of abliteration: data collection. We want to process these tokenized datasets and store the residual stream activations in <code>harmful</code> and <code>harmless</code>. This is managed by the <a href="https://github.com/TransformerLensOrg/TransformerLens">transformer_lens</a> library.</p><pre><code>batch_size = 32

# Initialize defaultdicts to store activations
harmful = defaultdict(list)
harmless = defaultdict(list)

# Process the training data in batches
num_batches = (n_inst_train + batch_size - 1) // batch_size

for i in tqdm(range(num_batches)):
    print(i)
    start_idx = i * batch_size
    end_idx = min(n_inst_train, start_idx + batch_size)

    # Run models on harmful and harmless prompts, cache activations
    harmful_logits, harmful_cache = model.run_with_cache(
        harmful_tokens[start_idx:end_idx],
        names_filter=lambda hook_name: 'resid' in hook_name,
        device='cpu',
        reset_hooks_end=True
    )
    harmless_logits, harmless_cache = model.run_with_cache(
        harmless_tokens[start_idx:end_idx],
        names_filter=lambda hook_name: 'resid' in hook_name,
        device='cpu',
        reset_hooks_end=True
    )

    # Collect and store the activations
    for key in harmful_cache:
        harmful[key].append(harmful_cache[key])
        harmless[key].append(harmless_cache[key])

    # Flush RAM and VRAM
    del harmful_logits, harmless_logits, harmful_cache, harmless_cache
    gc.collect()
    torch.cuda.empty_cache()

# Concatenate the cached activations
harmful = {k: torch.cat(v) for k, v in harmful.items()}
harmless = {k: torch.cat(v) for k, v in harmless.items()}</code></pre><p>We can now compute the refusal direction for each layer. This corresponds to the mean difference between the activations of harmful and harmless instructions, which is then normalized. We sort them in descending order in <code>activation_scored</code>.</p><pre><code># Helper function to get activation index
def get_act_idx(cache_dict, act_name, layer):
    key = (act_name, layer)
    return cache_dict[utils.get_act_name(*key)]

# Compute difference of means between harmful and harmless activations at intermediate layers
activation_layers = ["resid_pre", "resid_mid", "resid_post"]
activation_refusals = defaultdict(list)

for layer_num in range(1, model.cfg.n_layers):
    pos = -1  # Position index
    for layer in activation_layers:
        harmful_mean_act = get_act_idx(harmful, layer, layer_num)[:, pos, :].mean(dim=0)
        harmless_mean_act = get_act_idx(harmless, layer, layer_num)[:, pos, :].mean(
            dim=0
        )
        refusal_dir = harmful_mean_act - harmless_mean_act
        refusal_dir = refusal_dir / refusal_dir.norm()
        activation_refusals[layer].append(refusal_dir)

selected_layers = ["resid_pre"]
activation_scored = sorted(
    [
        activation_refusals[layer][l - 1]
        for l in range(1, model.cfg.n_layers)
        for layer in selected_layers
    ],
    key=lambda x: abs(x.mean()),
    reverse=True,
)</code></pre><p>The final step of the process consists of evaluating the refusal directions we calculated. To do this, we&#8217;re going to apply the refusal direction to each residual stream and each block during inference. In the following snippet, we get generations for four test harmful instructions and 20 blocks (or layers).</p><pre><code>def _generate_with_hooks(
    model: HookedTransformer,
    tokenizer: AutoTokenizer,
    tokens: Int[Tensor, "batch_size seq_len"],
    max_tokens_generated: int = 64,
    fwd_hooks=[],
) -&gt; List[str]:
    all_tokens = torch.zeros(
        (tokens.shape[0], tokens.shape[1] + max_tokens_generated),
        dtype=torch.long,
        device=tokens.device,
    )
    all_tokens[:, : tokens.shape[1]] = tokens
    for i in range(max_tokens_generated):
        with model.hooks(fwd_hooks=fwd_hooks):
            logits = model(all_tokens[:, : -max_tokens_generated + i])
            next_tokens = logits[:, -1, :].argmax(
                dim=-1
            )  # greedy sampling (temperature=0)
            all_tokens[:, -max_tokens_generated + i] = next_tokens
    return tokenizer.batch_decode(
        all_tokens[:, tokens.shape[1] :], skip_special_tokens=True
    )

def get_generations(
    model: HookedTransformer,
    tokenizer: AutoTokenizer,
    instructions: List[str],
    fwd_hooks=[],
    max_tokens_generated: int = 64,
    batch_size: int = 4,
) -&gt; List[str]:
    generations = []
    for i in tqdm(range(0, len(instructions), batch_size)):
        tokens = tokenize_instructions(
            tokenizer, instructions=instructions[i : i + batch_size]
        )
        generation = _generate_with_hooks(
            model,
            tokenizer,
            tokens,
            max_tokens_generated=max_tokens_generated,
            fwd_hooks=fwd_hooks,
        )
        generations.extend(generation)
    return generations

# Inference-time intervention hook
def direction_ablation_hook(
    activation: Float[Tensor, "... d_act"],
    hook: HookPoint,
    direction: Float[Tensor, "d_act"],
):
    if activation.device != direction.device:
        direction = direction.to(activation.device)
    proj = (
        einops.einsum(
            activation, direction.view(-1, 1), "... d_act, d_act single -&gt; ... single"
        )
        * direction
    )
    return activation - proj

# Testing baseline
N_INST_TEST = 4
baseline_generations = get_generations(
    model, tokenizer, harmful_inst_test[:N_INST_TEST], fwd_hooks=[]
)

# Evaluating layers defined earlier (needs human evaluation to determine best layer for refusal inhibition)
EVAL_N = 20  # Evaluate how many of the top N potential directions
evals = []
for refusal_dir in tqdm(activation_scored[:EVAL_N]):
    hook_fn = functools.partial(direction_ablation_hook, direction=refusal_dir)
    fwd_hooks = [
        (utils.get_act_name(act_name, layer), hook_fn)
        for layer in list(range(model.cfg.n_layers))
        for act_name in activation_layers
    ]
    intervention_generations = get_generations(
        model, tokenizer, harmful_inst_test[:N_INST_TEST], fwd_hooks=fwd_hooks
    )
    evals.append(intervention_generations)</code></pre><p>We stored all the generations in the <code>evals</code> list. We can now print them and manually select the layer (block) that provides an uncensored response for each instruction. I'm automatically excluding responses containing "I cannot" and "I can't" to filter out unwanted answers.</p><p>If you can&#8217;t find a layer that satisfies these requirements, you might want to test other residual streams in the previous <code>selected_layers</code> list, other instructions, additional blocks, etc.</p><pre><code># Print generations for human evaluation
blacklist = ["I cannot", "I can't"]
for i in range(N_INST_TEST):
    print(f"\033[1mINSTRUCTION {i}: {harmful_inst_test[i]}")
    print(f"\nBASELINE COMPLETION:\n{baseline_generations[i]}\033[0m")
    for layer_candidate in range(EVAL_N):
        if not any(word in evals[layer_candidate][i] for word in blacklist):
            print(f"\n---\n\nLAYER CANDIDATE #{layer_candidate} INTERVENTION COMPLETION:")
            print(evals[layer_candidate][i])</code></pre><p>In my case, the layer candidate 9 managed to provide uncensored answer for the four instructions. This is the one that we will select for the refusal direction. In the following, we implement weight orthogonalization to modify the weights and prevent the model from creating outputs with this direction. You can verify that the model is successfully uncensored by printing the completions.</p><pre><code>def get_orthogonalized_matrix(
    matrix: Float[Tensor, "... d_model"], vec: Float[Tensor, "d_model"]
) -&gt; Float[Tensor, "... d_model"]:
    proj = (
        einops.einsum(
            matrix, vec.view(-1, 1), "... d_model, d_model single -&gt; ... single"
        )
        * vec
    )
    return matrix - proj

# Select the layer with the highest potential refusal direction
LAYER_CANDIDATE = 9
refusal_dir = activation_scored[LAYER_CANDIDATE]

# Orthogonalize the model's weights
if refusal_dir.device != model.W_E.device:
    refusal_dir = refusal_dir.to(model.W_E.device)
model.W_E.data = get_orthogonalized_matrix(model.W_E, refusal_dir)

for block in tqdm(model.blocks):
    if refusal_dir.device != block.attn.W_O.device:
        refusal_dir = refusal_dir.to(block.attn.W_O.device)
    block.attn.W_O.data = get_orthogonalized_matrix(block.attn.W_O, refusal_dir)
    block.mlp.W_out.data = get_orthogonalized_matrix(block.mlp.W_out, refusal_dir)

# Generate text with abliterated model
orthogonalized_generations = get_generations(
    model, tokenizer, harmful_inst_test[:N_INST_TEST], fwd_hooks=[]
)

# Print generations
for i in range(N_INST_TEST):
    if len(baseline_generations) &gt; i:
        print(f"INSTRUCTION {i}: {harmful_inst_test[i]}")
        print(f"\033[92mBASELINE COMPLETION:\n{baseline_generations[i]}")
    print(f"\033[91mINTERVENTION COMPLETION:\n{evals[LAYER_CANDIDATE][i]}")
    print(f"\033[95mORTHOGONALIZED COMPLETION:\n{orthogonalized_generations[i]}\n")</code></pre><p>We&#8217;re now ready to use the model. We convert it back to the Hugging Face format and upload it to the HF hub.</p><pre><code># Convert model back to HF safetensors
hf_model = AutoModelForCausalLM.from_pretrained(MODEL_TYPE, torch_dtype=torch.bfloat16)
lm_model = hf_model.model

state_dict = model.state_dict()
lm_model.embed_tokens.weight = torch.nn.Parameter(state_dict["embed.W_E"].cpu())
for l in range(model.cfg.n_layers):
    lm_model.layers[l].self_attn.o_proj.weight = torch.nn.Parameter(
        einops.rearrange(
            state_dict[f"blocks.{l}.attn.W_O"], "n h m-&gt;m (n h)", n=model.cfg.n_heads
        ).contiguous()
    )
    lm_model.layers[l].mlp.down_proj.weight = torch.nn.Parameter(
        torch.transpose(state_dict[f"blocks.{l}.mlp.W_out"], 0, 1).contiguous()
    )

hf_model.push_to_hub(f"{MODEL_ID}-abliterated")</code></pre><h3>&#9878;&#65039; DPO Fine-Tuning</h3><p>I evaluated the abliterated and source models from the previous section on the Open LLM Leaderboard and on Nous&#8217; benchmark suite. Here are the results:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Rxz4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 424w, /__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 848w, /__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Rxz4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 424w, /__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 848w, /__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Rxz4!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4aa0ba-2cc6-484f-b09a-73b47d4b72d3_800x130.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>As you can see, the source model significantly outperforms Llama 3 8B Instruct. However, we observe a performance drop in the ablated version across all benchmarks. The ablation process successfully uncensored it but also degraded the model&#8217;s quality.</p><p>To address this issue, an idea consists of further training our abliterated model to heal it. Like most fine-tuned models, Llama 3 8B Instruct is quite brittle when it comes to supervised fine-tuning. An additional SFT would likely break the model&#8217;s performance.</p><p>Alternatively, preference alignment is quite light and shouldn&#8217;t lobotomize our abliterated model. DPO is a good candidate here for its ease of use and good track record. To implement it, I used <a href="https://colab.research.google.com/drive/1TsDKNo2riwVmU55gjuBgB1AXVtRRfRHW?usp=sharing">LazyAxolotl</a> (thanks to Wing Lian for creating <a href="https://github.com/OpenAccess-AI-Collective/axolotl">Axolotl</a>) with the <a href="https://huggingface.co/datasets/mlabonne/orpo-dpo-mix-40k">mlabonne/orpo-dpo-mix-40k</a> dataset. Here&#8217;s the configuration I used:</p><pre><code>base_model: mlabonne/Daredevil-8B-abliterated
model_type: LlamaForCausalLM
tokenizer_type: AutoTokenizer

load_in_8bit: false
load_in_4bit: true
strict: false
save_safetensors: true

rl: dpo
chat_template: chatml
datasets:
  - path: mlabonne/orpo-dpo-mix-40k
    split: train
    type: chatml.intel

dataset_prepared_path:
val_set_size: 0.0
output_dir: ./out

adapter: qlora
lora_model_dir:

sequence_len: 2048
sample_packing: false
pad_to_sequence_len: false

lora_r: 64
lora_alpha: 32
lora_dropout: 0.05
lora_target_linear: true
lora_fan_in_fan_out:

wandb_project: axolotl
wandb_entity:
wandb_watch:
wandb_name:
wandb_log_model:

gradient_accumulation_steps: 8
micro_batch_size: 1
num_epochs: 1
optimizer: paged_adamw_8bit
lr_scheduler: cosine
learning_rate: 5e-6
train_on_inputs: false
group_by_length: false

bf16: auto
fp16:
tf32:

gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true
warmup_steps: 100
evals_per_epoch: 0
eval_table_size:
eval_table_max_new_tokens: 128
saves_per_epoch: 1
debug:
deepspeed: deepspeed_configs/zero2.json
weight_decay: 0.0
special_tokens:
  pad_token: &lt;|end_of_text|&gt;</code></pre><p>I trained it using 6xA6000 GPUs with DeepSpeed ZeRO-2. The training took about 6 hours and 45 minutes. Here are the training curves I got from W&amp;B:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!JP5i!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 424w, /__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 848w, /__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!JP5i!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 424w, /__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 848w, /__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JP5i!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1acbc9c4-39f4-4c42-a74d-a24beca6d8cc_1200x702.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>It automatically uploaded the DPO fine-tuned model, called <a href="https://huggingface.co/mlabonne/NeuralDaredevil-8B-abliterated">mlabonne/NeuralDaredevil-8B-abliterated</a>. To see if it fixed our abliterated version, I evaluated it on the same benchmarks:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!dksB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 424w, /__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 848w, /__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 1272w, /__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!dksB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 424w, /__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 848w, /__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 1272w, /__u/substackcdn.com/image/fetch/$s_!dksB!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7807cd39-86b3-4621-b513-fc1ec7b3285a_800x134.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>We can see that this additional training allowed us to recover most of the performance drop due to abliteration. One area where the model doesn&#8217;t improve is GSM8K, a math dataset, which could mean the orpo-dpo-mix-40k would benefit from more math samples.</p><p>The final model is an uncensored LLM with state-of-the-art performance in the 8B category. I recommend it as an improved version of Llama 3 8B Instruct when you don&#8217;t need censorship. You can play with quantized versions like GGUF in LM Studio.</p><h3>Conclusion</h3><p>In this article, we introduced the concept of abliteration. This technique uses the model&#8217;s activations on harmless and harmful prompts to calculate a refusal direction. It then uses this direction to modify the model&#8217;s weights and ensure that we stop outputting refusals. This technique also demonstrates the fragility of safety fine-tuning and raises ethical considerations.</p><p>We applied abliteration to Daredevil-8B to uncensor it, which also degraded the model&#8217;s performance. We then healed it using DPO to create the NeuralDaredevil-8B model, a fully uncensored and high-quality 8B LLM. Abliteration is not limited to removing alignment and should be seen as a form of fine-tuning without retraining. Indeed, it can creatively be applied to other goals, like FailSpy&#8217;s <a href="https://huggingface.co/failspy/Llama-3-8B-Instruct-MopeyMule">MopeyMule</a>, which adopts a melancholic conversational style.</p><p>I hope you liked this article. If you want to see more follow me on <a href="https://huggingface.co/mlabonne/">Hugging Face</a> and Twitter <a href="https://twitter.com/maximelabonne">@maximelabonne</a>.</p><h3>References</h3><ul><li><p>FailSpy, &#8220;<a href="https://github.com/FailSpy/abliterator">abliterator library</a>,&#8221; GitHub, 2024.</p></li><li><p>Andy Arditi, Oscar Obeso, Aaquib111, wesg, Neel Nanda, &#8220;<a href="https://www.lesswrong.com/posts/jGuXSZgv6qfdhMCuJ/refusal-in-llms-is-mediated-by-a-single-direction">Refusal in LLMs is mediated by a single direction</a>,&#8221; Lesswrong, 2024.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Create Mixtures of Experts with MergeKit]]></title><description><![CDATA[Combine multiple models into a single MoE]]></description><link>https://maximelabonne.substack.com/p/create-mixtures-of-experts-with-mergekit-11b318c99562</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/create-mixtures-of-experts-with-mergekit-11b318c99562</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Wed, 27 Mar 2024 13:47:23 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/b012a8d2-dc6a-4d90-8fe5-fe15f732bacf_800x457.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4><em>Combine multiple models into a single&nbsp;MoE</em></h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!d6gW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!d6gW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!d6gW!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa6fb8159-1976-4527-91eb-963d15cb0780_800x457.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Thanks to the release of Mixtral, the <strong>Mixture of Experts</strong> (MoE) architecture has become popular in recent months. This architecture offers an interesting tradeoff: higher performance at the cost of increased VRAM usage. While Mixtral and other MoE architectures are pre-trained from scratch, another method of creating MoE has recently appeared. Thanks to Arcee&#8217;s <a href="https://github.com/arcee-ai/mergekit">MergeKit</a> library, we now have a new way of creating MoEs by ensembling several pre-trained models. These are often referred to as <strong>frankenMoEs</strong> or <strong>MoErges</strong> to distinguish them from the pre-trained MoEs.</p><p>In this article, we will detail how the MoE architecture works and how frankenMoEs are created. Finally, we will make our <a href="https://huggingface.co/mlabonne/Beyonder-4x7B-v3">own frankenMoE</a> with MergeKit and evaluate it on several benchmarks. The code is available on Google Colab in a wrapper called <a href="https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb#scrollTo=d5mYzDo1q96y">LazyMergeKit</a>.</p><p>Special thanks to <a href="https://github.com/cg123">Charles Goddard</a>, the creator of MergeKit, for proofreading this article.</p><h3>&#128256; Introduction to&nbsp;MoEs</h3><p>A Mixture of Experts is an architecture designed for improved efficiency and performance. It uses multiple specialized subnetworks, known as &#8220;<strong>experts</strong>.&#8221; Unlike dense models, where the entire network is activated, MoEs only activate relevant experts based on the input. This results in faster training and more efficient inference.</p><p>There are two components at the core of an MoE model:</p><ol><li><p><strong>Sparse MoE Layers</strong>: These replace the dense feed-forward network layers in the transformer architecture. Each MoE layer contains several experts, and only a subset of these experts are engaged for a given input.</p></li><li><p><strong>Gate Network or Router</strong>: This component determines which tokens are processed by which experts, ensuring that each part of the input is handled by the most suitable expert(s).</p></li></ol><p>In the following example, we show how a Mistral-7B block is transformed into an MoE block with a sparse MoE layer (feedforward network 1, 2, and 3) and a router. This example represents an MoE with three experts, where two are currently engaged (FFN 1 and FFN 3).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!T9Fv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 424w, /__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 848w, /__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 1272w, /__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!T9Fv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 424w, /__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 848w, /__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 1272w, /__u/substackcdn.com/image/fetch/$s_!T9Fv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e98d087-97a6-45d7-aaf8-ea9d889654b3_800x405.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>MoEs also come with their own set of challenges, especially in terms of fine-tuning and memory requirements. The fine-tuning process can be difficult due to the model&#8217;s complexity, with the need to <strong>balance expert usage</strong> during training to properly train the gating weights to select the most relevant ones. In terms of memory, even though only a fraction of the total parameters are used during inference, the entire model, including all experts, needs to be <strong>loaded into memory</strong>, which requires high VRAM capacity.</p><p>More specifically, there are two essential parameters when it comes to MoEs:</p><ul><li><p><strong>Number of experts</strong> (<code>num_local_experts</code>): This determines the total number of experts in the architecture (e.g., 8 for Mixtral). The higher the number of experts, the higher the VRAM usage.</p></li><li><p><strong>Number of experts/token</strong> (<code>num_experts_per_tok</code>): This determines the number of experts that are engaged for each token and each layer (e.g., 2 for Mixtral). There is a tradeoff between a high number of experts per token for accuracy (but diminishing returns) vs. a low number for fast training and inference.</p></li></ul><p>Historically, MoEs have underperformed dense models. However, the release of <a href="https://arxiv.org/abs/2401.04088">Mixtral-8x7B</a> in December 2023 shook things up and showed impressive performance for its size. Additionally, GPT-4 is also rumored to be an MoE, which would make sense as it would be a lot cheaper to run and train for OpenAI compared to a dense model. In addition to these recent excellent MoEs, we now have a new way of creating MoEs with MergeKit: frankenMoEs, also called MoErges.</p><h3>&#129503;&#8205;&#9794;&#65039; True MoEs vs. frankenMoEs</h3><p>The main difference between true MoEs and frankenMoEs is how they&#8217;re trained. In the case of true MoEs, the experts and the router are trained jointly. In the case of frankenMoEs, we upcycle existing models and initialize the router afterward.</p><p>In other words, we copy the weights of the layer norm and self-attention layers from a base model, and then copy the weights of the FFN layers found in each expert. This means that besides the FFNs, all the other parameters are shared. This explains why Mixtral-8x7B with eight experts doesn&#8217;t have 8*7 = 56B parameters, but about 45B. This is also why using two experts per token gives the inference speed (FLOPs) of a 12B dense model instead of 14B.</p><p>FrankenMoEs are about selecting the most relevant experts and initializing them properly. MergeKit currently implements three ways of initializing the routers:</p><ol><li><p><strong><a href="https://github.com/arcee-ai/mergekit/blob/9c691527f7192b5a2fc388555bfd3105e0898480/mergekit/scripts/mixtral_moe.py#L139-L142">Random</a></strong>: Random weights. Be careful when using it as the same experts might be selected every time (it requires further fine-tuning or <code>num_local_experts = num_experts_per_tok</code>, which means you don't need any routing).</p></li><li><p><strong><a href="https://github.com/arcee-ai/mergekit/blob/9c691527f7192b5a2fc388555bfd3105e0898480/mergekit/scripts/mixtral_moe.py#L91C1-L109C37">Cheap embed</a></strong>: It uses the raw embeddings of the input tokens directly and applies the same transformation across all layers. This method is computationally inexpensive and suitable for execution on less powerful hardware.</p></li><li><p><strong><a href="https://github.com/arcee-ai/mergekit/blob/9c691527f7192b5a2fc388555bfd3105e0898480/mergekit/scripts/mixtral_moe.py#L70-L88">Hidden</a></strong>: It creates hidden representations of a list of positive and negative prompts by extracting them from the last layer of the LLM. They are averaged and normalized to initialize the gates. More information about it is available on <a href="https://goddard.blog/posts/clown-moe/">Charles Goddard&#8217;s blog</a>.</p></li></ol><p>As you can guess, the &#8220;hidden&#8221; initialization is the most efficient to correctly route the tokens to the most relevant experts. In the next section, we will create our own frankenMoE using this technique.</p><h3>&#128187; Creating a frankenMoE</h3><p>To create our frankenMoE, we need to select <code>n</code> experts. In this case, we will rely on Mistral-7B thanks to its popularity and relatively small size. However, eight experts like in Mixtral is quite a lot, as we need to fit all of them in memory. For efficiency, I'll only use four experts in this example, with two of them engaged for each token and each layer. In this case, we will end up with a model with 24.2B parameters instead of 4*7 = 28B parameters.</p><p>Here, our goal is to create a well-rounded model that can do pretty much everything: write stories, explain articles, code in Python, etc. We can decompose this requirement into four tasks and select the best expert for each of them. This is how I decomposed it:</p><ul><li><p><strong>Chat model</strong>: a general-purpose model that is used in most interactions. I used <a href="https://huggingface.co/mlabonne/AlphaMonarch-7B">mlabonne/AlphaMonarch-7B</a>, which perfectly satisfies the requirements.</p></li><li><p><strong>Code model</strong>: a model capable of generating good code. I don&#8217;t have a lot of experience with Mistral-7B-based code models, but I found <a href="https://huggingface.co/beowolx/CodeNinja-1.0-OpenChat-7B">beowolx/CodeNinja-1.0-OpenChat-7B</a> particularly good compared to others.</p></li><li><p><strong>Math model</strong>: math is tricky for LLMs, which is why we want a model specialized in math. Thanks to its high MMLU and GMS8K scores, I chose <a href="https://huggingface.co/mlabonne/NeuralDaredevil-7B">mlabonne/NeuralDaredevil-7B</a> for this purpose.</p></li><li><p><strong>Role-play model</strong>: The goal of this model is to write high-quality stories and conversations. I selected <a href="https://huggingface.co/SanjiWatsuki/Kunoichi-DPO-v2-7B">SanjiWatsuki/Kunoichi-DPO-v2&#8211;7B</a> because of its good reputation and high MT-Bench score (8.51 vs. 8.30 for Mixtral).</p></li></ul><p>Now that we&#8217;ve identified the experts we want to use, we can create the YAML configuration that MergeKit will use to create our frankenMoE. This uses the mixtral branch of MergeKit. You can find more information about how to write the configuration <a href="https://github.com/arcee-ai/mergekit/blob/mixtral/docs/moe.md">on this page</a>. Here is our version:</p><pre><code>base_model: mlabonne/AlphaMonarch-7B
experts:
  - source_model: mlabonne/AlphaMonarch-7B
    positive_prompts:
    - "chat"
    - "assistant"
    - "tell me"
    - "explain"
    - "I want"
  - source_model: beowolx/CodeNinja-1.0-OpenChat-7B
    positive_prompts:
    - "code"
    - "python"
    - "javascript"
    - "programming"
    - "algorithm"
  - source_model: SanjiWatsuki/Kunoichi-DPO-v2-7B
    positive_prompts:
    - "storywriting"
    - "write"
    - "scene"
    - "story"
    - "character"
  - source_model: mlabonne/NeuralDaredevil-7B
    positive_prompts:
    - "reason"
    - "math"
    - "mathematics"
    - "solve"
    - "count"</code></pre><p>For each expert, I provide five basic positive prompts. You can be a bit fancier and write entire sentences if you want. The best strategy consists of using real prompts that should trigger a particular expert. You can also add negative prompts to do the opposite.</p><p>Once this is ready, you can save your configuration as <code>config.yaml</code>. In the same folder, we will download and install the <a href="https://github.com/arcee-ai/mergekit">mergekit</a> library (mixtral branch).</p><pre><code>git clone -b mixtral https://github.com/arcee-ai/mergekit.git
cd mergekit &amp;&amp; pip install -e .
pip install -U transformers</code></pre><p>If your computer has enough RAM (roughly 24&#8211;32 GB of RAM), you can run the following command:</p><pre><code>mergekit-moe config.yaml merge --copy-tokenizer</code></pre><p>If you don&#8217;t have enough RAM, you can shard the models instead as follows (it will take longer):</p><pre><code>mergekit-moe config.yaml merge --copy-tokenizer --allow-crimes --out-shard-size 1B --lazy-unpickle</code></pre><p>This command automatically downloads the experts and creates the frankenMoE in the <code>merge</code> directory. For the <code>hidden</code> gate mode, you can also use the <code>--load-in-4bit</code> and <code>--load-in-8bit</code> options to compute hidden states with lower precision.</p><p>Alternatively, you can copy your configuration into <a href="https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb#scrollTo=d5mYzDo1q96y">LazyMergekit</a>, a wrapper I made to simplify model merging. In this Colab notebook, you can input your model name, select the <code>mixtral</code> branch, specify your Hugging Face username/token, and run the cells. After creating your frankenMoE, it will also upload it to the Hugging Face Hub with a nicely formatted model card.</p><p>I called my model <a href="https://huggingface.co/mlabonne/Beyonder-4x7B-v3">Beyonder-4x7B-v3</a> and created <a href="https://huggingface.co/mlabonne/Beyonder-4x7B-v3-GGUF">GGUF versions</a> of it using <a href="https://colab.research.google.com/drive/1P646NEg33BZy4BfLDNpTz0V0lwIU3CHu#scrollTo=fD24jJxq7t3k">AutoGGUF</a>. If you can&#8217;t run GGUF versions on your local machine, you can also perform inference using this <a href="https://colab.research.google.com/drive/1SIfwhpLttmoZxT604LGVXDOI9UKZ_1Aq?usp=sharing">Colab notebook</a>.</p><p>To get a good overview of its capabilities, it has been evaluated on three different benchmarks: Nous&#8217; benchmark suite, EQ-Bench, and the Open LLM Leaderboard. This model is not designed to excel in traditional benchmarks, as the code and role-playing models generally do not apply to those contexts. Nonetheless, it performs remarkably well thanks to strong general-purpose experts.</p><p><strong>Nous</strong>: Beyonder-4x7B-v3 is one of the best models on Nous&#8217; benchmark suite (evaluation performed using <a href="https://github.com/mlabonne/llm-autoeval">LLM AutoEval</a>) and significantly outperforms the v2. See the entire leaderboard <a href="https://huggingface.co/spaces/mlabonne/Yet_Another_LLM_Leaderboard">here</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!7VRP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 424w, /__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 848w, /__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!7VRP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 424w, /__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 848w, /__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 1272w, /__u/substackcdn.com/image/fetch/$s_!7VRP!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9b0b8b44-a7dd-4172-a0f6-1b782f08bc75_800x328.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>EQ-Bench</strong>: It&#8217;s also the best 4x7B model on the <a href="https://eqbench.com/">EQ-Bench leaderboard</a>, outperforming older versions of ChatGPT and Llama-2&#8211;70b-chat. Beyonder is very close to Mixtral-8x7B-Instruct-v0.1 and Gemini Pro, which are (supposedly) much bigger models.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!p75M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 424w, /__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 848w, /__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 1272w, /__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!p75M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 424w, /__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 848w, /__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 1272w, /__u/substackcdn.com/image/fetch/$s_!p75M!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4a1a21f8-2374-4b0a-8a96-fb07d3fdf9ba_800x312.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p><strong>Open LLM Leaderboard</strong>: Finally, it&#8217;s also a strong performer on the Open LLM Leaderboard, significantly outperforming the v2 model.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!fCAC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 424w, /__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 848w, /__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!fCAC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 424w, /__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 848w, /__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fCAC!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c9c6f6f-93c1-43b4-933d-794cbec30867_800x185.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>On top of these quantitative evaluations, I recommend checking the model&#8217;s outputs in a more qualitative way using a GGUF version on <a href="https://lmstudio.ai/">LM Studio</a>. A common way of testing these models is to gather a private set of questions and check their outputs. With this strategy, I found that Beyonder-4x7B-v3 is quite robust to changes in the user and system prompts compared to other models, including AlphaMonarch-7B. This is pretty cool as it improves the usefulness of the model in general.</p><p>FrankenMoEs are a promising but still experimental approach. The trade-offs, like higher VRAM demand and slower inference speeds, can make it challenging to see their advantage over simpler merging techniques like SLERP or DARE TIES. Especially, when you use frankenMoEs with just two experts, they might not perform as well as if you had simply merged the two models. However, frankenMoEs excel in preserving knowledge, which can result in stronger models, as demonstrated by Beyonder-4x7B-v3. With the right hardware, these drawbacks can be effectively mitigated.</p><h3>Conclusion</h3><p>In this article, we introduced the Mixture of Experts architecture. Unlike traditional MoEs that are trained from scratch, MergeKit facilitates the creation of MoEs by ensembling experts, offering an innovative approach to improving model performance and efficiency. We detailed the process of creating a frankenMoE with MergeKit, highlighting the practical steps involved in selecting and combining different experts to produce a high-quality MoE.</p><p>Thanks for reading this article. I encourage you to try to make your own FrankenMoEs using <a href="https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb#scrollTo=d5mYzDo1q96y">LazyMergeKit</a>: select a few models, create your config based Beyonder&#8217;s, and run the notebook to create your own models! If you liked this article, please follow me on <a href="https://huggingface.co/mlabonne">Hugging Face</a> and X/Twitter <a href="https://twitter.com/maximelabonne">@maximelabonne</a>.</p><h3>References</h3><ul><li><p><a href="https://arxiv.org/abs/2401.04088">Mixtral of Experts</a> by Jiang et al. (2023)</p></li><li><p><a href="https://goddard.blog/posts/clown-moe/">Mixture of Experts for Clowns</a> by Charles Goddard (2023)</p></li><li><p><a href="https://huggingface.co/blog/moe">Mixture of Experts Explained</a> by Sanseviero et al. (2023)</p></li><li><p><a href="https://www.cs.toronto.edu/~hinton/absps/jjnh91.pdf">Adaptive Mixture of Local Experts</a> by Jacobs et al. (1991)</p></li><li><p><a href="https://arxiv.org/abs/2212.05055">Sparse Upcycling: Training Mixture-of-Experts from Dense Checkpoints</a> by Komatsuzaki et al. (2022)</p></li></ul><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link&#8202;&#8212;&#8202;Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p>]]></content:encoded></item><item><title><![CDATA[Merge Large Language Models with mergekit]]></title><description><![CDATA[Create your own models easily, no GPU required!]]></description><link>https://maximelabonne.substack.com/p/merge-large-language-models-with-mergekit-2118fb392b54</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/merge-large-language-models-with-mergekit-2118fb392b54</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 08 Jan 2024 03:17:00 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/2d8bd74b-11d2-48f2-87fc-c6c674283df6_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>Create your own models easily, no GPU required!</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!bFXf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!bFXf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!bFXf!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb70bd632-5d8d-4945-8571-4f464a6ad070_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Model merging is a technique that <strong>combines two or more LLMs</strong> into a single model. It&#8217;s a relatively new and experimental method to create new models for cheap (no GPU required). Model merging works surprisingly well and produced many state-of-the-art models on the <a href="https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard">Open LLM Leaderboard</a>.</p><p>In this tutorial, we will implement it using the <a href="https://github.com/cg123/mergekit">mergekit</a> library. More specifically, we will review four merge methods and provide examples of configurations. Then, we will use mergekit to create our own model, <a href="https://huggingface.co/mlabonne/Marcoro14-7B-slerp">Marcoro14&#8211;7B-slerp</a>, which became the best-performing model on the Open LLM Leaderboard (02/01/24).</p><p>The code is available on <a href="https://github.com/mlabonne/llm-course/blob/main/Mergekit.ipynb">GitHub</a> and <a href="https://colab.research.google.com/drive/1_JS7JKJAQozD48-LhYdegcuuZ2ddgXfr?usp=sharing">Google Colab</a>. I recommend using my automated notebook to easily run mergekit: <a href="https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb?usp=sharing">&#129393; LazyMergekit</a>.</p><p><em>A special thanks to <a href="https://www.linkedin.com/in/charles-goddard-7b6797b/">Charles Goddard</a>, the author of the mergekit library, for reviewing this article.</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!-ULH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 424w, /__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 848w, /__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!-ULH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17ac2603-1edb-4200-a306-1147a1898039_800x459.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 424w, /__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 848w, /__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 1272w, /__u/substackcdn.com/image/fetch/$s_!-ULH!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17ac2603-1edb-4200-a306-1147a1898039_800x459.png 1456w" sizes="100vw"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><h3>&#129309; Merge algorithms</h3><p>In this section, we will focus on four methods currently implemented in <a href="https://github.com/cg123/mergekit">mergekit</a>. Note that there are other methods, such as <a href="https://github.com/cg123/mergekit/tree/1011ef3a84e4c5545473602baf7ef32d535044a9#linear">linear</a> and <a href="https://arxiv.org/abs/2212.04089">Task Arithmetic</a>. If you&#8217;re interested in papers on model merging, I recommend <a href="https://huggingface.co/collections/osanseviero/model-merging-65097893623330a3a51ead66">this excellent collection</a> on Hugging Face.</p><h4>1. SLERP</h4><p><strong>Spherical Linear Interpolation</strong> (SLERP) is a method used to smoothly interpolate between two vectors. It maintains a constant rate of change and preserves the geometric properties of the spherical space in which the vectors reside.</p><p>There are several reasons to prefer SLERP over a traditional linear interpolation. For example, in high-dimensional spaces, linear interpolation can lead to a <strong>decrease in the magnitude</strong> of the interpolated vector (i.e., it reduces the scale of weights). Moreover, the change in direction of the weights often represents <strong>more meaningful information</strong> (like feature learning and representation) than the magnitude of change.</p><p>SLERP is implemented using the following steps:</p><ol><li><p>Normalize the input vectors to unit length, ensuring they represent directions rather than magnitudes</p></li><li><p>Calculate the angle between these vectors using their dot product.</p></li><li><p>If the vectors are nearly collinear, it defaults to linear interpolation for efficiency. Otherwise, SLERP computing scale factors based on the interpolation factor <code>t</code> (<code>t=0</code> = 100% of the first vector, <code>t=1</code> = 100% of model 2) and the angle between the vectors.</p></li><li><p>These factors are used to weigh the original vectors, which are then summed to obtain the interpolated vector.</p></li></ol><p>SLERP is currently the most popular merging method, but it is limited to combining only two models at a time. It is still possible to hierarchically combine multiple models, as shown in <a href="https://huggingface.co/EmbeddedLLM/Mistral-7B-Merge-14-v0.1">Mistral-7B-Merge-14-v0.1</a>.</p><p><em>Example of configuration:</em></p><pre><code>slices:
  - sources:
      - model: OpenPipe/mistral-ft-optimized-1218
        layer_range: [0, 32]
      - model: mlabonne/NeuralHermes-2.5-Mistral-7B
        layer_range: [0, 32]
merge_method: slerp
base_model: OpenPipe/mistral-ft-optimized-1218
parameters:
  t:
    - filter: self_attn
      value: [0, 0.5, 0.3, 0.7, 1]
    - filter: mlp
      value: [1, 0.5, 0.7, 0.3, 0]
    - value: 0.5
dtype: bfloat16</code></pre><p>This is a classic SLERP configuration, applied to every layer of both models. Note that we input a gradient of values for the interpolation factor <code>t</code>. The parameters for the self-attention and MLP layers will use different combinations of <a href="https://huggingface.co/OpenPipe/mistral-ft-optimized-1218">OpenPipe/mistral-ft-optimized-1218</a> and <a href="https://huggingface.co/mlabonne/NeuralHermes-2.5-Mistral-7B">mlabonne/NeuralHermes-2.5-Mistral-7B</a>. The other layers are a 50/50 mixture of the two models.</p><p>You can find the final model on the Hugging Face Hub at <a href="https://huggingface.co/mlabonne/NeuralPipe-7B-slerp">mlabonne/NeuralPipe-7B-slerp</a>.</p><h4>2. TIES</h4><p>Introduced in <a href="https://arxiv.org/abs/2306.01708">this paper</a> by Yadav et al., <strong>TIES-Merging</strong> is designed to efficiently merge multiple task-specific models into a single multitask model. It addresses two main challenges in model merging:</p><ul><li><p><strong>Redundancy in model parameters</strong>: It identifies and eliminates redundant parameters within task-specific models. This is achieved by focusing on the changes made during fine-tuning, identifying the top-k% most significant changes, and discarding the rest.</p></li><li><p><strong>Disagreement between parameter signs</strong>: Conflicts arise when different models suggest opposing adjustments to the same parameter. TIES-Merging resolves these conflicts by creating a unified sign vector that represents the most dominant direction of change across all models.</p></li></ul><p>TIES-Merging is divided into the following three steps:</p><ol><li><p><strong>Trim</strong>: Reduces redundancy in task-specific models by retaining only a fraction the most significant parameters (density parameter) and resetting the rest to zero.</p></li><li><p><strong>Elect Sign</strong>: Resolves sign conflicts across different models by creating a unified sign vector based on the most dominant direction (positive or negative) in terms of cumulative magnitude.</p></li><li><p><strong>Disjoint Merge</strong>: Averages parameter values that align with the unified sign vector, excluding zero values.</p></li></ol><p>Unlike SLERP, TIES can merge multiple models at a time.</p><p><em>Example of configuration:</em></p><pre><code>models:
  - model: mistralai/Mistral-7B-v0.1
    # no parameters necessary for base model
  - model: OpenPipe/mistral-ft-optimized-1218
    parameters:
      density: 0.5
      weight: 0.5
  - model: mlabonne/NeuralHermes-2.5-Mistral-7B
    parameters:
      density: 0.5
      weight: 0.3
merge_method: ties
base_model: mistralai/Mistral-7B-v0.1
parameters:
  normalize: true
dtype: float16</code></pre><p>With this config, we use Mistral-7B as a base model to calculate the delta weights. We merge the same two models: <a href="https://huggingface.co/OpenPipe/mistral-ft-optimized-1218">mistral-ft-optimized-1218</a> (50%) and <a href="https://huggingface.co/mlabonne/NeuralHermes-2.5-Mistral-7B">NeuralHermes-2.5-Mistral-7B</a> (30%) with normalization. Here, the density means that we&#8217;re only retaining 50% of the parameters of each model (the other half comes from the base model).</p><p>Note that the sum of the weights is not equal to 1 in the config, but the <code>normalize: true</code> parameter will automatically normalize them internally. This config is inspired by the parameters provided by the author of <a href="https://huggingface.co/Weyaxi/OpenHermes-2.5-neural-chat-7b-v3-1-7B">OpenHermes-2.5-neural-chat-7b-v3&#8211;1&#8211;7B</a>.</p><p>You can find the final model on the Hugging Face Hub at <a href="https://huggingface.co/mlabonne/NeuralPipe-7B-ties">mlabonne/NeuralPipe-7B-ties</a>.</p><h4>3. DARE</h4><p>Introduced by Yu et al. (2023), <a href="https://arxiv.org/abs/2311.03099">DARE</a> uses an approach similar to TIES with two main differences:</p><ul><li><p><strong>Pruning</strong>: DARE randomly reset fine-tuned weights to their original values (those of the base model).</p></li><li><p><strong>Rescaling</strong>: DARE rescales the weights to keep the expectations of model outputs approximately unchanged. It adds the rescaled weights of both (or more) models to the weights of the base model with a scale factor.</p></li></ul><p>Mergekit&#8217;s implementation of this method has two flavors: with the sign election step of TIES (<code>dare_ties</code>) or without (<code>dare_linear</code>).</p><p><em>Example of configuration:</em></p><pre><code>models:
  - model: mistralai/Mistral-7B-v0.1
    # No parameters necessary for base model
  - model: samir-fama/SamirGPT-v1
    parameters:
      density: 0.53
      weight: 0.4
  - model: abacusai/Slerp-CM-mist-dpo
    parameters:
      density: 0.53
      weight: 0.3
  - model: EmbeddedLLM/Mistral-7B-Merge-14-v0.2
    parameters:
      density: 0.53
      weight: 0.3
merge_method: dare_ties
base_model: mistralai/Mistral-7B-v0.1
parameters:
  int8_mask: true
dtype: bfloat16</code></pre><p>In this configuration, we merge three different models based on Mistral-7B using <code>dare_ties</code>. This time, I chose weights that sum to 1 (the sum should be between 0.9 and 1.1). The density parameter is a little higher than what's recommended in the paper (&lt;0.5), but it looks like it gives consistently better results (see <a href="https://github.com/cg123/mergekit/issues/26">this discussion</a>).</p><p>You can find it on the Hugging Face Hub at <a href="https://huggingface.co/mlabonne/Daredevil-7B">mlabonne/Daredevil-7B</a>. It&#8217;s also the best merge model in this article, outperforming even Marcoro14&#8211;7B-slerp.</p><h4>4. Passthrough</h4><p>The passthrough method differs significantly from the previous ones. By concatenating layers from different LLMs, it can produce models with an <strong>exotic number of parameters</strong> (e.g., 9B with two 7B parameter models). These models are often referred to as &#8220;frankenmerges&#8221; or &#8220;Frankenstein models&#8221; by the community.</p><p>This technique is very experimental, but it managed to create impressive models, like <a href="https://huggingface.co/alpindale/goliath-120b">goliath-120b</a> using two Llama 2 70B models. The recently released <a href="https://huggingface.co/upstage/SOLAR-10.7B-v1.0">SOLAR-10.7B-v1.0</a> also uses the same idea, called depth-up scaling <a href="https://arxiv.org/abs/2312.15166">in their paper</a>.</p><p><em>Example of configuration:</em></p><pre><code>slices:
  - sources:
    - model: OpenPipe/mistral-ft-optimized-1218
      layer_range: [0, 32]
  - sources:
    - model: mlabonne/NeuralHermes-2.5-Mistral-7B
      layer_range: [24, 32]
merge_method: passthrough
dtype: bfloat16</code></pre><p>The resulting frankenmerge will have all the 32 layers from the first model and 8 additional layers from the second model. This creates a frankenmerge with a total of 40 layers and 8.99B parameters. This config is inspired by <a href="https://huggingface.co/zyh3826/GML-Mistral-merged-v1">GML-Mistral-merged-v1</a>.</p><p>You can find the final model on the Hugging Face Hub at <a href="https://huggingface.co/mlabonne/NeuralPipe-9B-merged">mlabonne/NeuralPipe-9B-merged</a>.</p><h3>&#128187; Merge your own&nbsp;models</h3><p>In this section, we will use mergekit to load a merge configuration, run it, and upload the resulting model to the Hugging Face Hub.</p><p>First of all, we install mergekit directly from source as follows:</p><pre><code>!git clone https://github.com/cg123/mergekit.git
!cd mergekit &amp;&amp; pip install -q -e .</code></pre><p>In the following block, we load the merge configuration in a YAML format. We also specify the name of the merged model for future use. You can copy/paste any configuration from the previous section here.</p><p>This time, we will use two different models: <a href="https://huggingface.co/AIDC-ai-business/Marcoroni-7B-v3">Marcoroni-7B-v3</a> and <a href="https://huggingface.co/EmbeddedLLM/Mistral-7B-Merge-14-v0.1">Mistral-7B-Merge-14-v0.1</a> and merge them with the SLERP method. We save the config as a yaml file to be used as input in the merge command.</p><pre><code>import yaml

MODEL_NAME = "Marcoro14-7B-slerp"
yaml_config = """
slices:
  - sources:
      - model: AIDC-ai-business/Marcoroni-7B-v3
        layer_range: [0, 32]
      - model: EmbeddedLLM/Mistral-7B-Merge-14-v0.1
        layer_range: [0, 32]
merge_method: slerp
base_model: AIDC-ai-business/Marcoroni-7B-v3
parameters:
  t:
    - filter: self_attn
      value: [0, 0.5, 0.3, 0.7, 1]
    - filter: mlp
      value: [1, 0.5, 0.7, 0.3, 0]
    - value: 0.5
dtype: bfloat16

"""

# Save config as yaml file
with open('config.yaml', 'w', encoding="utf-8") as f:
    f.write(yaml_config)</code></pre><p>We run the merge command with the following parameters:</p><ul><li><p><code>--copy-tokenizer</code> to copy the tokenizer from the base model</p></li><li><p><code>--allow-crimes</code> and <code>--out-shard-size</code> to chunk the models into smaller shards that can be computed on a CPU with low RAM</p></li><li><p><code>--lazy-unpickle</code> to enable the experimental lazy unpickler for lower memory usage</p></li></ul><p>In addition, some models can require the <code>--trust_remote_code</code> flag (this is not the case with Mistral-7B).</p><p>This command will download the weights of all the models listed in the merge configuration and run the selected merge method (it should take ~10 minutes).</p><pre><code># Merge models
!mergekit-yaml config.yaml merge --copy-tokenizer --allow-crimes --out-shard-size 1B --lazy-unpickl</code></pre><p>The model is now merged and saved in the `merge` directory. Before uploading it, we can create a README file with all the information required for reproducibility. The following code block defines a Jinja template and automatically fills it with the data from the merge configuration.</p><pre><code>!pip install -qU huggingface_hub

from huggingface_hub import ModelCard, ModelCardData
from jinja2 import Template

username = "mlabonne"

template_text = """
---
license: apache-2.0
tags:
- merge
- mergekit
- lazymergekit
{%- for model in models %}
- {{ model }}
{%- endfor %}
---

# {{ model_name }}

{{ model_name }} is a merge of the following models using [mergekit](https://github.com/cg123/mergekit):

{%- for model in models %}
* [{{ model }}](https://huggingface.co/{{ model }})
{%- endfor %}

## &#129513; Configuration

```yaml
{{- yaml_config -}}
```
"""

# Create a Jinja template object
jinja_template = Template(template_text.strip())

# Get list of models from config
data = yaml.safe_load(yaml_config)
if "models" in data:
    models = [data["models"][i]["model"] for i in range(len(data["models"])) if "parameters" in data["models"][i]]
elif "parameters" in data:
    models = [data["slices"][0]["sources"][i]["model"] for i in range(len(data["slices"][0]["sources"]))]
elif "slices" in data:
    models = [data["slices"][i]["sources"][0]["model"] for i in range(len(data["slices"]))]
else:
    raise Exception("No models or slices found in yaml config")

# Fill the template
content = jinja_template.render(
    model_name=MODEL_NAME,
    models=models,
    yaml_config=yaml_config,
    username=username,
)

# Save the model card
card = ModelCard(content)
card.save('merge/README.md')</code></pre><p>Now that we have a model card, we can push the entire folder to the Hub.</p><pre><code>from google.colab import userdata
from huggingface_hub import HfApi

username = "mlabonne"

# Defined in the secrets tab in Google Colab
api = HfApi(token=userdata.get("HF_TOKEN"))

api.create_repo(
    repo_id=f"{username}/{MODEL_NAME}",
    repo_type="model"
)
api.upload_folder(
    repo_id=f"{username}/{MODEL_NAME}",
    folder_path="merge",
)</code></pre><p>The model is now available on the Hugging Face Hub at <a href="https://huggingface.co/mlabonne/Marcoro14-7B-slerp">mlabonne/Marcoro14&#8211;7B-slerp</a>. In another notebook, we can try the model on a free T4 GPU using the following code:</p><pre><code>!pip install -qU transformers accelerate

from transformers import AutoTokenizer
import transformers
import torch

model = "mlabonne/Marcoro14-7B-slerp"
messages = [{"role": "user", "content": "What is a large language model?"}]

tokenizer = AutoTokenizer.from_pretrained(model)
prompt = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
pipeline = transformers.pipeline(
    "text-generation",
    model=model,
    torch_dtype=torch.float16,
    device_map="auto",
)

outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)</code></pre><p>We&#8217;re asking the question &#8220;What is a Large Language Model?&#8221; and received this output:</p><blockquote><p><em>A large language model is a type of artificial intelligence (AI) system that has been trained on vast amounts of text data. It&#8217;s designed to understand and generate human-like language, making predictions on what words or phrases might come next in a sentence or document. These models use complex algorithms and neural network architectures to learn from the data and improve their performance over time. Some well-known large language models include GPT-3 from OpenAI and BERT from Google.</em></p></blockquote><p>It&#8217;s looking good, but we need a more comprehensive evaluation. For this kind of general-purpose model, there are a few interesting benchmarks:</p><ul><li><p><strong><a href="https://chat.lmsys.org/">Chatbot Arena</a></strong>, which compiles an Elo-based LLM leaderboard based on human votes.</p></li><li><p><strong><a href="https://chat.lmsys.org/">MT-bench</a></strong> (same link), which uses GPT-4 as a judge to grade model responses on a set of multi-turn questions.</p></li><li><p><strong><a href="https://github.com/teknium1/LLM-Benchmark-Logs">NousResearch benchmark suite</a></strong>, which aggregates four benchmarks: AGIEval, GPT4ALL, TruthfulQA, and Bigbench. GPT4ALL itself includes HellaSwag, OpenBookQA, Winogrande, ARC-Easy, ARC-Challenge, BoolQ, and PIQA.</p></li><li><p><strong><a href="https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard">Open LLM Leaderboard</a></strong>, which aggregates six benchmarks: ARC, HellaSwag, MMLU, Winogrande, GSM8K, and TruthfulQA.</p></li></ul><p>Unfortunately, we can&#8217;t submit our model to the Chatbot Arena. Instead, I chose to evaluate it using the Open LLM Leaderboard and NousResearch benchmarks.</p><p>I submitted our model to the <a href="https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard">Open LLM Leaderboard</a> (&#8220;&#128640; Submit here!&#8221; tab). As shown in the introduction, it ranked as <strong>the best 7B parameter model</strong> on the leaderboard. Here are the complete results:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!l9Wt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 424w, /__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 848w, /__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 1272w, /__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!l9Wt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 424w, /__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 848w, /__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 1272w, /__u/substackcdn.com/image/fetch/$s_!l9Wt!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721637e6-114c-4051-b4d8-9b5ab45bca6a_800x62.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The problem with the Open LLM Leaderboard is that these benchmarks are public. It means that people can train LLMs on the test data to get better results. By merging the best models, we also contaminate our own results. It is safe to assume that <strong>Marcoro14&#8211;7B-slerp is contaminated</strong> and some models used in this merge have been trained on the test set. If you want to create the best model and not hack the leaderboard, I recommend only using non-merge models to create your own merges.</p><p>This is why we don&#8217;t want to only rely on the OpenLLM Leaderboard. For NousResearch benchmark suite, I used <a href="https://github.com/mlabonne/llm-autoeval">&#129488; LLM AutoEval</a> to compute the scores automatically with a simple Colab notebook. Here are the results compared to the excellent <a href="https://huggingface.co/teknium/OpenHermes-2.5-Mistral-7B">OpenHermes-2.5-Mistral-7B</a>:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!2hao!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 424w, /__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 848w, /__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!2hao!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 424w, /__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 848w, /__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 1272w, /__u/substackcdn.com/image/fetch/$s_!2hao!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe6ac5909-7289-4724-b3b1-454e83d1b030_800x143.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>We get a significant improvement over this model on <strong>every benchmark</strong>. Note that NousResearch benchmark suite shares some tasks with the Open LLM Leaderboard: ARC-Challenge, TruthfulQA, HellaSwag, and Winogrande. To the best of my knowledge, Bigbench is the only benchmark that is 100% different (feel free to contact me if that&#8217;s not the case). However, one of the models we used in this merge could still have been trained on Bigbench.</p><h3>Conclusion</h3><p>In this article, we introduced the concept of merging LLMs with four different methods. We detailed how SLERP, TIES, DARE, and passthrough work and provided examples of configurations. Finally, we ran SLERP with mergekit to create <a href="https://huggingface.co/mlabonne/Marcoro14-7B-slerp">Marcoro14&#8211;7B-slerp</a> and upload it to the Hugging Face Hub. We obtained excellent performance on two benchmark suites: Open LLM Leaderboard (<strong>best-performing 7B model</strong>) and NousResearch. If you want to create your own merges, I recommend using my automated notebook <a href="https://colab.research.google.com/drive/1obulZ1ROXHjYLn6PPZJwRR6GzgQogxxb?usp=sharing">&#129393; LazyMergekit</a>.</p><p>Another way of combining multiple models is to merge them in a Mixture of Experts (MoE) architecture. In the next article, we&#8217;ll discuss how to do this in detail and create our <a href="https://huggingface.co/mlabonne/Beyonder-4x7B-v2">own Mixtral-like model</a>. If you liked this article, please follow me on Medium and Twitter <a href="https://twitter.com/maximelabonne">@maximelabonne</a>.</p><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link&#8202;&#8212;&#8202;Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p>]]></content:encoded></item><item><title><![CDATA[Fine-tune a Mistral-7b model with Direct Preference Optimization]]></title><description><![CDATA[Boost the performance of your supervised fine-tuned models]]></description><link>https://maximelabonne.substack.com/p/fine-tune-a-mistral-7b-model-with-direct-preference-optimization-708042745aac</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/fine-tune-a-mistral-7b-model-with-direct-preference-optimization-708042745aac</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 01 Jan 2024 18:09:45 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/39c96a37-f139-48ac-be0c-08fa955fd66e_800x457.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>Boost the performance of your supervised fine-tuned models</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!CN1E!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 424w, /__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 848w, /__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 1272w, /__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!CN1E!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 424w, /__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 848w, /__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 1272w, /__u/substackcdn.com/image/fetch/$s_!CN1E!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbc60ed0c-edfb-435f-b33e-fcae5b09f3cd_800x457.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Pre-trained Large Language Models (LLMs) can only perform next-token prediction, making them unable to answer questions. This is why these base models are then fine-tuned on pairs of instructions and answers to act as helpful assistants. However, this process can still be flawed: fine-tuned LLMs can be biased, toxic, harmful, etc. This is where Reinforcement Learning from Human Feedback (RLHF) comes into play.</p><p>RLHF provides different answers to the LLM, which are ranked according to a desired behavior (helpfulness, toxicity, etc.). The model learns to output the best answer among these candidates, hence mimicking the behavior we want to instill. Often seen as a way to censor models, this process has recently become popular for improving performance, as shown in <a href="https://huggingface.co/Intel/neural-chat-7b-v3-1">neural-chat-7b-v3&#8211;1</a>.</p><p>In this article, we will create <a href="https://huggingface.co/mlabonne/NeuralHermes-2.5-Mistral-7B">NeuralHermes-2.5</a>, by fine-tuning <a href="https://huggingface.co/teknium/OpenHermes-2.5-Mistral-7B">OpenHermes-2.5</a> using a RLHF-like technique: Direct Preference Optimization (DPO). For this purpose, we will introduce a preference dataset, describe how the DPO algorithm works, and apply it to our model. We&#8217;ll see that it significantly improves the performance of the base model on the Open LLM Leaderboard.</p><p>As per usual, the code is available on <a href="https://github.com/mlabonne/llm-course/blob/main/Fine_tune_a_Mistral_7b_model_with_DPO.ipynb">GitHub</a> and <a href="https://colab.research.google.com/drive/15iFBr1xWgztXvhrj5I9fBv20c7CFOPBE?usp=sharing">Google Colab</a>.</p><p><em><strong>Update</strong>: <a href="https://www.linkedin.com/in/jesse-th-davids/">Jessie Davids</a>, a reader who used this article and code, managed to create the best-performing model on the Open LLM Leaderboard ~7B param. Congrats to him! &#127881;</em></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!sbWq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!sbWq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!sbWq!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F145947c9-4f76-4598-8323-bbbb590e4878_800x247.jpeg 1456w" sizes="100vw"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><h3>&#129351; Preference datasets</h3><p>Preference datasets are not standardized, but they typically consist of a collection of answers that are ranked by humans. This ranking is essential, as the RLHF process fine-tunes LLMs to output the preferred answer. Here is an example of <a href="https://huggingface.co/datasets/Anthropic/hh-rlhf/viewer/default/train">Anthropic/hh-rlhf</a>, a popular preference dataset:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Uvv_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 424w, /__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 848w, /__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Uvv_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 424w, /__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 848w, /__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Uvv_!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5bb50c7c-885e-4394-95c2-634cf314f053_800x709.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The structure of the dataset is straightforward: for each row, there is one chosen (preferred) answer, and one rejected answer. The goal of RLHF is to guide the model to output the preferred answer.</p><p>Preference datasets are notoriously costly and difficult to make, as they require collecting manual feedback from humans. This feedback is also subjective and can easily be biased toward confident (but wrong) answers or contradict itself (different annotators have different values). Over time, several solutions have been proposed to tackle these issues, such as replacing human feedback with AI feedback (<a href="https://arxiv.org/abs/2212.08073">RLAIF</a>).</p><p>These datasets also tend to be a lot smaller than fine-tuning datasets. To illustrate this, the excellent <a href="https://huggingface.co/Intel/neural-chat-7b-v3-1">neural-chat-7b-v3&#8211;1</a> (best 7B LLM on the <a href="https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard">Open LLM Leaderboard</a> when it was released) uses 518k samples for fine-tuning (<a href="https://huggingface.co/datasets/Open-Orca/SlimOrca">Open-Orca/SlimOrca</a>) but only 12.9k samples for RLHF (<a href="https://huggingface.co/datasets/Intel/orca_dpo_pairs">Intel/orca_dpo_pairs</a>). In this case, the authors generated answers with GPT-4/3.5 to create the preferred answers, and with <a href="https://huggingface.co/meta-llama/Llama-2-13b-chat-hf">Llama 2 13b chat</a> to create the rejected responses. It&#8217;s a smart way to bypass human feedback and only rely on models with different levels of performance.</p><h3>&#127891; Direct Preference Optimization</h3><p>While the concept of RLHF has been used in robotics for a long time, it was popularized for LLMs in OpenAI&#8217;s paper <a href="https://arxiv.org/pdf/1909.08593.pdf">Fine-Tuning Language Models from Human Preferences</a>. In this paper, the authors present a framework where a reward model is trained to approximate human feedback. This reward model is then used to optimize the fine-tuned model&#8217;s policy using the <a href="https://arxiv.org/abs/1707.06347">Proximal Policy Optimization</a> (PPO) algorithm.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!cjZT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 424w, /__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 848w, /__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!cjZT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 424w, /__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 848w, /__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 1272w, /__u/substackcdn.com/image/fetch/$s_!cjZT!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1bcc90d-e07a-4dc9-8647-98ca7895c493_800x199.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The core concept of PPO revolves around making smaller, incremental updates to the policy, as larger updates can lead to instability or suboptimal solutions. From experience, this technique is unfortunately still unstable (loss diverges), difficult to reproduce (numerous hyperparameters, sensitive to random seeds), and computationally expensive.</p><p>This is where Direct Preference Optimization (DPO) comes into play. DPO simplifies control by treating the task as a classification problem. Concretely, it uses two models: the <strong>trained model</strong> (or policy model) and a copy of it called the <strong>reference model</strong>. During training, the goal is to make sure the trained model outputs higher probabilities for preferred answers than the reference model. Conversely, we also want it to output lower probabilities for rejected answers. It means we&#8217;re penalizing the LLM for bad answers and rewarding it for good ones.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!vJZP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 424w, /__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 848w, /__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 1272w, /__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!vJZP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 424w, /__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 848w, /__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 1272w, /__u/substackcdn.com/image/fetch/$s_!vJZP!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1ee117da-98f2-49c4-ad34-d3e01f8b7b92_800x295.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>By using the LLM itself as a reward model and employing binary cross-entropy objectives, DPO efficiently aligns the model&#8217;s outputs with human preferences without the need for extensive sampling, reward model fitting, or intricate hyperparameter adjustments. It results in a more stable, more efficient, and computationally less demanding process.</p><h3>&#128190; Formatting the&nbsp;data</h3><p>In this example, we&#8217;ll fine-tune the excellent <a href="https://huggingface.co/teknium/OpenHermes-2.5-Mistral-7B">OpenHermes-2.5-Mistral-7B</a>, which is a Mistral-7b model that was only supervised fine-tuned. To this end, we&#8217;ll use the <a href="https://huggingface.co/datasets/Intel/orca_dpo_pairs">Intel/orca_dpo_pairs</a> dataset to align our model and improve its performance. We call this new model NeuralHermes-2.5-Mistral-7B.</p><p>The first step consists of installing the required libraries as follows.</p><pre><code>pip install -q datasets trl peft bitsandbytes sentencepiece wandb</code></pre><p>Once it&#8217;s done, we can import the libraries. I&#8217;m also using the secrets tab in Google Colab to store my Hugging Face token.</p><pre><code>import os
import gc
import torch

import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, BitsAndBytesConfig
from datasets import load_dataset
from peft import LoraConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training
from trl import DPOTrainer
import bitsandbytes as bnb
from google.colab import userdata
import wandb

# Defined in the secrets tab in Google Colab
hf_token = userdata.get('huggingface')
wb_token = userdata.get('wandb')
wandb.login(key=wb_token)

model_name = "teknium/OpenHermes-2.5-Mistral-7B"
new_model = "NeuralHermes-2.5-Mistral-7B"</code></pre><p>OpenHermes-2.5-Mistral-7B uses a specific chat template, called <a href="https://huggingface.co/docs/transformers/chat_templating">ChatML</a>. Here is an example of a conversation formatted with this template:</p><pre><code>&lt;|im_start|&gt;system
You are a helpful chatbot assistant.&lt;|im_end|&gt;
&lt;|im_start|&gt;user
Hi&lt;|im_end|&gt;
&lt;|im_start|&gt;assistant
Hi, how can I help you?&lt;|im_end|&gt;</code></pre><p>As you can see, ChatML defines different roles (system, user, assistant) and appends special tokens (<code>&lt;|im_start|&gt;</code> and <code>&lt;|im_end|&gt;</code>) to separate them. Moreover, <a href="https://huggingface.co/docs/trl/main/en/dpo_trainer"><code>DPOTrainer</code></a> also requires a specific format with three columns: prompt, chosen, and rejected.</p><p>Our dataset contains four columns: system, question, chatgpt, and llama2&#8211;13b-chat. We&#8217;ll simply concatenate the system and question columns to the prompt column. We&#8217;ll also map the chatgpt column to &#8220;chosen&#8221; and llama2&#8211;13b-chat to &#8220;rejected&#8221;. To format the dataset in a reliable way, we&#8217;ll use the tokenizer&#8217;s <code>apply_chat_template()</code> function, which already uses ChatML.</p><pre><code>def chatml_format(example):
    # Format system
    if len(example['system']) &gt; 0:
        message = {"role": "system", "content": example['system']}
        system = tokenizer.apply_chat_template([message], tokenize=False)
    else:
        system = ""

    # Format instruction
    message = {"role": "user", "content": example['question']}
    prompt = tokenizer.apply_chat_template([message], tokenize=False, add_generation_prompt=True)

    # Format chosen answer
    chosen = example['chosen'] + "&lt;|im_end|&gt;\n"

    # Format rejected answer
    rejected = example['rejected'] + "&lt;|im_end|&gt;\n"

    return {
        "prompt": system + prompt,
        "chosen": chosen,
        "rejected": rejected,
    }

# Load dataset
dataset = load_dataset("Intel/orca_dpo_pairs")['train']

# Save columns
original_columns = dataset.column_names

# Tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "left"

# Format dataset
dataset = dataset.map(
    chatml_format,
    remove_columns=original_columns
)</code></pre><p>Let&#8217;s print a sample of the formatted dataset to confirm that everything works as expected:</p><pre><code>{'prompt': '&lt;|im_start|&gt;system\nYou are an AI assistant. You will be given a task. You must generate a detailed and long answer.&lt;|im_end|&gt;\n&lt;|im_start|&gt;user\nGenerate an approximately fifteen-word sentence that describes all this data: Midsummer House eatType restaurant; Midsummer House food Chinese; Midsummer House priceRange moderate; Midsummer House customer rating 3 out of 5; Midsummer House near All Bar One&lt;|im_end|&gt;\n&lt;|im_start|&gt;assistant\n',
'chosen': 'Midsummer House is a moderately priced Chinese restaurant with a 3/5 customer rating, located near All Bar One.&lt;|im_end|&gt;\n',
'rejected': ' Sure! Here\'s a sentence that describes all the data you provided:\n\n"Midsummer House is a moderately priced Chinese restaurant with a customer rating of 3 out of 5, located near All Bar One, offering a variety of delicious dishes."&lt;|im_end|&gt;\n'}</code></pre><p>We can see that the prompt combines system and user instructions. Thanks to the <code>add_generation_prompt=True</code> argument, it also appends the beginning of the assistant's answer. If you want to skip this step, you can directly used the preprocessed dataset as <a href="https://huggingface.co/datasets/mlabonne/chatml_dpo_pairs">mlabonne/chatml_dpo_pairs</a>.</p><h3>&#9881;&#65039; Training the model with&nbsp;DPO</h3><p>Next, we define the LoRA configurations to train the model. As described in <a href="https://medium.com/intel-analytics-software/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3">Intel&#8217;s blog post</a>, we set the rank value to be equal to the <code>lora_alpha</code>, which is unusual (2 * <code>r</code> as a rule of thumb). We also target all the linear modules with adapters.</p><pre><code># LoRA configuration
peft_config = LoraConfig(
    r=16,
    lora_alpha=16,
    lora_dropout=0.05,
    bias="none",
    task_type="CAUSAL_LM",
    target_modules=['k_proj', 'gate_proj', 'v_proj', 'up_proj', 'q_proj', 'o_proj', 'down_proj']
)</code></pre><p>We&#8217;re now ready to load the model we want to fine-tune with DPO. In this case, two models are required: the model to fine-tune as well as the reference model. This is mostly for the sake of readability, as the <code>DPOTrainer</code> object automatically creates a reference model if none is provided.</p><pre><code># Model to fine-tune
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    load_in_4bit=True
)
model.config.use_cache = False

# Reference model
ref_model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype=torch.float16,
    load_in_4bit=True
)</code></pre><p>The final step consists of providing all the hyperparameters to <code>TrainingArguments</code> and <code>DPOTrainer</code>:</p><ul><li><p>Among them, the <code>beta</code> parameter is unique to DPO since it controls the divergence from the initial policy (0.1 is a typical value for it).</p></li><li><p>Compared to the values described in <a href="https://medium.com/intel-analytics-software/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3">Intel&#8217;s blog post</a>, we lower the learning rate (from 5e-4 to 5e-5) and the number of steps (from 1,000 to 200). I manually optimized these values after a few runs to stabilize training and achieve the best results.</p></li></ul><p>We can now start training the model. Note that it requires an A100 GPU and takes between 1 hour to complete the training.</p><pre><code># Training arguments
training_args = TrainingArguments(
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    gradient_checkpointing=True,
    learning_rate=5e-5,
    lr_scheduler_type="cosine",
    max_steps=200,
    save_strategy="no",
    logging_steps=1,
    output_dir=new_model,
    optim="paged_adamw_32bit",
    warmup_steps=100,
    bf16=True,
    report_to="wandb",
)

# Create DPO trainer
dpo_trainer = DPOTrainer(
    model,
    ref_model,
    args=training_args,
    train_dataset=dataset,
    tokenizer=tokenizer,
    peft_config=peft_config,
    beta=0.1,
    max_prompt_length=1024,
    max_length=1536,
)

# Fine-tune model with DPO
dpo_trainer.train()</code></pre><p>Our model is now fine-tuned. You can check the project on Weights &amp; Biases <a href="https://wandb.ai/mlabonne/NeuralHermes-2-5-Mistral-7B/runs/axe71gr0?workspace=user-mlabonne">at this address</a>. Here are some interesting metrics to analyze:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Dih8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 424w, /__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 848w, /__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Dih8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 424w, /__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 848w, /__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Dih8!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe60f6d7d-7de8-49c1-8d63-3b58bd64ba12_800x398.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Interestingly, the training loss quickly drops to zero (before 50 steps), despite 100 warmup steps. Meanwhile, the other metrics keep evolving.</p><p>The train/rewards/chosen and train/rewards/rejected plots correspond to the mean difference between the log probabilities output by the trained and reference models. It makes sense that, over time, they diverge as our trained model learns the preferred answers. The train/rewards/margins plot also shows the difference between these two plots. Finally, the train/reward/accuracies plot shows the frequency of choosing the preferred answer. The trained model quickly reaches a perfect accuracy score, which is a good sign but could also mean that the difference between preferred and rejected answers is too obvious.</p><p>Now that it&#8217;s trained, we can merge the adapter with the original model. Next, we save the merged model and the tokenizer before pushing it to the Hugging Face Hub.</p><pre><code># Save artifacts
dpo_trainer.model.save_pretrained("final_checkpoint")
tokenizer.save_pretrained("final_checkpoint")

# Flush memory
del dpo_trainer, model, ref_model
gc.collect()
torch.cuda.empty_cache()

# Reload model in FP16 (instead of NF4)
base_model = AutoModelForCausalLM.from_pretrained(
    model_name,
    return_dict=True,
    torch_dtype=torch.float16,
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

# Merge base model with the adapter
model = PeftModel.from_pretrained(base_model, "final_checkpoint")
model = model.merge_and_unload()

# Save model and tokenizer
model.save_pretrained(new_model)
tokenizer.save_pretrained(new_model)

# Push them to the HF Hub
model.push_to_hub(new_model, use_temp_dir=False, token=hf_token)
tokenizer.push_to_hub(new_model, use_temp_dir=False, token=hf_token)</code></pre><p>Let&#8217;s see how our model performs in a real test. We&#8217;ll format the prompt to ask a basic question: &#8220;What is a Large Language Model?&#8221;</p><pre><code># Format prompt
message = [
    {"role": "system", "content": "You are a helpful assistant chatbot."},
    {"role": "user", "content": "What is a Large Language Model?"}
]
tokenizer = AutoTokenizer.from_pretrained(new_model)
prompt = tokenizer.apply_chat_template(message, add_generation_prompt=True, tokenize=False)

# Create pipeline
pipeline = transformers.pipeline(
    "text-generation",
    model=new_model,
    tokenizer=tokenizer
)

# Generate text
sequences = pipeline(
    prompt,
    do_sample=True,
    temperature=0.7,
    top_p=0.9,
    num_return_sequences=1,
    max_length=200,
)
print(sequences[0]['generated_text'])</code></pre><p>Here&#8217;s the answer from the model:</p><pre><code>A large language model is a type of artificial intelligence (AI) system that has been trained on vast amounts of text data. These models are designed to understand and generate human language, allowing them to perform various natural language processing tasks, such as text generation, language translation, and question answering. Large language models typically use deep learning techniques, like recurrent neural networks (RNNs) or transformers, to learn patterns and relationships in the data, enabling them to generate coherent and contextually relevant responses. The size of these models, in terms of the number of parameters and the volume of data they are trained on, plays a significant role in their ability to comprehend and produce complex language structures.</code></pre><p>Everything seems to be working, we can now evaluate the merged model. As this is a general-purpose model, we can leverage the <a href="https://github.com/EleutherAI/lm-evaluation-harness">lm-evaluation-harness</a> to evaluate it. As the process is quite resource-intensive, we can also directly submit it for evaluation on the <a href="https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard">Open LLM Leaderboard</a>. It took a few days, but here are the results compared to other OpenHermes models:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!hNAS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 424w, /__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 848w, /__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 1272w, /__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!hNAS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 424w, /__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 848w, /__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 1272w, /__u/substackcdn.com/image/fetch/$s_!hNAS!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F85f9aba3-9edb-4dd7-8d63-9d307fc1d914_800x322.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Compared to the original model, NeuralHermes-2&#8211;5-Mistral-7B model improved the average score by 6.7 points (particularly on GSM8K). This is an unexpectedly large improvement, which showcases the power of Direct Preference Optimization.</p><h3>Conclusion</h3><p>In this article, we fine-tuned an already supervised fine-tuned model using DPO and created our own <a href="https://huggingface.co/mlabonne/NeuralHermes-2.5-Mistral-7B">NeuralHermes-2.5</a> model. By leveraging a high-quality preference dataset, we created a sample-efficient fine-tuning pipeline that produced a significant improvement on the Open LLM Leaderboard. If you want to give it a try, you can find quantized variants of this model or use this <a href="https://huggingface.co/spaces/zhangtao103239/NeuralHermes-2.5-Mistral-7B-GGUF-Chat">Hugging Face Space</a>.</p><p>Note that our fine-tuning pipeline can still be improved in different ways. For example, the preference dataset is still quite raw and could be improved with more filtering and by using different models. In addition, numerous hyperparameters can still be tweaked to achieve better results. In particular, the learning rate can still be lowered to train the model on more steps and inject more preference data.</p><h3>References</h3><ul><li><p><a href="https://huggingface.co/blog/dpo-trl">Fine-tune Llama 2 with DPO</a> by Kashif Rasul, Younes Belkada, and Leandro von Werra.</p></li><li><p><a href="https://medium.com/intel-analytics-software/the-practice-of-supervised-finetuning-and-direct-preference-optimization-on-habana-gaudi2-a1197d8a3cd3">Supervised Fine-Tuning and Direct Preference Optimization on Intel Gaudi2</a> by Kaokao Lv, Wenxin Zhang, and Haihao Shen.</p></li><li><p><a href="https://github.com/mzbac/llama2-fine-tune">llama2-fine-tune</a> by mzbac.</p></li></ul><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link - Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p>]]></content:encoded></item><item><title><![CDATA[ExLlamaV2: The Fastest Library to Run LLMs]]></title><description><![CDATA[Quantize and run EXL2 models]]></description><link>https://maximelabonne.substack.com/p/exllamav2-the-fastest-library-to-run-llms-32aeda294d26</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/exllamav2-the-fastest-library-to-run-llms-32aeda294d26</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 20 Nov 2023 03:17:18 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/94c15e37-c05f-4ef5-bf51-498df19c2961_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>Quantize and run EXL2&nbsp;models</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!M8g7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!M8g7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!M8g7!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F184a70f8-6978-4c33-ab7b-17a3015c7a2e_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Quantizing Large Language Models (LLMs) is the most popular approach to reduce the size of these models and speed up inference. Among these techniques, GPTQ delivers amazing performance on GPUs. Compared to unquantized models, this method uses almost 3 times less VRAM while providing a similar level of accuracy and faster generation. It became so popular that it has recently been directly integrated into the <a href="https://huggingface.co/blog/gptq-integration">transformers library</a>.</p><p><strong><a href="https://github.com/turboderp/exllamav2">ExLlamaV2</a></strong> is a library designed to squeeze even more performance out of GPTQ. Thanks to new kernels, it&#8217;s optimized for (blazingly) fast inference. It also introduces a new quantization format, EXL2, which brings a lot of flexibility to how weights are stored.</p><p>In this article, we will see how to quantize base models in the EXL2 format and how to run them. As usual, the code is available on <a href="https://github.com/mlabonne/llm-course/blob/main/Quantize_models_with_ExLlamaV2.ipynb">GitHub</a> and <a href="https://colab.research.google.com/drive/1yrq4XBlxiA0fALtMoT2dwiACVc77PHou?usp=sharing">Google Colab</a>.</p><h3>&#9889; Quantize EXL2&nbsp;models</h3><p>To start our exploration, we need to install the ExLlamaV2 library. In this case, we want to be able to use some scripts contained in the repo, which is why we will install it from source as follows:</p><pre><code>git clone https://github.com/turboderp/exllamav2
pip install exllamav2</code></pre><p>Now that ExLlamaV2 is installed, we need to download the model we want to quantize in this format. Let&#8217;s use the excellent <a href="https://huggingface.co/HuggingFaceH4/zephyr-7b-beta">zephyr-7B-beta</a>, a <a href="https://huggingface.co/mistralai/Mistral-7B-v0.1">Mistral-7B</a> model fine-tuned using Direct Preference Optimization (DPO). It claims to outperform Llama-2 70b chat on the MT bench, which is an impressive result for a model that is ten times smaller. You can try out the base Zephyr model using <a href="https://huggingface.co/spaces/HuggingFaceH4/zephyr-chat">this space</a>.</p><p>We download zephyr-7B-beta using the following command (this can take a while since the model is about 15 GB):</p><pre><code>git lfs install
git clone https://huggingface.co/HuggingFaceH4/zephyr-7b-beta</code></pre><p>GPTQ also requires a <strong>calibration dataset</strong>, which is used to measure the impact of the quantization process by comparing the outputs of the base model and its quantized version. We will use the <a href="https://huggingface.co/datasets/wikitext">wikitext dataset</a> and directly download the test file as follows:</p><pre><code>wget https://huggingface.co/datasets/wikitext/resolve/9a9e482b5987f9d25b3a9b2883fc6cc9fd8071b3/wikitext-103-v1/wikitext-test.parquet</code></pre><p>Once it&#8217;s done, we can leverage the <a href="https://github.com/turboderp/exllamav2/blob/master/convert.py"><code>convert.py</code></a> script provided by the ExLlamaV2 library. We're mostly concerned with four arguments:</p><ul><li><p><code>-i</code>: Path of the base model to convert in HF format (FP16).</p></li><li><p><code>-o</code>: Path of the working directory with temporary files and final output.</p></li><li><p><code>-c</code>: Path of the calibration dataset (in Parquet format).</p></li><li><p><code>-b</code>: Target average number of bits per weight (bpw). For example, 4.0 bpw will give store weights in 4-bit precision.</p></li></ul><p>The complete list of arguments is available <a href="https://github.com/turboderp/exllamav2/blob/master/doc/convert.md">on this page</a>. Let&#8217;s start the quantization process using the <code>convert.py</code> script with the following arguments:</p><pre><code>mkdir quant
python python exllamav2/convert.py \
    -i base_model \
    -o quant \
    -c wikitext-test.parquet \
    -b 5.0</code></pre><p>Note that you will need a GPU to quantize this model. The official documentation specifies that you need approximately 8 GB of VRAM for a 7B model, and 24 GB of VRAM for a 70B model. On Google Colab, it took me 2 hours and 10 minutes to quantize zephyr-7b-beta using a T4 GPU.</p><p>Under the hood, ExLlamaV2 leverages the GPTQ algorithm to lower the precision of the weights while minimizing the impact on the output. You can find more details about the GPTQ algorithm <a href="https://medium.com/towards-data-science/4-bit-quantization-with-gptq-36b0f4f02c34">in this article</a>.</p><p>So why are we using the &#8220;EXL2&#8221; format instead of the regular GPTQ format? EXL2 comes with a few new features:</p><ul><li><p>It supports <strong>different levels of quantization</strong>: it&#8217;s not restricted to 4-bit precision and can handle 2, 3, 4, 5, 6, and 8-bit quantization.</p></li><li><p>It can <strong>mix different precisions</strong> within a model and within each layer to preserve the most important weights and layers with more bits.</p></li></ul><p>ExLlamaV2 uses this additional flexibility during quantization. It tries different quantization parameters and measures the error they introduce. On top of trying to minimize the error, ExLlamaV2 also has to achieve the target average number of bits per weight given as an argument. Thanks to this behavior, we can create quantized models with an average number of bits per weight of 3.5 or 4.5 for example.</p><p>The benchmark of different parameters it creates is saved in the <code>measurement.json</code> file. The following JSON shows the measurement for one layer:</p><pre><code>"key": "model.layers.0.self_attn.q_proj",
"numel": 16777216,
"options": [
    {
        "desc": "0.05:3b/0.95:2b 32g s4",
        "bpw": 2.1878662109375,
        "total_bits": 36706304.0,
        "err": 0.011161142960190773,
        "qparams": {
            "group_size": 32,
            "bits": [
                3,
                2
            ],
            "bits_prop": [
                0.05,
                0.95
            ],
            "scale_bits": 4
        }
    },</code></pre><p>In this trial, ExLlamaV2 used 5% of 3-bit and 95% of 2-bit precision for an average value of 2.188 bpw and a group size of 32. This introduced a noticeable error that is taken into account to select the best parameters.</p><h3>&#129433; Running ExLlamaV2 for Inference</h3><p>Now that our model is quantized, we want to run it to see how it performs. Before that, we need to copy essential config files from the <code>base_model</code> directory to the new <code>quant</code> directory. Basically, we want every file that is not hidden (<code>.*</code>) or a safetensors file. Additionally, we don't need the <code>out_tensor</code> directory that was created by ExLlamaV2 during quantization.</p><p>In bash, you can implement this as follows:</p><pre><code>!rm -rf quant/out_tensor
!rsync -av --exclude='*.safetensors' --exclude='.*' ./base_model/ ./quant/</code></pre><p>Our EXL2 model is ready and we have several options to run it. The most straightforward method consists of using the <code>test_inference.py</code> script in the ExLlamaV2 repo (note that I don&#8217;t use a chat template here):</p><pre><code>python exllamav2/test_inference.py -m quant/ -p "I have a dream"</code></pre><p>The generation is very fast (56.44 tokens/second on a T4 GPU), even compared to other quantization techniques and tools like GGUF/llama.cpp or GPTQ. You can find an in-depth comparison between different solutions in this <a href="https://oobabooga.github.io/blog/posts/gptq-awq-exl2-llamacpp/">excellent article</a> from oobabooga.</p><p>In my case, the LLM returned the following output:</p><pre><code> -- Model: quant/
 -- Options: ['rope_scale 1.0', 'rope_alpha 1.0']
 -- Loading model...
 -- Loading tokenizer...
 -- Warmup...
 -- Generating...

I have a dream. &lt;|user|&gt;
Wow, that's an amazing speech! Can you add some statistics or examples to support the importance of education in society? It would make it even more persuasive and impactful. Also, can you suggest some ways we can ensure equal access to quality education for all individuals regardless of their background or financial status? Let's make this speech truly unforgettable! 

Absolutely! Here's your updated speech:

Dear fellow citizens,

 Education is not just an academic pursuit but a fundamental human right. It empowers people, opens doors

 -- Response generated in 3.40 seconds, 128 tokens, 37.66 tokens/second (includes prompt eval.)</code></pre><p>Alternatively, you can use a chat version with the <code>chatcode.py</code> script for more flexibility:</p><pre><code>python exllamav2/examples/chatcode.py -m quant -mode llama</code></pre><p>If you&#8217;re planning to use an EXL2 model more regularly, ExLlamaV2 has been integrated into several backends like oobabooga&#8217;s <a href="https://github.com/oobabooga/text-generation-webui">text generation web UI</a>. Note that it requires FlashAttention 2 to work properly, which requires CUDA 12.1 on Windows at the moment (something you can configure during the installation process).</p><p>Now that we tested the model, we&#8217;re ready to upload it to the Hugging Face Hub. You can change the name of your repo in the following code snippet and simply run it.</p><pre><code>from huggingface_hub import notebook_login
from huggingface_hub import HfApi

notebook_login()
api = HfApi()
api.create_repo(
    repo_id=f"mlabonne/zephyr-7b-beta-5.0bpw-exl2",
    repo_type="model"
)
api.upload_folder(
    repo_id=f"mlabonne/zephyr-7b-beta-5.0bpw-exl2",
    folder_path="quant",
)</code></pre><p>Great, the model can be found on the <a href="https://huggingface.co/mlabonne/zephyr-7b-beta-5.0bpw-exl2">Hugging Face Hub</a>. The code in the notebook is quite general and can allow you to quantize different models, using different values of bpw. This is ideal for creating models dedicated to your hardware.</p><h3>Conclusion</h3><p>In this article, we presented ExLlamaV2, a powerful library to quantize LLMs. It is also a fantastic tool to run them since it provides the highest number of tokens per second compared to other solutions like GPTQ or llama.cpp. We applied it to the <a href="https://huggingface.co/HuggingFaceH4/zephyr-7b-beta">zephyr-7B-beta</a> model to create a 5.0 bpw version of it, using the new EXL2 format. After quantization, we tested our model to see how it performs. Finally, it was uploaded to the Hugging Face Hub and can be found <a href="https://huggingface.co/mlabonne/zephyr-7b-beta-5.0bpw-exl2">here</a>.</p><p>If you&#8217;re interested in more technical content around LLMs, <a href="https://medium.com/@mlabonne">follow me on Medium</a>.</p><h3>Articles about quantization</h3><p><strong><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">Introduction to Weight Quantization</a></strong><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c"><br></a><em><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">Reducing the size of Large Language Models with 8-bit quantization</a></em><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">towardsdatascience.com</a></p><p><strong><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">4-bit Quantization with GPTQ</a></strong><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34"><br></a><em><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">Quantize your own LLMs using AutoGPTQ</a></em><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">towardsdatascience.com</a></p><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link - Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p>]]></content:encoded></item><item><title><![CDATA[Quantize Llama models with GGML and llama.cpp]]></title><description><![CDATA[GGML vs. GPTQ vs. NF4]]></description><link>https://maximelabonne.substack.com/p/quantize-llama-models-with-ggml-and-llama-cpp-3612dfbcc172</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/quantize-llama-models-with-ggml-and-llama-cpp-3612dfbcc172</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 04 Sep 2023 15:02:03 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/41345b64-d319-4ca6-83c0-1b6cb0d58654_800x450.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>GGML vs. GPTQ vs.&nbsp;NF4</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!ZB9x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!ZB9x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 424w, /__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 848w, /__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 1272w, /__u/substackcdn.com/image/fetch/$s_!ZB9x!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F37a6075e-e99a-471b-9f78-7951258b05f1_800x450.png 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Due to the massive size of Large Language Models (LLMs), quantization has become an essential technique to run them efficiently. By reducing the precision of their weights, you can save memory and speed up inference while preserving most of the model&#8217;s performance. Recently, 8-bit and 4-bit quantization unlocked the possibility of <strong>running LLMs on consumer hardware</strong>. Coupled with the release of Llama models and parameter-efficient techniques to fine-tune them (LoRA, QLoRA), this created a rich ecosystem of local LLMs that are now competing with OpenAI&#8217;s GPT-3.5 and GPT-4.</p><p>Besides the naive approach covered <a href="https://medium.com/towards-data-science/introduction-to-weight-quantization-2494701b9c0c">in this article</a>, there are three main quantization techniques: NF4, GPTQ, and GGML. <a href="https://huggingface.co/blog/4bit-transformers-bitsandbytes">NF4</a> is a static method used by QLoRA to load a model in 4-bit precision to perform fine-tuning. <a href="https://medium.com/towards-data-science/4-bit-quantization-with-gptq-36b0f4f02c34">In a previous article</a>, we explored the GPTQ method and quantized our own model to run it on a consumer GPU. In this article, we will introduce the GGML technique, see how to quantize Llama models, and provide tips and tricks to achieve the best results.</p><p>You can find the code on <a href="https://colab.research.google.com/drive/1pL8k7m04mgE5jo2NrjGi8atB0j_37aDD?usp=sharing">Google Colab</a> and <a href="https://github.com/mlabonne/llm-course">GitHub</a>.</p><h3>What is&nbsp;GGML?</h3><p>GGML is a C library focused on machine learning. It was created by Georgi Gerganov, which is what the initials &#8220;GG&#8221; stand for. This library not only provides foundational elements for machine learning, such as tensors, but also a <strong>unique binary format</strong> to distribute LLMs.</p><p>This format recently changed to <strong>GGUF</strong>. This new format is designed to be extensible, so that new features shouldn&#8217;t break compatibility with existing models. It also centralizes all the metadata in one file, such as special tokens, RoPE scaling parameters, etc. In short, it answers a few historical pain points and should be future-proof. For more information, you can read the specification <a href="https://github.com/philpax/ggml/blob/gguf-spec/docs/gguf.md">at this address</a>. In the rest of the article, we will call &#8220;GGML models&#8221; all models that either use GGUF or previous formats.</p><p>GGML was designed to be used in conjunction with the <a href="https://github.com/ggerganov/llama.cpp">llama.cpp</a> library, also created by Georgi Gerganov. The library is written in C/C++ for efficient inference of Llama models. It can load GGML models and <strong>run them on a CPU</strong>. Originally, this was the main difference with GPTQ models, which are loaded and run on a GPU. However, you can now offload some layers of your LLM to the GPU with llama.cpp. To give you an example, there are 35 layers for a 7b parameter model. This drastically speeds up inference and allows you to run LLMs that don&#8217;t fit in your VRAM.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!aSki!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 424w, /__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 848w, /__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 1272w, /__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!aSki!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 424w, /__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 848w, /__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 1272w, /__u/substackcdn.com/image/fetch/$s_!aSki!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb89063da-6ad9-48b1-9d5e-efadd9a12ea1_1167x591.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>If command-line tools are your thing, llama.cpp and GGUF support have been integrated into many GUIs, like oobabooga&#8217;s <a href="https://github.com/oobabooga/text-generation-webui">text-generation-web-ui</a>, <a href="https://github.com/LostRuins/koboldcpp">koboldcpp</a>, <a href="https://lmstudio.ai/">LM Studio</a>, or <a href="https://github.com/marella/ctransformers">ctransformers</a>. You can simply load your GGML models with these tools and interact with them in a ChatGPT-like way. Fortunately, many quantized models are directly available on the <a href="https://huggingface.co/models?search=gg">Hugging Face Hub</a>. You&#8217;ll quickly notice that most of them are quantized by <a href="https://huggingface.co/TheBloke">TheBloke</a>, a popular figure in the LLM community.</p><p>In the next section, we will see how to quantize our own models and run them on a consumer GPU.</p><h3>How to quantize LLMs with&nbsp;GGML?</h3><p>Let&#8217;s look at the files inside of <a href="https://huggingface.co/TheBloke/Llama-2-13B-chat-GGML/tree/main">TheBloke/Llama-2&#8211;13B-chat-GGML</a> repo. We can see <strong>14 different GGML models</strong>, corresponding to different types of quantization. They follow a particular naming convention: &#8220;q&#8221; + the number of bits used to store the weights (precision) + a particular variant. Here is a list of all the possible quant methods and their corresponding use cases, based on model cards made by TheBloke:</p><ul><li><p><code>q2_k</code>: Uses Q4_K for the attention.vw and feed_forward.w2 tensors, Q2_K for the other tensors.</p></li><li><p><code>q3_k_l</code>: Uses Q5_K for the attention.wv, attention.wo, and feed_forward.w2 tensors, else Q3_K</p></li><li><p><code>q3_k_m</code>: Uses Q4_K for the attention.wv, attention.wo, and feed_forward.w2 tensors, else Q3_K</p></li><li><p><code>q3_k_s</code>: Uses Q3_K for all tensors</p></li><li><p><code>q4_0</code>: Original quant method, 4-bit.</p></li><li><p><code>q4_1</code>: Higher accuracy than q4_0 but not as high as q5_0. However has quicker inference than q5 models.</p></li><li><p><code>q4_k_m</code>: Uses Q6_K for half of the attention.wv and feed_forward.w2 tensors, else Q4_K</p></li><li><p><code>q4_k_s</code>: Uses Q4_K for all tensors</p></li><li><p><code>q5_0</code>: Higher accuracy, higher resource usage and slower inference.</p></li><li><p><code>q5_1</code>: Even higher accuracy, resource usage and slower inference.</p></li><li><p><code>q5_k_m</code>: Uses Q6_K for half of the attention.wv and feed_forward.w2 tensors, else Q5_K</p></li><li><p><code>q5_k_s</code>: Uses Q5_K for all tensors</p></li><li><p><code>q6_k</code>: Uses Q8_K for all tensors</p></li><li><p><code>q8_0</code>: Almost indistinguishable from float16. High resource use and slow. Not recommended for most users.</p></li></ul><p>As a rule of thumb, <strong>I recommend using Q5_K_M</strong> as it preserves most of the model&#8217;s performance. Alternatively, you can use Q4_K_M if you want to save some memory. In general, K_M versions are better than K_S versions. I cannot recommend Q2 or Q3 versions, as they drastically decrease model performance.</p><p>Now that we know more about the quantization types available, let&#8217;s see how to use them on a real model. You can execute the following code on a <strong>free T4 GPU</strong> on <a href="https://colab.research.google.com/drive/1pL8k7m04mgE5jo2NrjGi8atB0j_37aDD?usp=sharing">Google Colab</a>. The first step consists of compiling llama.cpp and installing the required libraries in our Python environment.</p><pre><code># Install llama.cpp
!git clone https://github.com/ggerganov/llama.cpp
!cd llama.cpp &amp;&amp; git pull &amp;&amp; make clean &amp;&amp; LLAMA_CUBLAS=1 make
!pip install -r llama.cpp/requirements.txt</code></pre><p>Now we can download our model. We will use the model we fine-tuned <a href="https://medium.com/towards-data-science/a-beginners-guide-to-llm-fine-tuning-4bae7d4da672">in the previous article</a>, <a href="https://huggingface.co/mlabonne/EvolCodeLlama-7b"><code>mlabonne/EvolCodeLlama-7b</code></a>.</p><pre><code>MODEL_ID = "mlabonne/EvolCodeLlama-7b"

# Download model
!git lfs install
!git clone https://huggingface.co/{MODEL_ID}</code></pre><p>This step can take a while. Once it&#8217;s done, we need to convert our weight to GGML FP16 format.</p><pre><code>MODEL_NAME = MODEL_ID.split('/')[-1]
GGML_VERSION = "gguf"

# Convert to fp16
fp16 = f"{MODEL_NAME}/{MODEL_NAME.lower()}.{GGML_VERSION}.fp16.bin"
!python llama.cpp/convert.py {MODEL_NAME} --outtype f16 --outfile {fp16}</code></pre><p>Finally, we can quantize the model using one or several methods. In this case, we will use the Q4_K_M and Q5_K_M methods I recommended earlier. This is the only step that actually requires a GPU.</p><pre><code>QUANTIZATION_METHODS = ["q4_k_m", "q5_k_m"]

for method in QUANTIZATION_METHODS:
    qtype = f"{MODEL_NAME}/{MODEL_NAME.lower()}.{GGML_VERSION}.{method}.bin"
    !./llama.cpp/quantize {fp16} {qtype} {method}</code></pre><p>Our two quantized models are now <strong>ready for inference</strong>. We can check the size of the bin files to see how much we compressed them. The FP16 model takes up 13.5 GB, while the Q4_K_M model takes up 4.08 GB (3.3 times smaller) and the Q5_K_M model takes up 4.78 GB (2.8 times smaller).</p><p>Let&#8217;s use llama.cpp to efficiently run them. Since we&#8217;re using a GPU with 16 GB of VRAM, we can offload every layer to the GPU. In this case, it represents 35 layers (7b parameter model), so we&#8217;ll use the <code>-ngl 35</code> parameter. In the following code block, we'll also input a prompt and the quantization method we want to use.</p><pre><code>import os

model_list = [file for file in os.listdir(MODEL_NAME) if GGML_VERSION in file]
prompt = input("Enter your prompt: ")
chosen_method = input("Please specify the quantization method to run the model (options: " + ", ".join(model_list) + "): ")

# Verify the chosen method is in the list
if chosen_method not in model_list:
    print("Invalid method chosen!")
else:
    qtype = f"{MODEL_NAME}/{MODEL_NAME.lower()}.{GGML_VERSION}.{method}.bin"
    !./llama.cpp/main -m {qtype} -n 128 --color -ngl 35 -p "{prompt}"</code></pre><p>Let&#8217;s ask the model &#8220;Write a Python function to print the nth Fibonacci numbers&#8221; using the Q5_K_M method. If we look at the logs, we can confirm that we successfully offloaded our layers thanks to the line &#8220;llm_load_tensors: offloaded 35/35 layers to GPU&#8221;. Here is the code the model generated:</p><pre><code>def fib(n):
    if n == 0 or n == 1:
        return n
    return fib(n - 2) + fib(n - 1)

for i in range(1, 10):
    print(fib(i))</code></pre><p>This wasn&#8217;t a very complex prompt, but it successfully produced a working piece of code in no time. With this GGML, you can use your local LLM as an assistant in a terminal using the interactive mode (<code>-i</code> flag). Note that this also works on Macbooks with Apple's Metal Performance Shaders (MPS), which is an excellent option to run LLMs.</p><p>Finally, we can push our quantized model to a new repo on the Hugging Face Hub with the &#8220;-GGUF&#8221; suffix. First, let&#8217;s log in and modify the following code block to match your username.</p><pre><code>!pip install -q huggingface_hub

username = "mlabonne"

from huggingface_hub import notebook_login, create_repo, HfApi
notebook_login()</code></pre><p>Now we can create the repo and upload our models. We use the <code>allow_patterns</code> parameter to filter which files to upload, so we don't push the entirety of the directory.</p><pre><code>api = HfApi()

# Create repo
create_repo(
    repo_id=f"{username}/{MODEL_NAME}-GGML",
    repo_type="model",
    exist_ok=True
)

# Upload bin models
api.upload_folder(
    folder_path=MODEL_NAME,
    repo_id=f"{username}/{MODEL_NAME}-GGML",
    allow_patterns=f"*{GGML_VERSION}*",
)</code></pre><p>We have successfully quantized, run, and pushed GGML models to the Hugging Face Hub! In the next section, we will explore how GGML actually quantize these models.</p><h3>Quantization with&nbsp;GGML</h3><p>The way GGML quantizes weights is not as sophisticated as GPTQ&#8217;s. Basically, it groups blocks of values and rounds them to a lower precision. Some techniques, like Q4_K_M and Q5_K_M, implement a <strong>higher precision for critical layers</strong>. In this case, every weight is stored in 4-bit precision, with the exception of half of the attention.wv and feed_forward.w2 tensors. Experimentally, this mixed precision proves to be a good tradeoff between accuracy and resource usage.</p><p>If we look into the <a href="https://github.com/ggerganov/ggml/blob/master/src/ggml.c">ggml.c file</a>, we can see how the blocks are defined. For example, the <code>block_q4_0</code> structure is defined as:</p><pre><code>#define QK4_0 32
typedef struct {
    ggml_fp16_t d;          // delta
    uint8_t qs[QK4_0 / 2];  // nibbles / quants
} block_q4_0;</code></pre><p>In GGML, weights are processed in blocks, each consisting of 32 values. For each block, a scale factor (delta) is derived from the largest weight value. All weights in the block are then scaled, quantized, and packed efficiently for storage (nibbles). This approach significantly reduces the storage requirements while allowing for a relatively simple and deterministic conversion between the original and quantized weights.</p><p>Now that we know more about the quantization process, we can compare the results with NF4 and GPTQ.</p><h3>NF4 vs. GGML vs.&nbsp;GPTQ</h3><p>Which technique is better for 4-bit quantization? To answer this question, we need to introduce the different backends that run these quantized LLMs. For GGML models, llama.cpp with Q4_K_M models is the way to go. For GPTQ models, we have two options: <a href="https://github.com/PanQiWei/AutoGPTQ">AutoGPTQ</a> or <a href="https://github.com/turboderp/exllama">ExLlama</a>. Finally, NF4 models can directly be run in transformers with the <code>--load-in-4bit</code> flag.</p><p>Oobabooga ran multiple experiments in an excellent <a href="https://oobabooga.github.io/blog/posts/perplexities/">blog post</a> that compare different models in terms of perplexity (lower is better):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!aT4x!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 424w, /__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 848w, /__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 1272w, /__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!aT4x!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 424w, /__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 848w, /__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 1272w, /__u/substackcdn.com/image/fetch/$s_!aT4x!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F89e3f43f-7d73-48ae-b6ed-85fed48d8f9b_800x509.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Based on these results, we can say that GGML models have a slight advantage in terms of perplexity. The difference is not particularly significant, which is why it is better to focus on the generation speed in terms of tokens/second. The best technique depends on your GPU: if you have enough VRAM to fit the entire quantized model, <strong>GPTQ with ExLlama</strong> will be the fastest. If that&#8217;s not the case, you can offload some layers and use <strong>GGML models with llama.cpp</strong> to run your LLM.</p><h3>Conclusion</h3><p>In this article, we introduced the GGML library and the new GGUF format to efficiently store these quantized models. We used it to <strong>quantize our own Llama model</strong> in different formats (Q4_K_M and Q5_K_M). We then ran the GGML model and pushed our bin files to the Hugging Face Hub. Finally, we delved deeper into GGML&#8217;s code to understand how it actually quantizes the weights and compared it to NF4 and GPTQ.</p><p>Quantization is a formidable vector to democratize LLMs by lowering the cost of running them. In the future, mixed precision and other techniques will keep improving the performance we can achieve with quantized weights. Until then, I hope you enjoyed reading this article and learned something new.</p><p>If you&#8217;re interested in more technical content around LLMs, <a href="https://medium.com/@mlabonne">follow me on Medium</a>.</p><h3>Articles about quantization</h3><p><strong><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">Part 1: Introduction to Weight Quantization</a></strong><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c"><br></a><em><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">Reducing the size of Large Language Models with 8-bit quantization</a></em><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">towardsdatascience.com</a></p><p><strong><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">Part 2: 4-bit Quantization with GPTQ</a></strong><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34"><br></a><em><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">Quantize your own LLMs using AutoGPTQ</a></em><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">towardsdatascience.com</a></p><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link&#8202;&#8212;&#8202;Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p>]]></content:encoded></item><item><title><![CDATA[A Beginner’s Guide to LLM Fine-Tuning]]></title><description><![CDATA[How to fine-tune Llama and other LLMs with one tool]]></description><link>https://maximelabonne.substack.com/p/a-beginners-guide-to-llm-fine-tuning-4bae7d4da672</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/a-beginners-guide-to-llm-fine-tuning-4bae7d4da672</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Wed, 30 Aug 2023 07:01:17 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/360d1251-2f8f-4d01-9013-95fb8781b894_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>How to fine-tune Llama and other LLMs with one&nbsp;tool</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!d-Xv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!d-Xv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!d-Xv!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F46f36347-7845-4d58-86bd-3531728db6ca_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The growing interest in Large Language Models (LLMs) has led to a surge in <strong>tools and wrappers designed to streamline their training process</strong>.</p><p>Popular options include <a href="https://github.com/lm-sys/FastChat">FastChat </a>from LMSYS (used to train <a href="https://huggingface.co/lmsys/vicuna-13b-v1.5">Vicuna</a>) and Hugging Face&#8217;s <a href="https://github.com/huggingface/transformers">transformers</a>/<a href="https://github.com/huggingface/trl">trl</a> libraries (used in <a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">my previous article</a>). In addition, each big LLM project, like <a href="https://github.com/nlpxucan/WizardLM/tree/main">WizardLM</a>, tends to have its own training script, inspired by the original <a href="https://github.com/tatsu-lab/stanford_alpaca">Alpaca</a> implementation.</p><p>In this article, we will use <strong><a href="https://github.com/OpenAccess-AI-Collective/axolotl">Axolotl</a></strong>, a tool created by the OpenAccess AI Collective. We will use it to fine-tune a <strong><a href="https://github.com/OpenAccess-AI-Collective/axolotl/blob/main/examples/llama-2/qlora.yml">Code Llama 7b</a></strong> model on an evol-instruct dataset comprised of 1,000 samples of Python code.</p><h3>&#129300; Why&nbsp;Axolotl?</h3><p>The main appeal of Axolotl is that it provides a one-stop solution, which includes numerous features, model architectures, and an active community. Here&#8217;s a quick list of my favorite things about it:</p><ul><li><p><strong>Configuration</strong>: All parameters used to train an LLM are neatly stored in a yaml config file. This makes it convenient for sharing and reproducing models. You can see an example for Llama 2 <a href="https://github.com/OpenAccess-AI-Collective/axolotl/tree/main/examples/llama-2">here</a>.</p></li><li><p><strong>Dataset Flexibility</strong>: Axolotl allows the specification of multiple datasets with varied prompt formats such as alpaca (<code>{"instruction": "...", "input": "...", "output": "..."}</code>), sharegpt:chat (<code>{"conversations": [{"from": "...", "value": "..."}]}</code>), and raw completion (<code>{"text": "..."}</code>). Combining datasets is seamless, and the hassle of unifying the prompt format is eliminated.</p></li><li><p><strong>Features</strong>: Axolotl is packed with SOTA techniques such as FSDP, deepspeed, LoRA, QLoRA, ReLoRA, sample packing, GPTQ, FlashAttention, xformers, and rope scaling.</p></li><li><p><strong>Utilities</strong>: There are numerous user-friendly utilities integrated, including the addition or alteration of special tokens, or a custom wandb configuration.</p></li></ul><p>Some well-known models trained using this tool are <a href="https://huggingface.co/openaccess-ai-collective/manticore-13b">Manticore-13b</a> from the OpenAccess AI Collective and <a href="https://huggingface.co/ehartford/Samantha-1.11-70b">Samantha-1.11&#8211;70b</a> from Eric Hartford. Like other wrappers, it is built on top of the transformers library and uses many of its features.</p><h3>&#9881;&#65039; Create your own config&nbsp;file</h3><p>Before anything, we need a configuration file. You can reuse an existing configuration from the <a href="https://github.com/OpenAccess-AI-Collective/axolotl/tree/main/examples"><code>examples</code></a> folder. In our case, we will tweak the <a href="https://github.com/OpenAccess-AI-Collective/axolotl/blob/main/examples/llama-2/qlora.yml">QLoRA config</a> for Llama 2 to create our own <strong>Code Llama</strong> model. The model will be trained on a subset of 1,000 Python samples from the <a href="https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1"><code>nickrosh/Evol-Instruct-Code-80k-v1</code></a> dataset.</p><p>First, we must change the <code>base_model</code> and <code>base_model_config</code> fields to "codellama/CodeLlama-7b-hf". To push our trained adapter to the Hugging Face Hub, let's add a new field <code>hub_model_id</code>, which corresponds to the name of our model, "EvolCodeLlama-7b". Now, we have to update the dataset to <a href="https://huggingface.co/datasets/mlabonne/Evol-Instruct-Python-1k"><code>mlabonne/Evol-Instruct-Python-1k</code></a> and set <code>type</code> to "alpaca".</p><p>There's no sample bigger than 2048 tokens in this dataset, so we can reduce the <code>sequence_len</code> to "2048" and save some VRAM. Talking about VRAM, we&#8217;re going to use a <code>micro_batch_size</code> of 10 and a <code>gradient_accumulation_steps</code> of 1 to maximize its use. In practice, you try different values until you use &gt;95% of the available VRAM.</p><p>For convenience, I'm going to add the name "axolotl" to the <code>wandb_project</code> field so it's easier to track on my account. I'm also setting the <code>warmup_steps</code> to "100" (personal preference) and the <code>eval_steps</code> to 0.01 so we'll end up with 100 evaluations.</p><p>Here&#8217;s how the final config file should look:</p><pre><code>base_model: codellama/CodeLlama-7b-hf
base_model_config: codellama/CodeLlama-7b-hf
model_type: LlamaForCausalLM
tokenizer_type: LlamaTokenizer
is_llama_derived_model: true
hub_model_id: EvolCodeLlama-7b

load_in_8bit: false
load_in_4bit: true
strict: false

datasets:
  - path: mlabonne/Evol-Instruct-Python-1k
    type: alpaca
dataset_prepared_path: last_run_prepared
val_set_size: 0.02
output_dir: ./qlora-out

adapter: qlora
lora_model_dir:

sequence_len: 2048
sample_packing: true

lora_r: 32
lora_alpha: 16
lora_dropout: 0.05
lora_target_modules:
lora_target_linear: true
lora_fan_in_fan_out:

wandb_project: axolotl
wandb_entity:
wandb_watch:
wandb_run_id:
wandb_log_model:

gradient_accumulation_steps: 1
micro_batch_size: 10
num_epochs: 3
optimizer: paged_adamw_32bit
lr_scheduler: cosine
learning_rate: 0.0002

train_on_inputs: false
group_by_length: false
bf16: true
fp16: false
tf32: false

gradient_checkpointing: true
early_stopping_patience:
resume_from_checkpoint:
local_rank:
logging_steps: 1
xformers_attention:
flash_attention: true

warmup_steps: 100
eval_steps: 0.01
save_strategy: epoch
save_steps:
debug:
deepspeed:
weight_decay: 0.0
fsdp:
fsdp_config:
special_tokens:
  bos_token: "&lt;s&gt;"
  eos_token: "&lt;/s&gt;"
  unk_token: "&lt;unk&gt;"</code></pre><p>You can also find this config file <a href="https://gist.github.com/mlabonne/8055f6335e2b85f082c8c75561321a66">here</a> as a GitHub gist.</p><p>Before we start training our model, I want to introduce a few parameters that are important to understand:</p><ul><li><p><strong>QLoRA</strong>: We&#8217;re using QLoRA for fine-tuning, which is why we&#8217;re loading the base model in 4-bit precision (NF4 format). You can check <a href="https://medium.com/towards-data-science/qlora-fine-tune-a-large-language-model-on-your-gpu-27bed5a03e2b">this article</a> from <a href="https://medium.com/u/ad2a414578b3">Benjamin Marie</a> to know more about QLoRA.</p></li><li><p><strong>Gradient checkpointing</strong>: It lowers the VRAM requirements by removing some activations that are re-computed on demand during the backward pass. It also slows down training by about 20%, according to Hugging Face&#8217;s <a href="https://huggingface.co/docs/transformers/v4.18.0/en/performance">documentation</a>.</p></li><li><p><strong>FlashAttention</strong>: This implements the <a href="https://github.com/Dao-AILab/flash-attention">FlashAttention </a>mechanism, which improves the speed and memory efficiency of our model thanks to a clever fusion of GPU operations (learn more about it in <a href="https://gordicaleksa.medium.com/eli5-flash-attention-5c44017022ad">this article</a> from <a href="https://medium.com/u/37f02ae83e8c">Aleksa Gordi&#263;</a>).</p></li><li><p><strong>Sample packing</strong>: Smart way of creating batches with as little padding as possible, by reorganizing the order of the samples (<a href="https://en.wikipedia.org/wiki/Bin_packing_problem">bin packing problem</a>). As a result, we need fewer batches to train the model on the same dataset. It was inspired by the <a href="https://github.com/imoneoi/multipack_sampler/tree/master">Multipack Sampler</a> (see <a href="https://mlabonne.github.io/blog/notes/Large%20Language%20Models/multipack_sampler.html">my note</a>) and <a href="https://arxiv.org/pdf/2107.02027.pdf">Krell et al.</a></p></li></ul><p>You can find FlashAttention in some other tools, but sample packing is relatively new. As far as I know, <a href="https://github.com/imoneoi/openchat">OpenChat </a>was the first project to use sample packing during fine-tuning. Thanks to Axolotl, we&#8217;ll use these techniques for free.</p><h3>&#129433; Fine-tune Code&nbsp;Llama</h3><p>Having the config file ready, it&#8217;s time to get our hands dirty with the actual fine-tuning. You might consider running the training on a Colab notebook. However, for those without access to a high-performance GPU, a more cost-effective solution consists of renting <strong>cloud-based GPU services</strong>, like AWS, <a href="https://lambdalabs.com/">Lambda Labs</a>, <a href="https://vast.ai/">Vast.ai</a>, <a href="https://www.banana.dev/">Banana</a>, or <a href="https://www.runpod.io/">RunPod</a>.</p><p>Personally, I use RunPod, which is a popular option in the fine-tuning community. It&#8217;s not the cheapest service but it hits a good tradeoff with a clean UI. You can easily replicate the following steps using your favorite service.</p><p>When your RunPod account is set up, go to Manage &gt; Templates and click on &#8220;New Template&#8221;. Here is a simple template:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!BQQg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 424w, /__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 848w, /__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!BQQg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 424w, /__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 848w, /__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 1272w, /__u/substackcdn.com/image/fetch/$s_!BQQg!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F238b12c7-3021-4294-a654-77ebbfc7eab8_800x510.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Let&#8217;s review the different fields and their corresponding values:</p><ul><li><p><strong>Template Name</strong>: Axolotl (you can choose whatever you want)</p></li><li><p><strong>Container Image</strong>: winglian/axolotl-runpod:main-py3.10-cu118&#8211;2.0.1</p></li><li><p><strong>Container Disk</strong>: 100 GB</p></li><li><p><strong>Volume Disk</strong>: 0 GB</p></li><li><p><strong>Volume Mount Path</strong>: /workspace</p></li></ul><p>In addition, there are two handy environment variables can include:</p><ul><li><p><strong>HUGGING_FACE_HUB_TOKEN</strong>: you can find your token on <a href="https://huggingface.co/settings/tokens">this page</a> (requires an account)</p></li><li><p><strong>WANDB_API_KEY</strong>: you can find your key on <a href="https://wandb.ai/authorize">this page</a> (requires an account)</p></li></ul><p>Alternatively, you can simply log in the terminal later (using huggingface-cli login and wandb login). Once you&#8217;re set-up, go to Community Cloud and deploy an RTX 3090. Here you can search for the name of your template and select it as follows:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!uPZw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 424w, /__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 848w, /__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!uPZw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 424w, /__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 848w, /__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uPZw!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00c343bc-9e51-450d-8977-6d90f51fea4a_1200x213.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>You can click on &#8220;Continue&#8221; and RunPod will deploy your template. You can see the installation in your pod&#8217;s logs (Manage &gt; Pods). When the option becomes available, click on &#8220;Connect&#8221;. Here, click on &#8220;Start Web Terminal&#8221; and then &#8220;Connect to Web Terminal&#8221;. You are now connected to your pod!</p><p>The following steps are <strong>the same no matter what service you choose</strong>:</p><ol><li><p>We install Axolotl and the PEFT library as follows:</p></li></ol><pre><code>git clone https://github.com/OpenAccess-AI-Collective/axolotl
cd axolotl

pip3 install -e .[flash-attn]
pip3 install -U git+https://github.com/huggingface/peft.git</code></pre><p>2. Download the config file we created:</p><pre><code>wget https://gist.githubusercontent.com/mlabonne/8055f6335e2b85f082c8c75561321a66/raw/93915a9563fcfff8df9a81fc0cdbf63894465922/EvolCodeLlama-7b.yaml</code></pre><p>3. You can now <strong>start fine-tuning the model</strong> with the following command:</p><pre><code>accelerate launch scripts/finetune.py EvolCodeLlama-7b.yaml</code></pre><p>If everything is configured correctly, you should be able to train the model in a little more than <strong>one hour</strong> (it took me 1h 11m 44s). If you check the GPU memory used, you&#8217;ll see almost 100% with this config, which means we&#8217;re optimizing it pretty nicely. If you&#8217;re using a GPU with more VRAM (like an A100), you can increase the micro-batch size to make sure you&#8217;re fully using it.</p><p>In the meantime, feel free to close the web terminal and check your loss on Weights &amp; Biases. We&#8217;re using tmux so the training won&#8217;t stop if you close the terminal. Here are my loss curves:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!sTLS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 424w, /__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 848w, /__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 1272w, /__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!sTLS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 424w, /__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 848w, /__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 1272w, /__u/substackcdn.com/image/fetch/$s_!sTLS!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0bd80c1f-bde6-44a7-a8b1-8fb9f57d1697_1200x508.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>We see a steady improvement in the eval loss, which is a good sign. However, you can also spot drops in the eval loss that are not correlated with a decrease in the quality of the outputs&#8230; The best way to evaluate your model is simply by using it: you can run it in the terminal with the command <code>accelerate launch scripts/finetune.py EvolCodeLlama-7b.yaml --inference --lora_model_dir="./qlora-out"</code>.</p><p>The QLoRA adapter should already be uploaded to the Hugging Face Hub. However, you can also <strong>merge the base Code Llama model with this adapter and push the merged model</strong> there by following these steps:</p><ol><li><p>Download <a href="https://gist.github.com/mlabonne/a3542b0519708b8871d0703c938bba9f">this script</a>:</p></li></ol><pre><code>wget https://gist.githubusercontent.com/mlabonne/a3542b0519708b8871d0703c938bba9f/raw/60abc5afc07f9d843bc23d56f4e0b7ab072c4a62/merge_peft.py</code></pre><p>2. Execute it with this command:</p><pre><code>python merge_peft.py --base_model=codellama/CodeLlama-7b-hf --peft_model=./qlora-out --hub_id=EvolCodeLlama-7b</code></pre><p>Congratulations, you should have <strong>your own EvolCodeLlama-7b</strong> on the Hugging Face Hub at this point! For reference, you can access my own model trained with this process here: <a href="https://huggingface.co/mlabonne/EvolCodeLlama-7b"><code>mlabonne/EvolCodeLlama-7b</code></a></p><p>Considering that our EvolCodeLlama-7b is a code LLM, it would be interesting to compare its performance with other models on <strong>standard benchmarks</strong>, such as <a href="https://github.com/openai/human-eval">HumanEval</a> and <a href="https://github.com/google-research/google-research/tree/master/mbpp">MBPP</a>. For reference, you can find a leaderboard at the following address: <a href="https://huggingface.co/spaces/bigcode/multilingual-code-evals">Multilingual Code Evals</a>.</p><p>If you&#8217;re happy with this model, you can <strong>quantize</strong> it with GGML for local inference with <a href="https://colab.research.google.com/drive/1pL8k7m04mgE5jo2NrjGi8atB0j_37aDD?usp=sharing">this free Google Colab notebook</a>. You can also fine-tune <strong>bigger models</strong> (e.g., 70b parameters) thanks to <a href="https://github.com/microsoft/DeepSpeed">deepspeed</a>, which only requires an additional config file.</p><h3>Conclusion</h3><p>In this article, we&#8217;ve covered the essentials of <strong>how to efficiently fine-tune LLMs</strong>. We customized parameters to train on our Code Llama model on a small Python dataset. Finally, we merged the weights and uploaded the result on Hugging Face.</p><p>I hope you found this guide useful. I recommend using Axolotl with a cloud-based GPU service to get some experience and upload a few models on Hugging Face. Build your own datasets, play with the parameters, and break stuff along the way. Like with every wrapper, don&#8217;t hesitate to check the source code to get a good intuition of what it&#8217;s actually doing. It will massively help in the long run.</p><p>Thanks to the OpenAccess AI Collective and all the contributors!</p><p>If you&#8217;re interested in more technical content around LLMs, <a href="https://medium.com/@mlabonne">follow me on Medium</a>.</p><h3>Related articles</h3><p><strong><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">Fine-Tune Your Own Llama 2 Model in a Colab Notebook</a></strong><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32"><br></a><em><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">A practical introduction to LLM fine-tuning</a></em><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">towardsdatascience.com</a></p><p><strong><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">4-bit Quantization with GPTQ</a></strong><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34"><br></a><em><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">Quantize your own LLMs using AutoGPTQ</a></em><a href="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34" title="https://towardsdatascience.com/4-bit-quantization-with-gptq-36b0f4f02c34">towardsdatascience.com</a></p><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link - Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p>]]></content:encoded></item><item><title><![CDATA[Graph Convolutional Networks: Introduction to GNNs]]></title><description><![CDATA[A step-by-step guide using PyTorch Geometric]]></description><link>https://maximelabonne.substack.com/p/graph-convolutional-networks-introduction-to-gnns-24b3f60d6c95</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/graph-convolutional-networks-introduction-to-gnns-24b3f60d6c95</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 14 Aug 2023 15:12:08 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/17a4172f-78b6-47a3-bf0d-7f97d64a20f6_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>A step-by-step guide using PyTorch Geometric</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Wj7t!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Wj7t!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!Wj7t!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F722a2112-ff84-4886-b4f7-0164b35f7a7e_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p><strong>Graph Neural Networks</strong> (GNNs) represent one of the most captivating and rapidly evolving architectures within the deep learning landscape. As deep learning models designed to process data structured as graphs, GNNs bring remarkable versatility and powerful learning capabilities.</p><p>Among the various types of GNNs, the <strong>Graph Convolutional Networks</strong> (GCNs) have emerged as the most <a href="https://paperswithcode.com/methods/category/graph-models">prevalent and broadly applied model</a>. GCNs are innovative due to their ability to leverage both the features of a node and its locality to make predictions, providing an effective way to handle graph-structured data.</p><p>In this article, we will delve into the mechanics of the GCN layer and explain its inner workings. Furthermore, we will explore its practical application for node classification tasks, using <a href="https://pytorch-geometric.readthedocs.io/en/latest/index.html">PyTorch Geometric</a> as our tool of choice.</p><p>PyTorch Geometric is a specialized extension of PyTorch that has been created specifically for the development and implementation of GNNs. It is an advanced, yet user-friendly library that provides a comprehensive suite of tools to facilitate graph-based machine learning. To commence our journey, the PyTorch Geometric installation will be required. If you are using Google Colab, <a href="https://pytorch.org/get-started/locally/">PyTorch</a> should already be in place, so all we need to do is execute a few additional commands.</p><p>All the code is available on <a href="https://colab.research.google.com/drive/1ZugveUjRrbSNwUbryeKJN2wyhGFRCw0q?usp=sharing">Google Colab</a> and <a href="https://github.com/mlabonne/graph-neural-network-course">GitHub</a>.</p><pre><code>!pip install torch_geometric</code></pre><pre><code>import torch
import numpy as np
import networkx as nx
import matplotlib.pyplot as plt</code></pre><p>Now that PyTorch Geometric is installed, let&#8217;s explore the dataset we will use in this tutorial.</p><h3>&#127760; I. Graph&nbsp;data</h3><p><a href="https://en.wikipedia.org/wiki/Graph_%28discrete_mathematics%29">Graphs</a> are an essential structure for representing relationships between objects. You can encounter graph data in a multitude of real-world scenarios, such as social and computer networks, chemical structures of molecules, natural language processing, and image recognition, to name a few.</p><p>In this article, we will study the infamous and much-used <a href="https://en.wikipedia.org/wiki/Zachary%27s_karate_club">Zachary&#8217;s karate club</a> dataset.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Ky-M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Ky-M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 424w, /__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 848w, /__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Ky-M!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F025f1c46-a27a-48ce-afca-82dccf1d6800_800x800.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The Zachary&#8217;s karate club dataset embodies the relationships formed within a karate club as observed by Wayne W. Zachary during the 1970s. It is a kind of social network, where each node represents a club member, and edges between nodes represent interactions that occurred outside the club environment.</p><p>In this particular scenario, the members of the club are split into four distinct groups. Our task is to <strong>assign the correct group to each member</strong> (node classification), based on the pattern of their interactions.</p><p>Let&#8217;s import the dataset with PyG&#8217;s built-in function and try to understand the <code>Datasets</code> object it uses.</p><pre><code>from torch_geometric.datasets import KarateClub</code></pre><pre><code># Import dataset from PyTorch Geometric
dataset = KarateClub()</code></pre><pre><code># Print information
print(dataset)
print('------------')
print(f'Number of graphs: {len(dataset)}')
print(f'Number of features: {dataset.num_features}')
print(f'Number of classes: {dataset.num_classes}')</code></pre><pre><code>KarateClub()
------------
Number of graphs: 1
Number of features: 34
Number of classes: 4</code></pre><p>This dataset only has 1 graph, where each node has a feature vector of 34 dimensions and is part of one out of four classes (our four groups). Actually, the <code>Datasets</code> object can be seen as a collection of <code>Data</code> (graph) objects.</p><p>We can further inspect our unique graph to know more about it.</p><pre><code># Print first element
print(f'Graph: {dataset[0]}')</code></pre><pre><code>Graph: Data(x=[34, 34], edge_index=[2, 156], y=[34], train_mask=[34])</code></pre><p>The <a href="https://pytorch-geometric.readthedocs.io/en/latest/modules/data.html"><code>Data</code></a> object is particularly interesting. Printing it offers a good summary of the graph we're studying:</p><ul><li><p><code>x=[34, 34]</code> is the <strong>node feature matrix</strong> with shape (number of nodes, number of features). In our case, it means that we have 34 nodes (our 34 members), each node being associated to a 34-dim feature vector.</p></li><li><p><code>edge_index=[2, 156]</code> represents the <strong>graph connectivity</strong> (how the nodes are connected) with shape (2, number of directed edges).</p></li><li><p><code>y=[34]</code> is the <strong>node ground-truth labels</strong>. In this problem, every node is assigned to one class (group), so we have one value for each node.</p></li><li><p><code>train_mask=[34]</code> is an optional attribute that tells which nodes should be used for training with a list of <code>True</code> or <code>False</code> statements.</p></li></ul><p>Let&#8217;s print each of these tensors to understand what they store. Let&#8217;s start with the node features.</p><pre><code>data = dataset[0]</code></pre><pre><code>print(f'x = {data.x.shape}')
print(data.x)</code></pre><pre><code>x = torch.Size([34, 34])
tensor([[1., 0., 0.,  ..., 0., 0., 0.],
        [0., 1., 0.,  ..., 0., 0., 0.],
        [0., 0., 1.,  ..., 0., 0., 0.],
        ...,
        [0., 0., 0.,  ..., 1., 0., 0.],
        [0., 0., 0.,  ..., 0., 1., 0.],
        [0., 0., 0.,  ..., 0., 0., 1.]])</code></pre><p>Here, the node feature matrix <code>x</code> is an identity matrix: it <strong>doesn't contain any relevant information</strong> about the nodes. It could contain information like age, skill level, etc. but this is not the case in this dataset. It means we'll have to classify our nodes just by looking at their connections.</p><p>Now, let&#8217;s print the edge index.</p><pre><code>print(f'edge_index = {data.edge_index.shape}')
print(data.edge_index)</code></pre><pre><code>edge_index = torch.Size([2, 156])
tensor([[ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,
          1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,  2,  2,  2,  3,
          3,  3,  3,  3,  3,  4,  4,  4,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,
          7,  7,  8,  8,  8,  8,  8,  9,  9, 10, 10, 10, 11, 12, 12, 13, 13, 13,
         13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 19, 20, 20, 21,
         21, 22, 22, 23, 23, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 27, 27,
         27, 27, 28, 28, 28, 29, 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 31,
         31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33,
         33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33],
        [ 1,  2,  3,  4,  5,  6,  7,  8, 10, 11, 12, 13, 17, 19, 21, 31,  0,  2,
          3,  7, 13, 17, 19, 21, 30,  0,  1,  3,  7,  8,  9, 13, 27, 28, 32,  0,
          1,  2,  7, 12, 13,  0,  6, 10,  0,  6, 10, 16,  0,  4,  5, 16,  0,  1,
          2,  3,  0,  2, 30, 32, 33,  2, 33,  0,  4,  5,  0,  0,  3,  0,  1,  2,
          3, 33, 32, 33, 32, 33,  5,  6,  0,  1, 32, 33,  0,  1, 33, 32, 33,  0,
          1, 32, 33, 25, 27, 29, 32, 33, 25, 27, 31, 23, 24, 31, 29, 33,  2, 23,
         24, 33,  2, 31, 33, 23, 26, 32, 33,  1,  8, 32, 33,  0, 24, 25, 28, 32,
         33,  2,  8, 14, 15, 18, 20, 22, 23, 29, 30, 31, 33,  8,  9, 13, 14, 15,
         18, 19, 20, 22, 23, 26, 27, 28, 29, 30, 31, 32]])</code></pre><p>In graph theory and network analysis, connectivity between nodes is stored using a variety of data structures. The <code>edge_index</code> is one such data structure, where the graph's connections are stored in <strong>two lists</strong> (156 directed edges, which equate to 78 bidirectional edges). The reason for these two lists is that one list stores the source nodes, while the second one identifies the destination nodes.</p><p>This method is known as a <strong>coordinate list</strong> (COO) format, which is essentially a means to efficiently store a <a href="https://en.wikipedia.org/wiki/Sparse_matrix#Storing_a_sparse_matrix">sparse matrix</a>. Sparse matrices are data structures that efficiently store matrices with a majority of zero elements. In the COO format, only non-zero elements are stored, saving memory and computational resources.</p><p>Contrarily, a more intuitive and straightforward way to represent graph connectivity is through an <strong>adjacency matrix</strong> <em>A</em>. This is a square matrix where each element <em>A</em>&#7522;&#11388;<em> s</em>pecifies the presence or absence of an edge from node <em>i</em> to node <em>j</em> in the graph. In other words, a non-zero element <em>A</em>&#7522;&#11388; implies a connection from node <em>i</em> to node <em>j</em>, and a zero indicates no direct connection.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!FP0Y!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 424w, /__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 848w, /__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!FP0Y!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 424w, /__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 848w, /__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 1272w, /__u/substackcdn.com/image/fetch/$s_!FP0Y!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3da9b7a4-8964-42a7-b881-5fc2359c4e3e_800x322.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>An adjacency matrix, however, is not as space-efficient as the COO format for sparse matrices or graphs with fewer edges. However, for clarity and easy interpretation, the adjacency matrix remains a popular choice for representing graph connectivity.</p><p>The adjacency matrix can be inferred from the <code>edge_index</code> with a utility function <code>to_dense_adj()</code>.</p><pre><code>from torch_geometric.utils import to_dense_adj</code></pre><pre><code>A = to_dense_adj(data.edge_index)[0].numpy().astype(int)
print(f'A = {A.shape}')
print(A)</code></pre><pre><code>A = (34, 34)
[[0 1 1 ... 1 0 0]
 [1 0 1 ... 0 0 0]
 [1 1 0 ... 0 1 0]
 ...
 [1 0 0 ... 0 1 1]
 [0 0 1 ... 1 0 1]
 [0 0 0 ... 1 1 0]]</code></pre><p>With graph data, it is relatively uncommon for nodes to be densely interconnected. As you can see, our adjacency matrix <em>A</em> is <strong>sparse</strong> (filled with zeros).</p><p>In many real-world graphs, most nodes are connected to only a few other nodes, resulting in a large number of zeros in the adjacency matrix. Storing so many zeros is not efficient at all, which is why the COO format is adopted by PyG.</p><p>On the contrary, ground-truth labels are easy to understand.</p><pre><code>print(f'y = {data.y.shape}')
print(data.y)</code></pre><pre><code>y = torch.Size([34])
tensor([1, 1, 1, 1, 3, 3, 3, 1, 0, 1, 3, 1, 1, 1, 0, 0, 3, 1, 0, 1, 0, 1, 0, 0,
        2, 2, 0, 0, 2, 0, 0, 2, 0, 0])</code></pre><p>Our node ground-truth labels stored in <code>y</code> simply encode the group number (0, 1, 2, 3) for each node, which is why we have 34 values.</p><p>Finally, let&#8217;s print the train mask.</p><pre><code>print(f'train_mask = {data.train_mask.shape}')
print(data.train_mask)</code></pre><pre><code>train_mask = torch.Size([34])
tensor([ True, False, False, False,  True, False, False, False,  True, False,
        False, False, False, False, False, False, False, False, False, False,
        False, False, False, False,  True, False, False, False, False, False,
        False, False, False, False])</code></pre><p>The train mask shows which nodes are supposed to be used for training with <code>True</code> statements. These nodes represent the training set, while the others can be considered as the test set. This division helps in model evaluation by providing unseen data for testing.</p><p>But we&#8217;re not done yet! The <a href="https://pytorch-geometric.readthedocs.io/en/latest/modules/data.html"><code>Data</code></a> object has a lot more to offer. It provides various utility functions that enable the investigation of several properties of the graph. For instance:</p><ul><li><p><code>is_directed()</code> tells you if the graph is <strong>directed</strong>. A directed graph signifies that the adjacency matrix is not symmetric, i.e., the direction of edges matters in the connections between nodes.</p></li><li><p><code>isolated_nodes()</code> checks if some nodes are <strong>not connected</strong> to the rest of the graph. These nodes are likely to pose challenges in tasks like classification due to their lack of connections.</p></li><li><p><code>has_self_loops()</code> indicates if at least one node is <strong>connected to itself</strong>. This is distinct from the concept of <a href="https://en.wikipedia.org/wiki/Loop_%28graph_theory%29">loops</a>: a loop implies a path that starts and ends at the same node, traversing other nodes in between.</p></li></ul><p>In the context of the Zachary&#8217;s karate club dataset, all these properties return <code>False</code>. This implies that the graph is not directed, does not have any isolated nodes, and none of its nodes are connected to themselves.</p><pre><code>print(f'Edges are directed: {data.is_directed()}')
print(f'Graph has isolated nodes: {data.has_isolated_nodes()}')
print(f'Graph has loops: {data.has_self_loops()}')</code></pre><pre><code>Edges are directed: False
Graph has isolated nodes: False
Graph has loops: False</code></pre><p>Finally, we can convert a graph from PyTorch Geometric to the popular graph library <a href="https://networkx.org/">NetworkX</a> using <a href="https://pytorch-geometric.readthedocs.io/en/latest/modules/utils.html?highlight=to_networkx#torch_geometric.utils.to_networkx"><code>to_networkx</code></a>. This is particularly useful to visualize a small graph with <code>networkx</code> and <code>matplotlib</code>.</p><p>Let&#8217;s plot our dataset with a different color for each group.</p><pre><code>from torch_geometric.utils import to_networkx</code></pre><pre><code>G = to_networkx(data, to_undirected=True)
plt.figure(figsize=(12,12))
plt.axis('off')
nx.draw_networkx(G,
                pos=nx.spring_layout(G, seed=0),
                with_labels=True,
                node_size=800,
                node_color=data.y,
                cmap="hsv",
                vmin=-2,
                vmax=3,
                width=0.8,
                edge_color="grey",
                font_size=14
                )
plt.show()</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!TfN5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 424w, /__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 848w, /__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!TfN5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 424w, /__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 848w, /__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TfN5!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F520bfc40-2593-41df-ac15-864083b1dd1b_800x795.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>This plot of Zachary&#8217;s karate club displays our 34 nodes, 78 (bidirectional) edges, and 4 labels with 4 different colors. Now that we&#8217;ve seen the essentials of loading and handling a dataset with PyTorch Geometric, we can introduce the <strong>Graph Convolutional Network</strong> architecture.</p><h3>&#9993;&#65039; II. Graph Convolutional Network</h3><p>This section aims to introduce and build the graph convolutional layer from the ground up.</p><p>In traditional neural networks, linear layers apply a <strong>linear transformation</strong> to the incoming data. This transformation converts input features <em>x</em> into hidden vectors <em>h</em> through the use of a weight matrix &#119830;. Ignoring biases for the time being, this can be expressed as:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!0bQy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 424w, /__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 848w, /__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!0bQy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 424w, /__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 848w, /__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 1272w, /__u/substackcdn.com/image/fetch/$s_!0bQy!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F93a74b2d-451c-4503-9c2d-efc690d6c7b0_800x22.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>With graph data, an additional layer of complexity is added through the <strong>connections between nodes</strong>. These connections matter because, typically, in networks, it&#8217;s assumed that similar nodes are more likely to be linked to each other than dissimilar ones, a phenomenon known as <a href="https://en.wikipedia.org/wiki/Network_homophily">network homophily</a>.</p><p>We can enrich our <strong>node representation</strong> by merging its features with those of its neighbors. This operation is called convolution, or neighborhood aggregation. Let&#8217;s represent the neighborhood of node <em>i</em> including itself as <em>&#209;</em>.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!P60T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 424w, /__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 848w, /__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!P60T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 424w, /__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 848w, /__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P60T!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffc9c5718-15b6-4e56-a6a7-9126baeeccd8_800x77.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Unlike filters in Convolutional Neural Networks (CNNs), our weight matrix &#119830; is unique and shared among every node. But there is another issue: nodes do not have a <strong>fixed number of neighbors</strong> like pixels do.</p><p>How do we address cases where one node has only one neighbor, and another has 500? If we simply sum the feature vectors, the resulting embedding <em>h</em> would be much larger for the node with 500 neighbors. To ensure a <strong>similar range</strong> of values for all nodes and comparability between them, we can normalize the result based on the <strong>degree</strong> of nodes, where degree refers to the number of connections a node has.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!TnTZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 424w, /__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 848w, /__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!TnTZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 424w, /__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 848w, /__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 1272w, /__u/substackcdn.com/image/fetch/$s_!TnTZ!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F577d9431-c2a6-4f7a-ad2c-cbee066cb28f_800x90.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We&#8217;re almost there! Introduced by Kipf et al. (2016), the <a href="https://arxiv.org/abs/1609.02907">graph convolutional layer</a> has one final improvement.</p><p>The authors observed that features from nodes with numerous neighbors propagate much more easily than those from more isolated nodes. To offset this effect, they suggested assigning <strong>bigger weights</strong> to features from nodes with fewer neighbors, thus balancing the influence across all nodes. This operation is written as:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!gFZE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 424w, /__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 848w, /__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!gFZE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 424w, /__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 848w, /__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 1272w, /__u/substackcdn.com/image/fetch/$s_!gFZE!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6a9d97e9-f5ad-4ce0-9689-8b3bfdbf9a8f_800x90.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Note that when <em>i</em> and <em>j</em> have the same number of neighbors, it is equivalent to our own layer. Now, let&#8217;s see how to implement it in Python with PyTorch Geometric.</p><h3>&#129504; III. Implementing a&nbsp;GCN</h3><p>PyTorch Geometric provides the <code>GCNConv</code> function, which directly implements the graph convolutional layer.</p><p>In this example, we&#8217;ll create a basic Graph Convolutional Network with a single GCN layer, a ReLU activation function, and a linear output layer. This output layer will yield <strong>four values</strong> corresponding to our four categories, with the highest value determining the class of each node.</p><p>In the following code block, we define the GCN layer with a 3-dimensional hidden layer.</p><pre><code>from torch.nn import Linear
from torch_geometric.nn import GCNConv

</code></pre><pre><code>class GCN(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.gcn = GCNConv(dataset.num_features, 3)
        self.out = Linear(3, dataset.num_classes)</code></pre><pre><code>    def forward(self, x, edge_index):
        h = self.gcn(x, edge_index).relu()
        z = self.out(h)
        return h, z</code></pre><pre><code>model = GCN()
print(model)</code></pre><pre><code>GCN(
  (gcn): GCNConv(34, 3)
  (out): Linear(in_features=3, out_features=4, bias=True)
)</code></pre><p>If we added a second GCN layer, our model would not only aggregate feature vectors from the neighbors of each node, but also from the neighbors of these neighbors.</p><p>We can <strong>stack several graph layers</strong> to aggregate more and more distant values, but there&#8217;s a catch: if we add too many layers, the aggregation becomes so intense that all the embeddings end up looking the same. This phenomenon is called <strong>over-smoothing</strong> and can be a real problem when you have too many layers.</p><p>Now that we&#8217;ve defined our GNN, let&#8217;s write a simple training loop with PyTorch. I chose a regular cross-entropy loss since it&#8217;s a multi-class classification task, with Adam as optimizer. In this article, we won&#8217;t implement a train/test split to keep things simple and focus on how GNNs learn instead.</p><p>The training loop is standard: we try to predict the correct labels, and we compare the GCN&#8217;s results to the values stored in <code>data.y</code>. The error is calculated by the cross-entropy loss and backpropagated with Adam to fine-tune our GNN's weights and biases. Finally, we print metrics every 10 epochs.</p><pre><code>criterion = torch.nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.02)</code></pre><pre><code># Calculate accuracy
def accuracy(pred_y, y):
    return (pred_y == y).sum() / len(y)</code></pre><pre><code># Data for animations
embeddings = []
losses = []
accuracies = []
outputs = []</code></pre><pre><code># Training loop
for epoch in range(201):
    # Clear gradients
    optimizer.zero_grad()</code></pre><pre><code>    # Forward pass
    h, z = model(data.x, data.edge_index)</code></pre><pre><code>    # Calculate loss function
    loss = criterion(z, data.y)</code></pre><pre><code>    # Calculate accuracy
    acc = accuracy(z.argmax(dim=1), data.y)</code></pre><pre><code>    # Compute gradients
    loss.backward()</code></pre><pre><code>    # Tune parameters
    optimizer.step()</code></pre><pre><code>    # Store data for animations
    embeddings.append(h)
    losses.append(loss)
    accuracies.append(acc)
    outputs.append(z.argmax(dim=1))</code></pre><pre><code>    # Print metrics every 10 epochs
    if epoch % 10 == 0:
        print(f'Epoch {epoch:&gt;3} | Loss: {loss:.2f} | Acc: {acc*100:.2f}%')</code></pre><pre><code>Epoch   0 | Loss: 1.40 | Acc: 41.18%
Epoch  10 | Loss: 1.21 | Acc: 47.06%
Epoch  20 | Loss: 1.02 | Acc: 67.65%
Epoch  30 | Loss: 0.80 | Acc: 73.53%
Epoch  40 | Loss: 0.59 | Acc: 73.53%
Epoch  50 | Loss: 0.39 | Acc: 94.12%
Epoch  60 | Loss: 0.23 | Acc: 97.06%
Epoch  70 | Loss: 0.13 | Acc: 100.00%
Epoch  80 | Loss: 0.07 | Acc: 100.00%
Epoch  90 | Loss: 0.05 | Acc: 100.00%
Epoch 100 | Loss: 0.03 | Acc: 100.00%
Epoch 110 | Loss: 0.02 | Acc: 100.00%
Epoch 120 | Loss: 0.02 | Acc: 100.00%
Epoch 130 | Loss: 0.02 | Acc: 100.00%
Epoch 140 | Loss: 0.01 | Acc: 100.00%
Epoch 150 | Loss: 0.01 | Acc: 100.00%
Epoch 160 | Loss: 0.01 | Acc: 100.00%
Epoch 170 | Loss: 0.01 | Acc: 100.00%
Epoch 180 | Loss: 0.01 | Acc: 100.00%
Epoch 190 | Loss: 0.01 | Acc: 100.00%
Epoch 200 | Loss: 0.01 | Acc: 100.00%</code></pre><p>Great! Without much surprise, we reach 100% accuracy on the training set (full dataset). It means that our model learned to correctly assign every member of the karate club to its correct group.</p><p>We can produce a neat visualization by animating the graph and see the evolution of the GNN&#8217;s predictions during the training process.</p><pre><code>%%capture
from IPython.display import HTML
from matplotlib import animation
plt.rcParams["animation.bitrate"] = 3000</code></pre><pre><code>def animate(i):
    G = to_networkx(data, to_undirected=True)
    nx.draw_networkx(G,
                    pos=nx.spring_layout(G, seed=0),
                    with_labels=True,
                    node_size=800,
                    node_color=outputs[i],
                    cmap="hsv",
                    vmin=-2,
                    vmax=3,
                    width=0.8,
                    edge_color="grey",
                    font_size=14
                    )
    plt.title(f'Epoch {i} | Loss: {losses[i]:.2f} | Acc: {accuracies[i]*100:.2f}%',
              fontsize=18, pad=20)</code></pre><pre><code>fig = plt.figure(figsize=(12, 12))
plt.axis('off')</code></pre><pre><code>anim = animation.FuncAnimation(fig, animate, \
            np.arange(0, 200, 10), interval=500, repeat=True)
html = HTML(anim.to_html5_video())
display(html)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!YZFI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 424w, /__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 848w, /__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 1272w, /__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!YZFI!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 424w, /__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 848w, /__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 1272w, /__u/substackcdn.com/image/fetch/$s_!YZFI!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fddd0bb66-4554-455a-b960-43701874900b_1200x1200.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The first predictions are random, but the GCN perfectly labels every node after a while. Indeed, the final graph is the same as the one we plotted at the end of the first section. But what does the GCN really learn?</p><p>By aggregating features from neighboring nodes, the GNN learns a vector representation (or <strong>embedding</strong>) of every node in the network. In our model, the final layer just learns how to use these representations to produce the best classifications. However, embeddings are the real products of GNNs.</p><p>Let&#8217;s print the embeddings learned by our model.</p><pre><code># Print embeddings
print(f'Final embeddings = {h.shape}')
print(h)</code></pre><pre><code>Final embeddings = torch.Size([34, 3])
tensor([[1.9099e+00, 2.3584e+00, 7.4027e-01],
        [2.6203e+00, 2.7997e+00, 0.0000e+00],
        [2.2567e+00, 2.2962e+00, 6.4663e-01],
        [2.0802e+00, 2.8785e+00, 0.0000e+00],
        [0.0000e+00, 0.0000e+00, 2.9694e+00],
        [0.0000e+00, 0.0000e+00, 3.3817e+00],
        [0.0000e+00, 1.5008e-04, 3.4246e+00],
        [1.7593e+00, 2.4292e+00, 2.4551e-01],
        [1.9757e+00, 6.1032e-01, 1.8986e+00],
        [1.7770e+00, 1.9950e+00, 6.7018e-01],
        [0.0000e+00, 1.1683e-04, 2.9738e+00],
        [1.8988e+00, 2.0512e+00, 2.6225e-01],
        [1.7081e+00, 2.3618e+00, 1.9609e-01],
        [1.8303e+00, 2.1591e+00, 3.5906e-01],
        [2.0755e+00, 2.7468e-01, 1.9804e+00],
        [1.9676e+00, 3.7185e-01, 2.0011e+00],
        [0.0000e+00, 0.0000e+00, 3.4787e+00],
        [1.6945e+00, 2.0350e+00, 1.9789e-01],
        [1.9808e+00, 3.2633e-01, 2.1349e+00],
        [1.7846e+00, 1.9585e+00, 4.8021e-01],
        [2.0420e+00, 2.7512e-01, 1.9810e+00],
        [1.7665e+00, 2.1357e+00, 4.0325e-01],
        [1.9870e+00, 3.3886e-01, 2.0421e+00],
        [2.0614e+00, 5.1042e-01, 2.4872e+00],
...
        [2.1778e+00, 4.4730e-01, 2.0077e+00],
        [3.8906e-02, 2.3443e+00, 1.9195e+00],
        [3.0748e+00, 0.0000e+00, 3.0789e+00],
        [3.4316e+00, 1.9716e-01, 2.5231e+00]], grad_fn=&lt;ReluBackward0&gt;)</code></pre><p>As you can see, embeddings do not need to have the same dimensions as feature vectors. Here, I chose to reduce the number of dimensions from 34 (<code>dataset.num_features</code>) to three to get a nice visualization in 3D.</p><p>Let&#8217;s plot these embeddings before any training happens, at epoch 0.</p><pre><code># Get first embedding at epoch = 0
embed = h.detach().cpu().numpy()</code></pre><pre><code>fig = plt.figure(figsize=(12, 12))
ax = fig.add_subplot(projection='3d')
ax.patch.set_alpha(0)
plt.tick_params(left=False,
                bottom=False,
                labelleft=False,
                labelbottom=False)
ax.scatter(embed[:, 0], embed[:, 1], embed[:, 2],
           s=200, c=data.y, cmap="hsv", vmin=-2, vmax=3)</code></pre><pre><code>plt.show()</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!4_1c!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 424w, /__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 848w, /__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!4_1c!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 424w, /__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 848w, /__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 1272w, /__u/substackcdn.com/image/fetch/$s_!4_1c!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70504eae-2808-4c73-b15f-a6e6185dc50b_800x800.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We see every node from Zachary&#8217;s karate club with their true labels (and not the model&#8217;s predictions). For now, they&#8217;re all over the place since the GNN is not trained yet. But if we plot these embeddings at each step of the training loop, we&#8217;d be able to visualize what the GNN truly learns.</p><p>Let&#8217;s see how they evolve over time, as the GCN gets better and better at classifying nodes.</p><pre><code>%%capture</code></pre><pre><code>def animate(i):
    embed = embeddings[i].detach().cpu().numpy()
    ax.clear()
    ax.scatter(embed[:, 0], embed[:, 1], embed[:, 2],
           s=200, c=data.y, cmap="hsv", vmin=-2, vmax=3)
    plt.title(f'Epoch {i} | Loss: {losses[i]:.2f} | Acc: {accuracies[i]*100:.2f}%',
              fontsize=18, pad=40)</code></pre><pre><code>fig = plt.figure(figsize=(12, 12))
plt.axis('off')
ax = fig.add_subplot(projection='3d')
plt.tick_params(left=False,
                bottom=False,
                labelleft=False,
                labelbottom=False)</code></pre><pre><code>anim = animation.FuncAnimation(fig, animate, \
              np.arange(0, 200, 10), interval=800, repeat=True)
html = HTML(anim.to_html5_video())
display(html)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!iEYm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 424w, /__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 848w, /__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 1272w, /__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!iEYm!,w_1456,c_limit,f_auto,q_auto:good,fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 424w, /__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 848w, /__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 1272w, /__u/substackcdn.com/image/fetch/$s_!iEYm!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_lossy/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b6b976f-5008-4e21-a4d3-3ff32cf7381a_1200x1200.gif 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Our Graph Convolutional Network (GCN) has effectively learned embeddings that group similar nodes into <strong>distinct clusters</strong>. This enables the final linear layer to distinguish them into separate classes with ease.</p><p>Embeddings are not unique to GNNs: they can be found everywhere in deep learning. They don&#8217;t have to be 3D either: actually, they rarely are. For instance, language models like <a href="https://arxiv.org/abs/1810.04805">BERT</a> produce embeddings with 768 or even 1024 dimensions.</p><p>Additional dimensions store more information about nodes, text, images, etc. but they also create bigger models that are more difficult to train. This is why keeping low-dimensional embeddings as long as possible is advantageous.</p><h3>Conclusion</h3><p>Graph Convolutional Networks are an incredibly versatile architecture that can be applied in <strong>many contexts</strong>. In this article, we familiarized ourselves with the PyTorch Geometric library and objects like <code>Datasets</code> and <code>Data</code>. Then, we successfully reconstructed a graph convolutional layer from the ground up. Next, we put theory into practice by implementing a GCN, which gave us an understanding of practical aspects and how individual components interact. Finally, we visualized the training process and obtained a clear perspective of what it involves for such a network.</p><p>Zachary&#8217;s karate club is a simplistic dataset, but it is good enough to understand the most important concepts in graph data and GNNs. Although we only talked about node classification in this article, there are other tasks GNNs can accomplish: <strong>link prediction</strong> (e.g., to recommend a friend), <strong>graph classification</strong> (e.g., to label molecules), <strong>graph generation</strong> (e.g., to create new molecules), and so on.</p><p>Beyond GCN, numerous GNN layers and architectures have been proposed by researchers. In the next article, we&#8217;ll introduce the <a href="https://mlabonne.github.io/blog/gat/">Graph Attention Network</a> (GAT) architecture, which dynamically computes the GCN&#8217;s normalization factor and the importance of each connection with an attention mechanism.</p><p>If you want to know more about graph neural networks, dive deeper into the world of GNNs with my book, <a href="https://mlabonne.github.io/blog/book.html">Hands-On Graph Neural Networks</a>.</p><h3>Next article</h3><p><strong><a href="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c" title="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c">Chapter 2: Graph Attention Networks: Self-Attention Explained</a></strong><a href="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c" title="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c"><br></a><em><a href="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c" title="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c">A guide to GNNs with self-attention using PyTorch Geometric</a></em><a href="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c" title="https://towardsdatascience.com/graph-attention-networks-in-python-975736ac5c0c">towardsdatascience.com</a></p><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link&#8202;&#8212;&#8202;Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p><p><em>If you&#8217;re already a member, you can <a href="https://medium.com/@mlabonne">follow me on Medium</a>.</em></p>]]></content:encoded></item><item><title><![CDATA[4-bit Quantization with GPTQ]]></title><description><![CDATA[Quantize your own LLMs using AutoGPTQ]]></description><link>https://maximelabonne.substack.com/p/4-bit-quantization-with-gptq-36b0f4f02c34</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/4-bit-quantization-with-gptq-36b0f4f02c34</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Mon, 31 Jul 2023 14:52:52 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/eea065b0-d9f5-465f-8481-8fdf67dfd778_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>Quantize your own LLMs using&nbsp;AutoGPTQ</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!o6m8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!o6m8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!o6m8!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8999f7b-43e6-4813-9040-d7e1086c980f_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Recent advancements in weight quantization allow us to run massive large language models on consumer hardware, like a LLaMA-30B model on an RTX 3090 GPU. This is possible thanks to novel 4-bit quantization techniques with minimal performance degradation, like <a href="https://arxiv.org/abs/2210.17323">GPTQ</a>, <a href="https://github.com/ggerganov/ggml">GGML</a>, and <a href="https://huggingface.co/blog/4bit-transformers-bitsandbytes">NF4</a>.</p><p>In the <a href="https://medium.com/towards-data-science/introduction-to-weight-quantization-2494701b9c0c">previous article</a>, we introduced na&#239;ve 8-bit quantization techniques and the excellent LLM.int8(). In this article, we will explore the popular <strong>GPTQ algorithm</strong> to understand how it works and implement it using the <a href="https://github.com/PanQiWei/AutoGPTQ">AutoGPTQ</a> library.</p><p>You can find the code on <a href="https://colab.research.google.com/drive/1lSvVDaRgqQp_mWK_jC9gydz6_-y6Aq4A?usp=sharing">Google Colab</a> and <a href="https://github.com/mlabonne/llm-course/tree/main">GitHub</a>.</p><h3>&#129504; Optimal Brain Quantization</h3><p>Let&#8217;s start by introducing the problem we&#8217;re trying to solve. For every layer &#8467; in the network, we want to find a quantized version <strong>&#372;&#8343;</strong><em> of the original weights </em><strong>W&#8343;</strong>. This is called the <strong>layer-wise compression problem</strong>. More specifically, to minimize performance degradation, we want the outputs (<strong>&#372;</strong>&#7528;<strong>X</strong>&#7528;) of these new weights to be as close as possible to the original ones (<strong>W</strong>&#7528;<strong>X</strong>&#7528;). In other words, we want to find:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!WD9v!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 424w, /__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 848w, /__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 1272w, /__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!WD9v!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ed05a441-015f-40fa-99e3-ad530534decd_800x63.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 424w, /__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 848w, /__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 1272w, /__u/substackcdn.com/image/fetch/$s_!WD9v!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fed05a441-015f-40fa-99e3-ad530534decd_800x63.png 1456w" sizes="100vw"></picture><div></div></div></a></figure></div><p>Different approaches have been proposed to solve this problem, but we&#8217;re interested in the <strong><a href="https://arxiv.org/abs/2208.11580">Optimal Brain Quantizer</a></strong> (OBQ) framework here.</p><p>This method is inspired by a <strong>pruning technique</strong> to carefully remove weights from a fully trained dense neural network (Optimal Brain Surgeon). It uses an approximation technique and provides explicit formulas for the best single weight <em>w&#67493;</em> to remove and optimal update <em>&#948;</em>&#42995; to adjust the set of remaining non-quantized weights <em>F</em> to make up for the removal:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!iwmC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 424w, /__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 848w, /__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 1272w, /__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!iwmC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 424w, /__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 848w, /__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 1272w, /__u/substackcdn.com/image/fetch/$s_!iwmC!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0aa1137f-e3e4-4205-a95d-d407665ec4ed_800x168.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>where quant(<em>w</em>) is the weight rounding given by the quantization and <strong>H</strong>&#42995; is the Hessian.</p><p>Using OBQ, we can quantize the easiest weight first and then adjust all remaining non-quantized weights to <strong>compensate for this precision loss</strong>. Then we pick the next weight to quantize, and so on.</p><p>A potential issue with this approach is when there are outlier weights, which can result in high <strong>quantization error</strong>. Usually, these outliers would be quantized last, when there are few non-quantized weights left that could be adjusted to compensate for the large error. This effect can worsen when some weights are pushed further outside the grid by intermediate updates. A simple heuristic is applied to prevent this: outliers are quantized as soon as they appear.</p><p>This process could be computationally heavy, especially for LLMs. To deal with this, the OBQ method uses a trick that avoids redoing the entire computation each time a weight is simplified. After quantizing a weight, it adjusts the matrix used in calculations (the Hessian) by <strong>removing the row and column</strong> associated with that weight (using Gaussian elimination):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!EHib!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 424w, /__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 848w, /__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 1272w, /__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!EHib!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afe22eff-f495-4c24-9842-68e5e996f652_800x82.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 424w, /__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 848w, /__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 1272w, /__u/substackcdn.com/image/fetch/$s_!EHib!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafe22eff-f495-4c24-9842-68e5e996f652_800x82.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The method also employs vectorization to process multiple rows of the weight matrix at once. Despite its efficiency, the OBQ&#8217;s computation time increases significantly as the size of the weight matrix increases. This cubic growth makes it difficult to use OBQ on very large models with billions of parameters.</p><h3>&#129518; The GPTQ Algorithm</h3><p>Introduced by Frantar et al. (2023), the <a href="https://arxiv.org/abs/2210.17323">GPTQ algorithm</a> takes inspiration from the OBQ method, but with significant improvements to scale it for (very) large language models.</p><h4>Step 1: Arbitrary Order&nbsp;Insight</h4><p>The OBQ method selects weights (parameters in a model) for quantization in a certain order, determined by which will <strong>add the least additional error</strong>. However, GPTQ observes that for large models, quantizing weights in any fixed order can perform just as well. This is because even though some weights might introduce more error individually, they are quantized later in the process when there are few other weights left that could increase the error. So the order doesn&#8217;t matter as much as we thought.</p><p>Based on this insight, GPTQ aims to quantize all weights in the <strong>same order for all rows</strong> of a matrix. This makes the process faster because certain computations have to be done only once for each column, rather than once for each weight.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!qexX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 424w, /__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 848w, /__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!qexX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 424w, /__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 848w, /__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 1272w, /__u/substackcdn.com/image/fetch/$s_!qexX!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8f1af173-baa0-46cb-a0be-6a566cdb0312_800x433.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><h4>Step 2: Lazy Batch-Updates</h4><p>This scheme won&#8217;t be fast because it requires updating a <strong>huge matrix</strong> with very few computations for each entry. This type of operation can&#8217;t utilize the full compute capabilities of GPUs and will be slowed down by memory limitations (memory throughput bottleneck).</p><p>To resolve this, GPTQ introduces &#8220;lazy batch&#8221; updates. It turns out that the final rounding decisions for a given column are only affected by updates performed on that column, not on later columns. Therefore, GPTQ can apply the algorithm to a <strong>batch of columns at a time</strong> (like 128 columns), updating only those columns and a corresponding block of the matrix. After a block is fully processed, the algorithm performs global updates on the entire matrix.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!Gz0C!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 424w, /__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 848w, /__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!Gz0C!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 424w, /__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 848w, /__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 1272w, /__u/substackcdn.com/image/fetch/$s_!Gz0C!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b21a19-a4b8-4355-a90b-b9862cbd7ddd_800x95.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><h4>Step 3: Cholesky Reformulation</h4><p>However, there&#8217;s one more issue to address. When the algorithm scales up to very large models, numerical inaccuracies can become a problem. Specifically, repeated applications of a certain operation can <strong>accumulate numerical errors</strong>.</p><p>To tackle this, GPTQ uses a <a href="https://en.wikipedia.org/wiki/Cholesky_decomposition">Cholesky decomposition</a>, a numerically stable method for solving certain mathematical problems. It involves precomputing some required information from the matrix using the Cholesky method. This approach, combined with a slight &#8220;dampening&#8221; (adding a small constant to diagonal elements of the matrix), helps the algorithm to avoid numerical issues.</p><p>The full algorithm can be summarized in a few steps:</p><ol><li><p>The GPTQ algorithm begins with a Cholesky decomposition of the Hessian inverse (a matrix that helps decide how to adjust the weights)</p></li><li><p>It then runs in loops, handling batches of columns at a time.</p></li><li><p>For each column in a batch, it quantizes the weights, calculates the error, and updates the weights in the block accordingly.</p></li><li><p>After processing the batch, it updates all remaining weights based on the block&#8217;s errors.</p></li></ol><p>The GPTQ algorithm was tested on various language generation tasks. It was compared with other quantization methods, like rounding all weights to the nearest quantized value (RTN). GPTQ was used with the BLOOM (176B parameters) and OPT (175B parameters) model families, and models were quantized using a <strong>single NVIDIA A100 GPU</strong>.</p><h3>&#128187; Quantize an LLM with&nbsp;AutoGPTQ</h3><p>GPTQ has been very popular to create models in 4-bit precision that can efficiently run on GPUs. You can find many examples on the Hugging Face Hub, especially from <a href="https://huggingface.co/TheBloke">TheBloke</a>. If you&#8217;re looking for an approach that is more CPU-friendly, <a href="https://github.com/ggerganov/ggml">GGML</a> is currently your best option. Finally, the <code>transformers</code> library with <code>bitsandbytes</code> allows you to quantize a model when it's loaded using the <code>load_in_4bit=true</code> argument, which requires downloading full models and storing them in your RAM.</p><p>Let&#8217;s implement the GPTQ algorithm using the AutoGPTQ library and quantize a GPT-2 model. This requires a GPU, but a free T4 on Google Colab will do. We start by loading the libraries and defining the model we want to quantize (in this case, GPT-2).</p><pre><code>!BUILD_CUDA_EXT=0 pip install -q auto-gptq transformers</code></pre><pre><code>import random

from auto_gptq import AutoGPTQForCausalLM, BaseQuantizeConfig
from datasets import load_dataset
import torch
from transformers import AutoTokenizer


# Define base model and output directory
model_id = "gpt2"
out_dir = model_id + "-GPTQ"</code></pre><p>We now want to load the model and the tokenizer. The tokenizer is loaded using the classic <code>AutoTokenizer</code> class from the <code>transformers</code> library. On the other hand, we need to pass a specific configuration (<code>BaseQuantizeConfig</code>) to load the model.</p><p>In this configuration, we can specify the number of bits to quantize (here, <code>bits=4</code>) and the group size (size of the lazy batch). Note that this group size is optional: we could also use <strong>one set of parameters</strong> for the entire weight matrix. In practice, these groups generally improve the quality of the quantization at a very low cost (especially with <code>group_size=1024</code>). The <code>damp_percent</code> value is here to help the Cholesky reformulation and should not be changed.</p><p>Finally, the <code>desc_act</code> (also called act order) is a tricky parameter. It allows you to <strong>process rows based on decreasing activation</strong>, meaning the most important or impactful rows (determined by sampled inputs and outputs) are processed first. This method aims to place most of the quantization error (inevitably introduced during quantization) on less significant weights. This approach improves the overall accuracy of the quantization process by ensuring the most significant weights are processed with greater precision. However, when used alongside group size, <code>desc_act</code> can lead to performance slowdowns due to the need to frequently reload quantization parameters. For this reason, we won't use it here (it will probably be fixed in the future, however).</p><pre><code># Load quantize config, model and tokenizer
quantize_config = BaseQuantizeConfig(
    bits=4,
    group_size=128,
    damp_percent=0.01,
    desc_act=False,
)
model = AutoGPTQForCausalLM.from_pretrained(model_id, quantize_config)
tokenizer = AutoTokenizer.from_pretrained(model_id)</code></pre><p>The quantization process <strong>relies heavily on samples</strong> to evaluate and enhance the quality of the quantization. They provide a means of comparison between the outputs produced by the origina and the newly quantized model. The larger the number of samples provided, the greater the potential for more accurate and effective comparisons, leading to improved quantization quality.</p><p>In the context of this article, we utilize the <strong><a href="https://huggingface.co/datasets/c4">C4 (Colossal Clean Crawled Corpus) dataset</a></strong> to generate our samples. The C4 dataset is a large-scale, multilingual collection of web text gathered from the Common Crawl project. This expansive dataset has been cleaned and prepared specifically for training large-scale language models, making it a great resource for tasks such as this. The WikiText dataset is another popular option.</p><p>In the following code block, we load 1024 samples from the C4 dataset, tokenize them, and format them.</p><pre><code># Load data and tokenize examples
n_samples = 1024
data = load_dataset("allenai/c4", data_files="en/c4-train.00001-of-01024.json.gz", split=f"train[:{n_samples*5}]")
tokenized_data = tokenizer("\n\n".join(data['text']), return_tensors='pt')

# Format tokenized examples
examples_ids = []
for _ in range(n_samples):
    i = random.randint(0, tokenized_data.input_ids.shape[1] - tokenizer.model_max_length - 1)
    j = i + tokenizer.model_max_length
    input_ids = tokenized_data.input_ids[:, i:j]
    attention_mask = torch.ones_like(input_ids)
    examples_ids.append({'input_ids': input_ids, 'attention_mask': attention_mask})</code></pre><p>Now that dataset is ready, we can start the quantization process with a batch size of 1. Optionally, we also use <a href="https://github.com/openai/triton">OpenAI Triton</a>, a CUDA alternative, to communicate with the GPU. Once this is done, we save the tokenizer and the model in a safetensors format.</p><pre><code># Quantize with GPTQ
model.quantize(
    examples_ids,
    batch_size=1,
    use_triton=True,
)

# Save model and tokenizer
model.save_quantized(out_dir, use_safetensors=True)
tokenizer.save_pretrained(out_dir)</code></pre><p>As per usual, the model and tokenizer can then be loaded from the output directory using the <code>AutoGPTQForCausalLM</code> and <code>AutoTokenizer</code> classes.</p><pre><code>device = "cuda:0" if torch.cuda.is_available() else "cpu"

# Reload model and tokenizer
model = AutoGPTQForCausalLM.from_quantized(
    out_dir,
    device=device,
    use_triton=True,
    use_safetensors=True,
)
tokenizer = AutoTokenizer.from_pretrained(out_dir)</code></pre><p>Let&#8217;s check that the model is working correctly. The AutoGPTQ model (mostly) works as a normal <code>transformers</code> model, which makes it compatible with inference pipelines, as shown in the following example:</p><pre><code>from transformers import pipeline

generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
result = generator("I have a dream", do_sample=True, max_length=50)[0]['generated_text']
print(result)</code></pre><pre><code>I have a dream," she told CNN last week. "I have this dream of helping my mother find her own. But, to tell that for the first time, now that I'm seeing my mother now, just knowing how wonderful it is that</code></pre><p>We managed to get a convincing completion from our quantized GPT-2 model. A more in-depth evaluation would require <strong>measuring the perplexity</strong> of the quantized model versus the original one. However, we will leave it out of the scope of this article.</p><h3>Conclusion</h3><p>In this article, we introduced the GPTQ algorithm, a state-of-the-art quantization technique to run LLMs on consumer-grade hardware. We showed how it addresses the layer-wise compression problem, based on an improved OBS technique with arbitrary order insight, lazy batch updates, and Cholesky reformulation. This novel approach <strong>significantly reduces memory and computation requirements</strong>, making LLMs accessible to a broader audience.</p><p>In addition, we <strong>quantized our own LLM model</strong> on a free T4 GPU and ran it to generate text. You can push your own version of a GPTQ 4-bit quantized model on the Hugging Face Hub. As mentioned in the introduction, GPTQ is not the only 4-bit quantization algorithm: <a href="https://github.com/ggerganov/ggml">GGML</a> and <a href="https://huggingface.co/blog/4bit-transformers-bitsandbytes">NF4</a> are excellent alternatives with slightly different scopes. I encourage you to learn more about them and give them a shot!</p><p>If you&#8217;re interested in more technical content around LLMs, follow me on Twitter <a href="https://twitter.com/maximelabonne">@maximelabonne</a>.</p><h3>References</h3><ul><li><p>B. Hassibi, D. G. Stork and G. J. Wolff, <a href="https://ieeexplore.ieee.org/document/298572">&#8220;Optimal Brain Surgeon and general network pruning,&#8221;</a> IEEE International Conference on Neural Networks, San Francisco, CA, USA, 1993, pp. 293&#8211;299 vol.1, doi: 10.1109/ICNN.1993.298572.</p></li><li><p>Elias Frantar, Sidak Pal Singh, &amp; Dan Alistarh. (2023). <a href="https://arxiv.org/abs/2208.11580">Optimal Brain Compression: A Framework for Accurate Post-Training Quantization and Pruning</a>.</p></li><li><p>Elias Frantar, Saleh Ashkboos, Torsten Hoefler, &amp; Dan Alistarh. (2023). <a href="https://arxiv.org/abs/2210.17323">GPTQ: Accurate Post-Training Quantization for Generative Pre-trained Transformers</a>.</p></li><li><p>Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, &amp; Peter J. Liu. (2020). <a href="https://arxiv.org/abs/1910.10683v3">Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer</a>.</p></li></ul><h3>Related articles</h3><p><strong><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">Introduction to Weight Quantization</a></strong><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c"><br></a><em><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">Reducing the size of Large Language Models with 8-bit quantization</a></em><a href="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c" title="https://towardsdatascience.com/introduction-to-weight-quantization-2494701b9c0c">towardsdatascience.com</a></p><p><strong><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">Fine-Tune Your Own Llama 2 Model in a Colab Notebook</a></strong><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32"><br></a><em><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">A practical introduction to LLM fine-tuning</a></em><a href="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32" title="https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32">towardsdatascience.com</a></p><p><em>Learn more about machine learning and support my work with one click&#8202;&#8212;&#8202;become a Medium member here:</em></p><p><strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">Join Medium with my referral link&#8202;&#8212;&#8202;Maxime Labonne</a></strong><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership"><br></a><em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story&#8230;</a></em><a href="https://medium.com/@mlabonne/membership" title="https://medium.com/@mlabonne/membership">medium.com</a></p><p><em>If you&#8217;re already a member, you can <a href="https://medium.com/@mlabonne">follow me on Medium</a>.</em></p>]]></content:encoded></item><item><title><![CDATA[Fine-Tune Your Own Llama 2 Model in a Colab Notebook]]></title><description><![CDATA[A practical introduction to LLM fine-tuning]]></description><link>https://maximelabonne.substack.com/p/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/fine-tune-your-own-llama-2-model-in-a-colab-notebook-df9823a04a32</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Tue, 25 Jul 2023 18:08:04 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/9ae57d20-64be-44c6-98a5-87ce1bba532d_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>A practical introduction to LLM fine-tuning</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!YJua!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!YJua!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!YJua!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe1b46a38-fbac-45e8-9838-b1730c88c14c_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>With the release of LLaMA v1, we saw a Cambrian explosion of fine-tuned models, including <a href="https://github.com/tatsu-lab/stanford_alpaca">Alpaca</a>, <a href="https://huggingface.co/lmsys/vicuna-13b-v1.3">Vicuna</a>, and <a href="https://huggingface.co/WizardLM/WizardLM-13B-V1.1">WizardLM</a>, among others. This trend encouraged different businesses to launch their own base models with licenses suitable for commercial use, such as <a href="https://github.com/openlm-research/open_llama">OpenLLaMA</a>, <a href="https://falconllm.tii.ae/">Falcon</a>, <a href="https://github.com/salesforce/xgen">XGen</a>, etc. The release of Llama 2 now combines the best elements from both sides: it offers a <strong>highly efficient base model along with a more permissive license</strong>.</p><p>During the first half of 2023, the software landscape was significantly shaped by the <strong>widespread use of APIs</strong> (like OpenAI API) to create infrastructures based on Large Language Models (LLMs). Libraries such as <a href="https://python.langchain.com/docs/get_started/introduction.html">LangChain</a> and <a href="https://www.llamaindex.ai/">LlamaIndex</a> played a critical role in this trend. Moving into the latter half of the year, the process of <strong>fine-tuning (or instruction tuning) these models is set to become a standard procedure</strong> in the LLMOps workflow. This trend is driven by various factors: the potential for cost savings, the ability to process confidential data, and even the potential to develop models that exceed the performance of prominent models like ChatGPT and GPT-4 in certain specific tasks.</p><p>In this article, we will see why instruction tuning works and how to implement it in a Google Colab notebook to create your own Llama 2 model. As usual, the code is available on <a href="https://colab.research.google.com/drive/1PEQyJO1-f6j0S_XJ8DV50NkpzasXkrzd?usp=sharing">Colab</a> and <a href="https://github.com/mlabonne/llm-course">GitHub</a>.</p><h3><strong>&#128295; </strong>Background on fine-tuning LLMs</h3><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!OVOE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 424w, /__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 848w, /__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 1272w, /__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!OVOE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 424w, /__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 848w, /__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 1272w, /__u/substackcdn.com/image/fetch/$s_!OVOE!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdca8e5b2-f9a5-4f36-a567-73474ef0dced_800x341.png 1456w" sizes="100vw"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>LLMs are pretrained on an extensive corpus of text. In the case of <a href="https://arxiv.org/abs/2307.09288">Llama 2</a>, we know very little about the composition of the training set, besides its length of 2 trillion tokens. In comparison, <a href="https://arxiv.org/abs/1810.04805">BERT</a> (2018) was &#8220;only&#8221; trained on the BookCorpus (800M words) and English Wikipedia (2,500M words). From experience, this is a <strong>very costly and long process</strong> with a lot of hardware issues. If you want to know more about it, I recommend reading <a href="https://github.com/facebookresearch/metaseq/blob/main/projects/OPT/chronicles/OPT175B_Logbook.pdf">Meta&#8217;s logbook</a> about the pretraining of the OPT-175B model.</p><p>When the pretraining is complete, auto-regressive models like Llama 2 can <strong>predict the next token</strong> in a sequence. However, this does not make them particularly useful assistants since they don&#8217;t reply to instructions. This is why we employ instruction tuning to align their answers with what humans expect. There are two main fine-tuning techniques:</p><ul><li><p><strong>Supervised Fine-Tuning</strong> (SFT): Models are trained on a dataset of instructions and responses. It adjusts the weights in the LLM to minimize the difference between the generated answers and ground-truth responses, acting as labels.</p></li><li><p><strong>Reinforcement Learning from Human Feedback</strong> (RLHF): Models learn by interacting with their environment and receiving feedback. They are trained to maximize a reward signal (using <a href="https://arxiv.org/abs/1707.06347">PPO</a>), which is often derived from human evaluations of model outputs.</p></li></ul><p>In general, RLHF is shown to capture <strong>more complex and nuanced </strong>human preferences, but is also more challenging to implement effectively. Indeed, it requires careful design of the reward system and can be sensitive to the quality and consistency of human feedback. A possible alternative in the future is the <a href="https://arxiv.org/abs/2305.18290">Direct Preference Optimization</a> (DPO) algorithm, which directly runs preference learning on the SFT model.</p><p>In our case, we will perform SFT, but this raises a question: why does fine-tuning work in the first place? As highlighted in the <a href="https://mlabonne.github.io/blog/notes/Large%20Language%20Models/orca.html">Orca paper</a>, our understanding is that fine-tuning <strong>leverages knowledge learned during the pretraining</strong> process. In other words, fine-tuning will be of little help if the model has never seen the kind of data you&#8217;re interested in. However, if that&#8217;s the case, SFT can be extremely performant.</p><p>For example, the <a href="https://mlabonne.github.io/blog/notes/Large%20Language%20Models/lima.html">LIMA paper</a> showed how you could outperform GPT-3 (DaVinci003) by fine-tuning a LLaMA (v1) model with 65 billion parameters on only 1,000 high-quality samples. The <strong>quality of the instruction dataset is essential</strong> to reach this level of performance, which is why a lot of work is focused on this issue (like <a href="https://arxiv.org/abs/2304.12244">evol-instruct</a>, Orca, or <a href="https://mlabonne.github.io/blog/notes/Large%20Language%20Models/phi1.html">phi-1</a>). Note that the size of the LLM (65b, not 13b or 7b) is also fundamental to leverage pre-existing knowledge efficiently.</p><p>Another important point related to the data quality is the <strong>prompt template</strong>. Prompts are comprised of similar elements: system prompt (optional) to guide the model, user prompt (required) to give the instruction, additional inputs (optional) to take into consideration, and the model&#8217;s answer (required). In the case of Llama 2, the authors used the following template:</p><pre><code>&lt;s&gt;[INST] &lt;&lt;SYS&gt;&gt;
System prompt
&lt;&lt;/SYS&gt;&gt;

User prompt [/INST] Model answer &lt;/s&gt;</code></pre><p>There are other templates, like the ones from Alpaca and Vicuna, and their impact is not very clear. In this example, we will reformat our instruction dataset to follow Llama 2&#8217;s template. For the purpose of this tutorial, I&#8217;ve already done it using the excellent <a href="https://huggingface.co/datasets/timdettmers/openassistant-guanaco"><code>timdettmers/openassistant-guanaco</code></a> dataset. You can find it on Hugging Face under the name <a href="https://huggingface.co/datasets/mlabonne/guanaco-llama2-1k"><code>mlabonne/guanaco-llama2-1k</code></a>.</p><h3>&#129433; How to fine-tune Llama&nbsp;2</h3><p>In this section, we will fine-tune a Llama 2 model with 7 billion parameters on a T4 GPU with high RAM using Google Colab (2.21 credits/hour). Note that a T4 only has 16 GB of VRAM, which is barely enough to <strong>store Llama 2&#8211;7b&#8217;s weights</strong> (7b &#215; 2 bytes = 14 GB in FP16). In addition, we need to consider the overhead due to optimizer states, gradients, and forward activations (see <a href="https://huggingface.co/docs/transformers/perf_train_gpu_one#anatomy-of-models-memory">this excellent article</a> for more information). This means that a full fine-tuning is not possible here: we need parameter-efficient fine-tuning (PEFT) techniques like <a href="https://arxiv.org/abs/2106.09685">LoRA</a> or <a href="https://arxiv.org/abs/2305.14314">QLoRA</a>.</p><p>To drastically reduce the VRAM usage, we must <strong>fine-tune the model in 4-bit precision</strong>, which is why we&#8217;ll use QLoRA here. The good thing is that we can leverage the Hugging Face ecosystem with the <code>transformers</code>, <code>accelerate</code>, <code>peft</code>, <code>trl</code>, and <code>bitsandbytes</code> libraries. We'll do this in the following code based on Younes Belkada's <a href="https://gist.github.com/younesbelkada/9f7f75c94bdc1981c8ca5cc937d4a4da">GitHub Gist</a>. First, we install and load these libraries.</p><pre><code><code>!pip install -q accelerate==0.21.0 peft==0.4.0 bitsandbytes==0.40.2 transformers==4.31.0 trl==0.4.7</code></code></pre><pre><code>import os
import torch
from datasets import load_dataset
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
    BitsAndBytesConfig,
    HfArgumentParser,
    TrainingArguments,
    pipeline,
    logging,
)
from peft import LoraConfig, PeftModel
from trl import SFTTrainer</code></pre><p>Let&#8217;s talk a bit about the parameters we can tune here. First, we want to load a <code>llama-2-7b-chat-hf</code> model and train it on the <code>mlabonne/guanaco-llama2-1k</code> (1,000 samples), which will produce our fine-tuned model <code>llama-2-7b-miniguanaco</code>. Feel free to change the dataset: there are many options on the <a href="https://huggingface.co/datasets">Hugging Face Hub</a>.</p><p>QLoRA will use a rank of 64 with a scaling parameter of 16 (see <a href="https://rentry.org/llm-training#low-rank-adaptation-lora_1">this article</a> for more information about LoRA parameters). We&#8217;ll load the Llama 2 model directly in 4-bit precision using the NF4 type and train it for one epoch. To get more information about the other parameters, check the <a href="https://huggingface.co/docs/transformers/main_classes/trainer#transformers.TrainingArguments">TrainingArguments</a>, <a href="https://huggingface.co/docs/peft/package_reference/peft_model">PeftModel</a>, and <a href="https://huggingface.co/docs/trl/main/en/sft_trainer">SFTTrainer</a> documentation.</p><pre><code># The model that you want to train from the Hugging Face hub
model_name = "daryl149/llama-2-7b-chat-hf"

# The instruction dataset to use
dataset_name = "mlabonne/guanaco-llama2-1k"

# Fine-tuned model name
new_model = "llama-2-7b-miniguanaco"

################################################################################
# QLoRA parameters
################################################################################

# LoRA attention dimension
lora_r = 64

# Alpha parameter for LoRA scaling
lora_alpha = 16

# Dropout probability for LoRA layers
lora_dropout = 0.1

################################################################################
# bitsandbytes parameters
################################################################################

# Activate 4-bit precision base model loading
use_4bit = True

# Compute dtype for 4-bit base models
bnb_4bit_compute_dtype = "float16"

# Quantization type (fp4 or nf4)
bnb_4bit_quant_type = "nf4"

# Activate nested quantization for 4-bit base models (double quantization)
use_nested_quant = False

################################################################################
# TrainingArguments parameters
################################################################################

# Output directory where the model predictions and checkpoints will be stored
output_dir = "./results"

# Number of training epochs
num_train_epochs = 1

# Enable fp16/bf16 training (set bf16 to True with an A100)
fp16 = False
bf16 = False

# Batch size per GPU for training
per_device_train_batch_size = 4

# Batch size per GPU for evaluation
per_device_eval_batch_size = 4

# Number of update steps to accumulate the gradients for
gradient_accumulation_steps = 2

# Enable gradient checkpointing
gradient_checkpointing = True

# Maximum gradient normal (gradient clipping)
max_grad_norm = 0.3

# Initial learning rate (AdamW optimizer)
learning_rate = 2e-4

# Weight decay to apply to all layers except bias/LayerNorm weights
weight_decay = 0.001

# Optimizer to use
optim = "paged_adamw_32bit"

# Learning rate schedule (constant a bit better than cosine)
lr_scheduler_type = "constant"

# Number of training steps (overrides num_train_epochs)
max_steps = -1

# Ratio of steps for a linear warmup (from 0 to learning rate) 
warmup_ratio = 0.03

# Group sequences into batches with same length
# Saves memory and speeds up training considerably
group_by_length = True

# Save checkpoint every X updates steps
save_steps = 10

# Log every X updates steps
logging_steps = 1

################################################################################
# SFT parameters
################################################################################

# Maximum sequence length to use
max_seq_length = None

# Pack multiple short examples in the same input sequence to increase efficiency
packing = False

# Load the entire model on the GPU 0
device_map = {"": 0}</code></pre><p>We can now load everything and start the fine-tuning process. We&#8217;re relying on multiple wrappers, so bear with me.</p><ul><li><p>First of all, we want to load the dataset we defined. If you changed it, you can <strong>preprocess it here</strong> and adapt it to the desired prompt template.</p></li><li><p>Then, we&#8217;re configuring <code>bitsandbytes</code> for 4-bit quantization.</p></li><li><p>Next, we're loading the Llama 2 model in 4-bit precision on a GPU with the corresponding tokenizer.</p></li><li><p>Finally, we're loading configurations for QLoRA, regular training parameters, and passing everything to the <code>SFTTrainer</code>. The training can finally start!</p></li></ul><pre><code># Load dataset (you can process it here)
dataset = load_dataset(dataset_name, split="train")

# Load tokenizer and model with QLoRA configuration
compute_dtype = getattr(torch, bnb_4bit_compute_dtype)

bnb_config = BitsAndBytesConfig(
    load_in_4bit=use_4bit,
    bnb_4bit_quant_type=bnb_4bit_quant_type,
    bnb_4bit_compute_dtype=compute_dtype,
    bnb_4bit_use_double_quant=use_nested_quant,
)

# Check GPU compatibility with bfloat16
if compute_dtype == torch.float16 and use_4bit:
    major, _ = torch.cuda.get_device_capability()
    if major &gt;= 8:
        print("=" * 80)
        print("Your GPU supports bfloat16: accelerate training with bf16=True")
        print("=" * 80)

# Load base model
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    quantization_config=bnb_config,
    device_map=device_map
)
model.config.use_cache = False
model.config.pretraining_tp = 1

# Load LLaMA tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right" # Fix weird overflow issue with fp16 training

# Load LoRA configuration
peft_config = LoraConfig(
    lora_alpha=lora_alpha,
    lora_dropout=lora_dropout,
    r=lora_r,
    bias="none",
    task_type="CAUSAL_LM",
)

# Set training parameters
training_arguments = TrainingArguments(
    output_dir=output_dir,
    num_train_epochs=num_train_epochs,
    per_device_train_batch_size=per_device_train_batch_size,
    gradient_accumulation_steps=gradient_accumulation_steps,
    optim=optim,
    save_steps=save_steps,
    logging_steps=logging_steps,
    learning_rate=learning_rate,
    weight_decay=weight_decay,
    fp16=fp16,
    bf16=bf16,
    max_grad_norm=max_grad_norm,
    max_steps=max_steps,
    warmup_ratio=warmup_ratio,
    group_by_length=group_by_length,
    lr_scheduler_type=lr_scheduler_type,
    report_to="tensorboard"
)

# Set supervised fine-tuning parameters
trainer = SFTTrainer(
    model=model,
    train_dataset=dataset,
    peft_config=peft_config,
    dataset_text_field="text",
    max_seq_length=max_seq_length,
    tokenizer=tokenizer,
    args=training_arguments,
    packing=packing,
)

# Train model
trainer.train()

# Save trained model
trainer.model.save_pretrained(output_dir)</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!uzze!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 424w, /__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 848w, /__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!uzze!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 424w, /__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 848w, /__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 1272w, /__u/substackcdn.com/image/fetch/$s_!uzze!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab4b5764-3f8e-42ca-82a3-1bf6f559c565_607x323.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The training can be very long, depending on the size of your dataset. Here, it took less than an hour on a T4 GPU. We can check the plots on tensorboard, as follows:</p><pre><code>%load_ext tensorboard
%tensorboard --logdir results/runs</code></pre><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!3XZS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 424w, /__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 848w, /__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!3XZS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 424w, /__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 848w, /__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 1272w, /__u/substackcdn.com/image/fetch/$s_!3XZS!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9784d20e-c8b2-4bd5-a480-b8b97e341cde_800x512.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>Let&#8217;s make sure that the model is behaving correctly. It would require a more exhaustive evaluation, but we can use the <strong>text generation pipeline</strong> to ask questions like &#8220;What is a large language model?&#8221; Note that I&#8217;m formatting the input to match Llama 2&#8217;s prompt template.</p><pre><code># Ignore warnings
logging.set_verbosity(logging.CRITICAL)

# Run text generation pipeline with our next model
prompt = "What is a large language model?"
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=200)
result = pipe(f"&lt;s&gt;[INST] {prompt} [/INST]")
print(result[0]['generated_text'])</code></pre><p>The model outputs the following response:</p><pre><code>A large language model is a type of artificial intelligence that is trained on a large dataset of text to generate human-like language. It is typically trained on a dataset of text that is much larger than the dataset used for smaller language models. The large dataset allows the model to learn more complex patterns in language, which can result in more accurate and natural-sounding language generation.

Large language models are often used for tasks such as text summarization, language translation, and chatbots. They are also used for more complex tasks such as writing articles, generating creative content, and even composing music.

Large language models are trained using a technique called deep learning, which involves using many layers of artificial neural networks to learn complex patterns in the data. The model is trained on a large dataset of text, and the neural networks are trained to predict the next word in a sequence of text given</code></pre><p>From experience, it is <strong>very coherent</strong> for a model with only 7 billion parameters. You can play with it and ask harder questions from evaluation datasets like <a href="https://github.com/suzgunmirac/BIG-Bench-Hard">BigBench-Hard</a>. Guanaco is an excellent dataset that has produced high-quality models in the past. You can train a Llama 2 model on the entire dataset using <a href="https://huggingface.co/datasets/mlabonne/guanaco-llama2"><code>mlabonne/guanaco-llama2</code></a>.</p><p>How can we store our new <code>llama-2-7b-miniguanaco</code> model now? We need to merge the weights from LoRA with the base model. Unfortunately, as far as I know, there is no straightforward way to do it: we need to reload the base model in FP16 precision and use the <code>peft</code> library to merge everything. Alas, it also creates a problem with the VRAM (despite emptying it), so I recommend <strong>restarting the notebook</strong>, re-executing the three first cells, and then executing the next one. Please contact me if you know a fix!</p><pre><code># Reload model in FP16 and merge it with LoRA weights
base_model = AutoModelForCausalLM.from_pretrained(
    model_name,
    low_cpu_mem_usage=True,
    return_dict=True,
    torch_dtype=torch.float16,
    device_map=device_map,
)
model = PeftModel.from_pretrained(base_model, output_dir)
model = model.merge_and_unload()

# Reload tokenizer to save it
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"</code></pre><p>Our weights are merged and we reloaded the tokenizer. We can now push everything to the Hugging Face Hub to save our model.</p><pre><code>!huggingface-cli login

model.push_to_hub(new_model, use_temp_dir=False)
tokenizer.push_to_hub(new_model, use_temp_dir=False)</code></pre><p>You can now use this model for inference by loading it like any other Llama 2 model from the Hub. It is also possible to reload it for more fine-tuning&#8202;&#8212;&#8202;perhaps with another dataset?</p><p>If you&#8217;re interested in a script instead of a notebook, I recommend following the instructions provided in this <a href="https://huggingface.co/blog/llama2">blog post</a>:</p><pre><code>pip install trl
git clone https://github.com/lvwerra/trl
python trl/examples/scripts/sft_trainer.py \
    --model_name meta-llama/Llama-2-7b-hf \
    --dataset_name timdettmers/openassistant-guanaco \
    --load_in_4bit \
    --use_peft \
    --batch_size 4 \
    --gradient_accumulation_steps 2</code></pre><h3>Conclusion</h3><p>In this article, we saw how to fine-tune a Llama 2 7b model using a Colab notebook. We introduced some necessary background on LLM training and fine-tuning, as well as important considerations related to instruction datasets. In the second section, we <strong>successfully fine-tuned the Llama 2 model</strong> with its native prompt template and custom parameters.</p><p>These fine-tuned models can then be integrated into LangChain and other architectures as an advantageous alternative to OpenAI API. Remember that, in this new paradigm, instruction datasets are the new gold, and the quality of your model heavily depends on the data it&#8217;s been fine-tuned on. So good luck building high-quality datasets!</p><p>If you&#8217;re interested in more content about LLMs, follow me on Twitter <a href="https://twitter.com/maximelabonne">@maximelabonne</a>.</p><h3>References</h3><ul><li><p>Hugo Touvron, Thomas Scialom, et al. (2023). <a href="https://arxiv.org/abs/2307.09288">Llama 2: Open Foundation and Fine-Tuned Chat Models</a>.</p></li><li><p>Philipp Schmid, Omar Sanseviero, Pedro Cuenca, &amp; Lewis Tunstall. Llama 2 is here&#8202;&#8212;&#8202;get it on Hugging Face. <a href="https://huggingface.co/blog/llama2">https://huggingface.co/blog/llama2</a></p></li><li><p>Rohan Taori, Ishaan Gulrajani, Tianyi Zhang, Yann Dubois, Xuechen Li, Carlos Guestrin, Percy Liang, &amp; Tatsunori B. Hashimoto. (2023). <a href="https://crfm.stanford.edu/2023/03/13/alpaca.html">Stanford Alpaca: An Instruction-following LLaMA model</a>.</p></li><li><p>Jacob Devlin, Ming-Wei Chang, Kenton Lee, &amp; Kristina Toutanova. (2019). <a href="https://arxiv.org/abs/1810.04805">BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding</a>.</p></li><li><p>Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, &amp; Luke Zettlemoyer. (2023). <a href="https://arxiv.org/abs/2305.14314">QLoRA: Efficient Finetuning of Quantized LLMs</a>.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Introduction to Weight Quantization]]></title><description><![CDATA[Reducing the size of Large Language Models with 8-bit quantization]]></description><link>https://maximelabonne.substack.com/p/introduction-to-weight-quantization-2494701b9c0c</link><guid isPermaLink="false">https://maximelabonne.substack.com/p/introduction-to-weight-quantization-2494701b9c0c</guid><dc:creator><![CDATA[Maxime Labonne]]></dc:creator><pubDate>Fri, 07 Jul 2023 07:58:09 GMT</pubDate><enclosure url="https://substack-post-media.s3.amazonaws.com/public/images/60f2d3bb-7618-4062-8ac1-1cf7f9ee822a_800x450.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4>Reducing the size of Large Language Models with 8-bit quantization</h4><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!OTvg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!OTvg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 424w, /__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 848w, /__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 1272w, /__u/substackcdn.com/image/fetch/$s_!OTvg!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F47c34216-89ae-4a4c-9a83-78df8931b81c_800x450.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div></div></div></a></figure></div><p>Large Language Models (LLMs) are known for their extensive computational requirements. Typically, the size of a model is calculated by multiplying the number of parameters (<strong>size</strong>) by the precision of these values (<strong>data type</strong>). However, to save memory, weights can be stored using lower-precision data types through a process known as quantization.</p><p>We distinguish two main families of weight quantization techniques in the literature:</p><ul><li><p><strong>Post-Training Quantization</strong> (PTQ) is a straightforward technique where the weights of an already trained model are converted to lower precision without necessitating any retraining. Although easy to implement, PTQ is associated with potential performance degradation.</p></li><li><p><strong>Quantization-Aware Training</strong> (QAT) incorporates the weight conversion process during the pre-training or fine-tuning stage, resulting in enhanced model performance. However, QAT is computationally expensive and demands representative training data.</p></li></ul><p>In this article, we focus on PTQ to reduce the precision of our parameters. To get a good intuition, we will apply both na&#239;ve and more sophisticated techniques to a toy example using a GPT-2 model.</p><p>The entire code is freely available on <a href="https://colab.research.google.com/drive/1DPr4mUQ92Cc-xf4GgAaB6dFcFnWIvqYi?usp=sharing">Google Colab</a> and <a href="https://github.com/mlabonne/llm-course/blob/main/Introduction_to_Weight_Quantization.ipynb">GitHub</a>.</p><h3>&#128218; Background on Floating Point Representation</h3><p>The choice of data type dictates the quantity of computational resources required, affecting the speed and efficiency of the model. In deep learning applications, balancing precision and computational performance becomes a vital exercise as higher precision often implies greater computational demands.</p><p>Among various data types, floating point numbers are predominantly employed in deep learning due to their ability to represent a wide range of values with high precision. Typically, a floating point number uses <em>n</em> bits to store a numerical value. These <em>n</em> bits are further partitioned into three distinct components:</p><ol><li><p><strong>Sign</strong>: The sign bit indicates the positive or negative nature of the number. It uses one bit where 0 indicates a positive number and 1 signals a negative number.</p></li><li><p><strong>Exponent</strong>: The exponent is a segment of bits that represents the power to which the base (usually 2 in binary representation) is raised. The exponent can also be positive or negative, allowing the number to represent very large or very small values.</p></li><li><p><strong>Significand/Mantissa</strong>: The remaining bits are used to store the significand, also referred to as the mantissa. This represents the significant digits of the number. The precision of the number heavily depends on the length of the significand.</p></li></ol><p>This design allows floating point numbers to cover a wide range of values with varying levels of precision. The formula used for this representation is:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!DHMn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 424w, /__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 848w, /__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 1272w, /__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!DHMn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 424w, /__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 848w, /__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 1272w, /__u/substackcdn.com/image/fetch/$s_!DHMn!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe0c4b88-b834-49d9-9d3f-6d33087199ca_800x35.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>To understand this better, let&#8217;s delve into some of the most commonly used data types in deep learning: float32 (FP32), float16 (FP16), and bfloat16 (BF16):</p><ul><li><p><strong>FP32</strong> uses 32 bits to represent a number: one bit for the sign, eight for the exponent, and the remaining 23 for the significand. While it provides a high degree of precision, the downside of FP32 is its high computational and memory footprint.</p></li><li><p><strong>FP16</strong> uses 16 bits to store a number: one is used for the sign, five for the exponent, and ten for the significand. Although this makes it more memory-efficient and accelerates computations, the reduced range and precision can introduce numerical instability, potentially impacting model accuracy.</p></li><li><p><strong>BF16</strong> is also a 16-bit format but with one bit for the sign, <em>eight</em> for the exponent, and <em>seven</em> for the significand. BF16 expands the representable range compared to FP16, thus decreasing underflow and overflow risks. Despite a reduction in precision due to fewer significand bits, BF16 typically does not significantly impact model performance and is a useful compromise for deep learning tasks.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!tAzf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 424w, /__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 848w, /__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 1272w, /__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!tAzf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 424w, /__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 848w, /__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 1272w, /__u/substackcdn.com/image/fetch/$s_!tAzf!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa07303ef-fe19-4771-b1ab-c242f25857ab_1200x700.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>In ML jargon, FP32 is often termed &#8220;full precision&#8221; (4 bytes), while BF16 and FP16 are &#8220;half-precision&#8221; (2 bytes). But could we do even better and store weights using a single byte? The answer is the INT8 data type, which consists of an 8-bit representation capable of storing 2&#8312; = 256 different values. In the next section, we&#8217;ll see how to convert FP32 weights into an INT8 format.</p><h3>&#128304; Na&#239;ve 8-bit Quantization</h3><p>In this section, we will implement two quantization techniques: a symmetric one with <strong>absolute maximum (absmax) quantization</strong> and an asymmetric one with <strong>zero-point quantization</strong>. In both cases, the goal is to map an FP32 tensor <strong>X</strong> (original weights) to an INT8 tensor <strong>X_quant</strong> (quantized weights).</p><p>With <strong>absmax quantization</strong>, the original number is divided by the absolute maximum value of the tensor and multiplied by a scaling factor (127) to map inputs into the range [-127, 127]. To retrieve the original FP16 values, the INT8 number is divided by the quantization factor, acknowledging some loss of precision due to rounding.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!38XM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 424w, /__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 848w, /__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 1272w, /__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!38XM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 424w, /__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 848w, /__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 1272w, /__u/substackcdn.com/image/fetch/$s_!38XM!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe4f5a3c1-39bb-48c5-9b3e-d3c9152c7aca_800x174.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>For instance, let&#8217;s say we have an absolution maximum value of 3.2. A weight of 0.1 would be quantized to<em> round(0.1 &#215; 127/3.2) = 4</em>. If we want to dequantize it, we would get <em>4 &#215; 3.2/127 = 0.1008</em>, which implies an error of 0.008. Here&#8217;s the corresponding Python implementation:</p><pre><code>import torch

def absmax_quantize(X):
    # Calculate scale
    scale = 127 / torch.max(torch.abs(X))

    # Quantize
    X_quant = (scale * X).round()

    # Dequantize
    X_dequant = X_quant / scale

    return X_quant.to(torch.int8), X_dequant</code></pre><p>With <strong>zero-point quantization</strong>, we can consider asymmetric input distributions, which is useful when you consider the output of a ReLU function (only positive values), for example. The input values are first scaled by the total range of values (255) divided by the difference between the maximum and minimum values. This distribution is then shifted by the zero-point to map it into the range [-128, 127] (notice the extra value compared to absmax). First, we calculate the scale factor and the zero-point value:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!JggM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 424w, /__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 848w, /__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!JggM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 424w, /__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 848w, /__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 1272w, /__u/substackcdn.com/image/fetch/$s_!JggM!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2b59d7a6-d54b-44b0-9796-2823e2cac7e6_800x118.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Then, we can use these variables to quantize or dequantize our weights:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!XTqF!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 424w, /__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 848w, /__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 1272w, /__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!XTqF!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 424w, /__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 848w, /__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 1272w, /__u/substackcdn.com/image/fetch/$s_!XTqF!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F48bb1b33-09f2-4df8-a05d-2a4c41d1abac_800x153.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Let&#8217;s take an example: we have a maximum value of 3.2 and a minimum value of -3.0. We can calculate the scale is <em>255/(3.2 + 3.0) = 41.13</em> and the zero-point <em>-round(41.13 &#215; -3.0) - 128 = 123 -128 = -5</em>, so our previous weight of 0.1 would be quantized to <em>round(41.13 &#215; 0.1 -5) = -1</em>. This is very different from the previous value obtained using absmax (4 vs. -1).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!P_Y5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 424w, /__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 848w, /__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!P_Y5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 424w, /__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 848w, /__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 1272w, /__u/substackcdn.com/image/fetch/$s_!P_Y5!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4faa56c5-c963-4e09-9931-adc24e7a8e22_1200x334.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>The Python implementation is quite straightforward:</p><pre><code>def zeropoint_quantize(X):
    # Calculate value range (denominator)
    x_range = torch.max(X) - torch.min(X)
    x_range = 1 if x_range == 0 else x_range

    # Calculate scale
    scale = 255 / x_range

    # Shift by zero-point
    zeropoint = (-scale * torch.min(X) - 128).round()

    # Scale and round the inputs
    X_quant = torch.clip((X * scale + zeropoint).round(), -128, 127)

    # Dequantize
    X_dequant = (X_quant - zeropoint) / scale

    return X_quant.to(torch.int8), X_dequant</code></pre><p>Instead of relying on complete toy examples, we can use these two functions on a real model thanks to the <code>transformers</code>library.</p><p>We start by loading the model and tokenizer for GPT-2. This is a very small model we probably don&#8217;t want to quantize, but it will be good enough for this tutorial. First, we want to observe the model&#8217;s size so we can compare it later and evaluate the <strong>memory savings</strong> due to 8-bit quantization.</p><pre><code>!pip install -q bitsandbytes&gt;=0.39.0
!pip install -q git+https://github.com/huggingface/accelerate.git
!pip install -q git+https://github.com/huggingface/transformers.git</code></pre><pre><code>from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
torch.manual_seed(0)

# Set device to CPU for now
device = 'cpu'

# Load model and tokenizer
model_id = 'gpt2'
model = AutoModelForCausalLM.from_pretrained(model_id).to(device)
tokenizer = AutoTokenizer.from_pretrained(model_id)

# Print model size
print(f"Model size: {model.get_memory_footprint():,} bytes")</code></pre><pre><code>Model size: 510,342,192 bytes</code></pre><p>The size of the GPT-2 model is approximately 487MB in FP32. The next step consists of quantizing the weights using zero-point and absmax quantization. In the following example, we apply these techniques to the first attention layer of GPT-2 to see the results.</p><pre><code># Extract weights of the first layer
weights = model.transformer.h[0].attn.c_attn.weight.data
print("Original weights:")
print(weights)

# Quantize layer using absmax quantization
weights_abs_quant, _ = absmax_quantize(weights)
print("\nAbsmax quantized weights:")
print(weights_abs_quant)

# Quantize layer using absmax quantization
weights_zp_quant, _ = zeropoint_quantize(weights)
print("\nZero-point quantized weights:")
print(weights_zp_quant)</code></pre><pre><code>Original weights:
tensor([[-0.4738, -0.2614, -0.0978,  ...,  0.0513, -0.0584,  0.0250],
        [ 0.0874,  0.1473,  0.2387,  ..., -0.0525, -0.0113, -0.0156],
        [ 0.0039,  0.0695,  0.3668,  ...,  0.1143,  0.0363, -0.0318],
        ...,
        [-0.2592, -0.0164,  0.1991,  ...,  0.0095, -0.0516,  0.0319],
        [ 0.1517,  0.2170,  0.1043,  ...,  0.0293, -0.0429, -0.0475],
        [-0.4100, -0.1924, -0.2400,  ..., -0.0046,  0.0070,  0.0198]])

Absmax quantized weights:
tensor([[-21, -12,  -4,  ...,   2,  -3,   1],
        [  4,   7,  11,  ...,  -2,  -1,  -1],
        [  0,   3,  16,  ...,   5,   2,  -1],
        ...,
        [-12,  -1,   9,  ...,   0,  -2,   1],
        [  7,  10,   5,  ...,   1,  -2,  -2],
        [-18,  -9, -11,  ...,   0,   0,   1]], dtype=torch.int8)

Zero-point quantized weights:
tensor([[-20, -11,  -3,  ...,   3,  -2,   2],
        [  5,   8,  12,  ...,  -1,   0,   0],
        [  1,   4,  18,  ...,   6,   3,   0],
        ...,
        [-11,   0,  10,  ...,   1,  -1,   2],
        [  8,  11,   6,  ...,   2,  -1,  -1],
        [-18,  -8, -10,  ...,   1,   1,   2]], dtype=torch.int8)</code></pre><p>The difference between the original (FP32) and quantized values (INT8) is clear, but the difference between absmax and zero-point weights is more subtle. In this case, the inputs look shifted by a value of -1. This suggests that the weight distribution in this layer is quite symmetric.</p><p>We can compare these techniques by quantizing every layer in GPT-2 (linear layers, attention layers, etc.) and create two new models: <code>model_abs</code> and <code>model_zp</code>. To be precise, we will actually replace the original weights with <em><strong>de</strong></em>-quantized ones. This has two benefits: it allows us to 1/ compare the distribution of our weights (same scale) and 2/ actually run the models.</p><p>Indeed, PyTorch doesn&#8217;t allow INT8 matrix multiplication by default. In a real scenario, we would dequantize them to run the model (in FP16 for example) but store them as INT8. In the next section, we will use the <a href="https://github.com/TimDettmers/bitsandbytes"><code>bitsandbytes</code></a> library to solve this issue.</p><pre><code>import numpy as np
from copy import deepcopy

# Store original weights
weights = [param.data.clone() for param in model.parameters()]

# Create model to quantize
model_abs = deepcopy(model)

# Quantize all model weights
weights_abs = []
for param in model_abs.parameters():
    _, dequantized = absmax_quantize(param.data)
    param.data = dequantized
    weights_abs.append(dequantized)

# Create model to quantize
model_zp = deepcopy(model)

# Quantize all model weights
weights_zp = []
for param in model_zp.parameters():
    _, dequantized = zeropoint_quantize(param.data)
    param.data = dequantized
    weights_zp.append(dequantized)</code></pre><p>Now that our models have been quantized, we want to check the impact of this process. Intuitively, we want to make sure that the quantized weights are <strong>close to the original ones</strong>. A visual way to check it is to plot the distribution of the dequantized and original weights. If the quantization is lossy, it would drastically change the weight distribution.</p><p>The following figure shows this comparison, where the blue histogram represents the original (FP32) weights, and the red one represents the dequantized (from INT8) weights. Note that we only display this plot between -2 and 2 because of outliers with very high absolute values (more on that later).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!o3bz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 424w, /__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 848w, /__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 1272w, /__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!o3bz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 424w, /__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 848w, /__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 1272w, /__u/substackcdn.com/image/fetch/$s_!o3bz!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1de5a5c7-e14e-42a0-8e57-69a444b83809_800x800.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Both plots are quite similar, with a surprising spike around 0. This spike shows that our quantization is quite lossy since reversing the process doesn&#8217;t output the original values. This is particularly true for the absmax model, which displays both a lower valley and a higher spike around 0.</p><p>Let&#8217;s compare the performance of the original and quantized models. For this purpose, we define a <code>generate_text()</code> function to generate 50 tokens with <a href="https://mlabonne.github.io/blog/posts/2023-06-07-Decoding_strategies.html">top-k sampling</a>.</p><pre><code>def generate_text(model, input_text, max_length=50):
    input_ids = tokenizer.encode(input_text, return_tensors='pt').to(device)
    output = model.generate(inputs=input_ids,
                            max_length=max_length,
                            do_sample=True,
                            top_k=30,
                            pad_token_id=tokenizer.eos_token_id,
                            attention_mask=input_ids.new_ones(input_ids.shape))
    return tokenizer.decode(output[0], skip_special_tokens=True)

# Generate text with original and quantized models
original_text = generate_text(model, "I have a dream")
absmax_text   = generate_text(model_abs, "I have a dream")
zp_text       = generate_text(model_zp, "I have a dream")

print(f"Original model:\n{original_text}")
print("-" * 50)
print(f"Absmax model:\n{absmax_text}")
print("-" * 50)
print(f"Zeropoint model:\n{zp_text}")</code></pre><pre><code>Original model:
I have a dream, and it is a dream I believe I would get to live in my future. I love my mother, and there was that one time I had been told that my family wasn't even that strong. And then I got the
--------------------------------------------------
Absmax model:
I have a dream to find out the origin of her hair. She loves it. But there's no way you could be honest about how her hair is made. She must be crazy.

We found a photo of the hairstyle posted on
--------------------------------------------------
Zeropoint model:
I have a dream of creating two full-time jobs in America&#8212;one for people with mental health issues, and one for people who do not suffer from mental illness&#8212;or at least have an employment and family history of substance abuse, to work part</code></pre><p>Instead of trying to see if one output makes more sense than the others, we can quantify it by calculating the <strong>perplexity</strong> of each output. This is a common metric used to evaluate language models, which measures the uncertainty of a model in predicting the next token in a sequence. In this comparison, we make the common assumption that the lower the score, the better the model is. In practice, a sentence with a high perplexity could also be correct.</p><p>We implement it using a minimal function since it doesn&#8217;t need to consider details like the length of the context window since our sentences are short.</p><pre><code>def calculate_perplexity(model, text):
    # Encode the text
    encodings = tokenizer(text, return_tensors='pt').to(device)

    # Define input_ids and target_ids
    input_ids = encodings.input_ids
    target_ids = input_ids.clone()

    with torch.no_grad():
        outputs = model(input_ids, labels=target_ids)

    # Loss calculation
    neg_log_likelihood = outputs.loss

    # Perplexity calculation
    ppl = torch.exp(neg_log_likelihood)

    return ppl

ppl     = calculate_perplexity(model, original_text)
ppl_abs = calculate_perplexity(model_abs, absmax_text)
ppl_zp  = calculate_perplexity(model_zp, absmax_text)

print(f"Original perplexity:  {ppl.item():.2f}")
print(f"Absmax perplexity:    {ppl_abs.item():.2f}")
print(f"Zeropoint perplexity: {ppl_zp.item():.2f}")</code></pre><pre><code>Original perplexity:  15.53
Absmax perplexity:    17.92
Zeropoint perplexity: 17.97</code></pre><p>We see that the perplexity of the original model is <strong>slightly lower</strong> than the two others. A single experiment is not very reliable, but we could repeat this process multiple times to see the difference between each model. In theory, zero-point quantization should be slightly better than absmax, but is also more costly to compute.</p><p>In this example, we applied quantization techniques to entire layers (per-tensor basis). However, we could apply it at different granularity levels: from the entire model to individual values. Quantizing the entire model in one pass would seriously degrade the performance, while quantizing individual values would create a big overhead. In practice, we often prefer the <strong>vector-wise quantization</strong>, which considers the variability of values in rows and columns inside of the same tensor.</p><p>However, even vector-wise quantization doesn&#8217;t solve the problem of outlier features. Outlier features are extreme values (negative or positive) that appear in all transformer layers when the model reach a certain scale (&gt;6.7B parameters). This is an issue since a single outlier can reduce the precision for all other values. But discarding these outlier features is not an option since it would <strong>greatly degrade</strong> the model&#8217;s performance.</p><h3>&#128290; 8-bit Quantization with LLM.int8()</h3><p>Introduced by <a href="https://arxiv.org/abs/2208.07339">Dettmers et al. (2022)</a>, LLM.int8() is a solution to the outlier problem. It relies on a vector-wise (absmax) quantization scheme and introduces mixed-precision quantization. This means that outlier features are processed in a FP16 format to retain their precision, while the other values are processed in an INT8 format. As outliers represent about 0.1% of values, this effectively reduces the memory footprint of the LLM by almost 2x.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!YgmE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 424w, /__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 848w, /__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!YgmE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 424w, /__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 848w, /__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 1272w, /__u/substackcdn.com/image/fetch/$s_!YgmE!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcc191403-ad0a-4d56-afd0-37d34ea891c2_800x274.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>LLM.int8() works by conducting matrix multiplication computation in three key steps:</p><ol><li><p>Extract columns from the input hidden states <strong>X</strong> containing outlier features using a custom threshold.</p></li><li><p>Perform the matrix multiplication of the outliers using FP16 and the non-outliers using INT8 with vector-wise quantization (row-wise for the hidden state <strong>X</strong> and column-wise for the weight matrix <strong>W</strong>).</p></li><li><p>Dequantize the non-outlier results (INT8 to FP16) and add them to the outlier results to get the full result in FP16.</p></li></ol><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!lkH1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 424w, /__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 848w, /__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!lkH1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 424w, /__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 848w, /__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 1272w, /__u/substackcdn.com/image/fetch/$s_!lkH1!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F09df01fd-48f2-4b81-bd2f-404a7e4bb4bd_1200x679.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Image by&nbsp;author</figcaption></figure></div><p>This approach is necessary because 8-bit precision is limited and can lead to substantial errors when quantizing a vector with large values. These errors also tend to amplify as they propagate through multiple layers.</p><p>We can easily use this technique thanks to the integration of the <code>bitsandbytes</code> library into the Hugging Face ecosystem. We just need to specify <code>load_in_8bit=True</code> when loading the model (it also requires a GPU).</p><pre><code>device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

model_int8 = AutoModelForCausalLM.from_pretrained(model_id,
                                             device_map='auto',
                                             load_in_8bit=True,
                                             )
print(f"Model size: {model_int8.get_memory_footprint():,} bytes")</code></pre><pre><code>Model size: 176,527,896 bytes</code></pre><p>With this extra line of code, the model is now almost three times smaller (168MB vs. 487MB). We can even compare the distribution of the original and quantized weights as we did earlier:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="/__u/substackcdn.com/image/fetch/$s_!fPhL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="/__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 424w, /__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 848w, /__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_webp, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 1456w" sizes="100vw"><img src="/__u/substackcdn.com/image/fetch/$s_!fPhL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e42f72af-4d9f-401c-955d-4355c1554a40_800x393.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:null,&quot;width&quot;:null,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:null,&quot;href&quot;:null,&quot;belowTheFold&quot;:true,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="/__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_424, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 424w, /__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_848, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 848w, /__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_1272, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 1272w, /__u/substackcdn.com/image/fetch/$s_!fPhL!, /__u/maximelabonne.substack.com/w_1456, /__u/maximelabonne.substack.com/c_limit, /__u/maximelabonne.substack.com/f_auto, /__u/maximelabonne.substack.com/q_auto:good, /__u/maximelabonne.substack.com/fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe42f72af-4d9f-401c-955d-4355c1554a40_800x393.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>In this case, we see spikes around -2, -1, 0, 1, 2, etc. These values correspond to the parameters stored in the INT8 format (non-outliers). You can verify it by printing the model&#8217;s weights using <code>model_int8.parameters()</code>.</p><p>We can also generate text with this quantized model and compare it to the original model.</p><pre><code># Generate text with quantized model
text_int8 = generate_text(model_int8, "I have a dream")

print(f"Original model:\n{original_text}")
print("-" * 50)
print(f"LLM.int8() model:\n{text_int8}")</code></pre><pre><code>Original model:
I have a dream, and it is a dream I believe I would get to live in my future. I love my mother, and there was that one time I had been told that my family wasn't even that strong. And then I got the
--------------------------------------------------
LLM.int8() model:
I have a dream. I don't know what will come of it, but I am going to have to look for something that will be right. I haven't thought about it for a long time, but I have to try to get that thing</code></pre><p>Once again, it is difficult to judge what is the best output, but we can rely on the perplexity metric to give us an (approximate) answer.</p><pre><code>print(f"Perplexity (original):   {ppl.item():.2f}")

ppl = calculate_perplexity(model_int8, text_int8)
print(f"Perplexity (LLM.int8()): {ppl.item():.2f}")</code></pre><pre><code>Perplexity (original):   15.53
Perplexity (LLM.int8()): 7.93</code></pre><p>In this case, the perplexity of the quantized model is twice as low as the original one. In general, this is not the case, but it shows that this quantization technique is very competitive. In fact, the authors of LLM.int8() show that the performance degradation is so low it&#8217;s negligible (&lt;1%). However, it has an additional cost in terms of computation: LLM.int8() is roughly about 20% slower for large models.</p><h3>Conclusion</h3><p>This article provided an overview of the most popular weight quantization techniques. We started by gaining an understanding of floating point representation, before introducing two techniques for 8-bit quantization: <strong>absmax</strong> and <strong>zero-point quantization</strong>. However, their limitations, particularly when it comes to handling outliers, led to <strong>LLM.int8()</strong>, a technique that also preserves the model&#8217;s performance. This approach underlines the progress being made in the field of weight quantization, revealing the importance of properly addressing outliers.</p><p>Looking forward, our next article will explore the GPTQ weight quantization technique in depth. This technique, introduced by <a href="https://arxiv.org/abs/2210.17323">Frantar et al.</a>, only utilizes 4 bits and represents a significant advancement in the field of weight quantization. We will provide a comprehensive guide on how to implement GPTQ using the AutoGPTQ library.</p><p>If you&#8217;re interested in more technical content around LLMs, follow me on Twitter <a href="https://twitter.com/maximelabonne">@maximelabonne</a>.</p><h3>References</h3><ul><li><p>T. Dettmers, M. Lewis, Y. Belkada, and L. Zettlemoyer, <a href="https://arxiv.org/abs/2208.07339">LLM.int8(): 8-bit Matrix Multiplication for Transformers at Scale</a>. 2022.</p></li><li><p>Y. Beldaka, and T. Dettmers, <a href="https://huggingface.co/blog/hf-bitsandbytes-integration">A Gentle Introduction to 8-bit Matrix Multiplication</a>, Hugging Face Blog (2022).</p></li><li><p>A. Gholami, S. Kim, Z. Dong, Z. Yao, M. W. Mahoney, and K. Keutzer, <a href="https://arxiv.org/abs/2103.13630">A Survey of Quantization Methods for Efficient Neural Network Inference</a>. 2021.</p></li><li><p>H. Wu, P. Judd, X. Zhang, M. Isaev, and P. Micikevicius, <a href="https://arxiv.org/abs/2004.09602">Integer Quantization for Deep Learning Inference: Principles and Empirical Evaluation</a>. 2020.</p></li><li><p>Lilian Weng, <a href="https://lilianweng.github.io/posts/2023-01-10-inference-optimization/">Large Transformer Model Inference Optimization</a>, Lil&#8217;Log (2023).</p></li><li><p>Kamil Czarnogorski, <a href="https://int8.io/local-large-language-models-beginners-guide/">Local Large Language Models</a>, Int8 (2023).</p></li></ul>]]></content:encoded></item></channel></rss>