<?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[Tensor Economics]]></title><description><![CDATA[We delve into the money behind AI]]></description><link>https://www.tensoreconomics.com</link><image><url>https://www.tensoreconomics.com/img/substack.png</url><title>Tensor Economics</title><link>https://www.tensoreconomics.com</link></image><generator>Substack</generator><lastBuildDate>Wed, 08 Apr 2026 19:22:51 GMT</lastBuildDate><atom:link href="https://www.tensoreconomics.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Piotr Mazurek]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[tensoreconomics@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[tensoreconomics@substack.com]]></itunes:email><itunes:name><![CDATA[Piotr Mazurek]]></itunes:name></itunes:owner><itunes:author><![CDATA[Piotr Mazurek]]></itunes:author><googleplay:owner><![CDATA[tensoreconomics@substack.com]]></googleplay:owner><googleplay:email><![CDATA[tensoreconomics@substack.com]]></googleplay:email><googleplay:author><![CDATA[Piotr Mazurek]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[AI infrastructure in the "Era of experience"]]></title><description><![CDATA[Intelligence involution, economies of scale in RL, everything async and multi-turn.]]></description><link>https://www.tensoreconomics.com/p/ai-infrastructure-in-the-era-of-experience</link><guid isPermaLink="false">https://www.tensoreconomics.com/p/ai-infrastructure-in-the-era-of-experience</guid><dc:creator><![CDATA[Piotr Mazurek]]></dc:creator><pubDate>Wed, 26 Nov 2025 19:08:16 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!xOXa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the famous essay from May 2025, &#8220;<a href="https://storage.googleapis.com/deepmind-media/Era-of-Experience%20/The%20Era%20of%20Experience%20Paper.pdf">Welcome to the Era of Experience</a>,&#8221; Rich Sutton and David Silver proposed a new paradigm of training AI models - models that learn not through predicting the next word against text scraped from Common Crawl, but through gaining experience via interaction with environments. <a href="https://www.youtube.com/watch?v=YD-9NG1Ke5Y">As we approach the exhaustion of easily scrapable text data</a>, we predict we&#8217;ll observe a shift toward AI models increasingly trained in this fashion via reinforcement learning (RL). In this text, we discuss the technical details underpinning this process.  </p><p>The text proceeds as follows: First, we introduce the concept of intelligence involution and discuss its consequences and why there is currently a strong incentive for custom RL models; then, we explain the basic principles behind GRPO; we briefly explain why RL training is so information sparse; and we do a deep dive into LoRA and the compute advantages of training and inference it unlocks. Then in the last section we discuss the broader implications; we show how the tech foundation can enable the emergence of the reinforcement fine-tuning (RFT) industry; we highlight where economies of scale can be realized and what some potential first applications of custom models are. We mention the remaining open challenges and the fundamental limitations that can potentially make RFT a similar flop as the first wave of SFT has been. </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tensoreconomics.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Tensor Economics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>We intend this text to provide the reader with the theoretical basis needed to reason about AI infrastructure in the context of reinforcement learning. We argue that in the next 6-12 months there are significant opportunities for new businesses to be built around recent developments in RL, particularly for product companies to build sustainable moats through custom models trained on their proprietary environments, as well as for infrastructure players to build &#8220;picks and shovels&#8221; enabling the RL economy.</p><h2>Intelligence involution and its consequences</h2><p>As of late 2025, it appears that the gap between available LLMs is extremely small. There are marginal differences between proprietary LLMs, with some models slightly stronger in some niches like <a href="https://eqbench.com/creative_writing.html">creative writing</a> or <a href="https://www.swebench.com/">coding</a>, but overall differences seem to be diminishing over time. Moreover, the gap between open-source and proprietary models is rapidly closing. EpochAI estimates (see Fig. 1) the lag at around three months; with Kimi K2 Thinking&#8217;s release, <a href="https://x.com/ArtificialAnlys/status/1986541785511043536">some argue</a> the gap has largely closed<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SeNy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SeNy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 424w, https://substackcdn.com/image/fetch/$s_!SeNy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 848w, https://substackcdn.com/image/fetch/$s_!SeNy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!SeNy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SeNy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg" width="1456" height="1073" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1073,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Image&quot;,&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="Image" title="Image" srcset="https://substackcdn.com/image/fetch/$s_!SeNy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 424w, https://substackcdn.com/image/fetch/$s_!SeNy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 848w, https://substackcdn.com/image/fetch/$s_!SeNy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!SeNy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54fc65a-16fe-4924-a54e-788f7b1818b9_2400x1769.jpeg 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 role="img" 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><title></title><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">Figure 1: The grate between open-weight models and closed weights models keep closing. Sourced from <a href="https://epoch.ai/data-insights/open-weights-vs-closed-weights-models">Epoch.ai</a></figcaption></figure></div><p>Interestingly, China now leads open-source development. Chinese models have overtaken Western ones in cumulative downloads worldwide (see Fig. 2). While downloads aren&#8217;t a perfect proxy for popularity<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>, the Twitter &#8220;vibe check&#8221; seems to confirm this. These days, every RL experiment appears built on Qwen. Recently, <a href="https://x.com/cursor_ai/status/1983567619946147967">Cursor</a> and <a href="https://x.com/cognition/status/1978867021669413252">Windsurf</a> <a href="https://x.com/auchenberg/status/1983901551048470974">appear to</a> have built their models on top of Chinese foundations as well. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pjOu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pjOu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 424w, https://substackcdn.com/image/fetch/$s_!pjOu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 848w, https://substackcdn.com/image/fetch/$s_!pjOu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 1272w, https://substackcdn.com/image/fetch/$s_!pjOu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pjOu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png" width="1456" height="713" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:713,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:null,&quot;alt&quot;:&quot;Image&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="Image" title="Image" srcset="https://substackcdn.com/image/fetch/$s_!pjOu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 424w, https://substackcdn.com/image/fetch/$s_!pjOu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 848w, https://substackcdn.com/image/fetch/$s_!pjOu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.png 1272w, https://substackcdn.com/image/fetch/$s_!pjOu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F77dd50af-668d-4557-b8b6-8eda842c5f90_1460x715.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 role="img" 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><title></title><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">Figure 2: China has overtaken the US in cumulative open-source AI model downloads: <a href="https://x.com/a16z/status/1984300599018733607/photo/1">A16Z twitter</a> </figcaption></figure></div><p>There are dozens of Chinese labs in this space, and it seems like every week a Chinese <a href="https://x.com/Meituan_LongCat/status/1984398560973242733">food delivery</a> company or <a href="https://x.com/XiaomiMiMo/status/1953820453723943146">consumer electronics firm</a> releases a competitive AI model. Next-token prediction appears to share characteristics with EVs, solar panels, or batteries - where Chinese &#8220;capital markets&#8221; are capable of supporting dozens of entities that relentlessly compete with each other, continuously driving down the price per unit of intelligence, glutting international markets, and <strong>making it close to impossible for competitors abroad to make any revenue with models not at the absolute bleeding edge</strong><a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>. While OpenAI, Anthropic and Google remain ahead and this doesn&#8217;t yet apply to them, if the trend continues, it seems inevitable their margins will eventually be affected.</p><p>We refer to this phenomenon as <strong>intelligence involution</strong>, where - <a href="https://www.ft.com/content/5f73d241-41f6-45d7-b8dd-1b35f2dd1349">similar to EVs</a> or solar - competition is so fierce that everyone makes close to zero profits, <strong>moats only come from scale</strong>, and the pace of competition slowly bleeds out anyone not at the absolute frontier. </p><p>Since competition is so fierce, it continuously drives down the price of tokens. For example, DeepSeek during the transition from v3 to v3.2 dropped prices from $2.19 to $0.42 per million output tokens - 5x cost reduction in a span of a few months while simultaneously boosting general model capabilities. </p><p>With competition in general-purpose models this brutal, requiring absolute frontier performance to generate any substantial revenue, <strong>the</strong> <strong>obvious choice for less sophisticated players seeking quick profits is model specialization</strong>: targeting a niche that should be more defensible than competing in the foundation model space.</p><p>Traditionally, companies specialized foundation models through Supervised Fine-Tuning (SFT). The approach was straightforward: collect input-output pairs for your domain, then retrain the model to mimic those outputs. However, as we enter the era of reasoning, SFT is being squeezed out of relevance by a &#8220;pincer movement&#8221; - it is becoming economically irrational for simple tasks and technically insufficient for complex ones.</p><p>For static knowledge or stylistic specialization, SFT has become largely unnecessary. Modern base models are now powerful enough that in-context examples (few-shot prompting) match fine-tuned performance without the complexity of managing model weights.</p><p>With the commoditization of prompt caching, this approach is also much cheaper. As of late 2025, caching allows us to &#8220;pin&#8221; massive instructions into memory at near-zero cost. For example, as of November 2025, <a href="https://api-docs.deepseek.com/quick_start/pricing">DeepSeek charges</a> $0.028 per million cached tokens. Storing 10,000 tokens of examples in the prompt and serving 1 million requests costs just $280 in caching fees:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{\\$0.028}{\\text{1M tokens}} \\times \\text{10,000 tokens in prompt} \\times \\text{1,000,000 requests} = \\$280&quot;,&quot;id&quot;:&quot;UTGYWKWRTH&quot;}" data-component-name="LatexBlockToDOM"></div><p>This is potentially cheap enough to eliminate the need for SFT entirely for straightforward tasks. Fine-tuning a custom model for the same task would cost thousands in compute and engineering time, only to yield a model that becomes obsolete the moment a better base model is released.</p><p>While caching kills SFT at the low end, the &#8220;Reasoning Data Barrier&#8221; kills it at the high end. Even if human data were available, SFT creates a fundamental ceiling: it limits models to mimicking human baselines rather than discovering novel strategies that surpass them. As per the <a href="https://storage.googleapis.com/deepmind-media/Era-of-Experience%20/The%20Era%20of%20Experience%20Paper.pdf">era of experience</a>, there are certain problems for which prompt-answer pairs simply do not exist. The only way to discover the right reasoning chains or tool sequences is for the model to interact with an external environment and observe the effects of its actions. Based on these observations, the model&#8217;s behavior is adjusted iteratively. Critically, we explicitly assume the correct steps are unknown upfront and can only be learned through interaction - by observing how the environment responds and adjusting accordingly.</p><p>The challenge intensifies with tool-calling and agentic workflows. When models need to orchestrate multiple tools - whether executing Python code, performing web searches, calling APIs like the SharePoint MCP server, or any other programmatic action (see Fig. 3) - the correct sequence of tool invocations and their specific parameters must be discovered through trial and error. Manually creating training examples for every possible toolchain and edge case quickly becomes infeasible.</p><p></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!m9pv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!m9pv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 424w, https://substackcdn.com/image/fetch/$s_!m9pv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 848w, https://substackcdn.com/image/fetch/$s_!m9pv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 1272w, https://substackcdn.com/image/fetch/$s_!m9pv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!m9pv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png" width="630" height="353.0769230769231" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:816,&quot;width&quot;:1456,&quot;resizeWidth&quot;:630,&quot;bytes&quot;:252577,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!m9pv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 424w, https://substackcdn.com/image/fetch/$s_!m9pv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 848w, https://substackcdn.com/image/fetch/$s_!m9pv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.png 1272w, https://substackcdn.com/image/fetch/$s_!m9pv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F92f389b2-be61-4be4-8664-c4af7e02c925_1758x985.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 role="img" 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><title></title><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">Figure 3: Example of two different RL rollouts involving different tool calls. LLM can take multiple paths, involving different tools used at different timestamps to achieve the final goal. Source: Building Cursor Composer with Sasha Rush, <a href="https://www.youtube.com/watch?v=md8D8eNj5JM">YouTube</a>.</figcaption></figure></div><p>This creates a natural opening for custom models. Many companies would prefer to own their intelligence stack entirely - for data privacy, cost control, and because they don&#8217;t want to depend on vendors whose priorities and pricing might shift unpredictably. Previously, this wasn&#8217;t feasible: building competitive models required frontier-level base intelligence that only a handful of labs had.</p><p><strong>Intelligence involution changes this calculus fundamentally. With open-source models now matching proprietary performance at a fraction of the cost, companies can build defensible RL-specialized models on top of these commodity foundations.</strong> The moat comes not from superior base intelligence - which is rapidly commoditizing - but from proprietary access to specialized environments and the continuous learning loops within them. These environments are unique and proprietary: a company&#8217;s internal research infrastructure spanning SharePoint, Confluence, and legacy enterprise systems; an e-commerce platform&#8217;s feedback loop where model behavior is continuously refined based on observed customer actions; a SaaS product&#8217;s onboarding flow that adapts based on real user engagement patterns, etc. None of these can be replicated by GPT-5 simply because OpenAI never had access to these interactions during training.</p><p>However, this defensibility comes at a cost of scale. Training a model for a specific environment to solve a specific problem is inherently less scalable than a single base model like the one powering ChatGPT, where hundreds of millions of users interact with the same foundation model, controlled purely through prompting.</p><p>To understand the cost structure and opportunities in RL, we need to examine how these models are actually trained. This requires introducing a few key concepts: GRPO, LoRA, and the fundamental information-theoretic principles that make RL feasible at scale.</p><h2>GRPO 101</h2><p>The &#8220;renaissance&#8221; of RL for large language models (LLMs) can be traced back to the introduction of <em>Group Relative Policy Optimization (GRPO</em>) in <em><a href="https://arxiv.org/pdf/2402.03300">DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models</a> </em>in April 2024. GRPO was the fundamental technique that enormously simplified running reinforcement learning with verifiable rewards (RLVR)-type training. Later it was applied in the famous <a href="https://arxiv.org/abs/2501.12948">DeepSeek R1</a> model that <a href="https://www.reuters.com/technology/artificial-intelligence/chinas-deepseek-sparks-ai-market-rout-2025-01-27/">shook the global financial markets</a> in January 2025.</p><p>The GRPO algorithm is conceptually quite simple; it can be compressed to 12 lines of pseudo-code (see Fig. 4). The main innovation comes from the fact that, in contrast to previous RL methods like <a href="https://arxiv.org/abs/1707.06347">PPO</a>, it is far simpler to implement. There is no need to train a separate critic model, and as measured empirically, it proves to be much more stable and sample efficient. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HgNT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HgNT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 424w, https://substackcdn.com/image/fetch/$s_!HgNT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 848w, https://substackcdn.com/image/fetch/$s_!HgNT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 1272w, https://substackcdn.com/image/fetch/$s_!HgNT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HgNT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png" width="1146" height="503" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:503,&quot;width&quot;:1146,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:127188,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HgNT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 424w, https://substackcdn.com/image/fetch/$s_!HgNT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 848w, https://substackcdn.com/image/fetch/$s_!HgNT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.png 1272w, https://substackcdn.com/image/fetch/$s_!HgNT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F784bc560-4edc-43d3-a9fc-5b2392431abd_1146x503.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 role="img" 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><title></title><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">Figure 4: GRPO algorithm; <a href="https://arxiv.org/pdf/2402.03300">arxiv</a></figcaption></figure></div><p>While it might seem complicated at first glance if the reader is unfamiliar with RL notation, upon closer inspection it is pretty simple. In Tab. 1 we present a detailed explanation and example values for all symbols in the algorithm from Fig. 4. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!08N1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!08N1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 424w, https://substackcdn.com/image/fetch/$s_!08N1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 848w, https://substackcdn.com/image/fetch/$s_!08N1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 1272w, https://substackcdn.com/image/fetch/$s_!08N1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!08N1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png" width="1021" height="343" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:343,&quot;width&quot;:1021,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:96375,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!08N1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 424w, https://substackcdn.com/image/fetch/$s_!08N1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 848w, https://substackcdn.com/image/fetch/$s_!08N1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.png 1272w, https://substackcdn.com/image/fetch/$s_!08N1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd1d0e6e4-902e-40d2-9aa5-180df2093f7a_1021x343.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 role="img" 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><title></title><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">Table 1: Notation and Variables Used in Group Relative Policy Optimization</figcaption></figure></div><p>GRPO is an example of so called <strong>gradient policy optimization algorithm. </strong>We use this name to refer to reinforcement learning methods that directly adjust a policy&#8217;s (model`s) parameters using gradients to maximize expected cumulative rewards. In gradient policy optimization algorithm we traditionally have two phases: </p><ul><li><p><strong>Rollout generation:</strong> Using the current policy, we generate outputs. For LLMs, a <strong>rollout is the sequence of tokens</strong> produced for a given prompt (see variable `outputs` in Fig. 5).</p></li><li><p><strong>Optimization step</strong>: We evaluate the generated rollout with a reward signal, then use the gradient of the policy (which shows how to change parameters to increase reward) to adjust the model parameters.</p></li></ul><p>In GRPO, for each prompt we sample G answers, calculate the average reward for this group, and subtract it from each individual reward to get the advantage - hence the name &#8220;group relative&#8221; policy optimization (see Fig. 5).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9DbG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9DbG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 424w, https://substackcdn.com/image/fetch/$s_!9DbG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 848w, https://substackcdn.com/image/fetch/$s_!9DbG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 1272w, https://substackcdn.com/image/fetch/$s_!9DbG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9DbG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png" width="470" height="474.1083916083916" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1154,&quot;width&quot;:1144,&quot;resizeWidth&quot;:470,&quot;bytes&quot;:226930,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9DbG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 424w, https://substackcdn.com/image/fetch/$s_!9DbG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 848w, https://substackcdn.com/image/fetch/$s_!9DbG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.png 1272w, https://substackcdn.com/image/fetch/$s_!9DbG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F33e8f4c8-b9f4-4e07-90d8-d3d79c60264e_1144x1154.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 role="img" 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><title></title><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">Figure 5: Advantage calculation in GRPO for the prompt &#8220;Solve: 2x + 3 = 7&#8221; with group size G=4. For each output, the advantage is computed as its reward minus the group&#8217;s mean reward (0.55 in this example).</figcaption></figure></div><p>During the training step, we first calculate the ratio of log-probabilities: new policy divided by old policy (see Fig. 6). We apply PPO-style clipping to this ratio, preventing the model from diverging too far from its previous version (previous optimization step). This clipped ratio is then multiplied by the advantage. As shown in Fig. 5, the advantage measures how much better (or worse) each completion performs relative to the group mean, to other completions for this exact prompt.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!usF2!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!usF2!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 424w, https://substackcdn.com/image/fetch/$s_!usF2!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 848w, https://substackcdn.com/image/fetch/$s_!usF2!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 1272w, https://substackcdn.com/image/fetch/$s_!usF2!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!usF2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png" width="1456" height="967" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:967,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:240015,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!usF2!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 424w, https://substackcdn.com/image/fetch/$s_!usF2!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 848w, https://substackcdn.com/image/fetch/$s_!usF2!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.png 1272w, https://substackcdn.com/image/fetch/$s_!usF2!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd9e673f4-fafd-4236-a286-b3582750a525_1514x1006.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 role="img" 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><title></title><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">Figure 6: GRPO loss calculation for each token. The advantage A[i] is the same for all tokens in a given output o_i. The loss combines a PPO-style clipped objective (preventing large policy updates) with a KL penalty term that keeps the policy close to a reference model.</figcaption></figure></div><p>The core idea behind every RL algorithm is to shift the model&#8217;s weights, so that high-scoring outputs become more likely and low-scoring ones become less so. </p><p>A key <strong>limitation specific to GRPO</strong> is that, unlike methods with a learned Critic (like PPO), it assigns the same advantage to all tokens in a sequence. While this means equal credit is assigned even in mixed-quality outputs- for example, in a multi-turn WORDLE game where the model guesses incorrectly for three turns but succeeds on the fourth - we accept this approximation because it removes the massive overhead of a value model. In practice, <a href="https://arxiv.org/abs/2402.03300">DeepSeek observed</a> that this coarser heuristic is not only significantly cheaper to calculate, but often leads to more stable training dynamics than trying to learn a complex token-level value function.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align*}\n\\textbf{1. The Rollout} &amp; \\\\\n\\text{Question } (q): &amp; \\quad \\text{\&quot;The secret word is } \\textbf{(LIGHT)}\\text{.\&quot;} \\\\\n\\text{Output } (o_i): &amp; \\quad [\\; \\underbrace{\\texttt{XYLOL}}_{\\color{red}{\\text{Step 1: Nonsense}}} \\;\\; \\rightarrow \\;\\; \\underbrace{\\texttt{LIGHT}}_{\\color{green}{\\text{Step 2: Correct}}} \\;] \\\\[1.5em]\n\\textbf{2. The Score} &amp; \\\\\n\\text{Reward } (r_i) - \\text{Baseline} &amp; = \\text{Advantage } (\\hat{A}_{i,t}) \\\\\n1.0 \\quad - \\quad 0.2 \\quad &amp; = \\quad \\mathbf{+0.8} \\\\[1.5em]\n\\textbf{3. The Optimization Issue} &amp; \\\\\n\\text{Gradient Update } (\\Delta \\theta) &amp; \\propto \\hat{A}_{i,t} \\cdot \\sum \\nabla \\log \\pi_\\theta(\\text{token}) \\\\\n&amp; = \\underbrace{\\mathbf{(+0.8)} \\cdot \\nabla \\log \\pi_\\theta({\\color{red}\\texttt{XYLOL}})}_{\\text{Problem: Reinforces Garbage}} \\\\\n&amp; \\quad + \\underbrace{\\mathbf{(+0.8)} \\cdot \\nabla \\log \\pi_\\theta({\\color{green}\\texttt{LIGHT}})}_{\\text{Desired: Reinforces Solution}}\n\\end{align*}&quot;,&quot;id&quot;:&quot;DDBSQSTIUL&quot;}" data-component-name="LatexBlockToDOM"></div><h2>Just 1 bit per rollout</h2><p>The &#8220;defining&#8221; blog-post of the recent boom in RL is &#8220;<em><a href="https://thinkingmachines.ai/blog/lora/">LoRA Without Regret</a>&#8221; </em>by John Schulman and the Thinking Machines team. The argument the authors make is that because<strong> policy gradient methods (like GRPO) are so information sparse (only 1 bit per rollout) LoRA adapters have enough capacity (enough parameters) to efficiently learn all of this information</strong> without the need to modify the original model parameters. This has profound implications for both training and inference which we discuss in detail in the next section. </p><p>As the authors put it:</p><blockquote><p>&#8230; when we get a few key details right, LoRA learns with the same sample efficiency as FullFT and achieves the same ultimate performance.</p></blockquote><p>The intuition behind this goes as follows. In GRPO, the gradient update for each rollout is proportional to</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\nabla_\\theta \\mathcal{L} \\propto \\nabla_\\theta \\log \\pi_\\theta(o_i | q) \\times \\hat{A}_i&quot;,&quot;id&quot;:&quot;ZAUMPUXAMK&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em>q</em> is the prompt, <em>o_i</em>&#8203; is the generated output (rollout), and <em>A_i</em>&#8203; is the advantage (reward minus group mean).</p><p>The gradient has two components:</p><p><strong>Direction</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\nabla_\\theta \\log \\pi_\\theta(o_i | q)&quot;,&quot;id&quot;:&quot;DYKIOQIQUQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>shows how to change the policy to make output <em>o_i</em>&#8203; more likely. This depends only on the current policy <em>&#960;</em>&#8203; and the sampled output&#8212;it contains <strong>zero information about the reward</strong>.</p><p><strong>Advantage</strong></p><p><em>A_i </em>s the same for all tokens in output <em>o_i</em>&#8203;. This scalar is where <strong>ALL information about the reward function</strong> resides. </p><p>By the <a href="https://en.wikipedia.org/wiki/Data_processing_inequality">data processing inequality</a>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Information in gradient} \\leq \\text{Information in advantage}&quot;,&quot;id&quot;:&quot;DASKOICYMZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>and:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Information in advantage} \\leq H(\\text{reward})&quot;,&quot;id&quot;:&quot;ENQLQRSGKL&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em>H </em>is <a href="https://en.wikipedia.org/wiki/Entropy">entropy</a> (the maximum information content). </p><p>While the calculated Advantage is technically a continuous real number (due to normalization against the group mean), its <strong>information content is bounded by the granularity of the reward function:</strong></p><p>If reward is binary (correct or incorrect)</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;H(Reward) = \\text{1 bit per trajectory}&quot;,&quot;id&quot;:&quot;WDCHUEYUAY&quot;}" data-component-name="LatexBlockToDOM"></div><p>If we have <strong>granular reward -</strong> the reward allows for partial credit (e.g., 5 levels: 0,0.25,0.5,0.75,1.0)</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;H(Reward)=log_2&#8203;(5)= \\text{2.3 bits per trajectory}&quot;,&quot;id&quot;:&quot;EXIGEQSAAH&quot;}" data-component-name="LatexBlockToDOM"></div><p>Depending on how &#8220;granular&#8221; your reward is it log_2(N) is the upper bound of what a single rollout provides. </p><p>This is much more sparse signal than the supervised training where each token provides ~1 bit of information, so training is way less efficient. It is possible that our rollout generates tens of thousands of tokens, and we put in hundreds of thousands of input tokens the tool calling, and all of this will be summarized into a few bits worth of information, requiring us to run tens of thousands of rollout to learn anything useful. </p><p>While this approach is inherently inefficient, as we previously discussed, in cases where we don&#8217;t know the correct labels, this &#8220;exploratory&#8221; approach seems to be the only one we know that works reliably.</p><p>The upside of this extreme information sparsity is that it can be efficiently encoded with very few parameters. To quote the Thinking Machines team:</p><blockquote><p><a href="https://arxiv.org/abs/2404.05405">Past work</a> has shown that neural networks can store 2 bits per parameter. These results pertain to the maximum amount of information absorbed in the long-training limit, not to the compute efficiency or rate of learning.</p></blockquote><p>The Thinky team showed (see Fig. 7) that LoRA adapters of fairly low ranks can learn from RL basically as well as full model fine-tuning. These results have since been independently replicated by many people in the community (see Fig. 8).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_jj-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_jj-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 424w, https://substackcdn.com/image/fetch/$s_!_jj-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 848w, https://substackcdn.com/image/fetch/$s_!_jj-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 1272w, https://substackcdn.com/image/fetch/$s_!_jj-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_jj-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png" width="1456" height="721" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:721,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:457793,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_jj-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 424w, https://substackcdn.com/image/fetch/$s_!_jj-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 848w, https://substackcdn.com/image/fetch/$s_!_jj-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.png 1272w, https://substackcdn.com/image/fetch/$s_!_jj-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa5b9152d-78bb-497f-a0c0-7c1e5b25b208_2626x1300.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 role="img" 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><title></title><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">Figure 7: &#8220;<em>Experiments on the DeepMath dataset with Qwen3-8b-base. In the left plot, we show the learning curve for different ranks and full fine-tuning. For each of these settings, we show the best learning rate, which results in the highest final performance. On the right, we plot learning rate vs final performance. As in our previous math experiments, LoRA seems to have a wider peak of near-optimal learning rates.</em>&#8220; <a href="https://thinkingmachines.ai/blog/lora/">Lora without regret</a>.</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!o_HZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!o_HZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 424w, https://substackcdn.com/image/fetch/$s_!o_HZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 848w, https://substackcdn.com/image/fetch/$s_!o_HZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 1272w, https://substackcdn.com/image/fetch/$s_!o_HZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!o_HZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png" width="490" height="360.96666666666664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:663,&quot;width&quot;:900,&quot;resizeWidth&quot;:490,&quot;bytes&quot;:280793,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!o_HZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 424w, https://substackcdn.com/image/fetch/$s_!o_HZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 848w, https://substackcdn.com/image/fetch/$s_!o_HZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.png 1272w, https://substackcdn.com/image/fetch/$s_!o_HZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6b3296a2-ab33-4516-ba1d-7990bcb65854_900x663.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 role="img" 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><title></title><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">Figure 8: One of the examples of community replicating the results observed by Thinky; <a href="https://x.com/zzlccc/status/1973612326747336767">twitter</a></figcaption></figure></div><p>This has profound implications for the economics of training and inference. LoRA makes it possible to train massive models on relatively modest hardware (within a single node), as long as the model parameters fit into memory. Moreover, if the model customization relies on LoRA adapters running on top of a single base model, this has significant effects on the economics of serving such models. It becomes possible to batch together multiple requests from multiple users, use a single base model, and assign different adapters to every request in the batch. This makes inference significantly more affordable. An inference provider might reuse a single base model for thousands of clients, each with their own custom adapter, serving their own custom-trained RL model.</p><p>In the next sections, we will delve into the details of why LoRA is so much more efficient in model training and why it has a much smaller memory footprint. We will then explain how multi-tenancy works in a modern inference engine and show how well such models perform and scale. <strong>We want to highlight once more the key insight: LoRA fine-tunings perform comparably to full model fine-tuning when trained with policy gradient methods such as GRPO (&#8220;no regret&#8221;)</strong>. Because the training signal is so information-sparse, there&#8217;s no penalty for training fewer parameters.</p><h2>Backpropagation and LoRA</h2><p>Before we proceed to training and inference, we should introduce the two concepts: </p><ul><li><p>How backpropagation in model training works.</p></li><li><p>How low-rank adaptation (LoRA) works.</p></li></ul><p>Let&#8217;s start with backpropagation. Consider a simple 2-layer neural network with <a href="https://en.wikipedia.org/wiki/Sigmoid_function">sigmoid</a> activation. The forward pass goes as follows: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n&amp;\\text{Input: } x \\text{ (or } a_0\\text{)}\\\\[0.5em]\n&amp;\\text{Layer 1: } z_1 = W^{(1)} x + b^{(1)}, \\text{ then } a_1 = \\sigma(z_1)\\\\[0.5em]\n&amp;\\text{Layer 2: } z_2 = W^{(2)} a_1 + b^{(2)}, \\text{ then } a_2 = \\sigma(z_2) \\text{ (output)}\\\\[0.5em]\n\\end{aligned}&quot;,&quot;id&quot;:&quot;IWDUOKLXVQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>Now if we intend to train the said network, we need to define some objective we want to minimize (<em>J</em>) and we will minimize it using <a href="https://en.wikipedia.org/wiki/Stochastic_gradient_descent">stochastic gradient descent (SGD)</a>. We want to optimize the parameters (weights) of the network to minimize our loss (the objective we defined). To find these values, we use the <a href="https://en.wikipedia.org/wiki/Chain_rule">chain rule</a>. </p><p>As a reminder, the chain rule states that for composite functions:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{d}{dx}h(g(x)) = h'(g(x)) \\cdot g'(x)&quot;,&quot;id&quot;:&quot;JMQUQEHDBI&quot;}" data-component-name="LatexBlockToDOM"></div><p>For multiple nested functions, we apply the chain rule repeatedly:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y = h(g(f(x))) \\quad \\Rightarrow \\quad \\frac{dy}{dx} = \\frac{dh}{dg} \\cdot \\frac{dg}{df} \\cdot \\frac{df}{dx}&quot;,&quot;id&quot;:&quot;UPRHRDRQCZ&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>A neural network is exactly this type of composition.</strong> Notice how our forward pass creates a chain of functions:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;x \\xrightarrow{W^{(1)}} z_1 \\xrightarrow{\\sigma} a_1 \\xrightarrow{W^{(2)}} z_2 \\xrightarrow{\\sigma} a_2 \\xrightarrow{J} \\text{loss}&quot;,&quot;id&quot;:&quot;JELPRSWMIO&quot;}" data-component-name="LatexBlockToDOM"></div><p>Hence to calculate the gradients we need to run the following steps:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n\\begin{aligned}\n&amp;\\text{1. Compute the cost: } J = \\frac{1}{2N} \\|y - a_2\\|_2^2\\\\[0.8em]\n&amp;\\text{2. Compute the derivative of cost with respect to } a_2\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial a_2} = \\frac{1}{N}(a_2 - y)\\\\[0.8em]\n&amp;\\text{3. Compute the derivative of cost with respect to } z_2\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial z_2} = \\frac{\\partial J}{\\partial a_2} \\cdot \\frac{\\partial a_2}{\\partial z_2} = \\frac{1}{N}(a_2 - y) \\cdot (a_2 \\cdot (1 - a_2))\\\\[0.8em]\n&amp;\\quad \\text{because } \\frac{\\partial a_2}{\\partial z_2} = a_2 \\cdot (1 - a_2) \\text{ as } a_2 = \\sigma(z_2)\n\\end{aligned}&quot;,&quot;id&quot;:&quot;ZCXDYSGYNC&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n&amp;\\text{4. Compute the derivative of cost with respect to } W^{(2)}\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial W^{(2)}} = \\frac{\\partial J}{\\partial z_2} \\cdot a_1\\\\\n&amp;\\quad \\text{because } \\frac{\\partial z_2}{\\partial W^{(2)}} = a_1 \\text{ as } z_2 = W^{(2)} a_1 + b^{(2)}\\\\[0.8em]\n&amp;\\text{5. Compute the derivative of cost with respect to } b^{(2)}\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial b^{(2)}} = \\frac{\\partial J}{\\partial z_2} \\cdot 1\\\\\n&amp;\\quad \\text{because } \\frac{\\partial z_2}{\\partial b^{(2)}} = 1 \\text{ as } z_2 = W^{(2)} a_1 + b^{(2)}\\\\[0.8em]\n&amp;\\text{6. Compute the derivative of cost with respect to } a_1\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial a_1} = \\frac{\\partial J}{\\partial z_2} \\cdot W^{(2)}\\\\\n&amp;\\quad \\text{because } \\frac{\\partial z_2}{\\partial a_1} = W^{(2)} \\text{ as } z_2 = W^{(2)} a_1 + b^{(2)}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;WNQLNJFLXU&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n&amp;\\text{7. Compute the derivative of cost with respect to } z_1\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial z_1} = \\frac{\\partial J}{\\partial a_1} \\cdot (a_1 \\cdot (1 - a_1))\\\\\n&amp;\\quad \\text{because } \\frac{\\partial a_1}{\\partial z_1} = a_1 \\cdot (1 - a_1) \\text{ as } a_1 = \\sigma(z_1)\\\\[0.8em]\n&amp;\\text{8. Compute the derivative of cost with respect to } W^{(1)}\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial W^{(1)}} = \\frac{\\partial J}{\\partial z_1} \\cdot x\\\\\n&amp;\\quad \\text{because } \\frac{\\partial z_1}{\\partial W^{(1)}} = x \\text{ as } z_1 = W^{(1)} x + b^{(1)}\\\\[0.8em]\n&amp;\\text{9. Compute the derivative of cost with respect to } b^{(1)}\\text{:}\\\\\n&amp;\\quad \\frac{\\partial J}{\\partial b^{(1)}} = \\frac{\\partial J}{\\partial z_1} \\cdot 1\\\\\n&amp;\\quad \\text{because } \\frac{\\partial z_1}{\\partial b^{(1)}} = 1 \\text{ as } z_1 = W^{(1)} x + b^{(1)}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;CUPYPCKSYU&quot;}" data-component-name="LatexBlockToDOM"></div><p>Notice how to calculate the gradient with respect to <em>W2</em> <strong>we need to store the values of intermediate activations - input to the layer 2, </strong><em><strong>a1</strong></em>. This requirement creates a significant memory burden: we must cache these intermediate activations during the forward pass to use them later in the backward pass. Crucially, this cost scales linearly with the batch size. For every additional example we process in parallel, we must allocate memory for its specific activations, explaining why increasing the batch size rapidly consumes available VRAM.</p><p>What is also important to notice is how much memory is consumed by storing the gradients of parameters. <strong>Since we need a gradient for every single weight in the layer it takes as much memory to store the gradients as it takes to store the weights themselves</strong>, further increasing the memory footprint. </p><p>In practice, estimating the memory footprint gets even more complicated. Some optimizers require additional memory - Adam, for example, stores momentum and variance estimates for each parameter, often doubling or tripling the memory needed beyond just weights and gradients. <strong>Our intention here is to provide the reader with intuitions on where compute and memory costs come from in model training, as this context is crucial for understanding why LoRA makes training more efficient.</strong></p><p>Under the hood, for the forward and backward pass, PyTorch implements the interface from Fig. 9. Notice how we need to cache the values of layer inputs (x) and how we need the values of the gradient with respect to the input from the next layer (grad_out) to come as an input parameter.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SyqX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SyqX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 424w, https://substackcdn.com/image/fetch/$s_!SyqX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 848w, https://substackcdn.com/image/fetch/$s_!SyqX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 1272w, https://substackcdn.com/image/fetch/$s_!SyqX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SyqX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png" width="728" height="365.5" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:731,&quot;width&quot;:1456,&quot;resizeWidth&quot;:728,&quot;bytes&quot;:261155,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SyqX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 424w, https://substackcdn.com/image/fetch/$s_!SyqX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 848w, https://substackcdn.com/image/fetch/$s_!SyqX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.png 1272w, https://substackcdn.com/image/fetch/$s_!SyqX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F15683ab3-fced-40e5-895a-fa689f0640e7_1852x930.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 role="img" 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><title></title><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">Figure 9: This is what&#8217;s actually happening when you use nn.Linear. Notice how the forward pass must cache x and weight, which are then used in the backward pass to compute gradients.</figcaption></figure></div><p>Looking at this, it is quite easy to see how we have to do roughly <strong>twice as many operations during the backward pass as we do during the forward. </strong>In the forward pass we need to do a single matrix multiplication  <em>W @ x; </em>in the backward pass we need to do two large-scale matrix multiplications, one to calculate the gradients with respect to weights and another to calculate gradients with respect to the inputs. </p><p><strong>LoRA</strong> (<a href="https://arxiv.org/abs/2106.09685">Low-Rank Adaptation</a>) is a popular efficient fine-tuning method. As we argued earlier, because of &#8220;no regret&#8221; property of gradient policy optimization methods, this is very likely how custom models of the future will be trained.</p><p>The idea behind LoRA is quite straightforward - instead of optimizing one big parameter matrix <em>W</em>, we freeze it and learn a low-rank update through two much smaller matrices, A and B.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\nW_{\\text{effective}} &amp;= W_{\\text{frozen}} + \\underbrace{B}_{d_{\\text{out}} \\times r} \\underbrace{A}_{r \\times d_{\\text{in}}} \\\\\nz &amp;= W_{\\text{effective}} x\n\\end{aligned}&quot;,&quot;id&quot;:&quot;LITCTXJINP&quot;}" data-component-name="LatexBlockToDOM"></div><p>where matrix <em>A</em> is the &#8220;Down-projection&#8221; (rank <em>r</em> by input dim) and matrix <em>B</em> is the &#8220;Up-projection&#8221; (output dim by rank <em>r</em>).</p><p>During training we freeze the original parameter (meaning we don&#8217;t calculate gradients for it), and we only calculate the gradients for the small matrices A and B. Since they are so much smaller, the typical ranks range is 1 to 16 - they are 3 to 4 orders of magnitude smaller than the original matrix. </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\n\\frac{\\partial J}{\\partial W_{\\text{frozen}}} &amp;= 0 \\quad \\text{(frozen!)}\\\\\n\n\\frac{\\partial J}{\\partial B} &amp;= \\frac{\\partial J}{\\partial z} \\cdot (Ax)^T \\\\\n\n\\frac{\\partial J}{\\partial A} &amp;= B^T \\cdot \\frac{\\partial J}{\\partial z} \\cdot x^T\n\n\\end{aligned}&quot;,&quot;id&quot;:&quot;NZOUFKKVEE&quot;}" data-component-name="LatexBlockToDOM"></div><p>The result is, on one hand, a massively reduced memory footprint for training. We used to store <em>grad_weights</em> of size (<em>out_features</em>, <em>in_features</em>). For example in <a href="https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct/blob/main/config.json#L17">Llama3.3. 70B</a>, if we apply this to the down projection in the MLP layer, it comes to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;d_{\\text{intermediate}} \\times d_{\\text{hidden}} = 28{,}672 \\times 8{,}192 = 234{,}881{,}024 \\text{ parameters}&quot;,&quot;id&quot;:&quot;VZUGGLPRMQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>However, if instead of storing the gradients for the full parameters, we store the gradients for matrices A and B, assuming we use rank 1:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\n\\begin{aligned}\n\\text{LoRA with } r=1\\text{:} \\quad &amp; A \\in \\mathbb{R}^{1 \\times 8192}, \\, B \\in \\mathbb{R}^{28672 \\times 1}\\\\\n\\text{Parameters: } &amp; 8{,}192 + 28{,}672 = 36{,}864\\\\\n\\text{Fraction of full: } &amp; \\frac{36{,}864}{234{,}881{,}024} \\approx 0.016\\%\n\\end{aligned}\n&quot;,&quot;id&quot;:&quot;YYTDJXJUCF&quot;}" data-component-name="LatexBlockToDOM"></div><p>The savings are not limited to just a massively reduced memory footprint. They also apply to compute, which is substantially reduced. In LoRA, if we are slightly smart about the order of operations, the <em>grad_A</em> and <em>grad_B</em> matrix multiplications are very small compared to <em>grad_weight</em> in full model training, in way fewer FLOPs per backward pass (see Fig. 10). The only big matrix multiplication remaining is calculating gradients with respect to the input (<em>grad_x</em>). This means that <strong>the cost of the backward pass in LoRA is roughly half that of full model fine-tuning; if we include the forward pass, LoRA training is about 2/3 of the compute cost of full model trainin</strong>g (the forward pass has roughly the same compute cost in both cases).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nIzd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nIzd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 424w, https://substackcdn.com/image/fetch/$s_!nIzd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 848w, https://substackcdn.com/image/fetch/$s_!nIzd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 1272w, https://substackcdn.com/image/fetch/$s_!nIzd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nIzd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png" width="1396" height="1154" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1154,&quot;width&quot;:1396,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:265779,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nIzd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 424w, https://substackcdn.com/image/fetch/$s_!nIzd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 848w, https://substackcdn.com/image/fetch/$s_!nIzd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.png 1272w, https://substackcdn.com/image/fetch/$s_!nIzd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7222f354-989a-458f-baa6-473a935e65cb_1396x1154.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 role="img" 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><title></title><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">Figure 10: Under the hood of LoRA training. The backward pass only computes gradients for the small A and B matrices, dramatically reducing both memory and compute compared to full fine-tuning.</figcaption></figure></div><p>All of this means that training of relatively big models can be successfully done on even a single node. As long as the model weights fit in memory, we should be able to train MoE-style models with hundreds of billions of parameters. In full-model fine-tuning, storing the gradients and optimizer states balloons the memory footprint far beyond what a single node can handle, requiring multiple nodes, which significantly increases the training complexity. With the adoption of LoRA, training can be executed on a single node. With the adoption of LoRA, the training itself can be executed on a single node, while inference runs on another independent setup.</p><h2> Economies of scale in inference</h2><p>As the seasoned readers of our publication probably already know, <strong>LLM inference is primarily memory-bound</strong>, meaning that token throughput is mainly limited by the time it takes to load the model parameters into the GPU&#8217;s streaming multiprocessors (SMs) from GPU memory rather than by the time it takes to perform calculations within SMs. If the reader is unfamiliar with the concept of a <em><a href="https://en.wikipedia.org/wiki/Roofline_model">roofline model</a></em> and computation being compute-bound or memory-bound, we highly recommend our past article that introduces these concepts and explores them in detail in the context of LLM inference.</p><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;3f5822da-219b-4ccb-9edb-d9a175a9f446&quot;,&quot;caption&quot;:&quot;The main product LLM companies offer these days is access to their models via an API, and the key question that will determine the profitability they can enjoy is the inference cost structure. In this text we will explain where the cost of serving/hosting LLMs comes from, how many tokens can be produced by a GPU, and why this is the case. We will build &#8230;&quot;,&quot;cta&quot;:&quot;Read full story&quot;,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;LLM Inference Economics from First Principles&quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:272309052,&quot;name&quot;:&quot;Piotr Mazurek&quot;,&quot;bio&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/da276514-e5cf-40ad-bc26-27a8a735f355_400x400.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:296369667,&quot;name&quot;:&quot;Felix Gabriel&quot;,&quot;bio&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78848ce3-10ed-4d04-8a25-421aa396d56b_400x400.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2025-05-14T18:00:32.360Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!NPca!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.tensoreconomics.com/p/llm-inference-economics-from-first&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:163319195,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:85,&quot;comment_count&quot;:9,&quot;publication_id&quot;:4520903,&quot;publication_name&quot;:&quot;Tensor Economics&quot;,&quot;publication_logo_url&quot;:&quot;&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><p>Being memory-bound has pretty straightforward implications. In order to decrease the cost of producing a token, we need to increase the number of tokens produced within a unit of time. If producing a token means mainly waiting to load the model parameters, we can load them once and use the same loaded parameters to serve multiple queries in a single batch.</p><p>This increases the cumulative number of tokens produced sublinearly - throughput improves with batch size, but at a diminishing rate. As we increase the batch size, this comes at a cost: the speed individual users experience will decline over time, as demonstrated in Fig. 11. This is mostly due to the KV cache growing larger. As we increase the batch size, the KV cache starts to dominate the load time, and the improvements we observe diminish. However, as we increase the batch size, we saturate the available compute better, driving down the cost of producing an individual token, making it cheaper to serve.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LDgc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LDgc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 424w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 848w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LDgc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png" width="1456" height="697" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:697,&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="https://substackcdn.com/image/fetch/$s_!LDgc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 424w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 848w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.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 role="img" 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><title></title><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">Figure 11: Theoretical estimation of throughput at different batch sizes vs real world observations. 2000 tokens in, 300 tokens out. 4xH100 SXM5. Figure from &#8220;<em><a href="https://www.tensoreconomics.com/p/llm-inference-economics-from-first">LLM Inference Economics from First Principles</a></em>&#8221;. Note that the x axis is log scale and y is linear scale. </figcaption></figure></div><p>This is even more relevant in the case of Mixture of Experts (MoE) models - the most popular architecture of powerful models as of November 2025,. As we wrote in our previous article on MoE inference:</p><blockquote><p>During the decode phase, <strong>each token in the batch is activating only a small subset of parameters at every layer</strong>. This means that each request requires us to load a different part of the model, as demonstrated in Fig. 12. As the number of requests in a batch increases, a more and more substantial portion of the model will have to be loaded from global memory. The experts are chosen semi-stochastically<a href="https://www.tensoreconomics.com/p/moe-inference-economics-from-first#footnote-1-172205574">1</a>, so some of the tokens in the batch will be routed to the same expert. As we progressively increase the batch size, more and more experts will be shared by different requests. This means that at the larger batch sizes we will partially recreate the situation from the dense model - sharing the cost of model loading between multiple users. Unfortunately this means that we <strong>will need significantly more requests.</strong></p></blockquote><div class="digest-post-embed" data-attrs="{&quot;nodeId&quot;:&quot;1f3e56eb-88fe-44ff-a85a-86b3ee8a5255&quot;,&quot;caption&quot;:&quot;The release of first DeepSeek R1, then Kimi K2 and then DeepSeek V3.1 mixture-of-expert (MoE) models has firmly established them as the leading architecture of large language models (LLMs) at the intelligence frontier. Due to their massive size (1 trillion parameters and up) and sparse computation pattern, selectively activating parameter subsets rather&#8230;&quot;,&quot;cta&quot;:&quot;Read full story&quot;,&quot;showBylines&quot;:true,&quot;size&quot;:&quot;sm&quot;,&quot;isEditorNode&quot;:true,&quot;title&quot;:&quot;MoE Inference Economics from First Principles &quot;,&quot;publishedBylines&quot;:[{&quot;id&quot;:272309052,&quot;name&quot;:&quot;Piotr Mazurek&quot;,&quot;bio&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/da276514-e5cf-40ad-bc26-27a8a735f355_400x400.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null},{&quot;id&quot;:385653408,&quot;name&quot;:&quot;Eric Schreiber&quot;,&quot;bio&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e5d2469-01fd-4246-a063-674903b9a60a_946x946.jpeg&quot;,&quot;is_guest&quot;:false,&quot;bestseller_tier&quot;:null}],&quot;post_date&quot;:&quot;2025-09-02T18:00:14.544Z&quot;,&quot;cover_image&quot;:&quot;https://substackcdn.com/image/fetch/$s_!qHWN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png&quot;,&quot;cover_image_alt&quot;:null,&quot;canonical_url&quot;:&quot;https://www.tensoreconomics.com/p/moe-inference-economics-from-first&quot;,&quot;section_name&quot;:null,&quot;video_upload_id&quot;:null,&quot;id&quot;:172205574,&quot;type&quot;:&quot;newsletter&quot;,&quot;reaction_count&quot;:34,&quot;comment_count&quot;:6,&quot;publication_id&quot;:4520903,&quot;publication_name&quot;:&quot;Tensor Economics&quot;,&quot;publication_logo_url&quot;:&quot;&quot;,&quot;belowTheFold&quot;:true,&quot;youtube_url&quot;:null,&quot;show_links&quot;:null,&quot;feed_url&quot;:null}"></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DPs4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DPs4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 424w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 848w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 1272w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DPs4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png" width="1456" height="801" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.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;:380617,&quot;alt&quot;:&quot;&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!DPs4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 424w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 848w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 1272w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.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 role="img" 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><title></title><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">Figure 12: Two request tokens activating different parts of the model, requiring us to load more weights, saturating the memory bandwidth. Figure from &#8220;<em><a href="https://www.tensoreconomics.com/p/moe-inference-economics-from-first">MoE Inference Economics from First Principles</a></em>&#8221;</figcaption></figure></div><p>The main thing the reader should take away from this is that <strong>the key to good inference economics is large batches where we share the cost of loading the model weights between as many users as possible, achieving economies of scale of sorts.</strong></p><p>This need for large batches might be problematic when we serve custom model fine-tunings. If we were to do full model fine-tuning for a model used by a particular user, this would be very hard to achieve unless we can guarantee massive demand. Some providers have this luxury - for example, <a href="https://cursor.com/blog/2-0">Cursor Composer</a>  clearly has enough demand to achieve the necessary batch sizes - but if we are serving a model trained via RL by a smaller company to achieve superhuman performance at some niche task, it won&#8217;t be possible to find enough demand. Luckily for us, LoRA addresses this problem.</p><p>Throughout this text, we refer to the model on top of which we add LoRA adapters as the &#8220;<strong>base model.&#8221;</strong> This should not be confused with &#8220;base model&#8221; meaning a pre-trained model before instruction tuning.<strong> </strong>The base model can be any model on top of which we would run; e.g., for <a href="https://huggingface.co/daniel-dona/Qwen3-Coder-30B-A3B-Instruct_extracted_LoRA">this model</a>, <a href="http://Qwen/Qwen3-30B-A3B-Instruct-2507">Qwen3-30B-A3B-Instruct-2507</a> would be considered a base model. </p><p>When we are running LoRA-based model fine-tunings, it is much easier to achieve the necessary batch sizes. We can gather requests from multiple users, each using their own LoRA adapter. During the forward pass, we share the cost of loading the base model weights across multiple users. We still need to load the LoRA weights, which adds a little overhead, but as we showed in the previous section, LoRA adapters have a minimal memory footprint, and loading them is very fast. </p><p>This idea is called <strong>multi-tenancy </strong>and is the core technique that will enable the era of experience-style custom models to be served cost-efficiently. The inference provider will be able to serve thousands of adapters built on top of the same base model. During inference, we allocate a dedicated buffer to store the LoRA adapters of predefined shapes. Such a setup enables dynamically loading the adapters for which there is currently demand. If the particular adapter is not used at some point in time, it is offloaded from the buffer and replaced by another adapter requested by another user. </p><p>The exact details of how to implement this are quite complex and beyond the scope of this text, but the high-level is demonstrated in Figure 13. Multi-tenancy means we are able to dynamically load different adapters and share the cost of using the base model across multiple users, driving down the cost for individual users. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!w76U!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!w76U!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 424w, https://substackcdn.com/image/fetch/$s_!w76U!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 848w, https://substackcdn.com/image/fetch/$s_!w76U!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 1272w, https://substackcdn.com/image/fetch/$s_!w76U!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!w76U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png" width="562" height="460.40459110473455" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1142,&quot;width&quot;:1394,&quot;resizeWidth&quot;:562,&quot;bytes&quot;:103769,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!w76U!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 424w, https://substackcdn.com/image/fetch/$s_!w76U!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 848w, https://substackcdn.com/image/fetch/$s_!w76U!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.png 1272w, https://substackcdn.com/image/fetch/$s_!w76U!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F74c25b5e-74b1-4dba-9b1d-3c8643523d07_1394x1142.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 role="img" 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><title></title><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">Figure 13: Visualization of how various LoRA adapters can be efficiently served alongside the base model. The batched computation of the base model is implemented by GEMM, with the computation in adapters implemented via a custom CUDA kernel. Figure from <a href="https://arxiv.org/pdf/2311.03285">S-LORA</a>.</figcaption></figure></div><p>Modern inference engines such as <a href="https://github.com/sgl-project/sglang/blob/main/python/sglang/srt/lora/lora_manager.py#L46">SGLang</a> and vLLM already have pretty sophisticated mechanisms to serve multiple LoRAs. In our experiments we were able to achieve ~85% of the baseline (no adapter) throughput when using LoRAs, as demonstrated in Fig. 14. Since the cost is a directly tied to the throughput achieved, this nicely shows how the cost of serving multiple adapters is only marginally higher than serving the base model alone.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6rQ5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6rQ5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 424w, https://substackcdn.com/image/fetch/$s_!6rQ5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 848w, https://substackcdn.com/image/fetch/$s_!6rQ5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 1272w, https://substackcdn.com/image/fetch/$s_!6rQ5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6rQ5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png" width="1456" height="1211" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1211,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1022520,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6rQ5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 424w, https://substackcdn.com/image/fetch/$s_!6rQ5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 848w, https://substackcdn.com/image/fetch/$s_!6rQ5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.png 1272w, https://substackcdn.com/image/fetch/$s_!6rQ5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F872831e0-a54b-40d0-b572-42c0e8946491_3995x3324.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 role="img" 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><title></title><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">Figure 14: Throughput comparison with <a href="https://github.com/tugot17/tokenomics#">tokenomics</a>. We measure the performance of SGLang v0.5.5 running on a single B200 rented from DataCrunch (Verda). We run <a href="https://huggingface.co/Qwen/Qwen3-32B">Qwen-32B</a> with <a href="https://huggingface.co/nicoboss/Qwen3-32B-Uncensored/tree/main">this</a> LoRA adapter. We compare the performance of Qwen32B without any adapters to performance when all requests are making calls requesting LoRA adapters. Lora rank is 32. Adapters are applied to both the attention and to MLP weights. We pretend that the setup is running with 8 distinct adapters (we load a single adapter with 8 different names). In the LoRA setup (blue line) each request uses LoRA. We simulate the uniform usage of the adapters (round-robin strategy). Full experiment setup can be found <a href="https://gist.github.com/tugot17/5bef4d8fde9fa1a8d37d00c3dc1ba48f">here</a>.</figcaption></figure></div><h2>Everything async and multi-turn</h2><p>As we discussed before, in RL training we have two phases: training and generating rollouts. The workflow goes as follows:</p><ol><li><p>We gather a set of prompts that we want to train the model on. This can be anything, from &#8220;write a Python program sorting numbers&#8221; to &#8220;solve this PhD-level math problem.&#8221; The only requirement is that we have some way to verify (or at least estimate) how well our model did on a particular problem.</p></li><li><p>We use the inference worker to produce the replies for a given prompt. Once the rollout is finished, we assign a reward to it. The exact reward formula is highly dependent on the problem; it can be anything from simple string matching (1 if matching, 0 if not) to sophisticated evaluations consisting of multiple steps such as compilation, running tests, comparing execution time, etc. </p></li><li><p>Once rewards are calculated, we can use them to calculate the advantages (as we showed in Fig. 5) and proceed to run the optimization step via GRPO as explained by the pseudocode in Fig. 4.</p></li><li><p>Once we run the optimization step and we have the new version of the model, we update the inference worker with the updated weights, and we repeat the cycle. </p></li></ol><p>This is a high-level overview of an RL training pipeline. However, in practice, making it work is extremely challenging. One canonical problem is token lag. Token lag refers to the number of optimizer steps between the current policy (&#960;_&#952; being trained) and the old policy (&#960;_&#952;_old that generated the samples). We sample the rollouts using some policy. We grade the outputs, and then we proceed to training. Due to memory limitations, we train on small batches, consisting of a few rollouts - not on all rollouts at the same time. We update the policy &#960; in each optimization step (on each minibatch). This means that as we calculate the next steps, the divergence between our current policy and the original policy from which we sampled the rollout widens. </p><p>In RL, this is traditionally measured through the <strong>Effective Sample Size, or ESS</strong>. When using off-policy RL, ESS measures how many samples from the current policy &#960;_&#952; would yield equivalent performance to weighted samples from the sampling policy &#960;_&#952;_old. The (normalized) ESS is defined as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{ESS} = \\frac{\\left(\\sum_{i=1}^{N} w_i\\right)^2}{N\\sum_{i=1}^{N} w_i^2}&quot;,&quot;id&quot;:&quot;UPBTYQXVZZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{importance weight: } w_i = \\frac{\\pi_\\theta(o_i|q)}{\\pi_{\\theta_{\\text{old}}}(o_i|q)}&quot;,&quot;id&quot;:&quot;JSYRRDCRJZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>N is the sample size.</p><p>ESS &#8776; 1.0 (100%): Perfect! Data is basically on-policy, all samples equally useful<br>ESS &#8776; 0.1 (10%): Most samples are useless, a few dominate &#8594; high variance, unstable training</p><p>ESS is like asking, &#8220;Out of my 1000 samples, how many are actually informative vs. just noise?&#8221; If only a few samples have all the importance weight, you effectively have very few useful samples.</p><p>As we move away from the original policy, the token lag increases, as demonstrated in Fig. 15. This causes ESS to decrease, meaning our samples become progressively less useful for training.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iK7w!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iK7w!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 424w, https://substackcdn.com/image/fetch/$s_!iK7w!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 848w, https://substackcdn.com/image/fetch/$s_!iK7w!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 1272w, https://substackcdn.com/image/fetch/$s_!iK7w!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iK7w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png" width="295" height="260.26362038664325" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:502,&quot;width&quot;:569,&quot;resizeWidth&quot;:295,&quot;bytes&quot;:38982,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iK7w!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 424w, https://substackcdn.com/image/fetch/$s_!iK7w!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 848w, https://substackcdn.com/image/fetch/$s_!iK7w!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.png 1272w, https://substackcdn.com/image/fetch/$s_!iK7w!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F824f0c9f-3030-423e-addf-f43c7c2bbc61_569x502.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 role="img" 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><title></title><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">Figure 15:  Token lag increases as we process batches in conventional RL. Darker green = more lag. By the time we train on the bottom rollouts, they&#8217;re much more off-policy than when they were generated. Figure from <a href="https://arxiv.org/pdf/2509.19128">PipelineRL</a>.</figcaption></figure></div><p>This is a major problem in RL - from the later samples we learn less and less. This naturally limits our sampling batch size. We can&#8217;t produce too many examples for the trainer, because they will not be very useful, as we&#8217;ve diverted too far from the sampling policy anyway. This limit in the batch size introduces another problem. Since inference is memory-bound, we want as large batches as possible to achieve high utilization and produce the maximum number of per second. Yet because of low ESS in samples coming later, we can&#8217;t effectively utilize these larger batches. This is very wasteful and limiting, substantially slowing down the training and driving up the costs. </p><p>To address this, nowadays most organizations are using some sort of <strong>Asynchronous RL. </strong>The concept is rather simple, as we demonstrate in Fig. 16. We operate three types of workers running concurrently: the training worker, the inference worker, the grading worker. They all run at the same time and communicate through queues. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xOXa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xOXa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 424w, https://substackcdn.com/image/fetch/$s_!xOXa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 848w, https://substackcdn.com/image/fetch/$s_!xOXa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 1272w, https://substackcdn.com/image/fetch/$s_!xOXa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xOXa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png" width="1456" height="1095" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1095,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:548138,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xOXa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 424w, https://substackcdn.com/image/fetch/$s_!xOXa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 848w, https://substackcdn.com/image/fetch/$s_!xOXa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.png 1272w, https://substackcdn.com/image/fetch/$s_!xOXa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F35c7052d-ac89-496c-a8ba-2002653365d7_2721x2047.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 role="img" 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><title></title><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">Figure 16: High-level overview of async RL. Three workers run concurrently and communicate through queues. Inference workers pick up prompts, run rollouts, which may involve multiple turns of interaction with tool calls and environment feedbac, and place finished rollouts in a queue. Grading workers pick them up and assign rewards - this can be simple string matching, code compilation and testing, or LLM-as-judge evaluation. Once rewards are calculated and advantages computed, training workers pick up examples and run GRPO optimization steps.</figcaption></figure></div><p>First, we have inference workers. They pick up prompts from the prompt queue and sample the rollouts, then they push the rollouts to the &#8220;completed rollout queue,&#8221; where they can be picked up by the grading worker. Depending on the problem, grading can either be very fast, e.g., for a simple string comparison, or take longer than generating the rollout itself, e.g., when it requires time-consuming compilation of a CUDA kernel. <strong>Ideally, we would like to scale the grading workers so that the overall throughput of the system is limited by the speed of the inference workers rather than by the grading workers</strong>, since the grading workers are usually CPU-bound - hence scaling them should be much cheaper than scaling the GPU-based inference.</p><p>After the rollout has been assigned a reward, we can proceed to calculate the advantage. In GRPO, advantage for rollout <em>i </em>is calculated as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;{Advantage}_i = reward_i - \\text{average reward across all rollouts for this prompt}&quot;,&quot;id&quot;:&quot;DIKTPMIZZP&quot;}" data-component-name="LatexBlockToDOM"></div><p>This means we can only calculate it after we have graded all rollouts for the same prompt. In Fig. 5, we demonstrated a simple example of this calculation.</p><p>Multi-turn interactions and tool usage add additional complexity to this pipeline. In multi-turn RL, instead of generating a single response, the model engages in back-and-forth exchanges, each turn building on previous context. The rollout now consists of multiple conversation turns, and t<strong>he reward might only be assigned after the entire conversation concludes</strong>. For example: &#8220;Did the model successfully build a computer program I asked for across all turns?&#8221; or &#8220;The model made 6 guesses in WORDLE - did it guess the correct word in the end?&#8221;</p><p>Additionally, modern RL setups often involve tool-calling, where the model can invoke external functions during generation, for example, as demonstrated in Fig. 3 in the context of Cursor Composer. The &#8220;conversation&#8221; might consist of model replies, feedback from the environment (e.g., &#8220;you did not guess correctly, try again&#8221;), and the results of function calls (e.g., what the Python interpreter returns). While there exist all sorts of sophisticated &#8220;agentic frameworks,&#8221; at the end of the day, an &#8220;agent&#8221; is just a loop: iterate over turns, pass context to the model, execute any tool calls, append results back to the context, and repeat. We provide a high-level example of such a system in Fig. 17.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CiK3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CiK3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 424w, https://substackcdn.com/image/fetch/$s_!CiK3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 848w, https://substackcdn.com/image/fetch/$s_!CiK3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 1272w, https://substackcdn.com/image/fetch/$s_!CiK3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CiK3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png" width="1446" height="1638" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1638,&quot;width&quot;:1446,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:341228,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CiK3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 424w, https://substackcdn.com/image/fetch/$s_!CiK3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 848w, https://substackcdn.com/image/fetch/$s_!CiK3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.png 1272w, https://substackcdn.com/image/fetch/$s_!CiK3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1deb4e08-be98-4c0b-864d-ac2955f39c79_1446x1638.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 role="img" 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><title></title><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">Figure 17: A minimal implementation of an agentic loop. We define the tools our model can use; using the single common interface provided by <a href="https://modelcontextprotocol.io/docs/getting-started/intro">MCP</a>, we ask the model to provide function calls, then we run these functions and append their outputs to the conversation. We continue with this setup as long as the model returns the function calls; when it just returns a reply, we assume the rollout concluded and the model provided the final answer - answer that we can grade using the grader worker. </figcaption></figure></div><p>Once we grade the examples, we can proceed to training and run an RL optimization step. The trainer worker requests <em>batch size B </em>examples from the graded examples queue. In practice we would most likely choose the biggest batch size that will fit into GPU memory. We calculate the RL loss (e.g. GRPO), run a single optimizer step, and send the updated weights to the inference workers. </p><p>Inference workers, when they get a weight update, briefly pause generation to update the model weights, and then continue from where they stopped. Crucially, the KV-cache is not recomputed, meaning it goes out of sync with the new weights - a misalignment that adds to the unintuitive nature of why this works at all. Consequently, <strong>a single rollout will be comprised of tokens sampled using various, continuously updated versions of the policy.</strong> It ensures that the token lag will be spread relatively evenly across all examples, as demonstrated in Fig. 18, not concentrated in the examples processed later in time by the training worker (as we saw in Fig. 15).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fDzZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fDzZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 424w, https://substackcdn.com/image/fetch/$s_!fDzZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 848w, https://substackcdn.com/image/fetch/$s_!fDzZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 1272w, https://substackcdn.com/image/fetch/$s_!fDzZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fDzZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png" width="354" height="280.46884272997033" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5612497b-2aa0-450a-a391-5627449058c5_674x534.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:534,&quot;width&quot;:674,&quot;resizeWidth&quot;:354,&quot;bytes&quot;:52397,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fDzZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 424w, https://substackcdn.com/image/fetch/$s_!fDzZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 848w, https://substackcdn.com/image/fetch/$s_!fDzZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.png 1272w, https://substackcdn.com/image/fetch/$s_!fDzZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5612497b-2aa0-450a-a391-5627449058c5_674x534.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 role="img" 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><title></title><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">Figure 18: In async RL, token lag is distributed within each rollout rather than across batches. Earlier tokens have higher lag (darker green), but every batch has the same lag structure. This maintains more consistent training effectiveness than conventional RL. Figure from <a href="https://arxiv.org/pdf/2509.19128">PipelineRL</a>.</figcaption></figure></div><p>While it seems unintuitive that it works at all, it has been shown empirically that it performs remarkably well, learning different problems much faster than conventional RL. The key additional benefit of <strong>async RL is that it enables sustainably running larger batches </strong>and producing more tokens in the same amount of time, resulting in faster training through better hardware utilization.</p><p>In RL the learning speed can be expressed as a simple product between how good our samples are at teaching the model the new task and the number of samples we process per unit of time. </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\underbrace{\\frac{\\Delta R}{\\Delta t}}_{\\text{speed}} = \\underbrace{\\frac{\\Delta R}{\\Delta S}}_{\\text{effectiveness}} \\times \\underbrace{\\frac{\\Delta S}{\\Delta t}}_{\\text{throughput}}&quot;,&quot;id&quot;:&quot;IRUDRWGOXF&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where:</p><ul><li><p><strong>Speed</strong> (&#916;R/&#916;t): How fast does reward improve over time?</p></li><li><p><strong>Effectiveness</strong> (&#916;R/&#916;S): How much does reward improve per sample? (data quality)</p></li><li><p><strong>Throughput</strong> (&#916;S/&#916;t): How many samples can we process per unit time? (computational efficiency)</p></li></ul><p>In classic RL the batch size (throughput) was naturally limited - as over time the effectiveness of the samples was going down, to zero at some point, meaning that increasing the batch size provided no additional benefits. With Async RL the effectiveness is maintained for longer, and we can operate on substantially larger batches, driving up the throughput and increasing the learning speed as a result (see Fig. 19).  </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CdFu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CdFu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 424w, https://substackcdn.com/image/fetch/$s_!CdFu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 848w, https://substackcdn.com/image/fetch/$s_!CdFu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 1272w, https://substackcdn.com/image/fetch/$s_!CdFu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CdFu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png" width="446" height="321.6118769883351" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:680,&quot;width&quot;:943,&quot;resizeWidth&quot;:446,&quot;bytes&quot;:155742,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CdFu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 424w, https://substackcdn.com/image/fetch/$s_!CdFu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 848w, https://substackcdn.com/image/fetch/$s_!CdFu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.png 1272w, https://substackcdn.com/image/fetch/$s_!CdFu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F581bf529-82eb-44a3-b344-07f9dae8fe46_943x680.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 role="img" 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><title></title><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">Figure 19: Demonstration how async RL (Pipeline RL in this case) achieves higher learning speed (&#916;R/&#916;S x &#916;S/&#916;t) across different setups. Figure from <a href="https://arxiv.org/pdf/2509.19128">PipelineRL</a>.</figcaption></figure></div><p>The best introduction to async RL the reader can find is &#8220;<em>PipelineRL: Faster On-policy Reinforcement Learning for Long Sequence Generation</em>.&#8221; We want to highlight this to the readers as a truly remarkable work! Very well written, with a great <a href="https://github.com/ServiceNow/PipelineRL">open-source implementation</a>. We highly recommend the reader give it a read when they have time if they want to understand async RL concepts at a deeper level.</p><h1>LoRA in RL</h1><p>Both the training itself and rollout generation can greatly benefit from combining async RL with LoRA. </p><p>In model training, when we use LoRA, we don&#8217;t need to store the gradients and optimizer states for all the parameters. We just need to store the base model weights, gradients for small adapters (3-4 orders of magnitude smaller, as we showed earlier), and activations<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a>. Since gradients and optimizer states are a substantial portion of the memory footprint during full model training, this means that when training using just the LoRA adapters we can massively increase the batch size. The memory footprint of activations will still scale linearly with the batch size, as will the FLOPs, but LoRA requires only about 2/3 of the FLOPs compared to full fine-tuning.</p><p>While the exact details depend on factors such as which base model we are using, where we apply LoRAs, and what the LoRA rank is, the key takeaway is that LoRAs enable us to run training at <strong>substantially larger batches due to massively reduced memory requirements for gradients and optimizer states.</strong> This means that the training worker can process rollouts from the inference workers faster. Since it processes rollouts faster, at some point the training worker will start to idle - there won&#8217;t be enough rollouts to consume. This means <strong>we can reassign the workers, moving some compute resources (GPUs) from training to inference, further accelerating the throughput.</strong> Now inference has more resources because training requires fewer, so we can produce more rollouts.</p><p>As we discussed in the previous section, running inference with LoRA adapters results in only minuscule performance degradation compared to the baseline (&#8221;without regret&#8221;). This has profound implications for the economics of rollout generation. It becomes technically feasible to combine rollout generation from multiple policies, each optimizing different reward functions, all built on top of the same base model within a single inference setup.</p><p>Inference is memory-bound, so throughput and utilization per GPU increase as we increase the batch size. If we combine multiple LoRA adapters, we can linearly scale the batch size, driving down the marginal cost of producing a token, decreasing the overall cost or enabling much larger scale on some fixed budget as a result. </p><p>This property can be extremely useful both for RFT and for full model fine-tuning. For we can use multiple policies and combine them into a single massive batch, fully utilizing the provided compute. Already today a number of companies, such as <a href="https://tinker-docs.thinkingmachines.ai/model-lineup">Thinking Machines</a> or <a href="https://docs.wandb.ai/training/serverless-rl">Weights and Biases</a>, offer &#8220;RL as a service&#8221;-type of products, where clients can train their LoRA-based model fine-tunings running on top of open-source models. Using a single inference setup for multiple clients can be an important axis of cost optimization for these providers, driving down the costs and increasing the margin (assuming there is enough demand, which remains unclear as of today).</p><p>What is less obvious is that this ability to combine multiple independent policies into a single inference setup can also be valuable for organizations training universal foundation models. Often when training the model, initially the team would train a few different, independent models, each optimizing a different reward function. After we have a few trained models with good performance on these independent tasks, we would apply some sort of model distillation technique to bring all of these capabilities into the single final model. For example in the <a href="https://github.com/deepseek-ai/DeepSeek-V3.2-Exp/blob/main/DeepSeek_V3_2.pdf">report for DeepSeek v3.2</a> we read:</p><blockquote><p>For each task, we initially develop a specialized model dedicated exclusively to that particular domain, with all specialist models being fine-tuned from the same pre-trained DeepSeek-V3.2 base checkpoint. In addition to writing tasks and general question-answering, our framework encompasses five specialized domains: mathematics, competitive programming, general logical reasoning, agentic coding, and agentic search. Each specialist is trained with large-scale Reinforcement Learning (RL) computing. Furthermore, we employ different models to generate training data for long chain-of-thought reasoning (thinking mode) and direct response generation (non-thinking mode). Once the specialist models are prepared, they are used to produce the domain-specific data for the final checkpoint</p></blockquote><p>If the DeepSeek team were to train these models through LoRA adapters (remember &#8220;no regret&#8221;), they could combine prompts for different models and run them on top of a single inference setup. This would be much, much more efficient than running five separate setups. </p><p>The mental picture we hope the reader takes away from reading this article is the visualization shown in Fig. 20. To increase the throughput of token generation, we need to run very large batches. This comes at a tradeoff - any single generation will be relatively slow, but this doesn&#8217;t matter much for RL rollout generation, since we don&#8217;t have human users impatiently waiting for a response to appear. All we care about is producing as many tokens as possible given a hardware budget, and here we achieve just that. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ITJm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ITJm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 424w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 848w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 1272w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ITJm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png" width="1301" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a44075b8-972d-4433-983e-506bb49f460b_1301x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1301,&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="https://substackcdn.com/image/fetch/$s_!ITJm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 424w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 848w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 1272w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.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 role="img" 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><title></title><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">Figure 20: To achieve full utilization of GPU resources in an inference setup, large batches are required. This decreases the throughput per request, but the cumulative throughput, what we care about in the end, is maximized. Combining multiple policies running on top of a single base model makes it easier to achieve larger batches, driving down the cost for each client.</figcaption></figure></div><p>The ability to run larger batches is especially relevant for large-scale MoE models, such as DeepSeek. As we elaborated in detail in our previous text on &#8220;<a href="https://www.tensoreconomics.com/p/moe-inference-economics-from-first">MoE Inference Economics from First Principles</a>,&#8221; this class of models, due to their sparse computation patterns, greatly benefits from a high concentration of GPU resources in a single setup. <strong>If the inference provider is capable of running a setup spanning multiple nodes, the performance per GPU will be significantly improved compared to a setup spanning one or two nodes</strong>, as demonstrated in Fig. 21. This means that if our training setup allows for larger batches, we can combine multiple nodes, increasing the performance per GPU. All these factors compound, resulting in substantially faster and cheaper training of RL models.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G0p1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G0p1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 424w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 848w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 1272w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G0p1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png" width="1456" height="895" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:895,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:55806,&quot;alt&quot;:&quot;&quot;,&quot;title&quot;:&quot;&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" title="" srcset="https://substackcdn.com/image/fetch/$s_!G0p1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 424w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 848w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 1272w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.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 role="img" 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><title></title><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">Figure 21: Token throughput for DeepSeek v3 measured on NVL72 <a href="https://lmsys.org/blog/2025-06-16-gb200-part-1/">SGLang Blog.</a></figcaption></figure></div><p>Additional benefit of the minuscule memory footprint of LoRAs comes up during the policy update when the training worker sends the updated policy to the inference workers. Because the LoRA weights are so small, sending them from one worker to another is very quick. There is little to no overhead - updates are fast and inference GPUs aren&#8217;t left idling during synchronization.</p><h1>Intelligence markets through RFT</h1><p>In this text we tried to introduce the technical details that will underpin the &#8220;experience economy.&#8221; We argue that policy gradient optimization methods, such as GRPO, are very information sparse, providing only <em>log(N)</em> bits per rollout, where <em>N</em> is the reward granularity. Because of this, the data learned by the model can be efficiently encoded in very few parameters. We can do this parameter-efficient fine-tuning technique, such as LoRA, without any penalty (&#8220;no regret&#8221;) to the model performance compared to the full model fine-tuning. </p><p>LoRA makes training substantially cheaper because we don&#8217;t need to store the optimizer states nor gradients for the parameters. Hence, on the fixed hardware budget, we can run substantially larger batches, increasing the speed of training. In the context of RL, this means that we can allocate fewer resources for training and more towards inference workers, driving up the data generation speed. </p><p>LoRA unlocks the ability to scale the batch size, which plays nicely with ideas of AsyncRL - the leading paradigm of doing RL in 2025. In AsyncRL different tokens in a single rollout are sampled using multiple continuously updated policies. Empirically it has been shown to improve the end-to-end performance as the token lag is spread more evenly throughout the samples. </p><p>Because competing with the foundation&#8217;s general-purpose model is so challenging and capital intensive, focusing on model specialization seems like a promising path for less resourceful organizations. The biggest of the recent releases in this domain was the introduction of <a href="https://thinkingmachines.ai/tinker/">Tinker</a> by Thinking Machines, where they enable organizations to run RL workloads. The distributed training is abstracted away and handled by Thiky. The user of the API has to only focus on reward modeling. Pricing is divided into inference parts (prefill + sampling) and training parts (see Fig. 22).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G2gl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G2gl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 424w, https://substackcdn.com/image/fetch/$s_!G2gl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 848w, https://substackcdn.com/image/fetch/$s_!G2gl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 1272w, https://substackcdn.com/image/fetch/$s_!G2gl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G2gl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png" width="568" height="557.1091445427728" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1330,&quot;width&quot;:1356,&quot;resizeWidth&quot;:568,&quot;bytes&quot;:174952,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G2gl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 424w, https://substackcdn.com/image/fetch/$s_!G2gl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 848w, https://substackcdn.com/image/fetch/$s_!G2gl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.png 1272w, https://substackcdn.com/image/fetch/$s_!G2gl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9eb2229f-d9bc-484b-989a-0c5145e20cf2_1356x1330.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 role="img" 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><title></title><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">Figure 22: Token level pricing of <a href="https://thinkingmachines.ai/tinker/">Tinker</a> 18.11.2025. Sampling is substanitally pricer than prices offered by the inference prividers such as Together or Fireworks. This demonstrates the potential to improve the margins if an inference provider offers such a service.</figcaption></figure></div><p>The RFT-type services, in our opinion, offer a great opportunity for NeoClouds to increase the margins on compute in smaller clusters. RFT is specifically well positioned to utilize the smaller clusters (a few hundred nodes). Since the memory requirements are so significantly reduced, and we have only 2/3rds of the FLOPs of full-model fine-tuning, training can be conducted on substantially reduced resources, potentially even within a single H100 node for models of +200B parameters. Moreover, using multi-tenancy, it is possible to gather requests from multiple users into a single large batch, further increasing the cost competitiveness. </p><p>This has great potential to improve the profit margins on the underutilized compute resources gathered in the smaller datacenter - the compute that up until now was of limited potential, as it was not possible to run larger training runs of it - thing that offers the highest margins. </p><p>You can see that NeoClouds are already interested in this direction. E.g., in September 2025, <a href="https://techcrunch.com/2025/09/03/coreweave-acquires-agent-training-startup-openpipe/">CoreWeave acquired</a> one of the startups pioneering RFT - OpenPipe. CoreWeave <a href="https://wandb.ai/wandb/wb-announcements/reports/W-B-being-acquired-by-CoreWeave--VmlldzoxMTY0MDI1MQ">also acquired</a> Weights and Biases, which also <a href="https://wandb.ai/wandb_fc/product-announcements-fc/reports/Introducing-Serverless-RL--VmlldzoxNDY0MDIzOQ">offers </a>an RL-as-a-service-type product, since October 2025.</p><p>The big question is whether there is actually a market for RFT - if there is any point in developing these capabilities, or will the smart models be able to just &#8220;figure it out&#8221; in context, as they get more and more intelligent? This we can&#8217;t answer. What can be argued is that as of today it is not the case; there are clearly moats to be built in this fashion. There are some capabilities that are inherently &#8220;not there&#8221; in cloud models. </p><p>Two good examples are the model&#8217;s ability for persuasion in a particular domain. The best example here is the <a href="https://arxiv.org/abs/2507.21983">AdLlama paper</a> from Meta. Researchers first train a reward model based on the user preference data. The reward model is able to estimate which headline will &#8220;click&#8221; with users and which will be ignored. Then the said model was used to optimize Llama 2 (it took them a while to publish this paper) using PPO, so it is more likely to produce more persuasive outcomes. The high-level overview we present in Figure 23. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lO0N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lO0N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 424w, https://substackcdn.com/image/fetch/$s_!lO0N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 848w, https://substackcdn.com/image/fetch/$s_!lO0N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 1272w, https://substackcdn.com/image/fetch/$s_!lO0N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lO0N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png" width="1456" height="930" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:930,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:256381,&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://www.tensoreconomics.com/i/176868258?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lO0N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 424w, https://substackcdn.com/image/fetch/$s_!lO0N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 848w, https://substackcdn.com/image/fetch/$s_!lO0N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.png 1272w, https://substackcdn.com/image/fetch/$s_!lO0N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2ea28ad-53cf-4e2f-bccc-68939f797b0e_1850x1182.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 role="img" 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><title></title><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">Figure 23: &#8220;<em>Our first contribution, illustrated in the left panel, is RLPF, a reinforcement learning (RL) approach to post-training an LLM based on an aggregate performance metric. We apply RLPF to a generative AI feature in Meta&#8217;s Ads Manager that helps advertisers generate new ad text variations. To do this, we use Facebook ad performance data (i.e., click-through rates) to train a reward model, which can score the effectiveness of a piece of ad text. Subsequently, we align the LLM toward this reward model using RL, which involves iteratively generating and scoring ad text, illustrated in lower part of the figure. The resulting LLM is called &#8220;AdLlama.&#8221; Our second contribution, illustrated in the right panel, are the results of a large-scale advertiser A/B test, encompassing approximately 35,000 advertisers and 640,000 ad variations, which showed that advertisers who received AdLlama achieved 6.7% higher advertiser-level click-through rates (CTR). To our knowledge, this study is the largest reported so far that investigates the use of generative AI in an ecologically valid setting&#8221; </em>. Figure from <a href="https://arxiv.org/pdf/2507.21983">AdLlama paper.</a></figcaption></figure></div><p>Data on how to best persuade the users of Facebook are clearly not available directly on the Common Crawl. It requires a pretty sophisticated data-gathering mechanism that also can be further refined by providing specific demographic data (e.g., user age, sex, embedding of preferences, etc.) to make the reward model more accurate. A language model optimized using such a reward model is most likely to be much, much better at persuasion than off-the-shelf GPT, though it is fair to say that in the future, as models get more intelligent, the ability to persuade might be just &#8220;baked&#8221; in them, since they already have a pretty high <a href="https://eqbench.com/">emotional intelligence</a>.</p><p>Another example of successful RFT is building custom deep research systems. The most successful deep research<a href="https://tongyi-agent.github.io/blog/introducing-tongyi-deep-research/"> models</a> today are already trained today with RL reward modeling. Training is organized as follows: we ask a question, the model does a number of function calls, web searches, and coding, and maybe searches through third-party tools, and after a number of turns produces a final answer (like in the simple agent loop we introduced in Fig. 17), and the system provides a reward based on how well the model did on this task. </p><p>Every company has slightly different data; some use Confluence, others some obscure SAP system written in the 1980s, and others just a continuously updated Excel sheet. It can be argued that this might be too diverse for an out-of-the-box model to be able to search through it successfully, and to build a competitive advantage, companies should be training models that get better at utilizing THEIR data over time. Whether the overhead of this will be too substantial, building good environments is challenging and requires some expertise, or it will be worth it remains to be seen as of now. </p><p>The major challenge of RFT is that it requires building custom environments for every problem to be solved, which is inherently not scalable. LLMs can potentially help here, in aiding humans in building these environments, but in our experience, as of late 2025, in zero-shot fashion setups, LLMs exhibit a pretty poor performance when it comes to reward modeling, requiring substantial supervision from humans. Not surprisingly, most of the companies in this space right now focus on building &#8220;picks and shovels&#8221; of RFT, be it the fine-tuning platforms like we discussed for Thinking Machines or building the environments hub like <a href="https://app.primeintellect.ai/dashboard/environments">Prime Intellect</a>. </p><p>While these make it easier to iterate on custom models, the main problem of making custom models useful - how to scale environment building and reward modeling remains unsolved. The training foundations are there - the unknown remains the path to scaling.</p><h1>Acknowledgments</h1><p>Thanks to each of you for giving me feedback. <a href="https://x.com/LukasBluebaum">Lukas</a> (absolute &#128016;) for having an insane eye for detail and correcting me on errors small and not so small. <a href="https://x.com/pieterdelobelle">Pieter</a> for giving it a first read and pointing out networking advantages, <a href="https://x.com/JordanNanos">Jordan</a> for discussing the NeoCloud perspective with me. <a href="https://x.com/_nvedant_">Vedant</a> (big win for Mistral) for his comments on ICL and era of experience. <a href="https://x.com/SzymonOzog_">Szymon</a> and <a href="https://berkenkamp.me/">Felix</a> for providing me with small suggestions on how to direct this text, and to <a href="https://x.com/felix_red_panda">Felix</a> for discussing with me the token lag problem. <a href="https://x.com/neurosp1ke">Andreas</a> for challenging the 1 bit idea.</p><pre><code>@online{tensoreconomics2025aiinfraineraofexperince,
  author = {Piotr Mazurek},
  title = {AI infrastructure in the "Era of experience"},
  url = {https://www.tensoreconomics.com/p/ai-infrastructure-in-the-era-of-experience},
  urldate = {2025-11-16},
  year = {2025},
  month = {November},
  publisher = {Substack}
}</code></pre><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>At tensoreconomics we doubt this is actually the case as of today. We believe that there still remains a gap between open-source models and frontier models from Anthropic, OpenAI and most recently Google. The gap is poorly captured by the existing benchmarks, but it is clearly showed by the consumer interest. People just don&#8217;t use these free models, but pay for Claude, GPT or Gemini subscriptions. </p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>E.g. <a href="https://huggingface.co/facebook/opt-125m">facebook/opt-125m</a> models have 4M monthly downloads as of November 2025, even though no one is using them. It is most likely caused by them being the default model used in <a href="https://docs.vllm.ai/en/latest/getting_started/quickstart/#installation">vllm documentation</a>. </p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p>There are limits to this analogy. For example, until recently the Chinese model providers were unable to secure enough compute capacity to serve their models competitively. Users wanting to use Chinese models typically access them through Western inference providers, such as Together or Fireworks. This is in clear contrast to the traditional model where Western companies dominated &#8220;IP&#8221; and Chinese companies dominated manufacturing; here the dynamic is reversed.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-4" href="#footnote-anchor-4" class="footnote-number" contenteditable="false" target="_self">4</a><div class="footnote-content"><p>The exact footprint of activations stored is highly dependent on the activations checkpointing strategy. </p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Why are embeddings so cheap?]]></title><description><![CDATA[or a lesson in profiling and FLOPS per dollar]]></description><link>https://www.tensoreconomics.com/p/why-are-embeddings-so-cheap</link><guid isPermaLink="false">https://www.tensoreconomics.com/p/why-are-embeddings-so-cheap</guid><dc:creator><![CDATA[Piotr Mazurek]]></dc:creator><pubDate>Wed, 24 Sep 2025 18:09:45 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Zr2N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Embeddings are a fundamental component of every modern retrieval augmented generation (RAG) system. State-of-the-art (SOTA) embeddings are provided by companies such as OpenAI or Google at prices up to two orders of magnitude lower on a per-token basis than prices for generative models such as GPT or Gemini. In this analysis, we show what computations are required to produce an embedding and how, based on these computations, we can derive the true dollar cost of processing a token.</p><p><strong>Our contention is that since the cost of processing a token is so minuscule and all embedding models converge to similar semantic representations, this means that no provider enjoys a sustainable moat. This results in underlying low costs being passed directly onto the consumers, driving prices to rock bottom.</strong> </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tensoreconomics.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Tensor Economics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>As we demonstrate, with sufficient demand and scale, the price to process a million input tokens can be driven below 1&#162; for SOTA embedding models topping the evaluation leaderboards.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Cost per million tokens}= \\frac{\\text{GPU cost per hour}}{\\text{tokens per second} \\times 3600} \\times 10^6 = \\frac{\\$0.37/\\text{hr}}{11440\\text{ tokens/s} \\times 3600 \\text{ s/hr}} \\times 10^6 = \\$0.0090&quot;,&quot;id&quot;:&quot;HNIBJRUZTA&quot;}" data-component-name="LatexBlockToDOM"></div><p>The insight we hope you take from reading this analysis is that, unlike GPT-style autoregressive models, modern embedding models are primarily <strong>compute-bound, not memory-bound</strong>, meaning they largely don't benefit from batching. We show that <strong>FLOPS/dollar</strong> is the key hardware parameter for optimizing cost structure when building an embedding API.</p><p>The remaining sections proceed as follows. First, we estimate the FLOPs of a forward pass based on model architecture, comparing these FLOPs with the cost of loading the model from global memory. Then we benchmark a real-world embedding inference system, showing how quickly computations saturate our system and how little additional utilization we gain from batching. Finally, we dive deep into CUDA profiling, examining which kernels are invoked and profiling them in detail to identify system limitations.</p><p>We assume that the reader is familiar with the concepts presented in our previous text: <a href="https://www.tensoreconomics.com/p/llm-inference-economics-from-first">LLM Inference Economics from First Principles</a>. Before proceeding to read this, the reader should be familiar at a high level with how transformer models work, what it means to be compute- or memory-bound, what the FLOP is, and how many FLOPs there are in a matrix multiplication. We highly recommend you get familiar with these concepts first, as we will be building on top of this understanding. If you are unfamiliar with these concepts, please read the previous text first. </p><h1>Introduction</h1><p>Embedding models transform sequences of data, typically text or images, into semantic representations. These representations take the form of high-dimensional vectors that capture meaning across different dimensions.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Embedding model}(\\text{\&quot;Robert Moses was an American urban planner\&quot;}) = \\begin{align}\n    \\begin{bmatrix}\n           0.12 \\\\\n           -2.23 \\\\\n           5.73 \\\\\n           \\vdots \\\\\n          2.12\n         \\end{bmatrix}\n  \\end{align}&quot;,&quot;id&quot;:&quot;ENRCHHOMPK&quot;}" data-component-name="LatexBlockToDOM"></div><p>This semantic representation can be later used in downstream tasks, such as &#8220;find me the document semantically similar to the question my user is asking&#8221;. Similarity is computed using linear algebra operations such as dot products or cosine similarity between vectors. While there <a href="https://arxiv.org/abs/2508.21038">exist some limits</a> to what can be captured in this kind of single vector representation embeddings remain the fundamental block of any modern RAG system. </p><p>One of the first companies to offer the semantic embedding as an endpoint was OpenAI, back in <a href="https://community.openai.com/t/introducing-embeddings/13319">December 2021</a>. Since then, their embedding models have been updated and competitors like Google and Cohere have launched their own offerings, though OpenAI remains the market leader.</p><p>What is pretty special about the embedding endpoints is how cost-efficient they are to use. While OpenAI is charging up to $15/1M input and $60/1M output tokens for their O1 reasoning model<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>,  embedding models are offered at an astonishingly small 10 cents/1M input tokens for the most popular `text-embedding-ada-002` model (see Fig. 1).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fAPX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fAPX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 424w, https://substackcdn.com/image/fetch/$s_!fAPX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 848w, https://substackcdn.com/image/fetch/$s_!fAPX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 1272w, https://substackcdn.com/image/fetch/$s_!fAPX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fAPX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png" width="624" height="224.57142857142858" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:524,&quot;width&quot;:1456,&quot;resizeWidth&quot;:624,&quot;bytes&quot;:183334,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fAPX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 424w, https://substackcdn.com/image/fetch/$s_!fAPX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 848w, https://substackcdn.com/image/fetch/$s_!fAPX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 1272w, https://substackcdn.com/image/fetch/$s_!fAPX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8c43736b-8173-4e0d-a50e-292898ed7789_3216x1158.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Figure 1: <a href="https://platform.openai.com/docs/pricing#embeddings">OpenAI embedding pricing</a> as of 13.09.2025.</figcaption></figure></div><p>To illustrate how cheap it is, embedding the <strong>entire</strong> English Wikipedia corpus would cost approximately:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{4.9B words} \\times \\frac{4}{3}\\text{tokens per word} \\times (1000 \\times \\text{\\$0.10/1M tokens}) = \\$650&quot;,&quot;id&quot;:&quot;ZUCHAMFSCO&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>5B words or ~10M pages of text for $650.</strong></p><p>If we look at the offerings from other competitors, the prices are mostly within a ballpark of this, with Google's <a href="https://ai.google.dev/gemini-api/docs/embeddings">gemini-embedding-001</a> at $0.15/1M input tokens and <a href="https://cohere.com/pricing">Cohere&#8217;s Embed 4</a> at $0.12/1M input tokens.</p><p>While these prices might appear as artificially low if we "count the FLOPS," we can clearly see that they are reflected in the underlying cost structure of processing a token. <strong>Generating an embedding is just extremely cheap, and these savings are passed directly onto the consumers.</strong> There's another factor driving prices down: embedding models are <a href="https://arxiv.org/pdf/2505.12540v2">converging to similar semantic representations</a> regardless of their architecture. If all models capture semantics similarly, differentiation becomes nearly impossible. <strong>This makes serving raw embedding a terrible business to be in and forces companies that used to specialize in this to pivot more towards the end-to-end search services that can command higher margins.</strong></p><h1>Qwen3 Embedding architecture</h1><p>For our analysis, we use  <a href="https://huggingface.co/Qwen/Qwen3-Embedding-8B">Qwen3-Embedding-8B</a> as our example model. As of September 2025 it is a model topping the embedding tasks leaderboards (see Fig. 2). While many people validly point out the limitations of the <a href="https://x.com/Nils_Reimers/status/1870812625505849849">real-world usefulness of using MTEB as a proxy</a> for model quality, due to models overfitting on test data, it remains widely adopted. Since we don&#8217;t care that much about the exact model performance but more about the compute cost of generating an embedding representation, it should not be a problem for our analysis.</p><p>We make several key assumptions about commercial embedding models. We assume that closed-source models like <em>text-embedding-ada-002</em> and <em>gemini-embedding-001</em> share similar architectural designs with Qwen3. Specifically, we assume they are dense transformer models that produce embeddings via <strong>a single forward pass</strong> and are relatively compact at under 10B parameters.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LBlG!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LBlG!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 424w, https://substackcdn.com/image/fetch/$s_!LBlG!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 848w, https://substackcdn.com/image/fetch/$s_!LBlG!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 1272w, https://substackcdn.com/image/fetch/$s_!LBlG!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LBlG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png" width="724" height="554.2558970693352" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1071,&quot;width&quot;:1399,&quot;resizeWidth&quot;:724,&quot;bytes&quot;:222107,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LBlG!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 424w, https://substackcdn.com/image/fetch/$s_!LBlG!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 848w, https://substackcdn.com/image/fetch/$s_!LBlG!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.png 1272w, https://substackcdn.com/image/fetch/$s_!LBlG!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F700aa586-e40b-4ec4-8a78-bb94e6eaebb3_1399x1071.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 role="img" 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><title></title><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">Figure 2: <a href="https://huggingface.co/spaces/mteb/leaderboard">MTEB Leaderboard</a> 8.09.2025</figcaption></figure></div><p>The architecture of Qwen3 embedding is very simple, to quote the Qwen team:</p><blockquote><p>The Qwen3 embedding &#8230; models are built on the dense version of Qwen3 foundation models and are available in three sizes: 0.6B, 4B, and 8B parameters. We initialize these models using the Qwen3 foundation models to leverage their capabilities in text modeling and instruction following. </p><p>For text embeddings, we utilize LLMs with causal attention, appending an <strong>[EOS]</strong> token at the end of the input sequence. The final embedding is derived from the hidden state of the last layer corresponding to this <strong>[EOS] token</strong>.</p></blockquote><p>This means that generating an embedding requires only a single forward pass through the model, extracting the hidden state corresponding to the final <strong>[EOS] token</strong> (see Fig. 3). In other words, embedding has (nearly) exactly the same compute footprint as completing the prefill phase, or producing the first output token, when using the auto-regressive version of Qwen3.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fuGL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fuGL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 424w, https://substackcdn.com/image/fetch/$s_!fuGL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 848w, https://substackcdn.com/image/fetch/$s_!fuGL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 1272w, https://substackcdn.com/image/fetch/$s_!fuGL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fuGL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png" width="1042" height="642" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:642,&quot;width&quot;:1042,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:63666,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fuGL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 424w, https://substackcdn.com/image/fetch/$s_!fuGL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 848w, https://substackcdn.com/image/fetch/$s_!fuGL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.png 1272w, https://substackcdn.com/image/fetch/$s_!fuGL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F55532d48-3733-49ff-bc16-f6763429e5e2_1042x642.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 role="img" 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><title></title><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">Figure 3: Model architecture of <a href="https://arxiv.org/pdf/2506.05176">Qwen3-Embedding</a>.</figcaption></figure></div><h1>Counting FLOPs </h1><p>*Please be aware that FLOPS and FLOPs mean different things. <strong>FLOPs</strong> (small s) is the plural of floating-point operations not considering time at all, but <strong>FLOPS</strong> (capital S) means floating-point operations that happen within a second.</p><p>In the <a href="https://www.tensoreconomics.com/i/163319195/total-flops-calculation">previous text</a> we estimated the total FLOPs of a forward pass of a Llama model at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total FLOPs of Llama} = {} &amp; \\text{num_hidden_layers} \\times \\\\\n&amp; (10S \\times \\text{hidden_size} + 25.5S \\times \\text{hidden_size}^2 \\\\\n&amp; + 4S^2 \\times \\text{hidden_size} + 5S^2 \\times \\text{num_attention_heads}) \\\\\n&amp; + 2 \\times \\text{hidden_size} \\times \\text{vocab_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;NICVDRCHOB&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where <em>S</em> is the sequence length of the processed sequence. </p><p>Qwen3 and Llama3 share a very similar architecture. Both are dense causal transformer models; both use <a href="https://arxiv.org/pdf/2305.13245">group query attention</a> and the silu activation function for MLP. One minor difference is that the ratio of <em>hidden_size </em>to <em>intermediate_size </em>is 3 (12288/4096, see Fig. 4) compared to Llama&#8217;s 3.5, though it is such an insignificant difference that we proceed to use the equation above to estimate the FLOPs of a forward pass of Qwen. For further details, please refer to the previous article. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d1f0!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d1f0!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 424w, https://substackcdn.com/image/fetch/$s_!d1f0!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 848w, https://substackcdn.com/image/fetch/$s_!d1f0!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 1272w, https://substackcdn.com/image/fetch/$s_!d1f0!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d1f0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png" width="406" height="587.5595505617978" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1288,&quot;width&quot;:890,&quot;resizeWidth&quot;:406,&quot;bytes&quot;:214487,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d1f0!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 424w, https://substackcdn.com/image/fetch/$s_!d1f0!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 848w, https://substackcdn.com/image/fetch/$s_!d1f0!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.png 1272w, https://substackcdn.com/image/fetch/$s_!d1f0!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fca552660-56e1-4657-9f5e-40a55ded1d14_890x1288.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 role="img" 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><title></title><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">Figure 4: Hugging Face config for <a href="https://huggingface.co/Qwen/Qwen3-Embedding-8B/blob/main/config.json">Qwen3-8B Embedding</a>.</figcaption></figure></div><p>Since for embedding representation we just use the hidden state of the last layer corresponding to the [EOS] token, this means we don&#8217;t need to calculate the probability distribution over the next predicted token, aka the <a href="https://www.tensoreconomics.com/i/163319195/lm-head">LM head</a>, meaning we can remove the FLOPs for calculating it. There are some extra FLOPs involved from the pooling layer, but for the sake of simplicity we skip them, as they involve very few operations. Bringing the total in a forward pass to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total FLOPs of Qwen Embedding} = {} &amp; \\text{num_hidden_layers} \\times \\\\\n&amp; (10S \\times \\text{hidden_size} + 25.5S \\times \\text{hidden_size}^2 \\\\\n&amp; + 4S^2 \\times \\text{hidden_size} + 5S^2 \\times \\text{num_attention_heads})\n\\end{aligned}&quot;,&quot;id&quot;:&quot;FPGMUAZQAZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>Assuming we are processing <em>S=1024 tokens</em> and using the Qwen config as in Fig. 4 (<em>num_hidden_layers=36</em>, <em>hidden_size=4096</em>, <em>num_attention_heads=32</em>), we can quite easily estimate the total FLOPs at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total FLOPs of Qwen Embedding} = {} &amp; 36 \\times \\\\\n&amp; (10 \\times 1024 \\times \\text{4096} + 25.5 \\times 1024 \\times \\text{4096}^2 \\\\\n&amp; + 4 \\times 1024^2 \\times \\text{4096} + 5 \\times 1024^2 \\times \\text{32})=\\\\\n&amp; 16.4 \\text{ TFLOPs}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;LNFVQUPZMT&quot;}" data-component-name="LatexBlockToDOM"></div><p>Using this, we can easily estimate the upper bound of how long it takes to process a sentence of 1024 tokens. To do so, we need to look into the FLOPS and memory bandwidth of a GPU. Performance can be capped either by us having to do too many operations (compute-bound) or by a need to load too much data (memory-bound). </p><p><a href="https://resources.nvidia.com/en-us-hopper-architecture/nvidia-h100-tensor-c">On paper</a> NVIDIA H100 SXM5 delivers 989 TFLOPS of compute for BF16 with accumulation in FP32. It also features a fast high bandwidth memory (HBM) offering up to 3.3 TB/s throughput. However, in practice, due to the power constraints, H100 is not capable of actually achieving these declared FLOPS. As <a href="https://www.thonking.ai/p/strangely-matrix-multiplications">Horace He</a> explains:</p><blockquote><p><em>This observation that GPUs are unable to sustain their peak clock speed due to power throttling is one of the primary factors that separates &#8220;real&#8221; matmul performance from Nvidia&#8217;s marketed specs.</em></p><p><em>The figure that Nvidia provides for marketing is:</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS} = \\text{Tensor Cores on GPU} \\cdot \\text{Max Clock Speed} \\cdot \\text{FLOP per Tensor Core Instruction}&quot;,&quot;id&quot;:&quot;PVUHDSUBLN&quot;}" data-component-name="LatexBlockToDOM"></div><p><em>For example, on an H100, there are <a href="https://resources.nvidia.com/en-us-tensor-core">528 tensor cores per GPU</a> (4 per SM), the max clock speed for these is 1.830 Ghz, and the FLOP per tensor-core instruction is 1024. Thus, we have </em><code>1.830e9 * 528 * 1024 = 989 TFLOPS</code><em>, exactly Nvidia&#8217;s listed number.</em></p><p><em>However, you can only achieve this number by sustaining 1.83 Ghz clocks, and as we&#8217;ve seen above, the GPU just doesn&#8217;t have enough power to do that!</em></p></blockquote><p>In our <a href="https://gist.github.com/tugot17/897237824f7960bdb4a7857aed560a61">tests</a> we achieved ~750 TFLOPS in matrix multiplication (see Fig. 5) on H100 SXM, varying with matrix dimensions. As we will show later, most of the time in calculating embeddings is spent in large-scale matrix multiplications - hence this will be a pretty good indicator of the realistic end-to-end performance we can expect. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HL-j!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HL-j!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 424w, https://substackcdn.com/image/fetch/$s_!HL-j!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 848w, https://substackcdn.com/image/fetch/$s_!HL-j!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 1272w, https://substackcdn.com/image/fetch/$s_!HL-j!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HL-j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png" width="1456" height="776" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:776,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:211931,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HL-j!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 424w, https://substackcdn.com/image/fetch/$s_!HL-j!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 848w, https://substackcdn.com/image/fetch/$s_!HL-j!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.png 1272w, https://substackcdn.com/image/fetch/$s_!HL-j!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F00a3d70e-3047-412b-b838-4b7436c6eb8d_1600x853.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 role="img" 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><title></title><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">Figure 5: FLOPS achieved on Nebius on NVIDIA H100 SXM running on CUDA 12.4. Code can be found <a href="https://gist.github.com/tugot17/897237824f7960bdb4a7857aed560a61">here</a>.</figcaption></figure></div><p>To calculate an embedding, we need to:</p><ul><li><p>Load the model weights <strong>once</strong> from global memory</p></li><li><p>Complete a forward pass involving ~16.4 TFLOPs of matrix multiplications and other calculations.</p></li></ul><p>The model size can be easily estimated based on the number of parameters at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{7.57B parameters} \\times \\text{2 bytes per parameter} = \\text{15.14GB}&quot;,&quot;id&quot;:&quot;PKAPYCWVID&quot;}" data-component-name="LatexBlockToDOM"></div><p>meaning that a single model load takes around:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Forward pass time}_{memory} = \\frac{\\text{Total size of a model}}{\\text{Memory bandwidth of an H100}} = \\frac{15.14}{3.3TB/s} = \\text{0.0046s}&quot;,&quot;id&quot;:&quot;TPPLUFSWZW&quot;}" data-component-name="LatexBlockToDOM"></div><p>Meanwhile, when we do all 16.4 TFLOPs worth of calculations we estimated above, we will wait approximately</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Forward pass time}_{compute} = \\frac{\\text{Total FLOPs of forward pass}}{\\text{Measured FLOPS of H100}} = \\frac{16.4 \\text{ TFLOPs}}{750 \\text{TFLOPS}}= 0,021s&quot;,&quot;id&quot;:&quot;DVTPDPFEQI&quot;}" data-component-name="LatexBlockToDOM"></div><p>In practice the memory loading and computations on a GPU are to some degree overlapped, meaning that the factor limiting our performance will be the larger of these two times - compute in this case, or in other words, our <strong>calculation will be more compute than memory bound.</strong> </p><p>Assuming 0.021s for a single forward pass, we can estimate the <strong>upper bound</strong> of embedding throughput as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Embeddings&nbsp;per&nbsp;second} = \\frac{1s}{\\text{Forward pass time}_{compute}} = \\frac{1s}{0.021s} = \\approx 47&quot;,&quot;id&quot;:&quot;SSKKDSTXLG&quot;}" data-component-name="LatexBlockToDOM"></div><p>In practice, we won't achieve these exact numbers. Both memory and compute figures represent <strong>theoretical upper bounds</strong>. Real-world performance falls short due to factors like imperfect memory-compute overlap, kernel launch overhead, and various computational inefficiencies.</p><h2>Real world benchmark</h2><p>To measure the real-world performance of an embedding model, we can use the popular LLM inference engine - <a href="https://github.com/sgl-project/sglang">SGLang</a>. Running it is quite simple (see Fig. 6) and should work out of the box on any H100 setup. SGLang provides an efficient inference platform, realized in the form of an OpenAI-compatible endpoint, and should be a good basis for our experiments. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gQui!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gQui!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 424w, https://substackcdn.com/image/fetch/$s_!gQui!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 848w, https://substackcdn.com/image/fetch/$s_!gQui!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 1272w, https://substackcdn.com/image/fetch/$s_!gQui!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gQui!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png" width="676" height="317.3504823151125" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:584,&quot;width&quot;:1244,&quot;resizeWidth&quot;:676,&quot;bytes&quot;:116256,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gQui!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 424w, https://substackcdn.com/image/fetch/$s_!gQui!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 848w, https://substackcdn.com/image/fetch/$s_!gQui!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.png 1272w, https://substackcdn.com/image/fetch/$s_!gQui!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa4b40a15-2cad-439e-9e71-8f25b82ef599_1244x584.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 role="img" 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><title></title><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">Figure 6: Command we use to run the SGLang instance powering our experiments. </figcaption></figure></div><p>We implemented a <a href="https://github.com/tugot17/tokenomics?tab=readme-ov-file#-embedding-benchmarks">simple benchmark</a> measuring inference engine response times. The benchmark takes two inputs: sequence length (in tokens) and batch size (simulating concurrent users). We sent batches of requests with predefined lengths to the API and measured processing time.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a></p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Zr2N!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Zr2N!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 424w, https://substackcdn.com/image/fetch/$s_!Zr2N!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 848w, https://substackcdn.com/image/fetch/$s_!Zr2N!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!Zr2N!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Zr2N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png" width="1456" height="966" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:966,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:601427,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Zr2N!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 424w, https://substackcdn.com/image/fetch/$s_!Zr2N!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 848w, https://substackcdn.com/image/fetch/$s_!Zr2N!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!Zr2N!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F721dc8fe-910a-4e19-a559-799245acb226_3564x2364.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 role="img" 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><title></title><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">Figure 7: Performance measured at different input sequence lengths. We run Qwen3-8B Embedding on Nebius on <strong>H100 SXM</strong> running on CUDA 12.4 with SGLang 0.5.1. Note that <strong>the x-axis is logscale.</strong></figcaption></figure></div><p>What the reader should immediately spot is how, <strong>despite batch size increasing, the number of embeddings processed within a second doesn&#8217;t scale significantly</strong>. For shorter sequences (260 and 520 tokens), increasing batch size from 1 to 64 yields only ~2.3x improvement in total token throughput. As sequence length increases and compute becomes more saturated, this scaling benefit diminishes ever further. For the longest sequences (5200 tokens), larger batch sizes provide virtually no benefit.</p><p>The reason for this situation can be largely explained by the FLOPS calculations we did above. We estimated that for <em>batch size=1 </em>and sequence length <em>S=1024 tokens,</em> the upper bound is ~47 embeddings per second, roughly double (47/25.3=1.86) what we observe in practice<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>. This gap is to be expected, as model calculations have extra overhead from launching multiple kernel grids, the lower arithmetic intensity of some kernels, and other inefficiencies.</p><p>Even at batch size=1, the computational workload substantially saturates the compute units. At larger sequence lengths, we're operating on increasingly large matrices with no spare compute resources available&#8212;the streaming multiprocessors (SMs) are fully occupied. As batches grow larger or sequences get longer, kernel launch overhead becomes a smaller fraction of total time, with most cycles spent on the calculations themselves.</p><p>What you need to remember, though, is that since we are compute bound and we only get marginal improvements in the number of embeddings processed with increased batch size, it has <strong>a severe impact on the latency experienced by each user</strong>. Since we do these larger and larger scale matrix multiplications, they take longer and longer to finish. This represents a traditional tradeoff in LLM inference - combined throughput vs. the latency experienced by each user. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sZ-u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sZ-u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 424w, https://substackcdn.com/image/fetch/$s_!sZ-u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 848w, https://substackcdn.com/image/fetch/$s_!sZ-u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!sZ-u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sZ-u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png" width="1456" height="972" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:972,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:645084,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sZ-u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 424w, https://substackcdn.com/image/fetch/$s_!sZ-u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 848w, https://substackcdn.com/image/fetch/$s_!sZ-u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!sZ-u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F867b3228-7ed2-46a9-9abf-9a6308fca11f_3541x2364.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 role="img" 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><title></title><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">Figure 8: Latencies corresponding to observations from Fig 7. We use the same hardware setup as for Fig. 7. By latency we mean how long do we wait for an entire batch (requests are batched together).</figcaption></figure></div><p>This contrasts sharply with autoregressive token generation. Here, because our computation is primarily memory rather than compute bound, increasing the batch yields substantial throughput gains. As Figure 9 shows, batch size increases correspond to significant improvements in overall throughput across all requests. The latency penalty for individual users is far less severe than with embeddings.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yjNg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yjNg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 424w, https://substackcdn.com/image/fetch/$s_!yjNg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 848w, https://substackcdn.com/image/fetch/$s_!yjNg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 1272w, https://substackcdn.com/image/fetch/$s_!yjNg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yjNg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png" width="1456" height="1816" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1816,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:476925,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yjNg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 424w, https://substackcdn.com/image/fetch/$s_!yjNg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 848w, https://substackcdn.com/image/fetch/$s_!yjNg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.png 1272w, https://substackcdn.com/image/fetch/$s_!yjNg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7bd772b8-4229-442b-b13a-1febf4662329_3086x3849.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 role="img" 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><title></title><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">Figure 9: Qwen3 8B benchmark on a single H100 SXM, 300 tokens in, 2000 tokens out.</figcaption></figure></div><p>Text generation's memory-bound nature creates this favorable scaling. We primarily wait for model weights to load for each token generated while compute resources remain underutilized. Loading the model once and "sharing" this cost across multiple users has minimal impact on per-user experience.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a></p><p><strong>The fundamental difference lies in computational bottlenecks.</strong> While autoregressive generation is limited by memory bandwidth and benefits from amortizing memory costs across batches, embeddings face the opposite constraint. Embedding generation requires only a single forward pass, but this pass involves large-scale matrix operations that fully saturate available compute. <strong>This is the main intuition we hope the reader takes out of this text. Embeddings are primarily compute bound</strong>. Due to this there is only limited benefit to batching, and it comes at the cost of severely increased latency experienced by each individual user. This means that, unlike in serving GPT-style models, there are very limited benefits to scale - running big batches doesn&#8217;t slash our cost &#8220;per user&#8221;. This further decreases the appeal of serving embeddings as a business. </p><h1>What profiling reveals</h1><p>What we calculated while doing the theoretical analysis of the Qwen embedding forward pass, and what we measured via our benchmarking script, can also be observed if we profile the forward pass and look at the individual kernels being invoked. The profile trace can be easily obtained from SGLang by hitting the `start_profile` and `stop_profile` endpoints. All calculations in between these calls will be captured by the <a href="https://docs.pytorch.org/tutorials/recipes/recipes/profiler_recipe.html">torch profiler</a> as demonstrated in Fig. 10. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Pfyn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Pfyn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 424w, https://substackcdn.com/image/fetch/$s_!Pfyn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 848w, https://substackcdn.com/image/fetch/$s_!Pfyn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 1272w, https://substackcdn.com/image/fetch/$s_!Pfyn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Pfyn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png" width="1456" height="1013" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1013,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:245518,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Pfyn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 424w, https://substackcdn.com/image/fetch/$s_!Pfyn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 848w, https://substackcdn.com/image/fetch/$s_!Pfyn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.png 1272w, https://substackcdn.com/image/fetch/$s_!Pfyn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F70fa6caf-021e-49bc-b1c5-55cbe5fe81d3_1498x1042.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 role="img" 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><title></title><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">Figure 10: How to send the profiling request to SGLang. </figcaption></figure></div><p>Before diving into our profiling results, it&#8217;s important to understand how to read these traces. Torch Profiler shows both CPU and GPU activity in a unified timeline, but they operate asynchronously.</p><ul><li><p>CPU timeline (top portion): Shows when the host code launches kernels, allocates memory, and performs other CPU operations</p></li><li><p>GPU timeline (bottom portion): Shows when kernels actually execute on the GPU hardware</p></li><li><p>Asynchronous execution: When the CPU &#8220;launches&#8221; a kernel, it doesn&#8217;t wait for completion&#8212;it immediately continues to the next instruction while the GPU executes the kernel independently</p></li></ul><p>This asynchronous nature means there&#8217;s often a visible gap between when a kernel is launched (CPU) and when it actually runs (GPU). When we look at the high-level (Fig. 11) trace of a forward pass, we can clearly see multiple (36) hidden layers being called. The kernels are pretty well packed together. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!5XG7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!5XG7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 424w, https://substackcdn.com/image/fetch/$s_!5XG7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 848w, https://substackcdn.com/image/fetch/$s_!5XG7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 1272w, https://substackcdn.com/image/fetch/$s_!5XG7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!5XG7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png" width="1456" height="1035" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1035,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1192200,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!5XG7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 424w, https://substackcdn.com/image/fetch/$s_!5XG7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 848w, https://substackcdn.com/image/fetch/$s_!5XG7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.png 1272w, https://substackcdn.com/image/fetch/$s_!5XG7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F548a9aac-2c84-4bde-9aa8-db7bfe7271ce_1696x1206.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 role="img" 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><title></title><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">Figure 11: High-level profiling trace. Profile for 2600 tokens, batch size 1.</figcaption></figure></div><p>When we look at the single-layer level (see Fig. 12), we can identify the individual components of a transformer layer. Even for a relatively long sequence of 2600 tokens, <strong>MLP computation visibly dominates execution time</strong>. Additionally, the reader should note that except for the time the GPU is working (kernel) is visible, there are some small, but still existing, gaps between the kernels and kernels invoked to prepare the data (the small pink rectangles before the flash attention kernel). All of these gaps and small kernels add extra overhead to our computation.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!F4iC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!F4iC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 424w, https://substackcdn.com/image/fetch/$s_!F4iC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 848w, https://substackcdn.com/image/fetch/$s_!F4iC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 1272w, https://substackcdn.com/image/fetch/$s_!F4iC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!F4iC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png" width="1456" height="972" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:972,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:547626,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!F4iC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 424w, https://substackcdn.com/image/fetch/$s_!F4iC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 848w, https://substackcdn.com/image/fetch/$s_!F4iC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.png 1272w, https://substackcdn.com/image/fetch/$s_!F4iC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3ac4683a-82e8-4bfd-9e8d-220935650ddd_1643x1097.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 role="img" 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><title></title><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">Figure 12: Single transformer layer profile. Profile for 2600 tokens, batch size 1, on NVIDIA <strong>H100 SXM5</strong>. For the convenience of the reader, we show which kernel is responsible for which element of a transformer block forward pass. </figcaption></figure></div><p>When we aggregate all of the kernels invoked during the forward pass, an interesting pattern emerges (see Fig. 13). The majority of time during a forward pass is spent computing <em>nvjet_tst_256x144_64x4&#8230;  </em>kernels - CUDA highly optimized matrix multiplication kernels. This is another one of the key observations we hope the reader takes out of reading this text. <strong>The vast majority of forward passes while calculating the embeddings are spent in matrix multiplication kernels</strong>. What it implies is that the 750 TFLOPs we calculated for matrix multiplication in the previous section will be a pretty good proxy for estimating our time of a forward pass, and as a result, the throughput.</p><p>Other kernels like fused SILU and RMS norm (primarily from <a href="https://github.com/flashinfer-ai/flashinfer">FlashInfer</a>) contribute smaller percentages of wall time and aren't explored further here.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JbRB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JbRB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 424w, https://substackcdn.com/image/fetch/$s_!JbRB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 848w, https://substackcdn.com/image/fetch/$s_!JbRB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!JbRB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JbRB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png" width="1456" height="1173" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1173,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:537720,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JbRB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 424w, https://substackcdn.com/image/fetch/$s_!JbRB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 848w, https://substackcdn.com/image/fetch/$s_!JbRB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.png 1272w, https://substackcdn.com/image/fetch/$s_!JbRB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6f8a255f-eef8-4d65-89aa-cc714891c7e0_1986x1600.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 role="img" 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><title></title><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">Figure 13: Kernel statistics aggregation. Profile for 2600 tokens, batch size 1, on NVIDIA <strong>H100 SXM5</strong>.</figcaption></figure></div><p>What should be pretty interesting to the reader is how small a percentage of the forward pass is spent calculating the attention. In our 2600-token example, only 6% of execution time occurs in the attention kernel. Note that the <em>flash attention </em>kernel represents just part of the attention block's total cost. As Figure 12 shows, substantial time is spent on <em>QKV projection</em>, <em>O projection</em>, and input preparation (such as applying RoPE).</p><p>Since attention has <em>O(N^2)</em> complexity with respect to length, and MLP grows linearly (we calculate the up and down projections for each token in the sequence), as we increase the input length, attention will represent a more and more significant portion of the forward pass time. E.g., in Fig. 14 we show that when we increase the sequence length to 8k tokens, the percentage of time spent in calculating the flash attention kernel grows from 6% to 15% of the total time. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IWvf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IWvf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 424w, https://substackcdn.com/image/fetch/$s_!IWvf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 848w, https://substackcdn.com/image/fetch/$s_!IWvf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 1272w, https://substackcdn.com/image/fetch/$s_!IWvf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IWvf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png" width="1456" height="1201" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1201,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:559609,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IWvf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 424w, https://substackcdn.com/image/fetch/$s_!IWvf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 848w, https://substackcdn.com/image/fetch/$s_!IWvf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.png 1272w, https://substackcdn.com/image/fetch/$s_!IWvf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F63a9c7f1-2460-483c-86d5-393357a0d220_1986x1638.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 role="img" 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><title></title><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">Figure 14: Kernel statistics aggregation. Profile for 8000 tokens, batch size 1, on NVIDIA <strong>H100 SXM5</strong>.</figcaption></figure></div><p>When we increase the batch size, the number of operations grows linearly both for the matrix multiplication kernels (we need to handle linearly more tokens) and for the flash attention kernel. You can see (Fig. 15) that as we increase the batch size, the percentage of the wall time remains (roughly) the same. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z8HW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z8HW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 424w, https://substackcdn.com/image/fetch/$s_!z8HW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 848w, https://substackcdn.com/image/fetch/$s_!z8HW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 1272w, https://substackcdn.com/image/fetch/$s_!z8HW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z8HW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png" width="1456" height="1201" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1201,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:558048,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!z8HW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 424w, https://substackcdn.com/image/fetch/$s_!z8HW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 848w, https://substackcdn.com/image/fetch/$s_!z8HW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.png 1272w, https://substackcdn.com/image/fetch/$s_!z8HW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F49ebe1be-b358-4fd4-82a6-052037378de8_1986x1638.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 role="img" 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><title></title><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">Figure 15: Kernel statistics aggregation. Profile for 2600 tokens, batch size 16, on NVIDIA <strong>H100 SXM5</strong>.</figcaption></figure></div><p>The traces demonstrate that most time is spent in matrix multiplication kernels. However, the torch profiler only shows <em>that</em> the GPU is working on these kernels&#8212;not <em>how efficiently</em> it's utilizing available compute resources. While we might assume NVIDIA's highly optimized kernels achieve good utilization, it would be nice to confirm this. </p><p>What we can do is we can run the NCU profile while producing an embedding. Such an option is also available in SGLang, though it is slightly more challenging to make it run than in the case of the torch profiler. </p><p>When profiling the kernel with NCU, it becomes pretty evident that we achieve very, very high compute utilization (see Fig. 16). Our compute throughput is pretty close to 100% of utilization. Note how since the majority of time is spent computing, the memory remains underutilized. </p><p>Since most of our time is spent in these matrix multiplication kernels, and they by default present a very good compute utilization, this bears the question, <strong>&#8220;What could be further improved?&#8221;</strong></p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!O_-D!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!O_-D!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 424w, https://substackcdn.com/image/fetch/$s_!O_-D!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 848w, https://substackcdn.com/image/fetch/$s_!O_-D!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 1272w, https://substackcdn.com/image/fetch/$s_!O_-D!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!O_-D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png" width="1456" height="281" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:281,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:211265,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!O_-D!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 424w, https://substackcdn.com/image/fetch/$s_!O_-D!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 848w, https://substackcdn.com/image/fetch/$s_!O_-D!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 1272w, https://substackcdn.com/image/fetch/$s_!O_-D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc903b9a9-09ba-4af8-8d92-880a3ebe910f_2826x546.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Figure 16: Profile of the <em>nvjet_tst_256x144_64x4_2x1_v_bz_coopA_TNT </em>kernel using the NCU shown in <a href="https://developer.nvidia.com/nsight-systems">NVIDIA Nsight Systems</a>. The profiling was done using H100 PCIe (different from other calculations shown in this text).</figcaption></figure></div><h1>From FLOPs to dollars</h1><p>As we calculated in the beginning of this text, generating embeddings is incredibly cheap. Embedding an entire English Wikipedia will set a user back around $650. <strong>Our contention is that the cheap prices offered to consumers are a result of the underlying cost structure</strong> <strong>- that producing the tokens is just incredibly efficient and that, due to competitive pressure, the cost savings are passed onto the consumers, driving the price basically to zero.</strong> </p><p>Based on the experiments we captured in Fig. 7, we can quite easily calculate what the total number of tokens processed per second is at different batch sizes at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Embeddings/second} \\times \\text{Tokens per embedding}&quot;,&quot;id&quot;:&quot;FCFPKMQNUW&quot;}" data-component-name="LatexBlockToDOM"></div><p>For example, with 1040-token sequences at batch size 4:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{32.2 embeddings/s} \\times \\text{1040 tokens/embedding} = \\text{33488 tokens/s}&quot;,&quot;id&quot;:&quot;WILGIVJNWS&quot;}" data-component-name="LatexBlockToDOM"></div><p>In Tab. 1 we present the number of tokens processed each second based on the numbers presented in Fig. 7. What the reader should note is that the numbers saturate around <em>~45k tokens/s, </em>which once again shows our calculation getting compute bound. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!l6oE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!l6oE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 424w, https://substackcdn.com/image/fetch/$s_!l6oE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 848w, https://substackcdn.com/image/fetch/$s_!l6oE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 1272w, https://substackcdn.com/image/fetch/$s_!l6oE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!l6oE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png" width="924" height="381" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:381,&quot;width&quot;:924,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:78332,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!l6oE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 424w, https://substackcdn.com/image/fetch/$s_!l6oE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 848w, https://substackcdn.com/image/fetch/$s_!l6oE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.png 1272w, https://substackcdn.com/image/fetch/$s_!l6oE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F20fd5ba8-0426-41c6-b2db-b77e7aaf2a6c_924x381.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 role="img" 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><title></title><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">Table 1: Tokens processed within a second assuming input sequences of different lengths and coming in different batches. Numbers for Qwen3 8B Embedding, run on NVIDIA H100 SXM5 with CUDA 12.4 on Nebius cloud.</figcaption></figure></div><p>Assuming that we are renting H100 for <em>$2/h, </em>we can estimate the cost of producing a million tokens as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Cost per million tokens} = \\frac{\\text{GPU cost per hour}}{\\text{tokens per second} \\times 3600} \\times 10^6\n&quot;,&quot;id&quot;:&quot;BEYOZXIQHI&quot;}" data-component-name="LatexBlockToDOM"></div><p> e.g., for embeddings of an input sequence of <em>1040 tokens </em>at batch size 4, we calculated above it would translate to around</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Cost per million tokens} = \\frac{\\$2/\\text{hr}}{33{,}488 \\text{ tokens/s} \\times 3600 \\text{ s/hr}} \\times 10^6 = \\$0.0166&quot;,&quot;id&quot;:&quot;PCXPLAQSLO&quot;}" data-component-name="LatexBlockToDOM"></div><p>or 1.66 cents for processing a million tokens.</p><p>In Tab. 2 we present the estimated pricing for different settings.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Fhoh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Fhoh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 424w, https://substackcdn.com/image/fetch/$s_!Fhoh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 848w, https://substackcdn.com/image/fetch/$s_!Fhoh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 1272w, https://substackcdn.com/image/fetch/$s_!Fhoh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Fhoh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png" width="924" height="381" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:381,&quot;width&quot;:924,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:74677,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Fhoh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 424w, https://substackcdn.com/image/fetch/$s_!Fhoh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 848w, https://substackcdn.com/image/fetch/$s_!Fhoh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.png 1272w, https://substackcdn.com/image/fetch/$s_!Fhoh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe132a56b-99af-406e-87e5-f0cb0a0fc039_924x381.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 role="img" 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><title></title><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">Table 2: Price for processing 1M input tokens, based on the numbers we presented in Tab. 1. We assume $2/h for NVIDIA <strong>H100 SXM</strong>.</figcaption></figure></div><p><strong>The prices estimated above build on the assumption that we enjoy 100% utilization</strong> at the given batch size, meaning that 24/7 we get requests coming in that we can compute and charge the user for. In practice we will for sure get periods of higher traffic when your API is bombarded by the requests and quiet periods, e.g., outside of business hours, when our compute will be mostly idling. </p><p>Our exact calculations will depend on these computation patterns, how many users you have per GPU, <strong>how much latency your users are willing to accept </strong>(see Fig. 8), and how time-concentrated our requests are. </p><p>Assuming that our typical request will be similar to <em>batch size 4 </em>of a request of size <em>1040 tokens</em> coming at the same time and this will happen around 10% of the time throughout the day, this would result in <em>32.2 x 3600 x 24 x 0.1 &#8776; 276k</em> requests. In such a case our cost for processing 1M input tokens would be around $0.0166 x 10 = $0.16, or 16 cents/1M tokens. Slightly above the OAI pricing for <em>ada-embeddings</em>. </p><p><strong>Other than bringing in more users, could we do anything else to improve our cost structure?</strong> </p><h1>Our metric - FLOPS per dollar</h1><p>Consider embedding generation from first principles. Our computation pattern has four key characteristics:</p><ol><li><p>We do just a single forward pass.</p></li><li><p>Our model is in bf16. It is relatively small, occupying only 15.2 GB of space (plus some space for activations); we can easily fit it on a single GPU, and we don&#8217;t need high communication between the GPU.</p></li><li><p>The forward pass is mostly compute bound - having fast memory brings us little benefit.</p></li><li><p>We know that our most important metric is how fast the GPU can do large matrix multiplications - FLOPS</p></li></ol><p>Since we're primarily FLOPS-bound, <strong>the metric we should optimize is FLOPS/dollar</strong>. Why pay premium prices for H100's 80GB of memory, ultra-fast memory bandwidth, and high-speed interconnects when our small model doesn't require these features? Most of our time is spent computing, not moving data.</p><p>The logical approach is finding GPUs with superior FLOPS/dollar ratios. Table 3 compares three popular options using on-demand cloud pricing: H100 SXM, A100, and RTX 4090.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sSPT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sSPT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 424w, https://substackcdn.com/image/fetch/$s_!sSPT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 848w, https://substackcdn.com/image/fetch/$s_!sSPT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 1272w, https://substackcdn.com/image/fetch/$s_!sSPT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sSPT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png" width="1208" height="435" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:435,&quot;width&quot;:1208,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66850,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sSPT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 424w, https://substackcdn.com/image/fetch/$s_!sSPT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 848w, https://substackcdn.com/image/fetch/$s_!sSPT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.png 1272w, https://substackcdn.com/image/fetch/$s_!sSPT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F325a9936-6098-4647-a8bc-0aa8303e9ab3_1208x435.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 role="img" 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><title></title><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">Table 3: TFLOPS declared by NVIDIA for H100 SXM, A100, and 4090. The pricing is an estimation; the exact pricing will depend on the current hardware availability. </figcaption></figure></div><p>On paper, the H100 dominates this comparison, achieving the best FLOPS/dollar ratio out of the three compared GPUs.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-5" href="#footnote-5" target="_self">5</a>. However, as we showed in Fig. 5, in practice H100s gets power-bound. The 989 989TFLOPS promised by Nvidia are unattainable.</p><p>Using the more more realistic 750 TFLOPS (as estimated in Fig. 5), the TFLOPS/$ ratio would drop to <em>750/2=375</em>, considerably below the RTX 4090's theoretical 445. To verify whether the RTX 4090 can achieve its declared 165 TFLOPS, we ran identical matrix multiplication benchmarks (Fig. 17). The RTX 4090 closely matches NVIDIA's specifications.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!F_l-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!F_l-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 424w, https://substackcdn.com/image/fetch/$s_!F_l-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 848w, https://substackcdn.com/image/fetch/$s_!F_l-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 1272w, https://substackcdn.com/image/fetch/$s_!F_l-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!F_l-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png" width="1456" height="867" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:867,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:187916,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!F_l-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 424w, https://substackcdn.com/image/fetch/$s_!F_l-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 848w, https://substackcdn.com/image/fetch/$s_!F_l-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.png 1272w, https://substackcdn.com/image/fetch/$s_!F_l-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd4c59096-a683-4d36-9a46-53222afd4456_2964x1764.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 role="img" 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><title></title><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">Figure 17: FLOPS achieved on Runpod on NVIDIA <strong>4090.</strong> Code can be found <a href="https://gist.github.com/tugot17/897237824f7960bdb4a7857aed560a61">here</a>.</figcaption></figure></div><p>The price difference is significant: H100 costs 5.4x more than RTX 4090 ($2/$0.37), while the performance difference is only:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{\\text{Real FLOPS of H100}}{\\text{Real FLOPS of 4090}}=\\frac{750}{165}\\approx 4.5\n&quot;,&quot;id&quot;:&quot;EYCNVDNHLD&quot;}" data-component-name="LatexBlockToDOM"></div><p>This suggests RTX 4090 should deliver better performance per dollar for embedding generation. Since embedding computation is dominated by large-scale matrix multiplication, this benchmark performance difference should accurately predict real-world embedding throughput differences.</p><p>To confirm this prediction, we ran identical benchmarks on the RTX 4090 (Figs. 18-19).<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-6" href="#footnote-6" target="_self">6</a>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!KGgP!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KGgP!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 424w, https://substackcdn.com/image/fetch/$s_!KGgP!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 848w, https://substackcdn.com/image/fetch/$s_!KGgP!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!KGgP!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KGgP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png" width="1456" height="966" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:966,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:564570,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KGgP!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 424w, https://substackcdn.com/image/fetch/$s_!KGgP!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 848w, https://substackcdn.com/image/fetch/$s_!KGgP!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!KGgP!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e01dd25-3246-4888-b69e-dedaf1c640be_3564x2364.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 role="img" 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><title></title><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">Figure 18: Performance measured at different input sequence lengths. We run Qwen3-8B Embedding on RunPod on NVIDIA <strong>4090</strong> with SGLang 0.5.1. Note that the x-axis is logscale.</figcaption></figure></div><p>The results mirror our H100 observations: as batch size increases, per-user latency grows (Fig. 19). The RTX 4090 demonstrates the same compute-bound behavior - limited throughput scaling with larger batches but severe latency penalties for individual users.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Kla9!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Kla9!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 424w, https://substackcdn.com/image/fetch/$s_!Kla9!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 848w, https://substackcdn.com/image/fetch/$s_!Kla9!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!Kla9!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Kla9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png" width="1456" height="971" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/df9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.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;:678878,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Kla9!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 424w, https://substackcdn.com/image/fetch/$s_!Kla9!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 848w, https://substackcdn.com/image/fetch/$s_!Kla9!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.png 1272w, https://substackcdn.com/image/fetch/$s_!Kla9!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdf9fdd6a-3555-4412-88d3-371ae46b88b8_3543x2364.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 role="img" 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><title></title><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">Figure 19: Latencies corresponding to observations from Fig. 18. We use the same hardware setup as for Fig. 18. By latency we mean how long do we wait for an entire batch (requests are batched together).</figcaption></figure></div><p>Especially for the shorter inputs, the 4090 performs surprisingly well. The H100-to-4090 performance ratio ranges from 25.3/7.2 = 3.5x at batch size 1 to 45.2/10.8 = 4.2x at larger batches - smaller gaps than the 4.5x difference we measured in pure matrix multiplication benchmarks.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mulK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mulK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 424w, https://substackcdn.com/image/fetch/$s_!mulK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 848w, https://substackcdn.com/image/fetch/$s_!mulK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 1272w, https://substackcdn.com/image/fetch/$s_!mulK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mulK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png" width="1456" height="1036" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1036,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:619621,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mulK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 424w, https://substackcdn.com/image/fetch/$s_!mulK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 848w, https://substackcdn.com/image/fetch/$s_!mulK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.png 1272w, https://substackcdn.com/image/fetch/$s_!mulK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87c63de1-4711-4cdb-9fe3-338bb1dbf8c9_4164x2964.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 role="img" 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><title></title><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">Figure 20: Comparison of NVIDIA H100 SXM vs NVIDIA 4090 on shorter prompts. We use the same setups as in Figure 7 and Figure 18, respectively. </figcaption></figure></div><p>As sequence length increases and we process larger matrices that more fully saturate compute resources, the performance ratio approaches our <strong>measured</strong> 4.5x matrix multiplication difference.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Xxlh!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Xxlh!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 424w, https://substackcdn.com/image/fetch/$s_!Xxlh!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 848w, https://substackcdn.com/image/fetch/$s_!Xxlh!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 1272w, https://substackcdn.com/image/fetch/$s_!Xxlh!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Xxlh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png" width="1456" height="1037" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1037,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:414264,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Xxlh!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 424w, https://substackcdn.com/image/fetch/$s_!Xxlh!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 848w, https://substackcdn.com/image/fetch/$s_!Xxlh!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.png 1272w, https://substackcdn.com/image/fetch/$s_!Xxlh!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe8d5bcc0-f287-4796-b910-3f77a499a1c5_4163x2964.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 role="img" 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><title></title><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">Figure 21: Figure 20: Comparison of NVIDIA H100 SXM vs NVIDIA 4090 on longer prompts. We use the same setups as in Figure 7 and Figure 18, respectively. </figcaption></figure></div><p>What should be pretty apparent is that <strong>the performance difference is smaller than the price difference between the H100 and the 4090</strong> - meaning that the per dollar spent, we should be able to produce more tokens. To confirm this, similarly to what we did for H100 in Tab. 1, we calculate the number of tokens processed within a second by 4090 in Tab. 4:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cZlH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cZlH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 424w, https://substackcdn.com/image/fetch/$s_!cZlH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 848w, https://substackcdn.com/image/fetch/$s_!cZlH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 1272w, https://substackcdn.com/image/fetch/$s_!cZlH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cZlH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png" width="1456" height="621" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:621,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142756,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cZlH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 424w, https://substackcdn.com/image/fetch/$s_!cZlH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 848w, https://substackcdn.com/image/fetch/$s_!cZlH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.png 1272w, https://substackcdn.com/image/fetch/$s_!cZlH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F153ce44b-874f-446d-be41-b88a473c0d55_1470x627.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 role="img" 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><title></title><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">Table 4: Tokens processed within a second assuming input sequences of different lengths and coming in different batches. Numbers for Qwen3 8B Embedding, run on NVIDIA <strong>4090</strong> on RunPod.</figcaption></figure></div><p>Assuming we pay $0.37 for an hour of 4090 and we use it to continuously embed an input sequence of <em>1040 tokens </em>at <em>batch size=4,</em> it would translate to around</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Cost per million tokens} = \\frac{\\$0.37/\\text{hr}}{9672 \\text{ tokens/s} \\times 3600 \\text{ s/hr}} \\times 10^6 = \\$0,01062&quot;,&quot;id&quot;:&quot;RWFPCXSWYQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>or around 1&#162; for 1M tokens - 36% cheaper than the number we achieved for H100. </p><p>In Tab. 5, we present the estimated pricing for processing 1M input tokens. Once again, please note that this assumes 100% utilization; in practice, you won&#8217;t be able to process it so cheaply unless you have some sort of a batching system and massive, not time-sensitive demand that can be spread evenly throughout the day.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1R2I!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1R2I!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 424w, https://substackcdn.com/image/fetch/$s_!1R2I!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 848w, https://substackcdn.com/image/fetch/$s_!1R2I!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 1272w, https://substackcdn.com/image/fetch/$s_!1R2I!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1R2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png" width="1456" height="618" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:618,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:135514,&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://www.tensoreconomics.com/i/173115165?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1R2I!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 424w, https://substackcdn.com/image/fetch/$s_!1R2I!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 848w, https://substackcdn.com/image/fetch/$s_!1R2I!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.png 1272w, https://substackcdn.com/image/fetch/$s_!1R2I!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57d269f7-a353-486e-89ed-c9386108eb02_1478x627.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 role="img" 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><title></title><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">Table 5: Price for processing 1M input tokens, based on the numbers we presented in Tab. 4. We assume $0.37/h for NVIDIA 4090.</figcaption></figure></div><p>Note how Tab. 5 demonstrates our point. We were able to find a GPU that offers a superior FLOPS/dollar compared to an H100; this better performance is clearly reflected in the cost for processing 1M tokens. In 4090, in a lot of cases, we are able to drive the price of 1M tokens below 1&#162;. If we have more demand, we can simply scale the number of 4090s, which should be cheaper than switching to an H100. </p><p>Interestingly, for a 4090 that costs only <em>24x$0.37=$8.8 </em>per day to rent, assuming we continuously get batches of <em>1040 tokens </em>at <em>batch size=32,</em> it can process </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{11024 tokens/s} \\times 3600s \\times 24h = 952M \\approx \\text{1B tokens/day}&quot;,&quot;id&quot;:&quot;OYERRTVEIE&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>We find it quite remarkable that a consumer-grade GPU that you can rent for less than </strong><em><strong>$9 </strong></em><strong>per day can process 1B tokens a day if provided enough demand.</strong></p><p>Noteworthy embeddings are not the only application where you might benefit from prioritizing FLOPS/dollar spent. Prefill, especially in agentic tasks with long context consisting of long tool calls, is another example. <a href="https://semianalysis.com/2025/09/10/another-giant-leap-the-rubin-cpx-specialized-accelerator-rack/">Recently NVIDIA released Rubin CPX</a> exactly for this purpose - a chip that&#8217;s heavy on compute but light on memory bandwidth, using cheaper GDDR7 instead of expensive HBM. It&#8217;s the same logic we&#8217;ve been discussing: when you&#8217;re compute-bound, optimize for FLOPS per dollar. </p><h1>Summary</h1><p>We started this text mentioning that embedding APIs are very cheap to use, and we argued that this underlying price is derived from low costs of producing the embedding representations rather than being subsidized below the cost of production. </p><p>We took the leading open-source embedding model, Qwen3 8B Embedding, and analyzed it in detail, including theoretical estimation of the FLOPS and real-world performance benchmarking. We did a deep dive into what is happening under the hood, showed which kernels are invoked, and showed how the majority of the execution time is spent in large-scale matrix multiplication. </p><p>Lastly, based on the observed performance, we calculated the price for processing 1M input tokens for different input-tokens/batch-size setups. Please once again note that the numbers shown assume a situation in which you enjoy 100% utilization, with the request being continuously batched. </p><p>GPUs are incredibly efficient at these sorts of workloads, driving the price down to zero. Since all leading models converge on a similar latent representation, and perform comparably no one has a pricing power enabling them to command higher prices. As the model gets more efficient, compute and energy get cheaper, and this situation will move towards the generative models as well. <strong>The embedding situation offers a nice pre-taste of the "intelligence involution&#8221; that is coming &#8230;</strong></p><h1>Acknowledgments</h1><p>Thanks to <a href="https://x.com/johannes_hage">Johannes</a> from <a href="https://x.com/PrimeIntellect">Prime Intellect</a> for providing me with the compute to run these experiments, and to <a href="https://x.com/jobergum">Jo</a> (check out his <a href="https://hornet.dev/">new retrieval company</a>), <a href="https://x.com/felix_red_panda/">Felix</a>, <a href="https://x.com/pabloiyu">Pablo</a> and <a href="https://x.com/SzymonOzog_">Szymon</a> for giving me comments for parts of this text. </p><pre><code>@online{tensoreconomics2025embeddings,
  author = {Piotr Mazurek},
  title = {Why are embeddings so cheap?},
  url = {https://www.tensoreconomics.com/p/why-are-embeddings-so-cheap},
  urldate = {2025-09-24},
  year = {2025},
  month = {September},
  publisher = {Substack}
}</code></pre><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>Prices as of 8.09.2025</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>Before each experiment we do a quick warmup of the GPU. We also repeat each experiment setup multiple times (e.g., 10) and measure the mean and the variance.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p>We have a small difference between the estimation and experiment. In our estimate we use 1024 tokens; in experiments we use 1040 tokens&#8212;a ~1.5% difference. It has a negligible impact on the calculations; we just want the reader to know we are aware of this minor difference. </p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-4" href="#footnote-anchor-4" class="footnote-number" contenteditable="false" target="_self">4</a><div class="footnote-content"><p>There is some limit to this; as we increase the batch size, the KV cache will represent a more and more substantial portion of the total memory loaded. As the KV cache starts to dominate the load, the per-user experience will start to be more and more impacted by the batch size.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-5" href="#footnote-anchor-5" class="footnote-number" contenteditable="false" target="_self">5</a><div class="footnote-content"><p>Note that if you were to buy these GPUs the ratio between the devices would be different, e.g. a new 4090 can be aquired for ~$3200 while a brand new H100 SXM5 would cost around 10x more.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-6" href="#footnote-anchor-6" class="footnote-number" contenteditable="false" target="_self">6</a><div class="footnote-content"><p>We rented a 4090 on RunPod, running within a container.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[MoE Inference Economics from First Principles ]]></title><description><![CDATA[DeepSeek &#128051;, Kimi, synthetic data markets and the token overcapacity issue]]></description><link>https://www.tensoreconomics.com/p/moe-inference-economics-from-first</link><guid isPermaLink="false">https://www.tensoreconomics.com/p/moe-inference-economics-from-first</guid><dc:creator><![CDATA[Piotr Mazurek]]></dc:creator><pubDate>Tue, 02 Sep 2025 18:00:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!qHWN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The release of first DeepSeek R1, then Kimi K2 and then DeepSeek V3.1 mixture-of-expert (MoE) models has firmly established them as the leading architecture of large language models (LLMs) at the intelligence frontier. Due to their massive size (1 trillion parameters and up) and sparse computation pattern, selectively activating parameter subsets rather than the entire model for each token, MoE-style LLMs present significant challenges for inference workloads, significantly altering the underlying inference economics. With the ever-growing consumer demand for AI models, as well as the internal need of AGI companies to generate trillions of tokens of synthetic data, the "cost per token" is becoming an ever more important factor, determining the profit margins and the cost of capex required for internal reinforcment learning (RL) training rollouts. </p><p>This analysis examines MoE architecture through the lens of hardware limitations and costs. Key bottlenecks: FLOPS, memory bandwidth, and inter-node connection speed directly impacts end-to-end performance and user scaling potential. Building on this foundation, we develop a theoretical cost model for large-scale model serving, comparing Deepseek V3.1 and Kimi K2 and showing how the hardware costs shape the business models of LLM inference providers. </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tensoreconomics.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Tensor Economics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>We use this world model to go from tokens to dollars - demonstrating how these models can be cost-effectively served to consumers at scale and how cheaply they can be used for synthetic data generation. We argue that this is a market opportunity currently flying under the radar and a potential growth engine for NeoClouds. Lastly, we address the elephant in the room - the surprising lack of consumption of these models. Despite the great dollar/performance ratio, the global consumption of open-source models remains surprisingly minuscule, suggesting a potential oversupply of inference providers and a capability gap that is felt by users but not necessarily reflected well in the benchmarks. </p><p>The remainder of this article proceeds as follows. We first examine DeepSeek's architecture in detail, covering multi-head latent attention (MLA), expert routing, and expert parallelism (EP). Building on DeepSeek's published optimizations&#8212;many of which are implemented in SGLang&#8212;we develop a theoretical performance model that works across diverse hardware specifications. We then validate this model against real-world performance data and use it to derive per-token pricing for different deployment configurations. </p><p><strong>For readers seeking a concise overview of inference economics, we recommend proceeding directly to section &#8220;Hardware considerations and profit margins&#8220;</strong>, returning to examine the DeepSeek V3.1 architectural details and the theoretical model formulation as reference material when needed.</p><p>Sections <em>&#8220;DeepSeek MoE Architecture&#8221;</em>,  &#8220;<em>Inference Optimization Techniques&#8221; and &#8220;Throughput: Theory vs Practice&#8221; </em>are based on the authors' work at Aleph Alpha. We publish the numbers and methods we used internally for estimating the hardware requirements and the numbers we observed through conducting experiments of running DeepSeekV3.1 on multi-node setups. The theoretical model appeared first on the <a href="https://aleph-alpha.com/deepseek-inference-theoretical-model-deriving-the-performance-from-hardware-primitives/">Aleph Alpha Blog.</a></p><h1>Introduction</h1><p>In January 2025, DeepSeek's <a href="https://arxiv.org/abs/2501.12948">release</a> of their R1 reasoning model <a href="https://www.reuters.com/technology/chinas-deepseek-sets-off-ai-market-rout-2025-01-27/">triggered</a> the so-called "DeepSeek shock" in the global financial markets - with major Western tech companies, most notably NVIDIA (see Fig. 1), taking massive (though short-lived) losses to their market caps. While it is not possible to establish what exactly spooked the investors, it seems widely accepted that the ultimate reason was the realization of how cost-efficient it was to train the original DeepSeek V3, with the figure reported in the paper of only <em>$5.6M</em>, orders of magnitude less than the figures <a href="https://www.wired.com/story/openai-ceo-sam-altman-the-age-of-giant-ai-models-is-already-over/">reported</a> by various western labs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!yrf7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!yrf7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 424w, https://substackcdn.com/image/fetch/$s_!yrf7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 848w, https://substackcdn.com/image/fetch/$s_!yrf7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 1272w, https://substackcdn.com/image/fetch/$s_!yrf7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!yrf7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png" width="1348" height="854" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:854,&quot;width&quot;:1348,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:114036,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!yrf7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 424w, https://substackcdn.com/image/fetch/$s_!yrf7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 848w, https://substackcdn.com/image/fetch/$s_!yrf7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.png 1272w, https://substackcdn.com/image/fetch/$s_!yrf7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc3ad2974-4b6c-4258-8c51-79f753435348_1348x854.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 role="img" 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><title></title><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">Figure 1: The "DeepSeek moment" for NVIDIA stock price, as investors priced in the potential savings in model training.</figcaption></figure></div><p>What stood out to industry insiders even more than the minuscule training budget was the massive cost advantage DeepSeek API offered. At only <em>$2.1/1M</em> output tokens, it provided an over 27x cost advantage (see Fig. 2) while nearly matching O1-preview's benchmark performance (the leading reasoning model at the time). </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8tMu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8tMu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 424w, https://substackcdn.com/image/fetch/$s_!8tMu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 848w, https://substackcdn.com/image/fetch/$s_!8tMu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 1272w, https://substackcdn.com/image/fetch/$s_!8tMu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8tMu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png" width="1101" height="552" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:552,&quot;width&quot;:1101,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:52829,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8tMu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 424w, https://substackcdn.com/image/fetch/$s_!8tMu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 848w, https://substackcdn.com/image/fetch/$s_!8tMu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.png 1272w, https://substackcdn.com/image/fetch/$s_!8tMu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F12911857-7a5e-4866-ba1b-cbb53302c5b5_1101x552.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 role="img" 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><title></title><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">Figure 2: o1-preview pricing in January 2025, from <a href="https://medium.com/towards-agi/openai-o1-api-pricing-explained-everything-you-need-to-know-cbab89e5200d">source</a></figcaption></figure></div><p>The DeepSeek team has been unprecedentedly open about the model and training details, and, most relevant to this analysis, about their inference infrastructure details. During the Open Source Week, among other things, they <a href="https://x.com/deepseek_ai/status/1893836827574030466">released</a> efficient multi-head latent attention (MLA) kernels, an expert parallel (EP) <a href="https://x.com/deepseek_ai/status/1894211757604049133">communication library</a>, and they published the details of their inference stack and setup, explaining the optimization techniques  and releasing the theoretical revenue figures (see Fig. 3).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-rzZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-rzZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 424w, https://substackcdn.com/image/fetch/$s_!-rzZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 848w, https://substackcdn.com/image/fetch/$s_!-rzZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 1272w, https://substackcdn.com/image/fetch/$s_!-rzZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-rzZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png" width="605" height="475" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:475,&quot;width&quot;:605,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:92075,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-rzZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 424w, https://substackcdn.com/image/fetch/$s_!-rzZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 848w, https://substackcdn.com/image/fetch/$s_!-rzZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.png 1272w, https://substackcdn.com/image/fetch/$s_!-rzZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61bd473d-586a-426f-b8ce-3dc6aaedb1a5_605x475.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 role="img" 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><title></title><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">Figure 3: <a href="https://x.com/deepseek_ai/status/1895688300574462431">#OpenSourceWeek</a>, when DeepSeek released their inference infrastructure details, lifting the veil on the economics behind LLM API pricing.</figcaption></figure></div><p>Understanding how DeepSeek achieved such dramatic cost advantages requires examining the underlying business model of AI inference. To quote <a href="https://www.linkedin.com/posts/semianalysis_the-modern-factory-is-an-ai-token-factory-activity-7348027764748271616-YnlH">Semianalysis</a> here:</p><blockquote><p>The modern factory is an AI token factory. Raw Silicon, electricity, and water comes into a Datacenter and what comes out is intelligence (in the form of tokens).</p></blockquote><p>The business model of an 'AI token factory' is straightforward. Like any factory, there are fixed equipment costs that owners want to spread across as many users as possible. In AI inference, this fixed cost is the hourly expense of running GPUs, and providers maximize efficiency by producing as many tokens as possible per hour. The more tokens produced, the lower the cost per token - enabling cheaper pricing or higher margins. This creates a classical economics model incentivizing economies of scale: substantial fixed costs (GPU servers) that must be divided across as many users as possible.</p><p>In this article we develop a comprehensive cost model to answer one fundamental question: <strong>what does it actually cost to generate a DeepSeek V3.1 token</strong>, and what factors impact this number? We aim to build a theoretical cost model enabling us to estimate the final throughput, given the hardware specification (FLOPS, memory bandwidth, and the interconnect) and the workload profile (batch size and number of input/output tokens). We hope this will help you build a more accurate world model of this topic and make informed decisions about hardware investments and deployment strategies. We will use said theoretical model to propose the best hardware setup for deployments of different characteristics (the latency/speed/cost tradeoff).</p><p>We aim the article at experienced readers. We strongly encourage you to read and understand the core messages of &#8220;<a href="https://www.tensoreconomics.com/p/llm-inference-economics-from-first">LLM Inference Economics from First Principles</a>"first. Before proceeding to reading this article, you should be familiar with topics such as what a FLOP is, what it means to be compute/memory bound, what a KV cache is and how to calculate its memory footprint, and what prefill and decode phases are. We assume the reader is familiar with said topics, and we strongly believe that without this background the topics in this text might prove challenging to understand.</p><p>DeepSeek V3.1 and Kimi K2 are two prominent examples of mixture-of-expert style models. Understanding their cost advantages requires examining how MoE economics differ from traditional dense models. The key challenge in MoE inference is that, unlike in dense models like Llama3, each processed token activates only a subset of parameters, rather than the entire model. As we learned in the <a href="https://www.tensoreconomics.com/i/163319195/the-decode-phase">previous text</a>, the decode (or token-by-token) phase is primarily memory bound, meaning that the majority of the execution time, and as a result most of the cost associated with running the model, comes down to the time of loading the model's parameters from the global memory. This property of dense models naturally incentivized amassing a batch as big as possible and sharing the cost of loading the model parameters across as many requests as possible, aka achieving a sort of economy of scale - fixed cost shared by multiple users.</p><p>For MoEs this becomes substantially more challenging. During the decode phase, each token in the batch is activating only a small subset of parameters at every layer. This means that each request requires us to load a different part of the model, as demonstrated in Fig. 4. As the number of requests in a batch increases, a more and more substantial portion of the model will have to be loaded from global memory. The experts are chosen semi-stochastically<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>, so some of the tokens in the batch will be routed to the same expert. As we progressively increase the batch size, more and more experts will be shared by different requests. This means that at the larger batch sizes we will partially recreate the situation from the dense model - sharing the cost of model loading between multiple users. Unfortunately this means that we will need significantly more requests, i.e. more users, to achieve the same "economies of scale" for MoE models. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!DPs4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!DPs4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 424w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 848w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 1272w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!DPs4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png" width="1456" height="801" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.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;:380617,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!DPs4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 424w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 848w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.png 1272w, https://substackcdn.com/image/fetch/$s_!DPs4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb997de1-f30e-4ed6-831f-e26b0fe5d355_1575x867.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 role="img" 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><title></title><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">Figure 4: Two request tokens activating different parts of the model, requiring us to load more weights, saturating the memory bandwidth</figcaption></figure></div><p>To illustrate this challenge: while DeepSeek V3.1 activates only 37B parameters for a single forward pass, this number grows nearly linearly with batch size as different queries activate different experts. At large batch sizes, the system may need to load close to the full 671B parameter model, creating severe memory bandwidth bottlenecks. Furthermore, this need for bigger batches requires substantially more resources to store the KV cache for all of the requests. These two factors necessitate running the model beyond a single node. To put it simply, there is not enough memory bandwidth, and there might not be enough space in memory on a single node to amass enough users to make model serving economically viable.</p><p>A GPU node is a specialized computer system designed with high-performance computation in mind. It is essentially a server with multiple GPUs, alongside hardware like CPUs, memory, or networking equipment. A popular example of a node would be a DGX system by NVIDIA, containing eight high-end GPUs (such as H100s, H200s, or B200s) in a single chassis, along with high-speed interconnects between the GPUs (NVLink). Within the node, the GPU-to-GPU (<em>Intra-node</em>) communication is possible at much higher speeds than the communication between the nodes (<em>inter-node</em>).</p><p>To effectively host large scale MoE-style models, an inference provider needs multiple GPU nodes. Ideally, we would like to split the model so that each GPU handles some subset of the experts and routes all relevant queries to this GPU. This way each GPU stays busy, and the GPUs do not need to communicate intermediate results as in tensor parallel (TP) setups<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a>. This approach is called expert-parallelism (EP). Note that expert choosing occurs at every layer, for every token. During the decode phase, as the model generates token after token, the new token is routed to different experts, located on different GPUs. </p><p>To quote DeepSeek themselves: </p><blockquote><p>Due to the large number of experts in DeepSeek-V3/R1&#8212;where only 8 out of 256 experts per layer are activated&#8212;the model&#8217;s high sparsity necessitates an extremely large overall batch size. This ensures sufficient batch size per expert, enabling higher throughput and lower latency. Large-scale cross-node EP is essential.<br><br>As we have adopted prefill-decode disaggregation architecture, we employ different degrees of parallelisms during the prefill and decode phases:<br><br>Prefilling Phase [Routed Expert EP32, MLA/Shared Expert DP32]: Each deployment unit <strong>spans 4 nodes </strong>with 32 redundant routed experts, where each GPU handles 9 routed experts and 1 shared expert.</p><p>Decoding Phase [Routed Expert EP144, MLA/Shared Expert DP144]: Each deployment unit <strong>spans 18</strong> nodes with 32 redundant routed experts, where each GPU manages 2 routed experts and 1 shared expert.</p></blockquote><p>Increasing the number of nodes operating within a single setup has a beneficial effect not only on the end-to-end performance but also on the <strong>per node performance</strong>. In other words, we get an increased return on investment (ROI) on our fixed cost of hardware (aka GPUs). This benefit is clearly demonstrated in one of the blog posts by Perplexity (see Fig. 5). You can see that as we increase the number of nodes involved (the EP number), the <strong>per node</strong> performance increases. We can compare it to a factory - investing more money into automation tools increases the returns on the tools the factory already owns. It has a compounding effect driving down the price per token as we increase the number of nodes in a setup, but it comes at a cost - we need substantially larger usage to utilize the setup.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Mgy6!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Mgy6!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 424w, https://substackcdn.com/image/fetch/$s_!Mgy6!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 848w, https://substackcdn.com/image/fetch/$s_!Mgy6!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 1272w, https://substackcdn.com/image/fetch/$s_!Mgy6!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Mgy6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png" width="1456" height="1158" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1158,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:982699,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Mgy6!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 424w, https://substackcdn.com/image/fetch/$s_!Mgy6!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 848w, https://substackcdn.com/image/fetch/$s_!Mgy6!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.png 1272w, https://substackcdn.com/image/fetch/$s_!Mgy6!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1aa8356b-f297-41ff-ad04-f9c7e6e79ffd_2664x2118.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 role="img" 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><title></title><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">Figure 5: Throughput <strong>per node</strong> by <a href="https://www.perplexity.ai/hub/blog/lower-latency-and-higher-throughput-with-multi-node-deepseek-deployment">Perplexity</a>.</figcaption></figure></div><p>While running a model in the multi-node setup in theory provides enormous economies of scale, enabling the running of bigger batches far more productively, running such an operation at scale is a highly sophisticated endeavor. It requires a mature software stack and an in-depth understanding of the underlying hardware by the people involved in developing such a stack. It is clearly reflected when we look at the list of people involved in the first open-source reproduction of a multi-node DeepSeek setup by SGLang (see Fig. 6). And while there exists an open-source reproduction, as of September 2025 it is still pretty hard to operate, requiring careful coordination of different package versions and branches of underlying software libraries. We are aware of a few public inference providers who, due to the reasons above, went with serving DeepSeek on a single H200 or B200 node. While this setup is far from optimal, it is far easier to maintain and provide it to clients.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Eztz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Eztz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 424w, https://substackcdn.com/image/fetch/$s_!Eztz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 848w, https://substackcdn.com/image/fetch/$s_!Eztz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 1272w, https://substackcdn.com/image/fetch/$s_!Eztz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Eztz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png" width="992" height="810" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:810,&quot;width&quot;:992,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:225832,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Eztz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 424w, https://substackcdn.com/image/fetch/$s_!Eztz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 848w, https://substackcdn.com/image/fetch/$s_!Eztz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.png 1272w, https://substackcdn.com/image/fetch/$s_!Eztz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4af9047c-d22d-4182-a3cf-dd7f073b06de_992x810.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 role="img" 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><title></title><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">Figure 6: List of people involved in the enabling the multi-node DeepSeek setup. <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/\#acknowledgment">SGLang blopost</a></figcaption></figure></div><h1>DeepSeek MoE Architecture</h1><p>Since the "DeepSeek moment" was the motivation for us to write this article, and DeepSeek V3.1 as of September 2025 remains the most popular open-source model according to OpenRouter (see Fig. 7), we will use it as a reference architecture we use in our calculations. All DeepSeek V3, DeepSeek R1, and DeepSeek V3.1 share exactly the same architectural details; they "only" differ by the values of weights and by their behavior during inference. </p><p>DeepSeek V3.1 is a hybrid model that, depending on the inference setting, produces thousands of so-called <em>reasoning tokens</em> before giving a final answer. The underlying inference math is the same at the per-token layer regardless of the setting, but due to potentially vastly different distributions of input to output tokens, the inference math we will achieve will be highly dependent on whether the model is used in the reasoning or non-reasoning mode, as it is reflected by the DeepSeek pricing page (see Fig. 32).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Cany!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Cany!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 424w, https://substackcdn.com/image/fetch/$s_!Cany!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 848w, https://substackcdn.com/image/fetch/$s_!Cany!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 1272w, https://substackcdn.com/image/fetch/$s_!Cany!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Cany!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png" width="1456" height="831" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:831,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:220122,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Cany!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 424w, https://substackcdn.com/image/fetch/$s_!Cany!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 848w, https://substackcdn.com/image/fetch/$s_!Cany!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.png 1272w, https://substackcdn.com/image/fetch/$s_!Cany!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1702570e-cb27-451d-92f5-56f3866754f7_1887x1077.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 role="img" 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><title></title><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">Figure 7: OpenRouter model popularity ranking, showing DeepSeekV3.1 as the most widely used open-source model, with the old DeepSeek V3 0324 remaining a close second (30.08.2025)</figcaption></figure></div><p>The DeepSeek architecture is summarized by the model configuration available on Hugging Face (see Fig. 8). It consists of 61 layers (<em>num-hidden-layers</em>), three of which are dense (<em>first-k-dense-replace</em>), and the remaining 58 are MoE layers. Each MoE layer contains a modified self-attention mechanism (multi-head latent attention, or MLA), a gating mechanism, and 257 experts - 1 shared expert and 256 routed experts - as defined by the <em>n-shared-experts</em> and <em>n-routed-experts</em>. The MoE layers are followed by a traditional language modeling (LM) head. The DeepSeek team also proposed a <em>multi-token prediction</em> (MTP) head for <a href="https://arxiv.org/abs/2211.17192">speculative decoding</a>. However, as modeling its real-world performance is complex and less relevant for larger batches, we exclude it from this analysis.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!viHU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!viHU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 424w, https://substackcdn.com/image/fetch/$s_!viHU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 848w, https://substackcdn.com/image/fetch/$s_!viHU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 1272w, https://substackcdn.com/image/fetch/$s_!viHU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!viHU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png" width="908" height="1526" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1526,&quot;width&quot;:908,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:267394,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!viHU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 424w, https://substackcdn.com/image/fetch/$s_!viHU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 848w, https://substackcdn.com/image/fetch/$s_!viHU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.png 1272w, https://substackcdn.com/image/fetch/$s_!viHU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a4a15d3-8aa0-4e2f-b793-6933aacc926d_908x1526.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 role="img" 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><title></title><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">Figure 8: DeepSeekV3 <a href="https://huggingface.co/deepseek-ai/DeepSeek-V3.1/blob/main/config.json">Hugging Face configuration</a>. Note that this is the exact same configuration as used in <a href="https://huggingface.co/deepseek-ai/DeepSeek-V3-0324/blob/main/config.json">DeepSeek V3</a> and <a href="https://huggingface.co/deepseek-ai/DeepSeek-R1-0528/blob/main/config.json">DeepSeek R1</a>.</figcaption></figure></div><p>Each layer consists of a Multi-head Latent Attention (MLA) followed by a DeepSeekMoE, as illustrated in Figure 9. MLA is a variant of traditional attention that compresses the KV cache using a linear algebra optimization. Instead of storing full key-value pairs like other models (such as Llama, Qwen, etc.), MLA stores only a compressed latent representation of size <em>kv-lora-rank</em> + <em>qk-rope-head-dim</em>. This reduces memory bandwidth requirements during token-by-token decoding, since less KV cache memory needs to be loaded to produce each token.</p><p>These optimizations compress the KV cache to 70KB per token - a 2-7x reduction <a href="https://arxiv.org/abs/2505.09343">compared to other models</a> (Qwen3 32B: 163KB, Llama 405B: 516KB per token). This compression directly translates to reduced memory bandwidth requirements and lower inference costs. We detail the computational mechanics of MLA later; the key insight is that this architectural choice fundamentally alters the economics of serving large language models, especially with long context (such as agentic) use cases. </p><p>Following the MLA is the DeepSeekMoE component (see Fig. 9). The routing mechanism uses a linear layer mapping from <em>hidden-size</em> to <em>n-routed-experts</em> to classify which experts are most relevant for each token based on its semantic content. Each token is individually routed to a different set of experts. It is a common confusion that the experts are selected at the sequence (or query) level; we want to highlight that this is not the case. DeepSeek selects the top eight experts per token, with routing scores serving as weights when combining expert outputs. </p><p>Each expert contains a standard MLP structure with SwiGLU activation: three linear layers (W1 and W3: <em>hidden-size</em> &#8594; <em>moe-intermediate-size</em>, W2: reverse). Crucially, the <em>moe-intermediate-size</em> (2048) is smaller than <em>hidden-size</em> (7168) - the opposite of traditional dense models like Llama 3.3 70B, where intermediate dimensions are 3.5x larger (28672 vs 8192). This compression reduces per-expert computational costs while maintaining model capacity through expert diversity.</p><p>Beyond the eight routed experts, every token also passes through a shared expert that provides base knowledge common to all inputs. This hybrid approach balances specialization with computational efficiency.</p><p>This architecture is repeated across all 58 MoE layers, followed by the LM head for next-token prediction. The key architectural innovations - MLA for memory efficiency and sparse expert activation - represent a fundamental shift from traditional dense transformers toward economically optimized inference. In the following sections, we analyze the computational details of MLA and MoE components, identifying the primary bottlenecks that determine serving costs and scaling limits.</p><p>If you are not interested in the architecture details and optimizations, and you just want to read the conclusions and meta analysis<strong> feel free to skip to section "Hardware considerations and profit margins"</strong>.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Gfzn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Gfzn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 424w, https://substackcdn.com/image/fetch/$s_!Gfzn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 848w, https://substackcdn.com/image/fetch/$s_!Gfzn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 1272w, https://substackcdn.com/image/fetch/$s_!Gfzn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Gfzn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png" width="1352" height="1070" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1070,&quot;width&quot;:1352,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:302280,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Gfzn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 424w, https://substackcdn.com/image/fetch/$s_!Gfzn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 848w, https://substackcdn.com/image/fetch/$s_!Gfzn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.png 1272w, https://substackcdn.com/image/fetch/$s_!Gfzn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e071b60-9a07-4a3f-b347-5336c364f6f6_1352x1070.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 role="img" 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><title></title><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">Figure 9: DeepSeek V3 MoE transformer layers consist of 3 shared experts and 256 routed experts. The router, a single weight matrix, predicts scores where the top 8 scores are chosen and the token is routed to the corresponding expert. In total a token goes through 9 out of 257 (256 routed + 1 shared) experts in each forward pass. Figure taken from <a href="https://arxiv.org/abs/2412.19437">DeepSeek V3</a>.</figcaption></figure></div><h1>Inference Optimization Techniques</h1><p>Due to <em>"<a href="https://arxiv.org/abs/2505.09343">policy and regulatory constraints</a>"</em>, aka export restrictions, the DeepSeek team is operating under severe compute constraints, both for training and for inference of their models. This hardware scarcity is evident when inspecting the average throughput of DeepSeek V3.1 reported by OpenRouter (see Fig. 10). While Western inference providers like <a href="https://fireworks.ai">Fireworks</a> and <a href="https://www.together.ai/">Together</a> serve it at a comfortable 60-80 tokens per second (tps), DeepSeek manages only ~25 tps. </p><p>For reasoning models, generating thousands of tokens before final answers, this leads to a significantly worse UX for interactive usecases. A typical math problem requiring 3,000 reasoning tokens takes 120 seconds <em>(3000 tokens/ 25 tps)</em> - forcing users into a 2-minute wait that limits practical applications to scenarios where user&#8217;s latency tolerance is high.</p><p>Faced with hardware scarcity, DeepSeek did what any good engineer would do: they got creative. Rather than designing for perfect conditions they'll never have, they optimized everything around their actual constraints. The inference optimizations detailed in a <a href="https://arxiv.org/abs/2505.09343">recent paper by DeepSeek</a> - from expert routing to MLA-MoE computation overlap to networking topology - reflect this constraint-driven mindset. We examine several optimizations that most impact our theoretical cost model.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8dhM!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8dhM!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 424w, https://substackcdn.com/image/fetch/$s_!8dhM!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 848w, https://substackcdn.com/image/fetch/$s_!8dhM!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 1272w, https://substackcdn.com/image/fetch/$s_!8dhM!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8dhM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png" width="1456" height="597" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:597,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:180533,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8dhM!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 424w, https://substackcdn.com/image/fetch/$s_!8dhM!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 848w, https://substackcdn.com/image/fetch/$s_!8dhM!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.png 1272w, https://substackcdn.com/image/fetch/$s_!8dhM!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73dee655-2fa3-4111-ae6b-31ed2103a29f_2268x930.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 role="img" 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><title></title><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">Figure 10: Average DeepSeek V3.1 throughput as measured by OpenRouter. Note how much slower than the Western providers DeepSeek is on average. This throughput difference suggests constrained hardware allocations, likely forcing DeepSeek to prioritize larger batch sizes over individual request latency. While this strategy reduces per-token serving costs through higher GPU utilization, it comes at the expense of user experience. 31.08.2025</figcaption></figure></div><h3>Expert Parallelism</h3><p>As shown later, expert layers contain approximately 661B parameters, representing 98.5% of the total parameter count. This distribution necessitates careful consideration of parallelization strategies. To minimize weight-related overhead, parameter distribution rather than duplication provides the optimal approach.</p><p>In traditional tensor parallel configurations with dense FFN layers, communication involves dispatching and combining <em>hidden-size</em> values per token and layer. MoE models introduce complexity because batch tokens route to different model components (different experts). Given the compact dimensions of expert weight matrices (<em>d-moe=2048</em>), <a href="https://www.tensoreconomics.com/i/163319195/tensor-parallelism">tensor parallel sharding</a> would fragment these matrices into excessively small components, resulting in suboptimal blocked matrix multiplication performance. Expert parallel sharding preserves matrix integrity, enabling more efficient memory access patterns during GEMM operations.</p><p>However, this approach increases total communication overhead to </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;d\\times (n_r^E + n_s^E)&quot;,&quot;id&quot;:&quot;LXYOFKDPZX&quot;}" data-component-name="LatexBlockToDOM"></div><p>per token and layer, where <em>d</em> is the model's hidden size. Because experts may reside on different devices, expert parallel distribution becomes more exposed to communication bottlenecks, fundamentally changing the performance characteristics compared to dense models.</p><p>For deployments with small numbers of devices, particularly single or dual-node configurations, or those with very bad inter-node communication hardware, tensor parallel sharding can achieve superior performance due to the reduced communication overhead.</p><h3>Expert Parallel Load Balancing</h3><p>Expert routing probabilities exhibit non-uniform distributions (see Fig. 11), causing some experts to receive disproportionately higher request volume while other experts remain underutilized. Naive uniform expert distribution across available devices creates two critical performance issues: (1) uneven communication patterns where bottlenecks stall entire forward passes, and (2) asymmetric computational loads across devices. Additionally, heavily utilized devices must handle increased activation loading and memory write-back operations, compounding performance degradation.</p><p>Load balancing strategies can mitigate these issues through intelligent expert distribution across devices to achieve more uniform computational loads. Furthermore, frequently accessed experts can be duplicated to reduce communication peaks, though this approach carries the trade-off of increased weight loading and reduced per-GPU KV cache capacity. Since the expert layer computation is most often memory bound, having the same number of experts on each device is optimal. Therefore, the number of additional experts per layer must be constrained to multiples of the expert parallel size.</p><p>An interesting use case are uneven node configurations, where redundant experts can be used to fill up underutilized devices to achieve balanced expert distribution. For instance, the <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">SGLang team reported</a> using nine nodes for decode operations (72 expert parallel size) with 32 additional experts, achieving favorable trade-offs between additional memory overhead and reduced communication peaks.</p><p>Importantly, expert load balancing becomes increasingly challenging as node count increases. This degradation occurs because fewer nodes concentrate more experts per device, increasing the probability of achieving system-wide balance. So for deployments on very few nodes, the improvement in expert balancedness is not worth the corresponding redundant experts.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UYY1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UYY1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 424w, https://substackcdn.com/image/fetch/$s_!UYY1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 848w, https://substackcdn.com/image/fetch/$s_!UYY1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 1272w, https://substackcdn.com/image/fetch/$s_!UYY1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UYY1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png" width="1456" height="852" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:852,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:190707,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UYY1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 424w, https://substackcdn.com/image/fetch/$s_!UYY1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 848w, https://substackcdn.com/image/fetch/$s_!UYY1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.png 1272w, https://substackcdn.com/image/fetch/$s_!UYY1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96faecc5-5424-446a-8f17-fbae3ac45742_1961x1147.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 role="img" 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><title></title><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">Figure 11: Expert imbalance during prefill and decode phases as reported by <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/\#case-study-expert-distribution-statistics">SGLang</a>. These are empirical observations from running over some specific datasets, so in your particular application the exact distribution will differ. The meta point, that experts usage is not uniformly distributed, stands, though.</figcaption></figure></div><h3>Location-Aware Expert Selection</h3><p>To minimize the limiting inter-node communication, expert selection can incorporate locality penalties that preferentially route tokens to experts residing on the same node where their attention computations were performed. This approach reduces cross-node communication overhead, which often represents a primary bottleneck in distributed MoE inference.</p><p>During training, DeepSeek V3 implemented expert routing constraints ensuring each token routes to at most <em>M</em> nodes. Node selection follows the sum of the highest <em>K&#7523;/M</em> affinity scores for experts distributed on each node, where <em>K&#7523;</em> represents the number of routed experts and <em>M</em> the maximum number of nodes per token.</p><p>This methodology can be adapted for inference scenarios but requires careful tuning to balance locality benefits against response quality. A notable consequence of this approach is that token routing patterns become dependent on the position of the sequence within the batch, potentially creating position-dependent expert utilization patterns that may affect model responses.</p><h3>Data Parallel Attention</h3><p>Attention computation employs a data-parallel approach, distributing requests across available devices (see Fig. 12). This strategy enables KV cache sequences to remain on single devices, eliminating the need for duplication or inter-device communication of the latent KV cache, which, on the other hand, would be required under tensor-parallel MLA computation due to projection matrices.</p><p>However, this data-parallel approach requires duplicating all MLA weights across devices, approximately 10 GB for DeepSeek V3.1, and they must be loaded during each forward pass. This presents scalability tradeoffs for large-scale deployments. Specifically, in configurations exceeding 64 GPUs, the MLA weight parameters can consume greater memory resources than the expert layers themselves. This duplication reduces available KV cache capacity and renders MLA computations memory-bound for most batch sizes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XO8u!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XO8u!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 424w, https://substackcdn.com/image/fetch/$s_!XO8u!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 848w, https://substackcdn.com/image/fetch/$s_!XO8u!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 1272w, https://substackcdn.com/image/fetch/$s_!XO8u!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XO8u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png" width="1456" height="634" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:634,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:564696,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XO8u!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 424w, https://substackcdn.com/image/fetch/$s_!XO8u!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 848w, https://substackcdn.com/image/fetch/$s_!XO8u!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.png 1272w, https://substackcdn.com/image/fetch/$s_!XO8u!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06ba16bf-16a7-4bd1-891e-430c6e440934_5400x2350.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 role="img" 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><title></title><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">Figure 12: Visualization of DP Attention from <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/\#case-study-expert-distribution-statistics">SGLang blogpost</a>. Different GPUs process different microbatches. It works both for dense layers (first 3 layers in DeepSeek) and mixture-of-experts layers.</figcaption></figure></div><h3>Hiding Communication with Two-Batch Overlap</h3><p>As shown previously, expert parallelism in MoE models generates approximately nine times the communication volume compared to traditional tensor parallelism. To mitigate this overhead, a two-batch overlap (TBO) strategy can be implemented to mask communication time behind computation. This approach partitions the global batch size into two micro-batches, enabling simultaneous execution where one micro-batch performs computation while the other handles communication operations.</p><p>Effective overlap implementation requires careful orchestration of computational and communication phases. Figure 13 illustrates a basic TBO configuration for decode operations. Since communication operations consume minimal computational resources, TBO can achieve runtime improvements of close to a factor of two in certain scenarios.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!groq!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!groq!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 424w, https://substackcdn.com/image/fetch/$s_!groq!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 848w, https://substackcdn.com/image/fetch/$s_!groq!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 1272w, https://substackcdn.com/image/fetch/$s_!groq!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!groq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png" width="1456" height="364" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:364,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:320193,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!groq!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 424w, https://substackcdn.com/image/fetch/$s_!groq!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 848w, https://substackcdn.com/image/fetch/$s_!groq!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 1272w, https://substackcdn.com/image/fetch/$s_!groq!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F91c2ef85-ab6f-46d7-a810-47d9cb0e67a2_1690x422.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Figure 13: Creating two mini-batches allows for overlapping the communication of one mini-batch with the computation of the other, thus in most cases hiding the communication from the overall runtime. Depending on the inference regime, different overlapping structures can be used. The figure depicts DeepSeeks setup for the decode phase during inference. Figure taken from <a href="https://github.com/deepseek-ai/profile-data">DeepSeek's profiling of V3</a>.</figcaption></figure></div><h3>Prefill Decode Disaggregation</h3><p>LLM inference comprises two distinct phases with fundamentally different computational characteristics. Prefill operations process entire input sequences simultaneously, creating compute-intensive workloads with high FLOP utilization but minimal KV cache requirements. Decode operations generate tokens iteratively, resulting in memory-bandwidth-bound computations. Also, decoding is much more latency sensitive due to its repetitive nature.</p><p>As explained in more detail on <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">SGLang's blog post</a> traditional unified engines process prefill and decode batches together, introducing three critical inefficiencies: (1) incoming prefill batches interrupt ongoing decode operations, causing substantial token generation delays; (2) data-parallel attention imbalances occur when workers simultaneously handle different batch types, increasing decode latency; and (3) incompatibility arises with advanced expert placement strategies that require different dispatch modes for each phase.</p><p>Prefill-decode disaggregation resolves these issues by separating workloads into dedicated clusters optimized for each phase's requirements, with prefill usually needing fewer resources than decode due to better compute utilization.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7GtU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7GtU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 424w, https://substackcdn.com/image/fetch/$s_!7GtU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 848w, https://substackcdn.com/image/fetch/$s_!7GtU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 1272w, https://substackcdn.com/image/fetch/$s_!7GtU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7GtU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png" width="1434" height="1120" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1120,&quot;width&quot;:1434,&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="https://substackcdn.com/image/fetch/$s_!7GtU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 424w, https://substackcdn.com/image/fetch/$s_!7GtU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 848w, https://substackcdn.com/image/fetch/$s_!7GtU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.png 1272w, https://substackcdn.com/image/fetch/$s_!7GtU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffefd25b4-9d12-47dc-97eb-a21942b2b2d9_1434x1120.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 role="img" 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><title></title><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">Figure 14: Upon receiving an input request, the workflow proceeds as follows: 1) A Prefill Server and a Decode Server pair via a handshake, establishing a local sender and receiver, respectively. 2) The Decode Server pre-allocates the KV cache, signaling the Prefill Server to begin the model forward pass and compute the KV caches. 3) Once computed, the data transfers to the Decode Server, which handles iterative token generation. As per <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/\#implementation-details">SGLang blogpost</a>.</figcaption></figure></div><h1>Theoretical Performance Model</h1><p>The theoretical performance model creates a virtual clone of our DeepSeek V3.1 model, enabling analysis of different hardware configurations to determine optimal MoE model serving strategies. Additionally, this framework allows identification of system bottlenecks across various deployment scenarios. While this model is specifically designed for <a href="https://arxiv.org/abs/2412.19437">DeepSeek V3</a> architecture, extensions to <a href="https://arxiv.org/abs/2507.20534">Kimi-K2</a> and other MoE architectures are quite simple.</p><p>The theoretical performance model analyzes attention (MLA in the case of DeepSeek V3.1) and expert computations separately, as these components may be constrained by different resources at different times. Since two-batch overlap techniques may be employed to hide communication, these two parts of the model may operate without overlap and are thus not able to hide the memory loading over both computations combined. Furthermore, the model accounts for communication across potentially heterogeneous networks incorporating different intra- and inter-node communication hardware. Communication time can be optionally overlapped using TBO. Finally, we consider scenarios where expert distribution is nonhomogeneous, resulting in imbalanced communication, increased memory loading, and uneven computation across GPUs, which can bottleneck the entire system.</p><p>With communication computation overlap, we define the total system performance as:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;t_{total} = \\max(t_{\\text{bottleneck_MLA}} + t_{\\text{bottleneck_EP}}, t_{\\text{communication}})&quot;,&quot;id&quot;:&quot;AHQZGFOOFA&quot;}" data-component-name="LatexBlockToDOM"></div><p>Without TBO, we can (1) look at the memory loading time and compute time for each block (EP and attention) and take the maximum; (2)  add the communication time; and (3) consider imbalanced experts:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;t_{total} = t_{\\text{bottleneck_MLA}} + t_{\\text{bottleneck_EP}} + t_{\\text{communication}}&quot;,&quot;id&quot;:&quot;AFDRZWZIYK&quot;}" data-component-name="LatexBlockToDOM"></div><p>The model operates under the following assumptions:</p><ul><li><p>No computational and memory loading overhead from the <a href="https://github.com/deepseek-ai/DeepEP">DeepEP</a> TBO communication library. This assumption does not hold in practice, as the library launches a non-negligible number of CUDA kernels.</p></li><li><p>All computations and weights are performed and stored in FP8, with the exception of communication operations, where dispatch occurs in BF16. This assumption is largely accurate since over <em>98%</em> of parameters reside in expert weights, which utilize 8-bit quantization.</p></li><li><p>The analysis focuses exclusively on decode performance <strong>without considering prefill</strong> operations. Theoretical derivations for prefill performance will be presented.</p></li></ul><p>First lets look at the execution times of the MLA and expert MLP networks of a transformer block based on the operations performed and the memory loaded. Second we consider the communication. For reference all variable names are listed in Table 1.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!uJuK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!uJuK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 424w, https://substackcdn.com/image/fetch/$s_!uJuK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 848w, https://substackcdn.com/image/fetch/$s_!uJuK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 1272w, https://substackcdn.com/image/fetch/$s_!uJuK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!uJuK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png" width="1456" height="876" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:876,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:418210,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!uJuK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 424w, https://substackcdn.com/image/fetch/$s_!uJuK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 848w, https://substackcdn.com/image/fetch/$s_!uJuK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.png 1272w, https://substackcdn.com/image/fetch/$s_!uJuK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbac7f90f-6b87-4133-b7b9-cefe30b7e45c_2094x1260.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 role="img" 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><title></title><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">Table 1: Nomenclature of the symbols used in this description for DeepSeek V3, including the name in the publicly available <a href="https://huggingface.co/deepseek-ai/DeepSeek-V3-0324">config.json</a> file.</figcaption></figure></div><h3>Memory Loading</h3><p>To estimate the time spent loading from memory, we look at what gets loaded during each forward pass. First let's look at the MLA secondly at the expert networks.</p><h4>MLA</h4><p>The memory requirements during inference for the MLA can be categorized into three primary components: MLA weights (read), KV cache (read and write), and activations (write). </p><p><strong>MLA weights</strong> are read once per forward pass. The MLA mechanism requires several weight matrices per layer, stored in FP8 format. As outlined for <a href="https://arxiv.org/abs/2405.04434">DeepSeek v2</a>, during inference, the up-projection matrices for the K- and V-tensors can be included into other matrices, thus reducing the overall number of matrices.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{DQ} \\in \\mathbb{R}^{d_c' \\times d} = 1536 \\times 7168 = 11.0\\text{MB}&quot;,&quot;id&quot;:&quot;ROLVUCOZFD&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{UQ} \\in \\mathbb{R}^{d_h \\times n_h \\times d_c'} = 128 \\times 128 \\times 1536 = 25.2\\text{MB}&quot;,&quot;id&quot;:&quot;FECGSMWSGE&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{QR} \\in \\mathbb{R}^{d^R_h \\times n_h \\times d_c'} = 64 \\times 128 \\times 1536 = 12.6\\text{MB}&quot;,&quot;id&quot;:&quot;BLJIHNEFJN&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{DKV} \\in \\mathbb{R}^{d_c \\times d} = 512 \\times 7168 = 3.7\\text{MB}&quot;,&quot;id&quot;:&quot;YUYWAESRRJ&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{UK} \\in \\mathbb{R}^{d_h \\times n_h \\times d_c} = 128 \\times 128 \\times 512 = 8.4\\text{MB}&quot;,&quot;id&quot;:&quot;OWZHQLGWBI&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{UV} \\in \\mathbb{R}^{d_h \\times n_h \\times d_c} = 128 \\times 128 \\times 512 = 8.4\\text{MB}&quot;,&quot;id&quot;:&quot;XCPDNQOKFK&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{KR} \\in \\mathbb{R}^{d^R_h \\times d} = 64 \\times 7168 = 0.5 \\text{MB}&quot;,&quot;id&quot;:&quot;BUJIWIPFRY&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{O} \\in \\mathbb{R}^{d \\times d_h \\times n_h} = 7168 \\times 128 \\times 128 = 117.4\\text{MB}&quot;,&quot;id&quot;:&quot;MGFCHNLTFZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>This yields a total of 187.2 MB per layer, resulting in 11.4 GB total attention weights that must be replicated across each data-parallel attention rank.</p><p><strong>KV Cache</strong> size is significantly reduced in MLA architectures compared to traditional attention mechanisms. The cache size per token is determined by </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;(d_c + d_R^h)\\times L&quot;,&quot;id&quot;:&quot;XBGMYLBTKF&quot;}" data-component-name="LatexBlockToDOM"></div><p>where d_c = 512 represents the KV compression dimension, d^h_R = 64 denotes the per-head dimension of decoupled queries and keys, and L = 61 is the number of layers.</p><p>The memory requirement becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2 \\times (d_c + d_R^h) \\times L = 2 \\times (512 + 64) \\times 61 = 70\\text{KB per token}&quot;,&quot;id&quot;:&quot;NEGFIQNFDU&quot;}" data-component-name="LatexBlockToDOM"></div><p>For a batch processing <em>S</em> input tokens and generating <em>B</em> output tokens, the system loads <em>S x B</em> tokens and saves <em>B</em> tokens to cache. </p><p><strong>Activation vectors</strong> require temporary storage for communication between expert computations. These activations are loaded once and written back once during the forward pass:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;A = 2 \\times B \\times d \\times L \\approx B \\times 0.9\\text{MB}&quot;,&quot;id&quot;:&quot;INNIQEPZEV&quot;}" data-component-name="LatexBlockToDOM"></div><p>While non-negligible for very large batch sizes, activation memory remains relatively small compared to weight and cache requirements.</p><h4>Expert Networks</h4><p>For the expert MLP networks, we have two sources of memory transfers: model weights, which get read once for each forward pass; and activations, which get loaded once in FP8 and written back once in BF16.</p><p><strong>The latent vectors</strong> are loaded from and saved back to memory for communication. We load them once in FP8 and write them back once in BF16. This part is often negligible. </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}A&amp;=(1+2)\\times B\\times d \\times L \\approx B\\times 1.4 MB\\\\\n    A_\\text{total per GPU}&amp;=(1+2)\\times B\\times d \\times L \\times \\frac{1}{\\beta_{eb}} \\times \\frac{n_{\\text{shared_experts_used}} + n_{\\text{routed_experts_used}}}{n\\_GPUs}\\end{aligned}&quot;,&quot;id&quot;:&quot;KAMNNWGERS&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>The expert MLP</strong> is made up of two weight matrices W_1 and W_2, which perform a down-projection followed by an up-projection. Note that traditional transformer models have a larger intermediate space thus they first up-project, which makes the matrices much larger. Secondly, we have to account for the SwiGLU gate weight matrix as well. So the size of one expert is </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}W_1=W_2&amp;= d_{moe} \\times d = 2048 \\times 7168 \\approx 14.7 \\text{MB}\\\\\nW_{\\text{Gate}} &amp;= d_{moe} \\times d = 2048 \\times 7168 \\approx 14.7 \\text{MB}\\\\\nW_E &amp;= W_1 + W_\\text{Gate}+ W_2 = 3\\times \\text{moe_intermediate_size} \\times d \\approx 45\\text{MB}.\\end{aligned}&quot;,&quot;id&quot;:&quot;SNZMXTZLIB&quot;}" data-component-name="LatexBlockToDOM"></div><p>Lastly, we have to account for the router in each expert which is of size</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W_{\\text{router}} = d \\times  \\text{routed_experts}&quot;,&quot;id&quot;:&quot;MJOXLSFOMB&quot;}" data-component-name="LatexBlockToDOM"></div><p>To get the expert weights per devices, the weights are distributed evenly over the devices. Additionally we assume that one device has to hold the full router (overestimation). So for each expert layer we get:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}&amp;W_{\\text{experts per GPU}} = n_{\\text{layers}}^\\text{experts}\\times \\\\\n        &amp;\\left( W_E \\times \\lceil \\frac{n_{\\text{shared_experts}} + n_{\\text{routed_experts}} + n_{\\text{additional_experts}}}{n\\_GPUs} \\rceil  + W_{\\text{router}}\\right)\\end{aligned}&quot;,&quot;id&quot;:&quot;MHQOQNGBGS&quot;}" data-component-name="LatexBlockToDOM"></div><p>For DeepSeek V3.1 not all transformer layers are using the MoE architecture. The first three layers are made from traditional dense MLPs. Using <em>d_dense</em> as the intermediate size we get:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}W_1^d=W_2^d&amp;= d_{dense} \\times d =  18432 \\times 7168 \\approx 132 \\text{MB}\\\\\nW_{\\text{Gate}}^d &amp;= d_{dense} \\times d =  18432 \\times 7168 \\approx 132 \\text{MB}\\\\\nW_{MLP}^d &amp;= W_1^d + W_\\text{Gate}^d+ W_2^d = 3\\times d_{dense} \\times d \\approx 396\\text{MB}.\\end{aligned}&quot;,&quot;id&quot;:&quot;YZITXKJDXM&quot;}" data-component-name="LatexBlockToDOM"></div><p>When serving in expert parallel with SGLang these weights are sharded data parallel. Thus:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W_{\\text{MLP per GPU}}^\\text{dense} = n_{\\text{layers}}^\\text{dense}\\times W_{MLP}^d\\approx 3 \\times 396\\text{MB} \\approx 1.2\\text{GB}&quot;,&quot;id&quot;:&quot;HZQPSGALYZ&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Embedding Layers</h3><p>The embedding matrix size is <em>V x d</em>, where <em>V</em> is the vocabulary size. As we need to embed and un-embed, and each embedding matrix is sharded across GPUs in a data-parallel fashion, the per-GPU size is: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W_{\\text{E per GPU}} = 2\\times V\\times d = 2 \\times 129280\\times 7168 \\approx 1.9 \\text{GB}&quot;,&quot;id&quot;:&quot;AFFSQACDAB&quot;}" data-component-name="LatexBlockToDOM"></div><p>As this is a large matrix with  V &#187; 100k, we assume this calculation is always memory-bound, and thus we only take into account the memory loading time.</p><h3>Computation</h3><p>To quantify computational latency, we examine the multi-head latent attention (MLA) mechanism following the architectural specification detailed in <a href="https://arxiv.org/abs/2405.04434">DeepSeek v2 Appendix C</a>. Our analysis incorporates matrix absorption optimizations that enable certain linear transformations to be merged during inference. We validate our computational framework against the <a href="https://calvinxky.github.io/mfu_calculation/deepseek3mfu.html">DeepSeek V3 training time calculator</a> to ensure consistency, though we need to employ some changes due to optimizations only possible during inference. Furthermore, the single-token generation characteristic of decode operations substantially simplifies several equations relative to training contexts where full sequence processing is required. We denote computations specific to prefill scenarios with <strong>Prefill</strong> annotations to distinguish where prefill diverges from decode execution paths.</p><p>Our computational analysis has three main parts: a vanilla MLA implementation baseline, optimized MLA with matrix absorption techniques, and expert network computational latency.</p><h4>MLA</h4><p>MLA computational demands differ substantially between prefill and decode phases due to sequence length scaling characteristics, necessitating phase-specific analysis of each MLA component. We begin by reviewing the MLA computation procedure as specified in <a href="https://arxiv.org/abs/2405.04434">DeepSeek v2 Appendix C</a>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align*}\n\\mathbf{c}_t^Q &amp;= W^{DQ} \\mathbf{h}_t, \\\\\n\\left[ \\mathbf{q}_{t,1}^C; \\mathbf{q}_{t,2}^C; \\dots; \\mathbf{q}_{t,n_h}^C \\right] &amp;= \\mathbf{q}_t^C = W^{UQ} \\mathbf{c}_t^Q, \\\\\n\\left[ \\mathbf{q}_{t,1}^R; \\mathbf{q}_{t,2}^R; \\dots; \\mathbf{q}_{t,n_h}^R \\right] &amp;= \\mathbf{q}_t^R = \\text{RoPE}(W^{QR} \\mathbf{c}_t^Q), \\\\\n\\mathbf{q}_{t,i} &amp;= \\left[ \\mathbf{q}_{t,i}^C; \\mathbf{q}_{t,i}^R \\right], \\\\\n\\mathbf{c}_t^{KV} &amp;= W^{DKV} \\mathbf{h}_t, \\\\\n\\left[ \\mathbf{k}_{t,1}^C; \\mathbf{k}_{t,2}^C; \\dots; \\mathbf{k}_{t,n_h}^C \\right] &amp;= \\mathbf{k}_t^C = W^{UK} \\mathbf{c}_t^{KV}, \\\\\n\\mathbf{k}_t^R &amp;= \\text{RoPE}(W^{KR} \\mathbf{h}_t), \\\\\n\\mathbf{k}_{t,i} &amp;= \\left[ \\mathbf{k}_{t,i}^C; \\mathbf{k}_{t,i}^R \\right], \\\\\n\\left[ \\mathbf{v}_{t,1}^C; \\mathbf{v}_{t,2}^C; \\dots; \\mathbf{v}_{t,n_h}^C \\right] &amp;= \\mathbf{v}_t^C = W^{UV} \\mathbf{c}_t^{KV}, \\\\\n\\end{align*}&quot;,&quot;id&quot;:&quot;LEEUTASLNR&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align*}\n\\mathbf{o}_{t,i} &amp;= \\sum_{j=1}^t \\text{Softmax}_j \\left( \\frac{\\mathbf{q}_{t,i}^T \\mathbf{k}_{j,i}}{\\sqrt{d_h + d_h^R}} \\right) \\mathbf{v}_{j,i}^C, \\\\\n\\mathbf{u}_t &amp;= W^O \\left[ \\mathbf{o}_{t,1}; \\mathbf{o}_{t,2}; \\dots; \\mathbf{o}_{t,n_h} \\right],\n\\end{align*}&quot;,&quot;id&quot;:&quot;CGQMVUYUAO&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em>c_t^Q</em>, <em>c_t^{KV}</em> are the compressed <em>Q</em> and <em>KV</em> tensors respectively. During decode operations, MLA requires up-projecting the K- and V-tensors for every token within the cache, leading to significant computational overhead. To mitigate this burden, the up-projection matrices for K- and V-tensors can be absorbed into existing matrix operations, thereby reducing the total number of matrix-vector multiplications, as briefly touched upon in the <a href="https://arxiv.org/abs/2405.04434">DeepSeek v2</a>. Through computational reordering, the self-attention mechanism, for instance, transforms to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\nq_{t,i}^T k_{j,i} &amp;= (W^{UQ}_{[i \\times n_h:(i+1), :]} c^Q_t)^T W^{UK}_{[i \\times n_h:(i+1), :]} c^{KV}_j + q_{t,i}^{R^T} k_{j,i}^R \\\\\n&amp;=  c^{QT}_t (W^{{UQ}^T} W^{UK})_{[i \\times n_h:(i+1), :]} c^{KV}_{j,i} + q_t^{R^T} k_{j,i}^R,\n\\end{aligned}&quot;,&quot;id&quot;:&quot;OXLZUKGINQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>The most important advantage, as demonstrated in the following sections, is that the KV cache no longer requires up-projection operations. We apply analogous reordering to the V-tensor up-projection weight matrix <em>W^{UV}</em>, absorbing it into the output projection matrix <em>W^O</em>.</p><p>However, materializing </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{{UQ}^T} W^{UK}&quot;,&quot;id&quot;:&quot;KTPCOHMTGW&quot;}" data-component-name="LatexBlockToDOM"></div><p>increases the amount of memory transfer and reduces available KV cache capacity. But there is a way to have our cake and eat it. Our approach diverges from DeepSeek's hint by avoiding materialization of the resulting composite matrix. Instead, we achieve efficiency through dynamic computation: rather than storing the composite matrix </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{{UQ}^T} W^{UK}&quot;,&quot;id&quot;:&quot;MDXIIUSUTC&quot;}" data-component-name="LatexBlockToDOM"></div><p>we compute it on-demand during each forward pass while calculating <em>q_t^C</em>. This strategy maintains an identical memory footprint and loading patterns while eliminating the computationally expensive sequence-length dependency imposed upon us due to the up-projections of K- and V-tensors during the decode phase.</p><p>To understand the computational requirements of MLA, we begin with analyzing the straightforward vanilla implementation to establish baseline FLOP counts, then progress to the optimized variant and show its performance improvements.</p><h4>Vanilla MLA Implementation</h4><p>The vanilla implementation follows the MLA specification from <a href="https://arxiv.org/abs/2405.04434">DeepSeek v2 Appendix C</a>, comprising three phases: latent projection, self-attention, and output projection.</p><p><strong>Latent Up-/Down-Projection</strong> The latent projection involves two sequential operations: down-projection to the latent space, followed by up-projection to the attention dimension. For the sake of simplicity, we ignore the RoPE and Softmax calculations.</p><p><strong>Prefill:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\style{color:grey}{FLOPs_\\text{q_down_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d \\times d_c'} \\\\\n\\style{color:grey}{FLOPs_\\text{q_up_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d_c' \\times n_h \\times d_h} \\\\\n\\style{color:grey}{FLOPs_\\text{q_RoPE_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d_c' \\times n_h \\times d^R_h} \\\\\n\\style{color:grey}{FLOPs_\\text{kv_down_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d \\times d_c} \\\\\n\\style{color:grey}{FLOPs_\\text{k_up_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times n_h \\times d_c \\times d_h^{qk}} \\\\\n\\style{color:grey}{FLOPs_\\text{k_RoPE_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d \\times d^R_h} \\\\\n\\style{color:grey}{FLOPs_\\text{v_up_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times n_h \\times d_c \\times d_h^{v}}\n\\end{align}&quot;,&quot;id&quot;:&quot;TOSUSNZTOR&quot;}" data-component-name="LatexBlockToDOM"></div><p>During decode operations, most sequence-length dependencies can be eliminated since intermediate values are either used once or cached. However, performing K- and V-tensor projections for each token in the context remains necessary due to caching in latent format. This creates a problematic sequence-length dependency that significantly degrades performance. So vanilla decode projection becomes <strong>Decode (single token)</strong>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nFLOPs_{\\text{q_down_proj}} = 2 \\times B \\times d \\times d_c' \\\\\nFLOPs_{\\text{q_up_proj}} = 2 \\times B \\times d_c' \\times n_h \\times d_h \\\\\nFLOPs_{\\text{q_RoPE_proj}} = 2 \\times B \\times d_c' \\times n_h \\times d^R_h \\\\\nFLOPs_{\\text{kv_down_proj}} = 2 \\times B \\times d \\times d_c \\\\\nFLOPs_{\\text{k_up_proj}} = 2 \\times B \\times S \\times n_h \\times d_c \\times d_h^{qk} \\\\\nFLOPs_{\\text{k_RoPE_proj}} = 2 \\times B \\times d \\times d^R_h \\\\\nFLOPs_{\\text{v_up_proj}} = 2 \\times B \\times S \\times n_h \\times d_c \\times d_h^{v}\n\\end{align}&quot;,&quot;id&quot;:&quot;ZSBAAVCPRO&quot;}" data-component-name="LatexBlockToDOM"></div><p>where the <em>FLOPs_{k_RoPE_proj}</em> only need to be calculated once for each <em>k</em>, as they are cached.</p><p><strong>Attention Computation </strong>The attention mechanism computes query-key interactions against cached key-value pairs, exhibiting computational complexity that scales with sequence length.</p><p><strong>Prefill:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\style{color:grey}{FLOPs_\\text{qk_scores}} &amp;\\style{color:grey}{= 2 \\times B \\times S^2 \\times n_h \\times (d_h + d^R_h)} \\\\\n\\style{color:grey}{FLOPs_\\text{$\\times$v}} &amp;\\style{color:grey}{= B \\times S^2 \\times n_h \\times d_h}&nbsp;\\\\\n\\style{color:grey}{FLOPs_{\\sum_{t}}} &amp;\\style{color:grey}{= B \\times O(S^2) \\times n_h \\times d_h}\n\\end{align}&quot;,&quot;id&quot;:&quot;YGKXILADFY&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Decode:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nFLOPs_\\text{qkv} &amp;= B \\times n_h \\times S \\times (3 \\times d_h + 2 \\times d^R_h)\n\\end{align}&quot;,&quot;id&quot;:&quot;CDECYWWRIP&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Output Linear Transformation </strong>The final linear transformation projects attention outputs back to the model's hidden dimension:</p><p><strong>Prefill:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n\\style{color:grey}{FLOPs_\\text{out_lin} = 2 \\times B \\times S \\times n_h \\times d_h \\times d}\n\\end{equation}&quot;,&quot;id&quot;:&quot;CXGWNGKWRP&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Decode:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\nFLOPs_\\text{out_lin} = 2 \\times B \\times n_h \\times d_h \\times d\n\\end{equation}&quot;,&quot;id&quot;:&quot;BZJUXLUBUE&quot;}" data-component-name="LatexBlockToDOM"></div><p>We now examine the computational modifications when implementing the non-materialized matrix-absorption approach.</p><h4>Matrix-Absorbed MLA Implementation</h4><p>The primary goal of the two matrix absorptions:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{UK} \\to W^{UQ} \\text{ and } W^{UV} \\to W^{O}&quot;,&quot;id&quot;:&quot;RVZKNXEXZR&quot;}" data-component-name="LatexBlockToDOM"></div><p>is to eliminate per-token KV cache up-projections by enabling direct computation on compressed KV-tensors. This fundamentally alters the memory access pattern.</p><p><strong>Latent Up-/Down-Projection </strong>Since we absorb the up-projection matrices for K- and V-tensors, we no longer need to perform these projections.</p><p><strong>Prefill:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\style{color:grey}{FLOPs_\\text{q_down_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d \\times d_c'} \\\\\n\\style{color:grey}{FLOPs_\\text{q_RoPE_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d_c' \\times n_h \\times d^R_h} \\\\\n\\style{color:grey}{FLOPs_\\text{kv_down_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d \\times d_c} \\\\\n\\style{color:grey}{FLOPs_\\text{k_RoPE_proj}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times d \\times d^R_h} \\\\\n\\end{align}&quot;,&quot;id&quot;:&quot;FLKABSLNQU&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Decode:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nFLOPs_\\text{q_down_proj} &amp;= 2 \\times B \\times d \\times d_c' \\\\\nFLOPs_\\text{q_RoPE_proj} &amp;= 2 \\times B \\times d_c' \\times n_h \\times d^R_h\\\\\nFLOPs_\\text{kv_down_proj} &amp;= 2 \\times B \\times d \\times d_c \\\\\nFLOPs_\\text{k_RoPE_proj} &amp;= 2 \\times B \\times d \\times d^R_h,\n\\end{align}&quot;,&quot;id&quot;:&quot;WTOSVSASHC&quot;}" data-component-name="LatexBlockToDOM"></div><p>This eliminates the sequence-length dependency during the projection stage, which constitutes a significant computational bottleneck.</p><p><strong>Attention Computation </strong>In this self-attention computation, we need to take the absorbed </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W^{{UQ}^T} W^{UK}&quot;,&quot;id&quot;:&quot;PEFYWPFETN&quot;}" data-component-name="LatexBlockToDOM"></div><p> into account. </p><p><strong>Prefill:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\style{color:grey}{FLOPs_\\text{q $W^{UQ^T}$}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times n_h \\times d_h \\times d_c'} \\\\\n\\style{color:grey}{FLOPs_\\text{$\\times W^{UK}$}} &amp;\\style{color:grey}{= 2 \\times B \\times S \\times n_h \\times d_h \\times d_c} \\\\\n\\style{color:grey}{FLOPs_\\text{qk_scores}} &amp;\\style{color:grey}{= 2 \\times B \\times S^2 \\times n_h \\times (d_c + d_h^R)} \\\\\n\\style{color:grey}{FLOPs_\\text{$\\times$v}} &amp;\\style{color:grey}{= B \\times S^2 \\times n_h \\times d_c} \\\\\n\\style{color:grey}{FLOPs_{\\sum_{t}}} &amp;\\style{color:grey}{= B \\times O(S^2) \\times n_h \\times d_c}\n\\end{align}&quot;,&quot;id&quot;:&quot;HRPWKGAJPD&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Decode:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nFLOPs_\\text{q $W^{UQ^T}$} &amp;= 2 \\times B \\times n_h \\times d_h \\times d_c' \\\\\nFLOPs_\\text{$\\times W^{UK}$} &amp;= 2 \\times B \\times n_h \\times d_h \\times d_c \\\\\nFLOPs_\\text{qk_scores} &amp;= 2 \\times B \\times S \\times n_h \\times (d_c + d_h^R) \\\\\nFLOPs_\\text{$\\times$v} &amp;= B \\times S \\times n_h \\times d_c \\\\\nFLOPs_{\\sum_{t}} &amp;= B \\times S \\times n_h \\times d_c,\n\\end{align}&quot;,&quot;id&quot;:&quot;RIXXWAIIVI&quot;}" data-component-name="LatexBlockToDOM"></div><p>As shown, the sequence-length dependency is eliminated for FLOPs&#215;W^(UK) and FLOPs&#215;W^(UV) without introducing additional matrix materialization.</p><p><strong>Output Linear Transformation </strong>The final linear transformation again projects attention outputs to the model dimension, incorporating the absorption of W^UV into W^O. We again avoid materializing the absorbed matrix to minimize memory overhead.</p><p><strong>Prefill:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n{FLOPs_\\text{out_lin} = 2 \\times B \\times S \\times (n_h \\times d_h \\times d + n_h \\times d_h \\times d_c)}\n\\end{equation}&quot;,&quot;id&quot;:&quot;AGHWKYFVRB&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Decode:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\nFLOPs_\\text{out_lin} = 2 \\times B \\times (n_h \\times d_h \\times d + n_h \\times d_h \\times d_c)\n\\end{equation}&quot;,&quot;id&quot;:&quot;ARRIZVYOQO&quot;}" data-component-name="LatexBlockToDOM"></div><h4>Expert Networks</h4><p>Following the MLA computational analysis, expert-network computation is relatively simple. Each expert module comprises two components: (1) a router and (2) the experts themselves. The experts consist of two layers with inverse dimensions and a SwiGLU activation function, incorporating gate projection weights of matching dimensions.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\text{Down-projection: } &amp; B \\times 2 \\times d \\times d_\\text{moe} \\\\\n\\text{Up-projection: } &amp;B \\times 2 \\times d \\times d_\\text{moe} \\\\\n\\text{Gate projection: } &amp;B \\times 2 \\times d \\times d_\\text{moe} \\\\\n\\end{align}&quot;,&quot;id&quot;:&quot;FVPDOVDNGT&quot;}" data-component-name="LatexBlockToDOM"></div><p>In total, for all experts, we get:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nFLOPs_{\\text{linear_layers}}&amp;=3\\times 2 \\times B \\times d \\times d_{\\text{moe}}\\\\\nFLOPs_{\\text{router}}&amp;=2 \\times B \\times d \\times n_r^E \\\\ \nFLOPs_{\\text{moe_total}}&amp;=FLOPs_{\\text{linear_layers}} \\times (n_s^E + n_{r,u}^E) + FLOPs_{\\text{router}}.\n\\end{align}&quot;,&quot;id&quot;:&quot;ACZCDJOZBL&quot;}" data-component-name="LatexBlockToDOM"></div><p>With expert imbalance (characterized by the expert imbalance factor &#946;_eb that we introduce in later sections),</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;$FLOPs_{\\text{moe_total}}= FLOPs_{\\text{linear_layers}} \\times \\frac{1}{\\beta_{eb}} \\times \\frac{n_{s,u}^E + n_{r,u}^E}{n_GPUs} + \\frac{FLOPs_{\\text{router}}}{n_GPUs}$&quot;,&quot;id&quot;:&quot;URBJPZGODJ&quot;}" data-component-name="LatexBlockToDOM"></div><h2>Communication</h2><h4>Communication Base Model</h4><p>Following the analysis presented in the <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">SGLang blog post</a>, the only inter-GPU communications stem from expert-parallelism sharding. Figure 16 illustrates this communication pattern during forward passes within individual layers. Each layer has two distinct communication phases: a dispatch phase routing tokens from data-parallel MLA blocks to selected experts, followed by a combine phase aggregating expert computation results for propagation to the next data-parallel MLA block in the subsequent layer.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RzxA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RzxA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 424w, https://substackcdn.com/image/fetch/$s_!RzxA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 848w, https://substackcdn.com/image/fetch/$s_!RzxA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 1272w, https://substackcdn.com/image/fetch/$s_!RzxA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RzxA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png" width="615" height="579" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:579,&quot;width&quot;:615,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:89678,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RzxA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 424w, https://substackcdn.com/image/fetch/$s_!RzxA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 848w, https://substackcdn.com/image/fetch/$s_!RzxA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.png 1272w, https://substackcdn.com/image/fetch/$s_!RzxA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd157184d-7c0a-4f5a-ade1-1e1c30b54b02_615x579.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 role="img" 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><title></title><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">Figure 16: Communication pattern during expert-parallel sharding. Each GPU sends out n(r,u)^E + n(s,u)^E = 9 messages going from the MLA to the expert computation and receives n(r,u)^E + n(s,u)^E = 9 many messages going from the experts computation to the next MLA step. This communication can happen intra- or inter-node, where systems with larger EP size increase the percentage of inter-node communication. The base image was taken from the <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">SGLang blog post</a>.</figcaption></figure></div><p>The <a href="https://arxiv.org/abs/2505.09343">DeepSeekV3 scaling analysis</a> establishes a baseline communication model assuming uniform expert distribution across devices, where "each device holds one expert&#8217;s parameters and processes approximately 32 tokens at a time". This configuration corresponds to a 257-GPU deployment with homogeneous network connections (each GPU-to-GPU connection has the same bandwidth and latency). We extend their formulation to accommodate arbitrary system configurations under assumptions of uniform network topology and perfectly balanced expert allocation. For each GPU communication link, each dispatch and combine operation processes </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{B}{2\\times n_{\\text{GPUs}}}&quot;,&quot;id&quot;:&quot;FTSFYNSVIR&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>tokens (accounting for dual-batch overlap), with replication across </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;n_{total,u}^E = n_{r,u}^E + n_{s,u}^E$&quot;,&quot;id&quot;:&quot;HVQLQRAYXZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>The total communication volume per GPU link per forward pass for DeepSeek V3.1 architectures becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\t\\text{comm_amount}_{\\text{v3 / r1}} &amp;= \\underbrace{2}_{\\substack{\\text{2b-overlap} \\\\ \\text{$\\rightarrow$ 2 }  \\times \\text{total time}}} \\times \\underbrace{(1\\text{Byte} + 2\\text{Bytes})}_{\\substack{\\text{dispatch in FP8 (1 byte),} \\\\ \\text{combine in BF16 (2 bytes)}}} \\times \\frac{B}{2 \\times n_{\\text{GPUs}}} \\times n_{total,u}^E \\times d \\times L \\\\\n\t&amp; = 2 \\times \\frac{B}{2 \\times n_{\\text{GPUs}}} \\times 3 \\times (8+1) \\times 7168 \\times 61 \\\\\n &amp;= \\frac{B}{n_{\\text{GPUs}}} \\times 0.0118 \\text{ GB}.\n\t\\end{aligned}&quot;,&quot;id&quot;:&quot;BUBSKJGRAM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The leading factor of 2 reflects computation-communication micro-batch overlap, where consecutive batch processing introduces sequential dependencies. Dispatch operations utilize FP8 precision while combine phases use BF16 precision.</p><p>The effective communication bandwidth corresponds to the minimum link bandwidth within the system topology. In well-balanced configurations without bottlenecks this is the link to each GPU. In general cases the constraint becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{comm_bandwidth} = \\min(\\text{comm_bandwidth}_{\\text{GPU}},  \\frac{\\text{comm_bandwidth}_{\\text{system bottleneck}}}{n_{\\text{GPUs using bottleneck}}}).&quot;,&quot;id&quot;:&quot;HLECSBFAVV&quot;}" data-component-name="LatexBlockToDOM"></div><p>Within homogeneous network environments, the communication execution time follows:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;t_{\\text{comm}} = \\text{comm_amount}_{\\text{v3 / r1}} \\times \\frac{1}{\\text{comm_bandwidth}}.&quot;,&quot;id&quot;:&quot;RZEEIWDLMN&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>Improvement 1: Non-Heterogeneous Communication Links</h4><p>Standard systems often have different interconnect speeds for intra- and inter-node communication. Given that <em>1/n_nodes </em>of total communication volume remains within individual nodes, this fraction of communication becomes negligible in heterogeneous network configurations where interconnect speeds differ substantially (for example, NVLink at 450 GB/s versus InfiniBand at 50 GB/s). The NVL72 rack configuration represents a notable exception, providing uniform NVLink connectivity across all nodes within the rack.</p><p>For systems with heterogeneous interconnections, the total communication time becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\tt_{\\text{comm}} = \\text{comm_amount}_{\\text{v3 / r1}} \\times max(&amp; \\frac{n_{\\text{nodes}}-1}{n_{\\text{nodes}}} \\times \\frac{1}{\\text{comm_bandwidth}_{\\text{inter-node}}},  \\\\\n\t&amp; \\frac{1}{n_{\\text{nodes}}} \\times \\frac{1}{\\text{comm_bandwidth}_{\\text{intra-node}}} )\n\t\\end{aligned}&quot;,&quot;id&quot;:&quot;OXUQHUJXNN&quot;}" data-component-name="LatexBlockToDOM"></div><h4>Improvement 2: Expert Imbalance</h4><p>Our initial analysis assumed uniform expert distribution across GPUs, enabling straightforward communication volume calculations from the data-parallel MLA perspective. However, this assumption breaks down in practical deployments. As an easy counter example, consider a system deploying 9 experts across 8 GPUs: one GPU must accommodate 2 experts due to the discreteness of the experts, resulting in nearly double the communication overhead compared to balanced configurations:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n2\\times \\underbrace{2}_{\\substack{\\text{2b-overlap} \\\\ \\text{$\\rightarrow$ 2 }  \\times \\text{total time}}} \\times \\underbrace{(1\\text{Byte} + 2\\text{Bytes})}_{\\substack{\\text{dispatch in FP8 (1 byte),} \\\\ \\text{combine in BF16 (2 bytes)}}} \\times \\frac{B}{2} \\times d \\times L &amp;= 2\\times B \\times \\frac{1}{8+1} \\times 0.0118 \\text{ GB} \\\\\n&amp; > \\frac{B}{8} \\times 0.0118 \\text{ GB}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;AAPHZDKQRR&quot;}" data-component-name="LatexBlockToDOM"></div><p>While sufficiently large batch sizes with random expert routing (and appropriate shared expert replication) could theoretically rebalance this load, empirical measurements in production systems show inherent differences in expert utilization that contradicts this assumption.</p><p>From the perspective of individual GPUs hosting experts, the communication volume becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\underbrace{2}_{\\substack{\\text{2b-overlap} \\\\ \\text{$\\rightarrow$ 2 }  \\times \\text{total time}}} \\times \\underbrace{(1\\text{Byte} + 2\\text{Bytes})}_{\\substack{\\text{dispatch in FP8 (1 byte),} \\\\ \\text{combine in BF16 (2 bytes)}}} \\times \\frac{B}{2} \\times d \\times L \\times \\frac{n_{total,u}^E}{n_{\\text{GPUs}}}\\\\\n\\end{aligned}&quot;,&quot;id&quot;:&quot;UKNUBDOVKS&quot;}" data-component-name="LatexBlockToDOM"></div><p>Incorporating the expert load imbalance factor (introduced in the next section) into the formulation yields:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{comm_amount}_{\\text{v3 / r1}} = B \\times (1+2) \\times d \\times L \\times \\frac{1}{\\beta_{eb}} \\times \\frac{n_{total,u}^E}{n_{\\text{GPUs}}}&quot;,&quot;id&quot;:&quot;GIIRSGSQVB&quot;}" data-component-name="LatexBlockToDOM"></div><p>For heterogeneous network configurations, the resulting communication time then becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\nt_{\\text{comm}} &amp;= \\text{comm_amount}_{\\text{v3 / r1}} \\times \\max\\left( \\frac{n_{\\text{nodes}}-1}{n_{\\text{nodes}}} \\times \\frac{1}{\\text{comm_bandwidth}_{\\text{inter-node}}}, \\right.\\\\ \n&amp;\\left. \\frac{1}{n_{\\text{nodes}}} \\times \\frac{1}{\\text{comm_bandwidth}_{\\text{intra-node}}} \\right)\n\\end{aligned}&quot;,&quot;id&quot;:&quot;UGUYTFYNCI&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>List of Common Interconnects</h4><p>Table 2 presents unidirectional bandwidth specifications for all-to-all communication patterns for commonly used interconnect technologies, where communication throughput is constrained by the bandwidth available to individual GPUs (unidirectional bandwidth):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GYlS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GYlS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 424w, https://substackcdn.com/image/fetch/$s_!GYlS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 848w, https://substackcdn.com/image/fetch/$s_!GYlS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 1272w, https://substackcdn.com/image/fetch/$s_!GYlS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GYlS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png" width="1970" height="444" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/783e50d9-974e-4635-9703-a18acfde0612_1970x444.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:444,&quot;width&quot;:1970,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:112085,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb5b1b9d5-6d91-4591-89ea-17c31febfd0a_1970x444.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GYlS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 424w, https://substackcdn.com/image/fetch/$s_!GYlS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 848w, https://substackcdn.com/image/fetch/$s_!GYlS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 1272w, https://substackcdn.com/image/fetch/$s_!GYlS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F783e50d9-974e-4635-9703-a18acfde0612_1970x444.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Table 2: Unidirectional bandwidth specifications across different interconnect technologies.</figcaption></figure></div><h2>Expert Balancedness</h2><p>The distribution of the experts over the GPUs can have a big impact on the communication and execution times of the expert layers. As an illustrative example, we can take a system with 2x8 H100 GPUs and distribute all the experts uniformly. In this case, there is a GPU which has the shared expert plus roughly 16 routed ones. Since all items in a batch will go to the shared expert, this GPU has to load roughly </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{1+\\frac{n_{\\text{shared_experts_used}} + n_{\\text{routed_experts_used}}}{n_\\text{GPUs}}}{\\frac{n_{\\text{shared_experts_used}} + n_{\\text{routed_experts_used}}}{n_\\text{GPUs}}} \\approx 2,7\\times&quot;,&quot;id&quot;:&quot;UQFZJLROWK&quot;}" data-component-name="LatexBlockToDOM"></div><p>more activations than the other GPUs. Furthermore, 2.7 times more communication volume will go through the link connecting to the GPU.</p><p>To model this imbalance, we define and expose the variable <em>&#946;_eb</em> to the user. Similar to the definition of SGLang, <em>&#946;_eb</em> is defined as the ratio between mean expert load and maximum expert load among GPUs, so:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\beta_{eb} = mean_{layers}\\left(\\frac{\\text{avg routed request per layer}}{\\text{max routed request (of any GPU) per layer}}\\right)&quot;,&quot;id&quot;:&quot;BEOXHATBJK&quot;}" data-component-name="LatexBlockToDOM"></div><p>Therefore, <em>&#946;_eb_gpu=1</em> is a balanced case and <em>&#946;_eb=1/n_GPUs</em> would be completely imbalanced. Thus the average load increases by <em>L_imbalanced = (1/&#946;_ep) &#215; L_balanced</em>.</p><p>For balancing the experts, some <em>n_additional_experts</em> get duplicated onto multiple GPUs. This can lead to an increase in EP memory loading time. As EP is often memory-bound, this can lead to an increased EP execution time. Thus balancing the experts is a tradeoff between loading more weights and more homogeneous communication and computation. Finally, one has to ensure that (<em>n_routed_experts</em> + <em>n_additional_experts)</em> modulo <em>ep_size</em> = 0, as otherwise imbalance in the memory loading and computations would be introduced by design.</p><p>Figure 17 from the <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">SGLang blog post</a> shows examples of expert balancedness given a number of GPUs and potentially active load balancing.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hcvy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hcvy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 424w, https://substackcdn.com/image/fetch/$s_!hcvy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 848w, https://substackcdn.com/image/fetch/$s_!hcvy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 1272w, https://substackcdn.com/image/fetch/$s_!hcvy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hcvy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png" width="1456" height="1090" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1090,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146861,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hcvy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 424w, https://substackcdn.com/image/fetch/$s_!hcvy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 848w, https://substackcdn.com/image/fetch/$s_!hcvy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.png 1272w, https://substackcdn.com/image/fetch/$s_!hcvy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F1b4006cf-8f7a-4632-8d37-4c5981b049ef_2583x1933.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 role="img" 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><title></title><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">Figure 17: Achieved expert balancedness given a fixed number of devices using expert parallel load balancing. <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">Source</a></figcaption></figure></div><h2>From Parts to the Whole</h2><p>Given all of these considerations, we implemented a theoretical model estimating the model throughput given the hardware. It should make it easier to understand the tradeoffs between the latency, throughput, and cost between different hardware providers. </p><p>The model includes a number of assumptions, such as: </p><ul><li><p>All weights are stored in FP8; the MLA is computed in BF16; the matrix multiplications in the expert layers are performed in FP8. The communication is done in FP8 apart from the dispatch which is done in BF16.</p></li><li><p>We make some strong assumptions about the overhead for compute, memory bandwidth, and communication. We assume the same level of inefficiency across different hardware to make it fair. The levels are arbitrary and arguably can be one of the leading sources of error in our calculation. These inefficiencies in reality are also not the same for every hardware and are strongly dependent on the implementation.</p></li><li><p>To make the calculations simpler we assume that no MTP is performed. We managed to make it run with MTP; however, we deemed the performance gains not worth the increase in complexity of the model, especially for larger batches.</p></li><li><p>We only looked at the decode performance without taking into account prefill.</p></li><li><p>We assume no compute and memory loading overheads from the <a href="https://github.com/deepseek-ai/DeepEP">DeepEP</a> two-batch communication library. This is not true, as these operations start a significant number of CUDA kernels, which can have downstream effects on highly optimized kernels like GEMM, as they will no longer get the expected number of threads.</p></li></ul><p>At a high level, the performance model comprises three primary execution components: MLA computation, expert parallel (EP) computation, and communication overhead. For both MLA and EP operations, we determine whether memory bandwidth or computational throughput constitutes the limiting factor. Communication can be optionally overlapped using two-batch overlap (TBO), where total execution time for one forward pass becomes </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;T_{TBO}=2\\times T(B/2)&quot;,&quot;id&quot;:&quot;PEMRNMFJYL&quot;}" data-component-name="LatexBlockToDOM"></div><p>The high-level model structure follows:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nT_{bottleneck}^{MLA}(B, S) &amp;= \\max\\left(T_{mem}^{MLA}(B, S), T_{comp}^{MLA}(B, S)\\right) \\\\\nT_{bottleneck}^{EP}(B, S) &amp;= \\max\\left(T_{mem}^{EP}(B, S), T_{comp}^{EP}(B, S)\\right) \\\\\nT_{total}^{\\text{no }TBO} (B, S) &amp;= T_{bottleneck}^{MLA}(B, S) + T_{bottleneck}^{EP}(B, S) + T_{comms}(B) \\\\\nT_{total}^{TBO} (B, S) &amp;= 2\\times\\max\\left(T_{bottleneck}^{MLA}\\left(\\frac{B}{2}, S\\right) + T_{bottleneck}^{EP}\\left(\\frac{B}{2}, S \\right), T_{comms}\\left(\\frac{B}{2}\\right)\\right)\n\\end{align}&quot;,&quot;id&quot;:&quot;ERWYSEHBQQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>Computational, memory, and communication time estimates use the previously derived formulae, adjusted for real-world implementation inefficiencies. Practical systems rarely achieve theoretical peak performance, necessitating inefficiency factors across all components. The DeepEP communication library documentation indicates <em>40 GB/s</em> achieved throughput from <em>50 GB/s</em> theoretical peak, yielding a communication overhead of ~25%. FlashMLA achieves approximately <em>66%</em> MFU. Expert-layer computational performance, based on DeepGEMM benchmarks showing <em>1550 TFLOPs</em> from <em>1980 TFLOPs</em> theoretical FP8 dense peak performance results in an EP computation overhead factor of ~30%. Both computational inefficiencies receive an additional <em>10%</em> penalty to account for suboptimal input conditions and overhead between the kernels.</p><p>Memory inefficiency estimation proves more challenging without profiling. Due to some operations, such as matrix multiplication, requiring multiple loading operations for the same value, and the fact that most kernels are optimized for compute bound scenarios, we apply a conservative inefficiency factor of <em>2.0</em> to account for these overheads.</p><p>Token generation rates are calculated as the inverse of total execution time, with global throughput scaling by concurrent batch size:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\nTPS_{request} &amp;= \\frac{1}{T_{total}^{TBO}} \\\\\nTPS_{global} &amp;= \\frac{1}{T_{total}^{TBO}} \\times B\n\\end{align}&quot;,&quot;id&quot;:&quot;SBDELOJFBP&quot;}" data-component-name="LatexBlockToDOM"></div><p>It is important to note that this model does not consider whether the proposed configurations are viable under real-world memory constraints. For instance, long context sequences can drastically reduce the maximum number of concurrent sequences due to memory limitations, resulting in significantly lower throughput than theoretical predictions. </p><h2>Predictions and Real-World Comparison</h2><p>To validate our theoretical model we compare it to real world measurements using three vastly different hardware setups:</p><ul><li><p>4x8 H100: This is the basic setup that we consider reasonable to maintain by a large enterprise. This was also the setup we managed to obtain, therefore we have the measurements for all reasonable batch sizes.</p></li><li><p>9x8 H100: This is the setup from the <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">SGLang blog post</a> including their tuned performance measurements.</p></li><li><p>12x4 B200: This involves 48 out of 72 GPUs in an NVL72 setup. We use this to visualize how differently the new generation of hardware performs. This is also a setup tested by the <a href="https://lmsys.org/blog/2025-06-16-gb200-part-1">SGLang team</a>.</p></li></ul><p>Figures 18 and 19 demonstrate that our theoretical model achieves reasonable agreement with empirical measurements. The first figure presents a systems total throughput and tokens per second (TPS) per request, while the second emphasizes efficiency by showing TPS per GPU.</p><p>As anticipated, our model overestimates actual performance by a considerable margin and we have to tune the model with our inefficiency factors. This discrepancy arises from two primary factors: first, individual component kernels fail to achieve peak performance as discussed previously; and second, peak performance of these individual components is rarely attained with constrained batch sizes. Furthermore, end-to-end optimization is often suboptimal, resulting in kernels optimized for different operational scenarios. These factors justify our incorporated inefficiency assumptions.</p><p>Small batch size estimation proved particularly challenging, as illustrated in Figure 18. At batch size 32, actual performance in our setup (shown in blue) exceeds theoretical predictions (given our inefficiency factors; it does not exceed the upper bound posed by the hardware itself). In our model, we assumed uniform expert activation probability, which does not reflect reality. In practice, fewer experts are activated, resulting in higher throughput than predicted. As batch size increases, throughput converges to predicted levels, indicating activation of most to all available experts.</p><p>Consistent with our stated assumptions, the model does not assess whether given batch sizes are practically feasible under given systems memory constraints. In our system configuration, sequence eviction begins after batch size 1024, causing a sharp decline in per-request throughput and total throughput saturation. Increasing node count expands the amount of memory available for KV cache, enabling larger batch sizes as demonstrated by the two SGLang configurations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!k_Yy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!k_Yy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 424w, https://substackcdn.com/image/fetch/$s_!k_Yy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 848w, https://substackcdn.com/image/fetch/$s_!k_Yy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!k_Yy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!k_Yy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png" width="1456" height="1607" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1607,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:687403,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!k_Yy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 424w, https://substackcdn.com/image/fetch/$s_!k_Yy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 848w, https://substackcdn.com/image/fetch/$s_!k_Yy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!k_Yy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa7367032-2ab9-40cd-9265-9fc0bdaa2191_3608x3983.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 role="img" 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><title></title><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">Figure 18: Comparing the theoretical model with real world measurements for decode throughput performance. The measurements for the 4x8 H100 setup were conducted using our <a href="https://github.com/tugot17/tokenomics">tokenomics benchmark,</a> running AIME requests against the model. Data for the two other setups stems from the SGLang <a href="https://lmsys.org/blog/2025-06-16-gb200-part-1/">two</a> <a href="https://lmsys.org/blog/2025-05-05-large-scale-ep/">blogposts</a> Our model works well in different scenarios on multiple hardware setups.</figcaption></figure></div><h1>Throughput: Theory vs Practice</h1><p>Examining Figure 19, we observe that <strong>increasing batch size per GPU improves system efficiency</strong> substantially. However, realizing these optimal batch sizes necessitates extensive memory allocation for storing KV cache. Given that total weight size remains largely static (excluding data-parallel MLA weights), distributing computation across additional GPUs reduces the per-GPU weight burden proportionally.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fNkJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fNkJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 424w, https://substackcdn.com/image/fetch/$s_!fNkJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 848w, https://substackcdn.com/image/fetch/$s_!fNkJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 1272w, https://substackcdn.com/image/fetch/$s_!fNkJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fNkJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png" width="1456" height="962" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:962,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:450603,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fNkJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 424w, https://substackcdn.com/image/fetch/$s_!fNkJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 848w, https://substackcdn.com/image/fetch/$s_!fNkJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.png 1272w, https://substackcdn.com/image/fetch/$s_!fNkJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb6edd27c-237c-4d99-b17c-756ab907dc49_3613x2387.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 role="img" 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><title></title><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">Figure 19: Per-GPU efficiency across all configurations demonstrates consistent scaling characteristics. Measurements on our system (in blue) exhibit a performance ceiling due to token memory constraints that trigger sequence evictions, preventing running the full batch concurrently. This limitation clearly illustrates that additional memory capacity would enable our system to achieve higher throughput levels, validating the case for larger setups.</figcaption></figure></div><p>An increasing problem that large-scale systems pose is the <strong>communication overhead</strong>, which scales linearly with batch size. Consequently, configurations with large batch sizes and short sequence lengths may encounter communication bottlenecks. This phenomenon manifests in Figure 19 where the <em>4x8 H100</em> configuration achieves higher per-GPU throughput at batch size 512 compared to the <em>9x8 H100 setup</em>, because the latter becomes communication-bound. Nevertheless, the former configuration cannot sustain these batch sizes in practice and will evict sequences, effectively running at smaller batch sizes. This also demonstrates the advantages of the NVL72 super node for inference workloads, effectively mitigating potential communication constraints.</p><p><strong><a href="https://arxiv.org/abs/2507.20534">Kimi-K2</a></strong> represents the first open-source LLM surpassing 1T parameters. The model employs the essentially identical architecture to DeepSeek V3.1, just with more routed experts per layer. As demonstrated in Figure 20, this configuration yields reduced throughput, particularly under memory-bound conditions where MLA runtime remains minimal. However, achieving equivalent batch sizes across identical hardware configurations is infeasible for large batches, as Kimi-K2 requires greater GPU memory allocation for storing its weights. Consequently, while theoretical performance degradation appears modest, practical performance disparities may be more pronounced due to reduced effective batch sizes compared to DeepSeek V3.1 deployment.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!f21k!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!f21k!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 424w, https://substackcdn.com/image/fetch/$s_!f21k!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 848w, https://substackcdn.com/image/fetch/$s_!f21k!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!f21k!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!f21k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png" width="1456" height="1593" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1593,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:813648,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!f21k!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 424w, https://substackcdn.com/image/fetch/$s_!f21k!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 848w, https://substackcdn.com/image/fetch/$s_!f21k!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!f21k!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd7db7e2-3a2f-4a46-bf9e-0e9505e01159_3641x3983.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 role="img" 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><title></title><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">Figure 20: Comparison of theoretical predictions for Kimi K2 to DeepSeek v3. Even though Kimi K2 has a lot more weights, its only slightly larger due to the MLA and the communication being the same in both models. However, we dont model if a given setup would actually have enough memory and thus would be able to run a given batch size. Kimi K2 would reach this limit much earlier leading to more evictions and smaller achievable batch sizes.</figcaption></figure></div><p>Similar challenges with increased KV cache evictions and diminished effective batch sizes emerge when <strong>serving long sequences</strong>, as their KV cache demands substantial memory space. Although sequence length exerts a comparatively small impact on decode performance, as shown in Figure 21 (while exhibiting quadratic dependency during prefill on the sequence length), it constrains to running very low batch sizes, significantly reducing system efficiency. </p><p>For example, a 4&#215;8 H100 setup provides roughly 20 GB of GPU memory per GPU for the KV cache. At a context length of 32,768 tokens, this translates to a maximum effective batch size of </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{20\\times 10^9 \\times 4 \\times 8}{70\\times10^3\\times32768} \\approx 279 &quot;,&quot;id&quot;:&quot;UIDGLMTFGP&quot;}" data-component-name="LatexBlockToDOM"></div><p>In practice, fragmentation of the KV cache and other inefficiencies reduce this number further. <a href="https://github.com/deepseek-ai/open-infra-index/blob/main/202502OpenSourceWeek/day_6_one_more_thing_deepseekV3R1_inference_system_overview.md">DeepSeek reports</a> a much shorter average context length of 4989 tokens, which remains within manageable parameters.</p><p>Production serving environments typically operate under service level agreement (<strong>SLA</strong>) requirements that mandate minimum TPS thresholds per request. As illustrated in Figure 22, these performance guarantees often impose surprisingly restrictive limits on achievable batch sizes. Providers find themselves constrained to operate with smaller batches to meet per-request latency requirements, resulting in suboptimal efficiency. This constraint disproportionately affects smaller deployment configurations, creating a natural advantage for large-scale enterprise operations, serving to hundreds of thousands of customers.</p><p>Our previous analysis has given limited attention to the prefill phase. During <strong>prefill</strong>, the system computes the complete KV cache for all input tokens and generates the first output token. The computational complexity of this phase scales quadratically with sequence length due to the full attention computation required. For shorter sequences, prefill duration remains substantially shorter than the subsequent decode phase. However, in long-context scenarios, prefill can exceed decode time, creating significant system bottlenecks.</p><p>Serving frameworks typically interrupt decode operations to process prefill batches, stalling the entire inference pipeline. Additionally, prefill operations are generally compute-bound rather than memory-bound, requiring distinct optimization strategies compared to decode. Large-scale deployments address this by implementing prefill-decode disaggregation, physically separating these phases across different instances. The prefill instance typically operates on fewer GPUs than the decode instance, reflecting the shorter duration and different resource requirements of prefill operations. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!d58L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!d58L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 424w, https://substackcdn.com/image/fetch/$s_!d58L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 848w, https://substackcdn.com/image/fetch/$s_!d58L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!d58L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!d58L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png" width="1456" height="1622" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1622,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:887448,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!d58L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 424w, https://substackcdn.com/image/fetch/$s_!d58L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 848w, https://substackcdn.com/image/fetch/$s_!d58L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!d58L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbb9fc7d2-a198-47fc-bccd-60fdab74e268_3576x3983.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 role="img" 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><title></title><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">Figure 21: Serving long contexts affects decode performance less than prefill, since prefill&#8217;s runtime scales quadratically with input sequence length. However, a much bigger factor for decode, one we don&#8217;t currently model, is the size of the KV cache. A large KV cache renders the MLA memory bound for larger batch sizes and additionally forces running at smaller effective batch sizes, preventing the operation from becoming compute-bound in any realistic setup.</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!pFq8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!pFq8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 424w, https://substackcdn.com/image/fetch/$s_!pFq8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 848w, https://substackcdn.com/image/fetch/$s_!pFq8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 1272w, https://substackcdn.com/image/fetch/$s_!pFq8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!pFq8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png" width="1456" height="892" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:892,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:232062,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!pFq8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 424w, https://substackcdn.com/image/fetch/$s_!pFq8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 848w, https://substackcdn.com/image/fetch/$s_!pFq8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.png 1272w, https://substackcdn.com/image/fetch/$s_!pFq8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2e2834b-de1c-4433-9f9c-5de84cd4255a_3571x2187.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 role="img" 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><title></title><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">Figure 22: The plots shows the maximum achievable batch size for running with at least 20 TPS per request. This limit is arbitrary but seems close to what providers often offer as an SLA. Again the setup using the NVL72 outshines the competition, allowing for more efficient serving given an SLA.</figcaption></figure></div><p>Interactive chat applications and agentic workflows frequently involve multi-turn sequences where consecutive requests share common prompt prefixes. Given the potential length of these conversational contexts, repeatedly executing prefill for shared content becomes highly inefficient. Sophisticated <strong>caching</strong> mechanisms can drastically improve performance by reusing computed KV caches across requests. Effective caching architectures extend beyond GPU memory to use CPU memory and even persisting to disk. Even disk-to-GPU transfers often outperform recomputation for sufficiently long sequences. Additionally on-disk caches can be held for longer, potentially for days.</p><p>Such caching infrastructure can also serve as a buffer layer between disaggregated prefill and decode instances. Systems like LMCache and Mooncake provide foundational solutions to this problem. However, setting up such a caching infrastructure is non-trivial, and we save this topic for a future blog post. For the current analysis, we note that while prefill can substantially impact overall system performance, well-designed caching strategies offer substantial mitigation. <a href="https://github.com/deepseek-ai/open-infra-index/blob/main/202502OpenSourceWeek/day_6_one_more_thing_deepseekV3R1_inference_system_overview.md">DeepSeek's production deployment reports</a> achieving approximately <em>56.3%</em> cache hit rates, demonstrating a good reduction in prefill time when deployed.</p><p>While open source inference frameworks such as SGLang and vLLM may not achieve the absolute peak performance of specialized commercial inference providers like Fireworks or Together, we believe the performance gap remains relatively narrow. Evidence from production deployments, as referenced in Tweet 23, suggests that open source solutions approach state-of-the-art efficiency levels achieved by major enterprise implementations.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xKi5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xKi5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 424w, https://substackcdn.com/image/fetch/$s_!xKi5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 848w, https://substackcdn.com/image/fetch/$s_!xKi5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 1272w, https://substackcdn.com/image/fetch/$s_!xKi5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xKi5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png" width="1438" height="948" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:948,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:255969,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xKi5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 424w, https://substackcdn.com/image/fetch/$s_!xKi5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 848w, https://substackcdn.com/image/fetch/$s_!xKi5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.png 1272w, https://substackcdn.com/image/fetch/$s_!xKi5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4d504b29-c6aa-430f-a610-4f70d7592cbe_1438x948.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 role="img" 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><title></title><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">Figure 23: Member of technical staff at Thinky suggesting that the open-source inference software is not that far behind the proparitary inference software stacks available inside the big labs. <a href="https://x.com/cHHillee/status/1949331629035712981">Twitter</a></figcaption></figure></div><p>Our theoretical analysis combined with empirical measurements indicates that proprietary inference providers likely achieve comparable computational efficiency to well-optimized local personal deployments. However, these commercial providers maintain competitive advantages through access to superior hardware and more favorable economies of scale. The primary differentiation appears to stem from infrastructure advantages and economies of scale rather than fundamental algorithmic or implementation superiority in the inference stack itself.</p><h1>Hardware considerations and profit margins</h1><p>When deciding on hardware for large-scale MoE inference setups like DeepSeek V3.1 or Kimi, several key factors must be considered. First, due to the sparse computation pattern and its effects on the parameters that need to be loaded for a forward pass, there are significant economies of scale from adding more GPUs to the setup. In other words, a combination of four nodes should outcompete two pairs of workers running on two nodes. This is pretty well visualized in the graph created by the SGLang team (see Fig. 24), where a setup of 72 GPUs vastly outperforms one with 16 GPUs involved on a <strong>per GPU basis</strong>, an observation that confirms what we have seen before in results from Perplexity (see Fig. 2).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!G0p1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!G0p1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 424w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 848w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 1272w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!G0p1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png" width="1456" height="895" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:895,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:55806,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!G0p1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 424w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 848w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.png 1272w, https://substackcdn.com/image/fetch/$s_!G0p1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F914d6736-5e02-49cc-bfcf-ceb95b23941b_2888x1775.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 role="img" 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><title></title><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">Figure 24: Token throughput measured on NVL72 <a href="https://lmsys.org/blog/2025-06-16-gb200-part-1/">SGLang Blog.</a> 2.08.2025</figcaption></figure></div><p>Second, cumulative throughput and per-user experience are highly dependent on the batch size at which the setup operates. This is well visualized in the benchmarks run we did for testing DeepSeek (see Fig. 18), and in the numbers provided by the SGLang team (see Fig. 25). The larger the allowed batch size the larger cumulative throughput but at a cost of worse "per user" experience (see Tab. 1) - a fundamental trade-off in inference optimization.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Vuaw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Vuaw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 424w, https://substackcdn.com/image/fetch/$s_!Vuaw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 848w, https://substackcdn.com/image/fetch/$s_!Vuaw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 1272w, https://substackcdn.com/image/fetch/$s_!Vuaw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Vuaw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png" width="1456" height="1090" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1090,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:55452,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Vuaw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 424w, https://substackcdn.com/image/fetch/$s_!Vuaw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 848w, https://substackcdn.com/image/fetch/$s_!Vuaw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.png 1272w, https://substackcdn.com/image/fetch/$s_!Vuaw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab6cda70-873a-4338-a571-973484fbabc3_2583x1933.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 role="img" 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><title></title><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">Figure 25: Token throughput measured on NVL72 <a href="https://lmsys.org/blog/2025-06-16-gb200-part-1/">SGLang Blog</a>. The input and output lengths are set to 2000 and 100, respectively.</figcaption></figure></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\text{throughput per GPU} \\times \\text{number of GPUs} \\times 3600s \\times 24h = \\text{daily token production}\n\\end{equation}&quot;,&quot;id&quot;:&quot;LHYPTWIXTO&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\text{H100 EP72 at bs 64} = 1400tps \\times 72 \\times 3600s \\times 24h = \\text{8.7B tokens/day}\n\\end{equation}&quot;,&quot;id&quot;:&quot;SUHRWJXUZG&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\frac{\\text{throughput per GPU}}{\\text{batch size}} = \\text{throughput per request}\n\\end{equation}&quot;,&quot;id&quot;:&quot;QBLQMZYTDZ&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\text{H100 EP72 at bs 64} = \\frac{1400tps}{64} = \\text{21.9 tokens/request}\n\\end{equation}&quot;,&quot;id&quot;:&quot;WZGGDTYOZE&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\frac{\\text{daily operational cost}}{\\text{daily token production (in millions)}} = \\text{cost per 1M tokens}\n\\end{equation}&quot;,&quot;id&quot;:&quot;CEKSJYOUYN&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\text{H100 EP72 at bs 64} = \\frac{\\$3,456}{8,700M} = \\$0.40 \\text{ per 1M tokens}\n\\end{equation}&quot;,&quot;id&quot;:&quot;SZQMSVXOCG&quot;}" data-component-name="LatexBlockToDOM"></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aCdp!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aCdp!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 424w, https://substackcdn.com/image/fetch/$s_!aCdp!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 848w, https://substackcdn.com/image/fetch/$s_!aCdp!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 1272w, https://substackcdn.com/image/fetch/$s_!aCdp!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aCdp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png" width="1456" height="379" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:379,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:122389,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aCdp!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 424w, https://substackcdn.com/image/fetch/$s_!aCdp!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 848w, https://substackcdn.com/image/fetch/$s_!aCdp!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.png 1272w, https://substackcdn.com/image/fetch/$s_!aCdp!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc7a6aaf3-c6c3-4c38-ad04-8fed94d1aeda_1858x484.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 role="img" 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><title></title><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">Table 3: Daily production token production, tps enjoyed by each user, and cost per 1M output tokens. We only consider here the decode phase and leave prefill out of the scope for now. We assume the numbers from SGLang blogpost. The input and output lengths are set to 2000 and 100, respectively. At longer context these numbers will look differently, but we hope this table shows the scale of overcapacity. We assume $2/h and B200 at $8/h. Especially the second number is to be treated with cautious as there is no official market for NVL72, no provider offers this on demand so there is some guessing on our part here.</figcaption></figure></div><p>Hardware selection is the next critical consideration. The optimal choice is highly contingent on the latency/throughput  requirements for your specific use case. While B200s in NVL72 will offer superior per-GPU performance compared to H100s, they come at a significantly higher price point - assuming you can even secure them<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a>. Depending on what the inference provider wants to prioritize, either cost or latency, it will affect the type of hardware that will be optimal here. </p><p>For your exact application, how many input and output tokens do you run with, how big is your profit per user, how big is your spread in the number of concurrent users per day, how flexible are users, and at the time of peak usage, how low can the tps drop to? All of these factors should impact what hardware will be optimal for you. </p><p>One of the interesting observations we made after running the theoretical model for different hardware setups was how much of a bottleneck for B200 slow interconnect is. There seems to be a massive performance gap between the numbers we estimate for B200s connected via InfiniBand and the ones connected by NVLink. This is obviously highly contingent on the model and how much we communicate between the nodes, but overall we believe that for model of a scale such as DeepSeek, running on B200s might be actually suboptimal, as the coms overhead is taking away most of the gains we get from faster memory and more FLOPS compared to H100s (see Fig. 27).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qHWN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qHWN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 424w, https://substackcdn.com/image/fetch/$s_!qHWN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 848w, https://substackcdn.com/image/fetch/$s_!qHWN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!qHWN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qHWN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png" width="1456" height="1607" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1607,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:668916,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qHWN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 424w, https://substackcdn.com/image/fetch/$s_!qHWN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 848w, https://substackcdn.com/image/fetch/$s_!qHWN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.png 1272w, https://substackcdn.com/image/fetch/$s_!qHWN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcfe4a5d2-cd49-4f7e-920d-fe0eb67540ec_3608x3983.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 role="img" 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><title></title><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">Figure 27: Comparing a system based on the DGX B200 nodes to an NVL72 reveals a striking difference: The DGX systems gets communication bound due to relying on Infiniband for the inter-node communication, drastically limiting the performance compared to the NVL72 system.</figcaption></figure></div><p>Another observation we hope you can take out from reading this text is how "chat centric" the current inference providers are. If you look at the throughput of DeepSeekV3 from various providers, as reported by <a href="https://openrouter.ai/deepseek/deepseek-chat-v3-0324">OpenRouter</a>, most of them offer very comfortable 50+ tps (see Fig. 28). While this is great if we have real time application like a chat, it is less than optimal if we want to use the model to generate the synthetic data. As we have seen multiple times throughout this text, in benchmark from Perplexity (see Fig. 5), in our theoretical estimations and in the real world observations we did (see Fig. 19), keeping the tps so high, while great for real-time applications, is suboptimal when we want to produce as large numbers of tokens as possible. For that the operational batch size would need to be largely increased. This would result in significantly degraded tps performance per request, but substantially higher overall throughput. For asynchronous or non-time-critical workloads, this trade-off is highly beneficial, dramatically reducing cost per token.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AynK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AynK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 424w, https://substackcdn.com/image/fetch/$s_!AynK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 848w, https://substackcdn.com/image/fetch/$s_!AynK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 1272w, https://substackcdn.com/image/fetch/$s_!AynK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AynK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png" width="1456" height="1188" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1188,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:256284,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AynK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 424w, https://substackcdn.com/image/fetch/$s_!AynK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 848w, https://substackcdn.com/image/fetch/$s_!AynK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.png 1272w, https://substackcdn.com/image/fetch/$s_!AynK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F029b2ec7-3268-42ff-9acb-e1ffc14977eb_1770x1444.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 role="img" 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><title></title><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">Figure 28: DeepSeek V3.1 speeds offered by various providers. 2.08.2025</figcaption></figure></div><p>Such setup would be ideal for synthetic data generation, where individual latency is irrelevant and the goal is maximizing total token production per dollar of hardware investment (Fig. 29). However, we believe that the current inference providers inadequately serve this market. While some offer batch discounts - Fireworks provides <em>40%</em> off batch APIs, DeepSeek offers <em>50%</em> off-peak pricing in China (see Fig. 32) - these limited options suggest significant unmet demand for flexible, throughput-optimized serving.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ITJm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ITJm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 424w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 848w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 1272w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ITJm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png" width="1301" height="630" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a44075b8-972d-4433-983e-506bb49f460b_1301x630.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:630,&quot;width&quot;:1301,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:137342,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ITJm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 424w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 848w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.png 1272w, https://substackcdn.com/image/fetch/$s_!ITJm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa44075b8-972d-4433-983e-506bb49f460b_1301x630.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 role="img" 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><title></title><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">Figure 29: Conceptual model showing the problem with using the same setup for synthetic data generation and real-time API.</figcaption></figure></div><p>This infrastructure gap presents a significant opportunity for NeoCloud providers specializing in short-term, high-throughput compute rentals. Already today some providers, like <a href="https://www.primeintellect.ai/">Prime Intellect</a>, offer on-demand access to the cluster of up to 64 H100s (see Fig. 30). Such a setup would be capable of daily generating billions of synthetic tokens even for large models like DeepSeek.</p><p>Reasoning traces from such data runs could be used for a reinforcement-learning fine-tuning (RLFT) in a product similar to the one <a href="https://platform.openai.com/docs/guides/rft-use-cases">offered by OpenAI</a>. We believe that using RL to train models that directly maximize the business-specific rewards shows significant growth potential. Think of a virtual assistant helping people in making purchasing decisions, which is rewarded with actual dollar revenues, amplifying the actions that better convert into sales, or a virtual companion that promotes deeply engaging conversations, keeping users longer in the app. There undoubtedly is a huge economic incentive for businesses to apply such techniques, maximizing the revenues in a similar way as YouTube or TikTok already do with recommendation engines. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eLe4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eLe4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 424w, https://substackcdn.com/image/fetch/$s_!eLe4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 848w, https://substackcdn.com/image/fetch/$s_!eLe4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 1272w, https://substackcdn.com/image/fetch/$s_!eLe4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eLe4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png" width="1456" height="540" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:540,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:155559,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eLe4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 424w, https://substackcdn.com/image/fetch/$s_!eLe4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 848w, https://substackcdn.com/image/fetch/$s_!eLe4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.png 1272w, https://substackcdn.com/image/fetch/$s_!eLe4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0e0c6aeb-415e-4786-af91-0ed897708fc6_2409x893.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 role="img" 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><title></title><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">Figure 30: H100 multi-node cluster available at Prime Intellect. Cluster of InfiniBand connected nodes costs $2.49 &#215; 64 &#8776; $160/h or $160/h &#215; 24 = $3825/day. We estimate such cluster to be able to produce up to 30B synthetic tokens within a day.</figcaption></figure></div><p>Furthermore, to improve the inference economics, such RL models could be trained using <a href="https://arxiv.org/pdf/2403.10704">LoRA adapters</a> or a similar technique and served alongside <a href="https://arxiv.org/pdf/2311.03285">thousands of other models</a>, all catered to specific use cases. This multi-tenant serving approach represents a compelling business opportunity for inference providers. Clients hosting their custom LoRA adapters on a provider's infrastructure face significant switching costs when migrating to competitors, as the adapters are optimized for specific serving configurations and client workflows. RLFT is based on unique and nuanced rewards that are very client-specific; unlike standard supervised fine-tuning (SFT), it much much more challenging to replicate it just via in-context learning, making it an even more compelling case for inference providers. </p><p>We expect the inference markets to further specialize in regard to offered throughput, latency, and pricing. It is only natural for providers of super-fast tokens like Groq and Cerebras to command a much higher premium for the tokens they deliver at few-second latencies and for other providers like NeoCloud specializing in high-latency, high-throughput inference scenarios focused on synthetic data generation. We hope to elaborate on this space in the future text. </p><h1>From Tokens to Dollars - Estimating Tokenomics</h1><p>Now we can finally address the original question: <strong>What is a fair price per DeepSeek V3.1 token?</strong> As we hope you know after reading through this text, the answer is an unsatisfying <strong>it depends</strong>. </p><p>The price per token depends on two factors: how much our hardware costs, and how many tokens it can produce per unit of time. As shown in numbers from Perplexity (Fig. 5) and SGLang results (Fig. 24), there are significant benefits to the performance <strong>per GPU</strong> when more GPUs are deployed. Putting more GPUs into serving a large-scale MoE model will yield higher performance per GPU and, as a result, lower our costs and boost profits.</p><p>Moreover, since LLM inference is heavily memory-bound, the batch size at which we serve the model significantly affects the combined throughput across all requests. The larger the batch size we use, the more tokens we cumulatively produce, but this comes at the cost of increased latency for each individual user, as reflected by Tab. 3.</p><p>Furthermore, not all hardware is created equal. While B200s will offer superior compute GPU performance compared to H100s, they are significantly more expensive (see Tab. 3), making them likely a less optimal option when optimizing for cost efficiency and producing as many tokens as possible while minimizing costs</p><p>All in all, while we cannot provide an exact number, we hope this analysis provides valuable insights into the factors impacting token pricing. The theoretical performance model we provide, though not perfect, should offer solid intuitions about expected performance and the trade-offs between different hardware options. </p><h1>The missing tokens</h1><p>Finally, we want to address the elephant in the room: the problem of missing tokens in the global market. As of this writing, DeepSeek V3.1. remains the most popular open-source model on OpenRouter. While displayed daily consumption hovers around 30B tokens per day, upon closer inspection it becomes clear that the majority of these are input tokens, not output tokens. Daily global consumption of DeepSeek V3.1 <strong>output</strong> <strong>tokens</strong> on OpenRouter is approximately 1B tokens. A quick examination of our numbers in Table 3 reveals that with a fraction of a single NVL72, we could meet this demand 20 times over while maintaining a reasonable &gt;30 tokens per second per request.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qGj8!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qGj8!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 424w, https://substackcdn.com/image/fetch/$s_!qGj8!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 848w, https://substackcdn.com/image/fetch/$s_!qGj8!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 1272w, https://substackcdn.com/image/fetch/$s_!qGj8!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qGj8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png" width="1456" height="664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:664,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:83845,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc6f57f-a305-44c0-bd79-cb5b42c860dc_1456x664.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qGj8!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 424w, https://substackcdn.com/image/fetch/$s_!qGj8!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 848w, https://substackcdn.com/image/fetch/$s_!qGj8!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.png 1272w, https://substackcdn.com/image/fetch/$s_!qGj8!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb2d2895f-831b-48ac-9404-b4fd4cfbfcf5_1456x664.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 role="img" 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><title></title><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">Figure 31: Daily DeepSeekV3.1 token production on <a href="https://openrouter.ai/deepseek/deepseek-chat-v3.1/activity">OpenRouter</a>. 30.08.2025</figcaption></figure></div><p>This is a pretty significant gap. How is it possible that the global consumption of the most popular open-source model is so small that it could be met by a single NVL72 with 20 times the capacity to spare? Given this low demand, how can so many inference providers sustain their businesses? Put simply: <strong>who is making money here?</strong></p><p>One might argue that we only account for the decoded tokens and that the majority of income comes from the input tokens. We do this because, due to the <strong>caching mechanism</strong>, it is quite challenging to accurately estimate how big portion of input tokens cost can be captured by the inference providers. </p><p>To <a href="https://github.com/deepseek-ai/open-infra-index/blob/main/202502OpenSourceWeek/day_6_one_more_thing_deepseekV3R1_inference_system_overview.md">quote DeepSeek</a>: </p><blockquote><p>Within the 24-hour statistical period ... Total input tokens: 608B, of which 342B tokens <em>56.3%</em> hit the on-disk KV cache. </p></blockquote><p>Caching drastically reduces the cost of prefill, slashing times to first token, and enabling the inference provider to move nodes from doing prefill to only working on decode. For example, DeepSeek offers a <em>75%</em> discount (see Fig. 32).</p><p>Assuming that the DeepSeek caching numbers hold across the industry, this would put the daily total profit achieved via OpenRouter at:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\text{Input tokens} +  \\text{Output tokens} = \\text{Cached input} + \\text{Cache miss input} + \\text{Output tokens}\n\\end{equation}&quot;,&quot;id&quot;:&quot;AEWVJWWWMX&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{equation}\n    \\text{Daily Profit} =  (28 \\times 1000 \\times 0.56 \\times \\$0.07) + (28 \\times 1000 \\times 0.44 \\times \\$0.27) + (0.800 \\times 1000 \\times \\$1.1)\n\\end{equation}&quot;,&quot;id&quot;:&quot;SZDVVVIHVR&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Daily Profit} = \\$1,097.60 + \\$3,326.40 + \\$880.00 = \\$5,304.00&quot;,&quot;id&quot;:&quot;QNHMVJRSAY&quot;}" data-component-name="LatexBlockToDOM"></div><p>spread across all of the inference providers. Some providers don't offer caching, some offer cheaper pricing, and some offer more expensive pricing than DeepSeek so estimating the exact amount being spent daily is difficult, but we don't expect it to be much different than that. Which begs a question? <strong>Where is the demand for DeepSeek?</strong></p><p><strong>The first natural answer is that</strong> <strong>OpenRouter just captures only a small portion of the global demand for DeepSeek models.</strong> <strong>The question is, how small?</strong><br>Even had it been just <em>1%</em>, assuming that our estimations are accurate, it could easily be fulfilled by 3 to 4 NVL72s. One caveat of this calculation is that our numbers (based on the SGLang benchmark) assume a short input length of 2000 tokens, something that we try to account for in our theoretical model. If we increase the context length from 2k to 32k the KV cache footprint increases 16x, severely limiting the batch size at which we can operate, considerably altering our potential margin. </p><p>Overall we don't have an answer backed by precise data for the question <em>"where are the missing tokens?"</em>; In the numbers <a href="https://github.com/deepseek-ai/open-infra-index/blob/main/202502OpenSourceWeek/day_6_one_more_thing_deepseekV3R1_inference_system_overview.md#statistics-of-deepseeks-online-service">revealed by DeepSeek</a>, they claim to be processing <strong>168B output tokens a day</strong> (these numbers are from Feburary 2025, the current numbers are likely significantly higher).  This is orders of magnitude more than OpenRouter, a gap that we find quite surprising, but that would largely answer this question. <strong>Perhaps the vast majority (&gt;</strong><em><strong>99.9%</strong></em><strong>) of the global demand for the DeepSeek tokens is matched by calling the providers directly and not via services gathering multiple providers.</strong> </p><p>The only other provider that we were able to find to openly share their numbers is Chutes (see Fig. 33). At around 0.2B output tokens and much lower pricing (only 80&#162;/1M output tokens), they generate an estimated daily income of $160 from output tokens of DeepSeek V3.1<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a>. On top of that, they seem to generate significantly more income from input tokens, but this seems to be mostly due to lack of caching. With the emergence of easily accessible caching solutions, such as <a href="https://github.com/LMCache/LMCache">LMCache</a> and <a href="https://github.com/kvcache-ai/Mooncake">Mooncake</a>, it is something we expect to be solved in the coming months, with the resulting savings being passed onto consumers. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!e2Qw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!e2Qw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 424w, https://substackcdn.com/image/fetch/$s_!e2Qw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 848w, https://substackcdn.com/image/fetch/$s_!e2Qw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 1272w, https://substackcdn.com/image/fetch/$s_!e2Qw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!e2Qw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png" width="1456" height="689" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:689,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:148073,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!e2Qw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 424w, https://substackcdn.com/image/fetch/$s_!e2Qw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 848w, https://substackcdn.com/image/fetch/$s_!e2Qw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.png 1272w, https://substackcdn.com/image/fetch/$s_!e2Qw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff4d58ca0-0c61-4e94-a0b5-7182505c7b7e_1761x833.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 role="img" 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><title></title><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">Figure 32: DeepSeek API pricing, Caching offers substantial savings of (1.0-7/27)=~75%. Note that deepseek-chat and deepseek-reasoner are the same model - DeepSeek V3.1, just with the reasoning setting on or off. 30.08.2025</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9CiQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9CiQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 424w, https://substackcdn.com/image/fetch/$s_!9CiQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 848w, https://substackcdn.com/image/fetch/$s_!9CiQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 1272w, https://substackcdn.com/image/fetch/$s_!9CiQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9CiQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png" width="857" height="688" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:688,&quot;width&quot;:857,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:53702,&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://www.tensoreconomics.com/i/172205574?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9CiQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 424w, https://substackcdn.com/image/fetch/$s_!9CiQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 848w, https://substackcdn.com/image/fetch/$s_!9CiQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.png 1272w, https://substackcdn.com/image/fetch/$s_!9CiQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4f7ec2f-e30a-417c-9bfe-86e6696320de_857x688.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 role="img" 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><title></title><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">Figure 33: Daily DeepSeekV3.1 token production on chutes. 30.08.2025.</figcaption></figure></div><p>While talking to industry insiders, it was suggested to us that some leading inference providers, those that have raised nine-figure funding rounds, are processing trillions of tokens daily, but as of September 2025, there is no publicly available evidence supporting such claims. <strong>We find this dichotomy between <a href="https://abc.xyz/2025-q2-earnings-call">Google</a>, <a href="https://mp.weixin.qq.com/s/wjX8krPPjlzPyf1r4oSn0A">ByteDance</a>, or <a href="https://www.investing.com/news/transcripts/earnings-call-transcript-microsoft-reports-q4-2025-earnings-beat-stock-rises-93CH-4161549">MSFT</a> declaring that they are processing trillions of tokens daily and the minuscule numbers we see for open-source providers to be quite perplexing!</strong></p><h1>Acknowledgements</h1><p>Thanks to <a href="https://x.com/felix_red_panda/">@felix_red_panda</a> for giving it a read before the publication, and bouncing out the ideas </p><pre><code>@online{tensoreconomics2025llm,
  author = {Piotr Mazurek, Eric Schreiber},
  title = {MoE Inference Economics from First Principles },
  url = {https://www.tensoreconomics.com/p/moe-inference-economics-from-first},
  urldate = {2025-09-02},
  year = {2025},
  month = {September},
  publisher = {Substack}
}</code></pre><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>We elaborate on this in a later part of the text</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-2" href="#footnote-anchor-2" class="footnote-number" contenteditable="false" target="_self">2</a><div class="footnote-content"><p>See our <a href="https://www.tensoreconomics.com/p/llm-inference-economics-from-first">previous article</a> on for the detial of TP.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-3" href="#footnote-anchor-3" class="footnote-number" contenteditable="false" target="_self">3</a><div class="footnote-content"><p>While investigating this topic with industry insiders, we learned that due to extremely limited supply, securing NVL72 is close to impossible at the moment.</p></div></div><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-4" href="#footnote-anchor-4" class="footnote-number" contenteditable="false" target="_self">4</a><div class="footnote-content"><p>Please note that for some reason, DeepSeek R1 and V3 0324 remain much more popular on chutes, with a combined output token production of ~2B tokens a day as of of 30.08.2025. </p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[LLM Inference Economics from First Principles]]></title><description><![CDATA[The main product LLM companies offer these days is access to their models via an API, and the key question that will determine the profitability they can enjoy is the inference cost structure.]]></description><link>https://www.tensoreconomics.com/p/llm-inference-economics-from-first</link><guid isPermaLink="false">https://www.tensoreconomics.com/p/llm-inference-economics-from-first</guid><dc:creator><![CDATA[Piotr Mazurek]]></dc:creator><pubDate>Wed, 14 May 2025 18:00:32 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!NPca!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The main product LLM companies offer these days is access to their models via an API, and the key question that will determine the profitability they can enjoy is the inference cost structure. In this text we will explain where the cost of serving/hosting LLMs comes from, how many tokens can be produced by a GPU, and why this is the case. We will build a (simplified) world model of LLM inference arithmetics, based on the popular open-source model-LLama 3.3. The goal is to develop an accurate intuition regarding LLM inference.</p><p>The topic of LLM inference economics has far-reaching implications beyond technical considerations. As AI capabilities rapidly advance, inference efficiency directly shapes both industry economics and accessibility. For AI labs, token production costs fundamentally determine profit margins and the cost of generating synthetic training data-more efficient inference means higher returns on a fixed investment in hardware that can fuel further research and development cycles. For users, lower token costs democratize access to these powerful tools, potentially transforming AI from a premium resource into an everyday utility available for even routine tasks. Understanding these cost structures isn't merely academic-it provides insight into one of the key economic forces that will shape AI development in the coming years as we approach increasingly capable systems.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tensoreconomics.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Tensor Economics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div><p>The primary cost behind a generated token boils down to the cost of compute - you need to buy or rent a GPU. In both cases, there is a fixed cost associated with running a GPU per hour. Each GPU can produce a limited number of tokens in an hour. The number of tokens produced per hour divided by the cost of hardware per hour will tell you the unit cost of generating a single token. This is how most of the LLM providers price their API offerings, and this will be the model we will explore.</p><h2>Model parameters and hardware requirements</h2><p>As a basis for our inference economics analysis, we will use <a href="https://github.com/meta-llama/llama-models/blob/main/models/llama3_3/MODEL_CARD.md">LLama 3.3 70B</a>. Even today it is still one of the most popular open-source models and an architecture around which <a href="https://huggingface.co/models?other=llama">a big portion of the industry standardized</a>. There are numerous model fine-tunes of the Llama weights, and while these models will produce different outputs, because they share the same model architecture, they require exactly the same compute resources to run them. Hence, we consider Llama a good candidate to provide a real-world example that will be representative but, at the same time, quite simple to grasp.</p><p>LLMs store their "knowledge" in parameters-essentially the weights that define the model's behavior. These parameters require memory to store and compute resources to process. Generally, the more parameters a model has, the greater its resource demands, but so are its potential capability on downstream tasks. Llama 3.3 70B has around 70 billion parameters, which is where its name comes from.</p><p>A so-called decoder-only transformer model, like Llama, usually consists of the following components:</p><ul><li><p>one input embedding layer-converting tokens, or words, into vector representations.</p></li><li><p>multiple transformer layers, each layer containing some parameters for the self-attention part and some for the MLP part.</p></li><li><p>language modeling (LM) head-the final layer</p></li></ul><p>We assume the reader has a basic understanding of these concepts; hence, we will not be providing the deep intuitions behind them. If you are unfamiliar with the transformer architecture, please stop here and check out <a href="https://jalammar.github.io/illustrated-transformer/">one</a> <a href="https://www.youtube.com/watch?v=kCc8FmEb1nY&amp;t">of</a> <a href="https://youtu.be/wjZofJX0v4M">these</a> amazing tutorials.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oGp3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oGp3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 424w, https://substackcdn.com/image/fetch/$s_!oGp3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 848w, https://substackcdn.com/image/fetch/$s_!oGp3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 1272w, https://substackcdn.com/image/fetch/$s_!oGp3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oGp3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png" width="908" height="1214" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1214,&quot;width&quot;:908,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:182560,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oGp3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 424w, https://substackcdn.com/image/fetch/$s_!oGp3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 848w, https://substackcdn.com/image/fetch/$s_!oGp3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.png 1272w, https://substackcdn.com/image/fetch/$s_!oGp3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdc011052-55b9-4286-8c73-9a1995ec2af3_908x1214.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 role="img" 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><title></title><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">Fig. 1: <a href="https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct/blob/main/config.json">Config</a> of llama 3.3 that will be using throughput this text as a reference model. </figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!NPca!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!NPca!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 424w, https://substackcdn.com/image/fetch/$s_!NPca!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 848w, https://substackcdn.com/image/fetch/$s_!NPca!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 1272w, https://substackcdn.com/image/fetch/$s_!NPca!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!NPca!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png" width="1264" height="1560" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1560,&quot;width&quot;:1264,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:590102,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!NPca!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 424w, https://substackcdn.com/image/fetch/$s_!NPca!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 848w, https://substackcdn.com/image/fetch/$s_!NPca!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.png 1272w, https://substackcdn.com/image/fetch/$s_!NPca!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2e9fec9c-f62e-4dbd-ab93-85c10f0bbb34_1264x1560.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 role="img" 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><title></title><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">Fig. 2 Llama architecture; <a href="https://devopedia.org/images/article/483/6445.1717130942.jpg">source</a></figcaption></figure></div><p>Now, let's break down the model's parameter count step by step, verifying that the claimed 70 billion parameters hold up. To do so, let&#8217;s start by looking at the Llama model config in Fig. 1. We can see there are multiple keys and values. Keys, such as <code>hidden_size</code> informing us about the sizes of specific parts of the model. We can use them to calculate the total model size. To grasp the high-level overview of the architecture, take a look at Fig. 2. You can see all three parts we described above, and the graph also shows some implementation details that we will dive into in the next section.</p><p>For input embedding layer, we need to convert every possible token position into its vector representation. Hence we have:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Input Embedding} = \\text{hidden_size} \\times \\text{vocab_size}\n&quot;,&quot;id&quot;:&quot;DFNAJBQBOQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>parameters.</p><p>Then we have <code>N</code> transformer layers (see Fig. 2). Each of these layers has typically many millions parameters that we will need to store in memory in order to run the model. Their sizes can be calculated with hyper parameters from the <code>config.json</code> above: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_q} = \\text{hidden_size} \\times \\text{head_size} \\times \\text{num_attention_heads} = \\text{hidden_size} \\times \\text{hidden_size}\n\n&quot;,&quot;id&quot;:&quot;RZQOLSKYZH&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_k} = \\text{hidden_size} \\times \\text{head_size} \\times \\text{num_key_value_heads} = \\text{hidden_size} \\times \\frac{\\text{hidden_size}}{8} ^*&quot;,&quot;id&quot;:&quot;XKHZRDYTWW&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_v} = \\text{hidden_size} \\times \\text{head_size} \\times \\text{num_key_value_heads} = \\text{hidden_size} \\times \\frac{\\text{hidden_size}}{8} ^*&quot;,&quot;id&quot;:&quot;HDCGIOEDZD&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_o} = \\text{hidden_size} \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;QVONWWBXQV&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_1} = \\text{hidden_size} \\times \\text{intermediate_size} = \\text{hidden_size} \\times \\text{hidden_size} \\times 3.5^*&quot;,&quot;id&quot;:&quot;ENMHVRBWIO&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_2} = \\text{hidden_size} \\times \\text{intermediate_size} = \\text{hidden_size} \\times \\text{hidden_size} \\times 3.5^*&quot;,&quot;id&quot;:&quot;MDUCFSHPAY&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{w_3} = \\text{intermediate_size} \\times \\text{hidden_size} = 3.5^* \\times \\text{hidden_size} \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;UWHOBJVCFM&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{2 $\\times$ RMS norm} = 2 \\times \\text{hidden_size} \\text{ parameters}&quot;,&quot;id&quot;:&quot;BTJWHSVDUU&quot;}" data-component-name="LatexBlockToDOM"></div><p>*The <code>w_v</code> and <code>w_k</code> being 1/8th the size of the <code>w_q</code> is something Llama architecture specific. This is due to the Llama team using a technique called <a href="https://arxiv.org/pdf/2305.13245">Group Query Attention</a> in which the model has fewer K and V heads than the total attention heads. You can verify this by looking at <code>num_key_value_heads</code> in the hyperparameters from the model config. The model <code>intermediate_size</code> being <code>3.5x</code> the hidden size is as well a Llama architecture-specific value. These were chosen by the Llama team, and we take them at face value, also to simplify our calculations.</p><p>Bringing us to a total of</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total per transformer block} = {} &amp; \\text{hidden_size}^2 + \\frac{\\text{hidden_size}^2}{8} + \\frac{\\text{hidden_size}^2}{8} \\\\\n&amp; + 3.5 \\times \\text{hidden_size}^2 + 3.5 \\times \\text{hidden_size}^2 \\\\\n&amp; + 3.5 \\times \\text{hidden_size}^2 + \\text{hidden_size}^2 \\\\\n&amp; + 2 \\times \\text{hidden_size} \\\\\n&amp; = 12.75 \\times \\text{hidden_size}^2 + 2 \\times \\text{hidden_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;GOEJVKKZIM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>per transformer block.</p><p>Finally, we apply a last RMS Norm before feeding the representation into the LM head, which converts vectors into token logits.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{RMS Norm} = \\text{hidden_size}&quot;,&quot;id&quot;:&quot;BXTUKYEVEF&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{LM Head} = \\text{hidden_size} \\times \\text{vocab_size}&quot;,&quot;id&quot;:&quot;WGCSPMUKRG&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Summing up all of these parameters we obtain:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total parameters} = {} &amp; \\text{vocab_size} \\times \\text{hidden_size} \\\\\n&amp; + \\text{num_hidden_layers} \\times (12.75 \\times \\text{hidden_size}^2 + 2 \\times \\text{hidden_size}) \\\\\n&amp; + \\text{hidden_size} \\\\\n&amp; + \\text{hidden_size} \\times \\text{vocab_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;TCLKJJMXJX&quot;}" data-component-name="LatexBlockToDOM"></div><p>We can find the values of each of these, <code>vocab_size</code> , <code>hidden_size</code> , <code>num_hidden_layers</code> in the config in Fig. 1. Substituting these values into the equation we will get:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total parameters} = {} &amp; 128256 \\times 8192 \\\\\n&amp; + 80 \\times (12.75 \\times 8192^2 + 2 \\times 8192) \\\\\n&amp; + 8192 \\\\\n&amp; + 8192 \\times 128256 \\\\\n&amp; = 70,553,706,496\n\\end{aligned}&quot;,&quot;id&quot;:&quot;XNKPYVANWH&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Each parameter is a floating-point number in a bfloat16 format-e.g., 0.22312, -4.3131. Storing each of these numbers takes 16 bits which is 2 bytes of memory. Given that we have a total of <code>70,553,706,496</code> parameters to store, we will need <code>141,107,412,992</code> bytes or 141GB just to store the model weights in GPU memory.</p><p>Note that 141GB is more memory than there is on the most common data center GPUs, such as the Nvidia A100 or H100. Each of these GPUs comes with only 80GB of total memory (we refer to this memory interchangeably as HBM, high bandwidth memory, or global memory). Hence, for serving models, we usually use multiple cards for a single instance of a model. In practice, for more optimal model serving, we want to use more, 4 or even 8 such GPUs. Let&#8217;s now just take it at face value, and we will elaborate on why this is the case in the later part of this text.</p><h2>Compute and memory bound</h2><p>When looking at the specification of a GPU, you should be paying most attention to two metrics:</p><ul><li><p>Compute: measured in FLOPS - how many floating-point operations (addition and multiplication) a GPU can do in a second*.</p></li><li><p>Memory bandwidth: how many bytes can be loaded from the global memory in a second.</p></li></ul><p>These two factors dictate how quickly you can process computations; they affect the speed of a single feedforward operation and determine the generation speed (measured in tokens per second, tps) and ultimately define your cost per token.</p><p>* Please be aware that FLOPS and FLOPs mean different things. <strong>FLOPs</strong> (small s) is the plural of floating-point operations not considering time at all but <strong>FLOPS</strong> (capital S) means floating-point operations that happen within a second</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cSyk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cSyk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 424w, https://substackcdn.com/image/fetch/$s_!cSyk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 848w, https://substackcdn.com/image/fetch/$s_!cSyk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 1272w, https://substackcdn.com/image/fetch/$s_!cSyk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cSyk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png" width="1200" height="543" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:543,&quot;width&quot;:1200,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:76111,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cSyk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 424w, https://substackcdn.com/image/fetch/$s_!cSyk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 848w, https://substackcdn.com/image/fetch/$s_!cSyk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.png 1272w, https://substackcdn.com/image/fetch/$s_!cSyk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd414a3c4-1bcc-46e1-9a43-dc1e338673c5_1200x543.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 role="img" 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><title></title><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">Fig. 3: Compute and memory bandwidth A100 cards vs H100 cards; <a href="https://www.databricks.com/blog/coreweave-nvidia-h100-part-1">source</a></figcaption></figure></div><p>A computer program (such as running an LLM) can be characterized by its arithmetic intensity. Arithmetic intensity is a concept that describes the ratio of computational operations, such as addition or multiplication (measured in FLOPs), to memory accesses (measured in bytes). A higher arithmetic intensity indicates that the program performs more computations per unit of data fetched from memory, which typically leads to better utilization of the processor's computational capabilities and reduced bottlenecking on memory bandwidth. LLM inference has a very low compute intensity because it involves repeatedly accessing large model weights from memory with relatively few computations per byte fetched.</p><p>For A100:</p><ul><li><p>FLOPS: 3.12 * 10^14 floating point operations can be performed in a per second</p></li><li><p>Memory: 2.03 * 10^12 bytes can be loaded from global memory (HBM) per a second</p></li></ul><p>For H100:</p><ul><li><p>FLOPS: 9.89 * 10^14 floating point operations can be performed in a per second</p></li><li><p>Memory: 3.35 * 10^12 bytes can be loaded from global memory (HBM) per a second</p></li></ul><p>As you'll see in the next parts of this text, LLM inference has both a phase that's heavily compute-bound (very high arithmetic intensity) and a heavily memory-bound (very low arithmetic intensity). The majority of the wall clock time is spent in the memory-bound phase, so the goal of efficient LLM inference is to maximize the utilization of the GPUs' compute capacity during the memory-bound phase. So increasing the arithmetic intensity for the memory-bound phase represents a fundamental optimization target that directly translates to improved inference economics.</p><p>In the context of LLMs, in order to generate a token, we need to load the entire model with all parameters from global memory (HBM) (we utilize the memory bandwidth) and calculate the intermediate activations (we use the compute). The ratio between compute and memory utilization is crucial in determining what can be optimized and how to enjoy better inference economics. In the next part we will go more in depth on the two phases of LLM inference:</p><ul><li><p>prompt processing or so called pre-fill phase</p></li><li><p>token-by-token or so called decoding phase</p></li></ul><p>The end-to-end latency of an LLM request depends critically on the efficiency of both these two phases.</p><h2>FLOPs in matrix multiplication</h2><p>Before delving into the two phases, let's clarify how we count floating point operations (FLOPs) in matrix multiplication.</p><p>When multiplying matrices <code>A</code> (shape <code>m&#215;n</code>) and <code>B</code> (shape <code>n&#215;o</code>), we produce matrix <code>C = A @ B</code> (shape <code>m&#215;o</code>). The computation involves:</p><ul><li><p>Taking each row from <code>A</code> and each column from <code>B</code></p></li><li><p>Computing their dot product to fill each element of <code>C</code></p></li></ul><p>For a single dot product between vectors of length n:</p><ul><li><p>We perform <code>n</code> multiplications</p></li><li><p>Followed by <code>n-1</code> additions</p></li><li><p>Resulting in <code>n + n-1 = 2n-1</code> operations total</p></li></ul><p>Since we need to compute this for every element in our result matrix <code>C (m&#215;o elements)</code>:</p><ul><li><p>Total FLOPs =<code> (2n-1) &#215; m &#215; o &#8776; 2mno</code></p></li></ul><p>For simplicity in this post, we'll use <strong>2mno</strong> as our FLOP count for matrix multiplication.</p><h2>Prompt processing/prefill phase</h2><p>The first phase of generating text with LLMs is prompt processing. In this phase an LLM is presented with a list of input (prompt) tokens, and we try to predict our first new token. The duration of this phase is what the API providers present as &#8220;latency&#8221; or &#8220;time to first token" (TTFT) (See Fig. 4).</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!QIEX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!QIEX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 424w, https://substackcdn.com/image/fetch/$s_!QIEX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 848w, https://substackcdn.com/image/fetch/$s_!QIEX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 1272w, https://substackcdn.com/image/fetch/$s_!QIEX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!QIEX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png" width="1456" height="245" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:245,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:68083,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!QIEX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 424w, https://substackcdn.com/image/fetch/$s_!QIEX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 848w, https://substackcdn.com/image/fetch/$s_!QIEX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 1272w, https://substackcdn.com/image/fetch/$s_!QIEX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3353331e-6a9d-4f9b-b7f5-da675b437b6f_1568x264.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a><figcaption class="image-caption">Fig. 4: You can see how latency, or time to first token, is reported in <a href="https://openrouter.ai/deepseek/deepseek-r1">OpenRouter</a></figcaption></figure></div><p></p><p>This phase is heavily <strong>compute bound</strong>, which is good; we utilize most of the compute we have available on our GPU. Let&#8217;s estimate the FLOPs of a single forward pass to see why it is the case.</p><p>Let&#8217;s manually count the FLOPs in the model during processing <code>S</code> tokens. For reference, we include the diagram of the Llama architecture (see Fig. 2).</p><h2>Embedding Layer</h2><p><strong>FLOPs:</strong></p><ul><li><p><strong>Lookup operation:</strong> Embedding lookups involve retrieving vectors from the embedding matrix and are considered to have negligible FLOPs since they involve memory access rather than arithmetic computations.</p></li></ul><h2>Self-Attention (Per Layer)</h2><h3>RMS Norm</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iTSc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iTSc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 424w, https://substackcdn.com/image/fetch/$s_!iTSc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 848w, https://substackcdn.com/image/fetch/$s_!iTSc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 1272w, https://substackcdn.com/image/fetch/$s_!iTSc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iTSc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png" width="1266" height="416" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/db45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:416,&quot;width&quot;:1266,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:86992,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iTSc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 424w, https://substackcdn.com/image/fetch/$s_!iTSc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 848w, https://substackcdn.com/image/fetch/$s_!iTSc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.png 1272w, https://substackcdn.com/image/fetch/$s_!iTSc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdb45ac73-5599-4fb9-9073-8fcef344b113_1266x416.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 role="img" 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><title></title><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><h3><br></h3><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{RMSNorm}} = {} &amp; S \\times \\text{hidden_size} \\times 1 \\text{ (square)} \\\\\n&amp; + S \\times \\text{hidden_size} \\text{ (mean)} \\\\\n&amp; + S \\times 1 \\text{ (add epsilon)} \\\\\n&amp; + S \\times 1 \\text{ (sqrt)} \\\\\n&amp; + S \\times \\text{hidden_size} \\text{ (division)} \\\\\n&amp; + S \\times \\text{hidden_size} \\text{ (multiplication)}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;XWIWWHKLKC&quot;}" data-component-name="LatexBlockToDOM"></div><p>Simplifying the expression:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned} \\text{FLOPS}_{\\text{RMSNorm}} = S \\times \\text{hidden_size} \\times 4 + S \\times 2 \\ \\approx 4 \\times S \\times \\text{hidden_size} \\end{aligned}\n&quot;,&quot;id&quot;:&quot;VVCBUKRGKT&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h3>Query Projection</h3><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;NBPJOVDLSL&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Weight:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_Q \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;GFOMUPIAUY&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Query}} &amp;= 2 \\times S \\times \\text{hidden_size} \\times \\text{hidden_size}\\\\\n&amp;= 2 \\times S \\times \\text{hidden_size}^2\n\\end{aligned}&quot;,&quot;id&quot;:&quot;FLBNSCIBFN&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h3>Keys and Values Projections</h3><p><em>As we explained before, the 1/8th part is Llama architecture specific due to multi-query attention; see the "Model parameters and hardware requirements" paragraph</em></p><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;BKTLPLOFRD&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Key Weight:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_K \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{hidden_size}/8}&quot;,&quot;id&quot;:&quot;YUILETQINI&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Value Weight: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_V \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{hidden_size}/8}&quot;,&quot;id&quot;:&quot;HCMRHEXAWD&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Key+Value}} &amp;= 2 \\times 2 \\times S \\times \\text{hidden_size} \\times \\text{hidden_size}/8\\\\\n&amp;= \\frac{1}{2} \\times S \\times \\text{hidden_size}^2\n\\end{aligned}&quot;,&quot;id&quot;:&quot;WKYSDIDSXY&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h3>Rotary Positional Embedding (RoPE)</h3><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cUCx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cUCx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 424w, https://substackcdn.com/image/fetch/$s_!cUCx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 848w, https://substackcdn.com/image/fetch/$s_!cUCx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 1272w, https://substackcdn.com/image/fetch/$s_!cUCx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cUCx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png" width="1362" height="668" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:668,&quot;width&quot;:1362,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:146056,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cUCx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 424w, https://substackcdn.com/image/fetch/$s_!cUCx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 848w, https://substackcdn.com/image/fetch/$s_!cUCx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.png 1272w, https://substackcdn.com/image/fetch/$s_!cUCx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F32558b70-29dd-495f-8cd9-8862157c1692_1362x668.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 role="img" 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><title></title><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">Fig. 6: RoPE implementation</figcaption></figure></div><h4>Shapes: </h4><p>- Query: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{q} \\in \\mathbb{R}^{S \\times \\text{head_dim} \\times \\text{num_attention_heads}}&quot;,&quot;id&quot;:&quot;WFTFBPRFJW&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Key: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{k} \\in \\mathbb{R}^{S \\times \\text{head_dim} \\times \\text{num_attention_heads}}&quot;,&quot;id&quot;:&quot;MOELRAFUKD&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Cosine:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{cos} \\in \\mathbb{R}^{S \\times \\text{head_dim}}&quot;,&quot;id&quot;:&quot;HLLZITNHVC&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Sine: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{sin} \\in \\mathbb{R}^{S \\times \\text{head_dim}}&quot;,&quot;id&quot;:&quot;UWLMPBJOPV&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>For each element in <strong>q</strong> and <strong>k</strong>, the following operations are performed:</p><ul><li><p><strong>Multiplications</strong>: 2 per tensor</p><ul><li><p>Multiply <strong>q</strong> with <strong>cos</strong></p></li><li><p>Multiply the rotated version of <strong>q</strong> (<strong>rotate_half(q))</strong> with <strong>sin</strong></p></li></ul></li><li><p><strong>Additions</strong>: 1 per tensor</p><ul><li><p>Add the two results to get the embedded <strong>q</strong></p></li></ul></li></ul><p>Since these operations are performed on both <strong>q</strong> and <strong>k</strong>, the total per element is:</p><p><strong>Total operations per element</strong>: 3 FLOPs per tensor x 2 tensors = <strong>6 FLOPs</strong></p><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\n\\text{FLOPS}_{\\text{RoPE}} = S \\times \\text{head_dim} \\times \\text{num_attention_heads} \\times 6 \\\n= S \\times \\text{hidden_size} \\times 6\n\n\\end{aligned}&quot;,&quot;id&quot;:&quot;VHZRIIGCMU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h3>Q &#215; K^T</h3><p><em>We assume the naive attention implementation. In practice, with algorithms like flash attention, we calculate it iteratively to save memory.</em></p><h4>Shapes: </h4><p>- Query: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{Q} \\in \\mathbb{R}^{S \\times \\text{num_attention_heads} \\times \\text{head_dim}}&quot;,&quot;id&quot;:&quot;KHMLGGZIEL&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Key: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{K} \\in \\mathbb{R}^{S \\times \\text{num_attention_heads} \\times \\text{head_dim}}&quot;,&quot;id&quot;:&quot;YCVATLFADP&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Transposed Key (after appropriate reshaping and transposition):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{K}^T&quot;,&quot;id&quot;:&quot;AMUBKEJNXJ&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Result: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{QK}^T \\in \\mathbb{R}^{\\text{num_attention_heads} \\times S \\times S}&quot;,&quot;id&quot;:&quot;OQHRFNQULC&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><p>For each attention head:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS per head} = 2 \\times S \\times \\text{head_dim} \\times S = 2S^2 \\times \\text{head_dim}&quot;,&quot;id&quot;:&quot;QAOZFJJOHX&quot;}" data-component-name="LatexBlockToDOM"></div><p>For all attention heads:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS total} = 2S^2 \\times \\text{head_dim} \\times \\text{num_attention_heads} = 2S^2 \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;XFABHNSHKX&quot;}" data-component-name="LatexBlockToDOM"></div><p><em>Note: This quadratic dependence on sequence length (S^2) is why attention becomes expensive for long sequences.</em></p><h3>Softmax</h3><p><em>It is kind of hard to estimate the FLOPs for Softmax. We approximate softmax as 5 FLOPs per element:</em></p><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{A} \\in \\mathbb{R}^{S \\times S \\times \\text{num_attention_heads}}&quot;,&quot;id&quot;:&quot;DBBXDYHGUQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Output: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{A}_{\\text{softmax}} \\in \\mathbb{R}^{S \\times S \\times \\text{num_attention_heads}}&quot;,&quot;id&quot;:&quot;CSENKTZMSK&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS}_{\\text{softmax}} = 5 \\times S \\times S \\times \\text{num_attention_heads} = 5S^2 \\times \\text{num_attention_heads}&quot;,&quot;id&quot;:&quot;NKADMJTDDW&quot;}" data-component-name="LatexBlockToDOM"></div><p><em>This is a simplified approximation of the actual operations in softmax (exponentiation, sum, division).</em></p><h3>Attention Output (Q @ K^T) @ V </h3><h4>Shapes: </h4><p>- Attention Scores: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{A}_{\\text{softmax}} \\in \\mathbb{R}^{S \\times S \\times \\text{num_attention_heads}}&quot;,&quot;id&quot;:&quot;HPOTPYESDK&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Value Matrix:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{V} \\in \\mathbb{R}^{S \\times \\text{head_size} \\times \\text{num_attention_heads}}&quot;,&quot;id&quot;:&quot;YGURZDZFRN&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Output: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{O} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;UMFZGOELQS&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h4>FLOPS:</h4><p>For each head:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS}_{\\text{attn output per head}} = 2 \\times S \\times S \\times \\text{head_size} = 2S^2 \\times \\text{head_size}&quot;,&quot;id&quot;:&quot;YXIIXUCWKI&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>For all heads:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS}_{\\text{attn output total}} = 2S^2 \\times \\text{head_size} \\times \\text{num_attention_heads} = 2S^2 \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;LHUUZQKMUG&quot;}" data-component-name="LatexBlockToDOM"></div><h3>O-Projection</h3><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{O} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;LLKVWALVEP&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Weight Matrix: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_O \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;FBEOZTREGB&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Output: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{O}_{\\text{proj}} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;ZZKZTLMQAT&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{FLOPS}_{\\text{O-projection}} = 2 \\times S \\times \\text{hidden_size} \\times \\text{hidden_size} = 2S \\times \\text{hidden_size}^2&quot;,&quot;id&quot;:&quot;QTHKSGWWBV&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Total FLOPs for Self-Attention</h3><p><strong>RMS Norm:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;4S \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;NVUARZECKM&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Query projection:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2S \\times \\text{hidden_size}^2&quot;,&quot;id&quot;:&quot;FQHELLODAM&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Keys and values projections:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;0.5S \\times \\text{hidden_size}^2&quot;,&quot;id&quot;:&quot;GAQWTBOKDR&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Positional Embedding (RoPE):</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;6S \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;IZEEROVRPH&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Q @ K^T (across all heads):</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2S^2 \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;PKZRXZWVFT&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Softmax (across all heads):</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;5S^2 \\times \\text{num_attention_heads}&quot;,&quot;id&quot;:&quot;QZEKHMQIFX&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Attention Output (Q @ K^T) @ V:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2S^2 \\times \\text{hidden_size}&quot;,&quot;id&quot;:&quot;KMQFFGXRAF&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>O-Projection:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2S \\times \\text{hidden_size}^2&quot;,&quot;id&quot;:&quot;SBWAZEXWYG&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>Total FLOPs:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;10S \\times \\text{hidden_size} + 4.5S \\times \\text{hidden_size}^2 + 4S^2 \\times \\text{hidden_size} + 5S^2 \\times \\text{num_attention_heads}&quot;,&quot;id&quot;:&quot;LKLBSCNEAV&quot;}" data-component-name="LatexBlockToDOM"></div><h2>MLP (Per Layer)</h2><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r8XW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r8XW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 424w, https://substackcdn.com/image/fetch/$s_!r8XW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 848w, https://substackcdn.com/image/fetch/$s_!r8XW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 1272w, https://substackcdn.com/image/fetch/$s_!r8XW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r8XW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png" width="1456" height="489" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:489,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:106998,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r8XW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 424w, https://substackcdn.com/image/fetch/$s_!r8XW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 848w, https://substackcdn.com/image/fetch/$s_!r8XW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.png 1272w, https://substackcdn.com/image/fetch/$s_!r8XW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feb006c01-24cd-44ec-9043-325355d53bfb_1548x520.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 role="img" 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><title></title><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>Gate W1</h2><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;BOIJMKTHGY&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Weight:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_1 \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{intermediate_size}} &quot;,&quot;id&quot;:&quot;WAMNWSJYKW&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Where <em>intermediate_size = 3.5 x hidden_size</em> (Llama specific)</p><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Gate W1}} &amp;= 2 \\times S \\times \\text{hidden_size} \\times 3.5 \\times \\text{hidden_size}\\\\\n&amp;= 7S \\times \\text{hidden_size}^2\n\\end{aligned}&quot;,&quot;id&quot;:&quot;UQODGEERCE&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Up W2</h3><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X} \\in \\mathbb{R}^{S \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;MBSUQPBQGY&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Weight: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{W}_2 \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{intermediate_size}}&quot;,&quot;id&quot;:&quot;OTETOSMPPS&quot;}" data-component-name="LatexBlockToDOM"></div><p>  - Where <em>intermediate_size = 3.5 x hidden_size</em> (Llama specific)</p><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Up W2}} &amp;= 2 \\times S \\times \\text{hidden_size} \\times 3.5 \\times \\text{hidden_size}\\\\\n&amp;= 7S \\times \\text{hidden_size}^2\n\\end{aligned}&quot;,&quot;id&quot;:&quot;PIOLAJQXXW&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Swish/SiLU Activation</h3><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X}_{\\text{gate}} \\in \\mathbb{R}^{S \\times \\text{intermediate_size}}&quot;,&quot;id&quot;:&quot;BTKABKJADR&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Where <em>intermediate_size = 3.5 x hidden_size</em> (Llama specific)</p><h4>FLOPS:</h4><p><em>We approximate the activation function as 5 FLOPs per element</em></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Swish}} &amp;= 5 \\times S \\times \\text{intermediate_size}\\\\\n&amp;= 5S \\times 3.5 \\times \\text{hidden_size}\\\\\n&amp;= 17.5S \\times \\text{hidden_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;VTWYWPPQIH&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Element-wise Multiplication</h3><h4>Shapes: </h4><p>- First Input:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{SiLU}(\\mathbf{X}_{\\text{gate}}) \\in \\mathbb{R}^{S \\times \\text{intermediate_size}}&quot;,&quot;id&quot;:&quot;ZYIYTURSCM&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Second Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X}_{\\text{up}} \\in \\mathbb{R}^{S \\times \\text{intermediate_size}}&quot;,&quot;id&quot;:&quot;DFHLIGGMFH&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Where <em>intermediate_size = 3.5 x hidden_size</em> (Llama specific)</p><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Element-wise Mult}} &amp;= S \\times \\text{intermediate_size}\\\\\n&amp;= S \\times 3.5 \\times \\text{hidden_size}\\\\\n&amp;= 3.5S \\times \\text{hidden_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;SIUWYPPWAY&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Down W3</h3><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X}_{\\text{combined}} \\in \\mathbb{R}^{S \\times \\text{intermediate_size}}&quot;,&quot;id&quot;:&quot;VMMHSLKYNA&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Where <em>intermediate_size = 3.5 x hidden_size</em> (Llama specific)</p><p>- Weight: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_3 \\in \\mathbb{R}^{\\text{intermediate_size} \\times \\text{hidden_size}}&quot;,&quot;id&quot;:&quot;QXYPKNIETT&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{Down W3}} &amp;= 2 \\times S \\times \\text{intermediate_size} \\times \\text{hidden_size}\\\\\n&amp;= 2 \\times S \\times 3.5 \\times \\text{hidden_size} \\times \\text{hidden_size}\\\\\n&amp;= 7S \\times \\text{hidden_size}^2\n\\end{aligned}&quot;,&quot;id&quot;:&quot;DDSXVKQXLI&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><h3>Total FLOPS MLP</h3><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total FLOPS}_{\\text{MLP}} &amp;= \\text{FLOPS}_{\\text{Gate W1}} + \\text{FLOPS}_{\\text{Up W2}} \\\\\n&amp;\\quad + \\text{FLOPS}_{\\text{Swish}} + \\text{FLOPS}_{\\text{Element-wise Mult}} + \\text{FLOPS}_{\\text{Down W3}}\\\\\n&amp;= 7S \\times \\text{hidden_size}^2 + 7S \\times \\text{hidden_size}^2 \\\\\n&amp;\\quad + 17.5S \\times \\text{hidden_size} + 3.5S \\times \\text{hidden_size} + 7S \\times \\text{hidden_size}^2\\\\\n&amp;= 21S \\times \\text{hidden_size}^2 + 21S \\times \\text{hidden_size}\\\\\n&amp;\\approx 21S \\times \\text{hidden_size}^2\n\\end{aligned}&quot;,&quot;id&quot;:&quot;NMRQVUDCMJ&quot;}" data-component-name="LatexBlockToDOM"></div><h2>LM Head</h2><p><em>During the inference, we only care about the next token prediction for the last token in our sequence. All of the other "next tokens" we already know, as they are part of the input prompt.</em></p><h4>Shapes: </h4><p>- Input: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{X} \\in \\mathbb{R}^{1 \\times \\text{hidden_size}}\n&quot;,&quot;id&quot;:&quot;EDTCRHCYVF&quot;}" data-component-name="LatexBlockToDOM"></div><p>- Weight: </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot; \\mathbf{W}_{\\text{LM}} \\in \\mathbb{R}^{\\text{hidden_size} \\times \\text{vocab_size}}&quot;,&quot;id&quot;:&quot;HLWIOBITRP&quot;}" data-component-name="LatexBlockToDOM"></div><h4>FLOPS:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{FLOPS}_{\\text{LM Head}} &amp;= 2 \\times 1 \\times \\text{hidden_size} \\times \\text{vocab_size}\\\\\n&amp;= 2 \\times \\text{hidden_size} \\times \\text{vocab_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;PXQFMLBNWO&quot;}" data-component-name="LatexBlockToDOM"></div><h2>Total FLOPs in a Llama Model</h2><p>Total FLOPs in the Llama model is a product of the number of FLOPs per transformer block times the number of blocks, plus the FLOPs for the LM head.</p><h3>Transformer Block</h3><h4>Components</h4><p><strong>- Attention:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;10S \\times \\text{hidden_size} + 4.5S \\times \\text{hidden_size}^2 + 4S^2 \\times \\text{hidden_size} + 5S^2 \\times \\text{num_attention_heads}&quot;,&quot;id&quot;:&quot;RMIOQIMBLJ&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>- MLP:</strong> </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;21S \\times \\text{hidden_size}^2&quot;,&quot;id&quot;:&quot;AKDSYUDDLZ&quot;}" data-component-name="LatexBlockToDOM"></div><h4>Total Per Block</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;10S \\times \\text{hidden_size} + 25.5S \\times \\text{hidden_size}^2 + 4S^2 \\times \\text{hidden_size} + 5S^2 \\times \\text{num_attention_heads}&quot;,&quot;id&quot;:&quot;CODBZEWKYH&quot;}" data-component-name="LatexBlockToDOM"></div><h3>Total FLOPs Calculation</h3><h4>Formula</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total FLOPs} = {} &amp; \\text{num_hidden_layers} \\times \\\\\n&amp; (10S \\times \\text{hidden_size} + 25.5S \\times \\text{hidden_size}^2 \\\\\n&amp; + 4S^2 \\times \\text{hidden_size} + 5S^2 \\times \\text{num_attention_heads}) \\\\\n&amp; + 2 \\times \\text{hidden_size} \\times \\text{vocab_size}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;RXBAJPYPRE&quot;}" data-component-name="LatexBlockToDOM"></div><h4>Example: Llama 3.3 70B</h4><p>For Llama 3.3 70B with:</p><ul><li><p>hidden_size = 8192</p></li><li><p>vocab_size = 128256</p></li><li><p>attention_heads = 64</p></li><li><p>num_hidden_layers = 80</p></li><li><p>S = 2048</p></li></ul><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Total FLOPs} = {} &amp; 80 \\times (10 \\times 2048 \\times 8192 + 25.5 \\times 2048 \\times 8192^2 \\\\\n&amp; + 4 \\times 2048^2 \\times 8192 + 5 \\times 2048^2 \\times 64) \\\\\n&amp; + 2 \\times 8192 \\times 128256 \\\\\n&amp; = 80 \\times 3.6436 \\times 10^{12} + 2.1013 \\times 10^9 \\\\\n&amp; = 2.9149 \\times 10^{14} + 2.1013 \\times 10^9 \\\\\n&amp; \\approx 2.9149 \\times 10^{14} \\\\\n&amp; = 291.49 \\times 10^{12} \\\\\n&amp; = 291.49 \\text{ TFLOPs}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;PSDQJUZAJU&quot;}" data-component-name="LatexBlockToDOM"></div><p><strong>291 TFLOPs</strong> is roughly the order of magnitude of FLOPs available in a modern GPU. For example, with H100 cards (see TFLOPS in Fig. 3), it would theoretically take roughly <code>291/989 = 0.29s</code> to process a prompt of 2048 tokens.</p><p>As a reminder, to load the model from global memory, we need to load <code>141 GB</code> worth of parameters. The memory bandwidth of a modern GPU is around <code>3350 GB/s</code>, meaning that in theory it will take <code>141/3350 = 0.04s</code> to load the entire model from global memory - roughly 7x faster than the time needed for all of the computations.</p><p>This demonstrates that in the pre-fill phase we are much more bound by the available compute than by the memory bandwidth. This is a desirable situation, as we want to utilize all of the existing compute resources.</p><h2>The decode phase</h2><p>This first forward pass for doing the prefill is computationally very expensive. We can eliminate doing large parts of that computation over and over again by introducing a special cache. This cache is called KV cache because it stores the key and value matrices for each token position.</p><p>In the attention mechanism, we calculate attention relationships between all tokens in the sequence. The key insight is that at step <code>S+1</code>, we've already calculated the attention between all of the first <code>S</code> tokens during the pre-fill phase. We can store these intermediate values in memory (the "cache") and only calculate new attention values involving the most recently generated token.</p><p>This optimization works elegantly with matrix operations:</p><h4>During Pre-fill (S tokens):</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\mathbf{Q} &amp;\\in \\mathbb{R}^{S \\times \\text{hidden_size}} \\\\\n\\mathbf{K}^T &amp;\\in \\mathbb{R}^{\\text{hidden_size} \\times S} \\\\\n\\mathbf{V} &amp;\\in \\mathbb{R}^{S \\times \\text{hidden_size}} \\\\\n\\end{align}&quot;,&quot;id&quot;:&quot;YTFBCTFWBX&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where <strong>d</strong> is the hidden dimension.</p><h4>The attention scores and outputs are computed as:</h4><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\text{Score Matrix} &amp;= \\mathbf{Q} \\cdot \\mathbf{K}^T \\in \\mathbb{R}^{S \\times S} \\\\\n\\text{Attention Output} &amp;= \\text{softmax}(\\text{Score Matrix}) \\cdot \\mathbf{V} \\in \\mathbb{R}^{S \\times d}\n\\end{align}&quot;,&quot;id&quot;:&quot;NNXDNTOJOY&quot;}" data-component-name="LatexBlockToDOM"></div><h4>During Token-by-Token Generation (token S+1):</h4><p>For generating the next token, we only need to compute:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\mathbf{Q}_{new} &amp;\\in \\mathbb{R}^{1 \\times \\text{hidden_size}} \\text{ [Only for the new token]} \\\\\n\\mathbf{K}^T_{cache} &amp;\\in \\mathbb{R}^{\\text{hidden_size} \\times S} \\text{ [From cache]} \\\\\n\\mathbf{K}^T_{new} &amp;\\in \\mathbb{R}^{\\text{hidden_size} \\times 1} \\text{ [For the new token]} \\\\\n\\mathbf{K}^T_{full} &amp;= [\\mathbf{K}^T_{cache} \\; | \\; \\mathbf{K}^T_{new}] \\in \\mathbb{R}^{\\text{hidden_size} \\times (S+1)} \\\\\n\\mathbf{V}_{cache} &amp;\\in \\mathbb{R}^{S \\times \\text{hidden_size}} \\text{ [From cache]} \\\\\n\\mathbf{V}_{new} &amp;\\in \\mathbb{R}^{1 \\times \\text{hidden_size}} \\text{ [For the new token]} \\\\\n\\mathbf{V}_{full} &amp;= [\\mathbf{V}_{cache} \\\\ \\mathbf{V}_{new}] \\in \\mathbb{R}^{(S+1) \\times \\text{hidden_size}}\n\\end{align}&quot;,&quot;id&quot;:&quot;GUBPQNOIAZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>The new attention calculation becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{align}\n\\text{Score Vector} &amp;= \\mathbf{Q}_{new} \\cdot \\mathbf{K}^T_{full} \\in \\mathbb{R}^{1 \\times (S+1)} \\\\\n\\text{Attention Output} &amp;= \\text{softmax}(\\text{Score Vector}) \\cdot \\mathbf{V}_{full} \\in \\mathbb{R}^{1 \\times \\text{hidden_size}}\n\\end{align}&quot;,&quot;id&quot;:&quot;IJYFJIQXOS&quot;}" data-component-name="LatexBlockToDOM"></div><p>The key efficiency gain comes from:</p><p>1. Reusing <em>K^T_cache</em> and <em>V_cache</em> from previous calculations</p><p>2. Only computing new key-value projections for the latest token</p><p>3. Reducing the attention calculation from <em>O(S^2)</em> to <em>O(S)</em> for each new token</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Oqzd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Oqzd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 424w, https://substackcdn.com/image/fetch/$s_!Oqzd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 848w, https://substackcdn.com/image/fetch/$s_!Oqzd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 1272w, https://substackcdn.com/image/fetch/$s_!Oqzd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Oqzd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png" width="1212" height="564" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:564,&quot;width&quot;:1212,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:181124,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Oqzd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 424w, https://substackcdn.com/image/fetch/$s_!Oqzd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 848w, https://substackcdn.com/image/fetch/$s_!Oqzd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.png 1272w, https://substackcdn.com/image/fetch/$s_!Oqzd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbbc54a6c-b50d-4e1e-99a2-4c5ceeb681fb_1212x564.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 role="img" 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><title></title><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">Fig. 8: We need only to calculate the query, key, and a value for the new token.</figcaption></figure></div><p>KV caching reduces the total FLOPs by a factor of approximately S for all parts of the forward pass:</p><ul><li><p>In self-attention, we only compute attention for the new token against all previous tokens</p></li><li><p>In the MLP and LM head components, we only process the new token</p></li><li><p>The LM head remains the same, but it is such a small fraction of the overall computations that we will skip it in our calculations.</p></li></ul><p>For example, with a 2048-token context:</p><ul><li><p>During pre-fill: ~291 TFLOPs total</p></li><li><p>For generating token 2049: <em>~291/2048 &#8776; 0.14</em> TFLOPs</p></li></ul><p>On an H100 GPU (989 TFLOP/s), this would take only:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{0.14 \\text{ TFLOP}}{989 \\text{ TFLOP/s}} \\approx 0.00014 \\text{ seconds}&quot;,&quot;id&quot;:&quot;DVCOXLVVKE&quot;}" data-component-name="LatexBlockToDOM"></div><p>This is approximately <code>2048</code> times faster than the pre-fill phase in terms of pure computation, but remember that we still need to load the entire model parameters (<code>141 GB)</code> from the global memory, and that now we need to also load the KV cache.</p><p>KV cache memory footprint can be easily calculated as</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;kv \\ cache = 2 \\times \\text{bytes_per_param} \\times \\text{num_hidden_layers} \\times \\text{head_size} \\times \\text{num_key_value_heads} \\times \\text{sequence_length}&quot;,&quot;id&quot;:&quot;FUDGCPHOQM&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>For Llama 3.3 70B with 2048 tokens using BF16 precision, this amounts to:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;kv \\ cache = 2 \\times 2 \\times 80 \\times 128 \\times 8 \\times 2048 = 671\\text{ MB}&quot;,&quot;id&quot;:&quot;BZQIVTMRPF&quot;}" data-component-name="LatexBlockToDOM"></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!05zN!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!05zN!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 424w, https://substackcdn.com/image/fetch/$s_!05zN!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 848w, https://substackcdn.com/image/fetch/$s_!05zN!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 1272w, https://substackcdn.com/image/fetch/$s_!05zN!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!05zN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png" width="668" height="431" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:431,&quot;width&quot;:668,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:43327,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!05zN!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 424w, https://substackcdn.com/image/fetch/$s_!05zN!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 848w, https://substackcdn.com/image/fetch/$s_!05zN!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.png 1272w, https://substackcdn.com/image/fetch/$s_!05zN!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F10cdbe00-5118-484d-81d5-dbb2dc15dd02_668x431.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 role="img" 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><title></title><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">Fig. 9: How the memory footprint of KV cache increases with sequence length for Llama 3.3 70B. Note that the x-axis uses a logarithmic scale (powers of 2), which visually compresses the exponential growth. In reality, the memory usage is growing superlinearly with sequence length, not linearly as might be incorrectly inferred from the graph's appearance.</figcaption></figure></div><p>While 671 MB may sound not that significant, this number scales linearly with the batch size (we elaborate on batches later) and with the sequence length (see Fig. 9). This is also the main reason why, at longer sequence lengths, the token-by-token generation* is slower than at shorter sequence lengths-on top of the model weights, the KV cache also needs to be loaded from global memory, increasing processing time for each token produced.</p><p>Model weights, plus KV cache, are roughly <code>141 + 0.6 &#8776; 142GB</code> so it takes <code>142/3350 = 0.04s</code> to load them from the global memory. We calculated above that it only takes <code>0.00014s</code> to do all computations (assuming 100% compute utilization) - so it takes two orders of magnitude more time to load the model weights than to do the actual computations. This is what we mean by the token-by-token phase of using LLMs being memory bound. We are primarily limited by the time memory transfer takes, not by the speed of compute.</p><p><strong>This is one of the insights we hope you take out of reading this article - the token-by-token phase is memory bound; the amount of available compute throughput is of secondary importance, as we massively underutilize the compute resources anyway while waiting for weights to be loaded.</strong></p><p>* we use the terms token-by-token phase, decode phase and generation phase interchangeably</p><h2>Scaling with the input length</h2><p>One of the main challenges in LLM serving is understanding how input prompt length affects end-to-end performance. Sequence length impacts both the prefill stage and the token-by-token decoding phase, though in fundamentally different ways.</p><p>The prompt processing phase exhibits <em>O(N^2)</em> computational complexity; as the sequence length grows, the processing time will grow quadratically*. We derived the FLOPs before as</p><ul><li><p><code>2 S&#178; hidden_size</code> for score matrix <code>Q @ K&#7511;</code></p></li><li><p><code>2 S&#178; hidden_size</code> for <code>(Q @ K&#7511;) @ V</code>.</p></li></ul><p>This is especially relevant for longer sequence lengths, where the time to the first token will quadratically increase with the length of the input sequence. You can experience this, e.g., when using the long-context Gemini that, as of May 2025, can take up to 2M tokens, but you can wait up to 2 minutes for the first token of the answer to be generated. The intuition you should have developed here is that as the input length keeps increasing, a larger and larger percentage of the total time of processing a request will be spent in prompt processing - the compute-bound part (see Fig. 10).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!TWjt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!TWjt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 424w, https://substackcdn.com/image/fetch/$s_!TWjt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 848w, https://substackcdn.com/image/fetch/$s_!TWjt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 1272w, https://substackcdn.com/image/fetch/$s_!TWjt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!TWjt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png" width="623" height="493" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:493,&quot;width&quot;:623,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:34908,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!TWjt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 424w, https://substackcdn.com/image/fetch/$s_!TWjt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 848w, https://substackcdn.com/image/fetch/$s_!TWjt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.png 1272w, https://substackcdn.com/image/fetch/$s_!TWjt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F79643180-3063-49f0-b2b5-f5ca89f6ec5c_623x493.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 role="img" 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><title></title><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">Fig. 10: As the prompt length increases, the compute required, and hence the time, increases quadratically, occupying an ever-increasing portion of the total processing time of a request. Please note: this is just a visualization to give you some intuitions; it is not actually based on real-world observations.</figcaption></figure></div><p>During the token-by-token phase, the relationship between the generation speed and the sequence length is less straightforward.</p><p>FLOP-wise compute is scaling linearly; the new token needs to attend to all of the tokens from the past, or <code>2 S hidden_size</code> for <code>Q @ K&#7511;</code> and <code>2 S hidden_size</code> for <code>(Q @ K&#7511;) @ V</code>, but as we already know, FLOPs are not that relevant for the token-by-token case because we are primarily memory bound. What is much more relevant is the size of the data that we need to load from the global memory.</p><p>As a reminder, for each forward pass, we need to load the entire model weights from the global memory; on top of this, we also need to load the KV cache from global memory. As we showed in the section above, as we increase the KV cached sequence length, it will occupy linearly more and more memory or by factor <code>S</code> in <code>2 x bytes_per_param x num_hidden_layers x head_size x num_key_value_heads x S.</code></p><p>Initially the size of the KV cache will be negligible compared to the model size that we need to load, but as we increase the size of the processed prompt, it will occupy an increasingly big portion of the memory (see Fig. 11). Note that if we decide to process larger batches (we discuss this in detail in a later section), the size of the KV cache will grow linearly w.r.t. batch size, as we need to cache the keys and values independently for all examples from the batch. Then at some point the size of the KV cache will overtake the size of the model itself.</p><p>The intuition to develop here is that for small batches and short sequences, the sequence length has minimal impact on throughput because loading model weights dominates the memory bandwidth utilization. However, as either batch size or sequence length increases, loading the KV cache takes an amount of time to load for each token, eventually surpassing the time consumed by loading of the model weights themselves.</p><p>This transition creates two distinct performance regimes: in the so-called model-dominated regime (short sequences/small batches), throughput remains relatively stable despite increasing sequence length. Once we enter the KV-cache-dominated regime, generation speed begins to degrade in proportion to sequence length. This is largely irrelevant for short sequence lengths but is a significant issue at very long sequence lengths (in the order of tens of thousands of tokens). The additional time loading the KV cache takes scales linearly w.r.t. sequence length.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ugJU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ugJU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 424w, https://substackcdn.com/image/fetch/$s_!ugJU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 848w, https://substackcdn.com/image/fetch/$s_!ugJU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 1272w, https://substackcdn.com/image/fetch/$s_!ugJU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ugJU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png" width="785" height="507" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/42566a64-5f28-4cea-bcb2-521025b48693_785x507.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:507,&quot;width&quot;:785,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:47018,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ugJU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 424w, https://substackcdn.com/image/fetch/$s_!ugJU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 848w, https://substackcdn.com/image/fetch/$s_!ugJU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.png 1272w, https://substackcdn.com/image/fetch/$s_!ugJU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F42566a64-5f28-4cea-bcb2-521025b48693_785x507.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 role="img" 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><title></title><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">Fig. 11: KV cache scaling with the increasing sequence length. At 128k tokens for Llama 3.3 70B, the KV cache for a single sentence will amount to 40GB.</figcaption></figure></div><p>*In the naive implementations of the attention mechanism memory would also scale quadratically when we realize the <code>SxS</code> score matrix, but <a href="https://github.com/Dao-AILab/flash-attention">flash attention</a> replaces these naive implementations. Flash attention is calculating <code>(Q @ K&#7511;) @ V</code> in an iterative way, where memory required is kept at <code>O(N)</code>.</p><h2>Multi GPU inference</h2><p>As you might have noted, the 141 GB we need to store the Llama 3.3 70B parameters is more than what we have available on a single Nvidia H100 GPU. H100 cards come with 80GB of HBM memory. We would need a minimum of two to store the model in memory; however, in practice, we would probably like to use more for the KV cache. If we have more memory available, we will be able to allocate a higher proportion of it to the KV cache and a smaller proportion to the model weights, allowing us to run larger batches. We would also linearly increase the available memory bandwidth, at the cost of an increased overhead in cross-GPU communication, though.</p><p>Using just two GPUs for Llama 3.3 70B would result in only having a tiny amount of memory available for KV cache because the model weights already take up 88% (<code>141/160=88%</code>) of that memory, leaving only 19GB of memory (<code>160-141=19GB</code>) available for KV cache (in practice even less than that because we can't use 100% of GPU memory but are limited to around 95%). We wouldn&#8217;t be able to run large batches nor long sequence lengths; this would be very inefficient. We touch on this in a later section, but being able to run larger batches is the key to enjoying the good inference economics.</p><p>GPU servers almost always come in deployments of 4 or 8 GPUs per node, so using 3 GPUs would be wasteful because that would lead to one GPU in the server being entirely unused in a lot of circumstances. Hence, we jump from 2 to 4 GPUs for a single model instance right away.</p><p>Let&#8217;s assume then we will run the Llama 3.3 70B on 4 H100 cards. There are two main ways to run large-scale AI models on multiple GPUs:</p><ul><li><p>Pipeline parallel</p></li><li><p>Tensor parallel</p></li></ul><p>Both offer different tradeoffs between throughput and latency. Let&#8217;s explore them briefly.</p><h2>Pipeline parallelism</h2><p>In the pipeline parallel (PP) setting, we split the model along the layers axis, meaning that each GPU will have a fraction of all layers in the model. E.g., in the case of Llama 3.3 70B with 80 hidden layers served on 4 GPUs, GPU:0 will host the first 20 layers, GPU:1 the next 20, and so on.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!lC_L!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!lC_L!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 424w, https://substackcdn.com/image/fetch/$s_!lC_L!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 848w, https://substackcdn.com/image/fetch/$s_!lC_L!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 1272w, https://substackcdn.com/image/fetch/$s_!lC_L!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!lC_L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png" width="864" height="372" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/eaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:372,&quot;width&quot;:864,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:85135,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!lC_L!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 424w, https://substackcdn.com/image/fetch/$s_!lC_L!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 848w, https://substackcdn.com/image/fetch/$s_!lC_L!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.png 1272w, https://substackcdn.com/image/fetch/$s_!lC_L!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Feaf845b6-1210-48ba-92c0-8b62b5e856c5_864x372.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 role="img" 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><title></title><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">Fig. 12: Pipeline parallelism with continuous batching visualization; <a href="https://docs.graphcore.ai/projects/tf-model-parallelism/en/latest/pipelining.html">source</a></figcaption></figure></div><p>The upside of such an approach is the very limited communications between the devices. We only need to broadcast activations from one device to the next one 3 times for a single forward pass.</p><p>We can also do pipelining - GPU:0 processes batch 0 and is passing it to GPU:1, then batch 1 is coming in, and GPU:0 can process batch 1 while GPU:1 is processing batch 0, etc. (see Fig. 12). This setting minimizes the stall time of each device, ensuring the maximum throughput; however, it comes at a price - at a single point in time, we only have access to 1/4 of the available compute and memory bandwidth per batch. So generation time is significantly slower than if we were to use all 4 GPUs at the same time.</p><p>In practice, orchestrating efficient overlapping batching can be quite challenging; hence, for the remaining part of this text, we will focus on analyzing the far more common tensor parallel setting.</p><h2>Tensor parallelism</h2><p>The mainstream parallelism strategy, used by a vast majority of LLM inference providers, is tensor parallelism (TP). In TP, individual neural network layers are split across multiple GPUs, harnessing the combined compute power and memory bandwidth of all devices. This approach significantly shortens per-layer inference time but introduces important trade-offs that must be carefully considered:</p><ol><li><p><strong>Communication Overhead</strong>: In regular intervals, e.g., twice per transformer block, the execution must synchronize across GPUs, introducing a significant delay (in the order of milliseconds) per synchronization event. This overhead varies significantly based on interconnect technology (NVLink, PCIe, etc.) and network topology.</p></li><li><p><strong>Sequential Batch Processing</strong>: Unlike pipeline parallelism, TP requires all GPUs to process the same batch simultaneously. A new batch cannot begin until the current one completes, reducing throughput efficiency under dynamic workloads.</p></li></ol><p>The most efficient parallelization strategy is to have a so-called column-wise split linear layer (we split by the column dimension) followed by the row-wise layer (split across the row dimension). Such a layout minimizes the synchronization to only one sync every two MLP layers.</p><p><strong>Mathematical Intuition:</strong></p><p>For a weight matrix <code>W&#8321;</code> split column-wise across 2 GPUs:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_1 = [\\mathbf{W}_{1,1} \\quad \\mathbf{W}_{1,2}], \\quad \\mathbf{W}_{1,i} \\in \\mathbb{R}^{d_{\\text{in}} \\times \\frac{d_{\\text{hid}}}{2}}&quot;,&quot;id&quot;:&quot;IKGKUMNZFI&quot;}" data-component-name="LatexBlockToDOM"></div><p>Each GPU computes its partial output independently (no communication):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{h}_1 = \\mathbf{x} \\mathbf{W}_{1,1}, \\quad \\mathbf{h}_2 = \\mathbf{x} \\mathbf{W}_{1,2}&quot;,&quot;id&quot;:&quot;OAFBYOTYTU&quot;}" data-component-name="LatexBlockToDOM"></div><p>The hidden layer activation becomes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{h} = [\\mathbf{h}_1 \\quad \\mathbf{h}_2]&quot;,&quot;id&quot;:&quot;NDIEZQCZAY&quot;}" data-component-name="LatexBlockToDOM"></div><p>No communication is needed here because each GPU has all the necessary</p><p>data. For the subsequent row-wise split in <code>W&#8322;</code>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{W}_2 = [\\mathbf{W}_{2,1} \\quad \\mathbf{W}_{2,2}], \\quad \\mathbf{W}_{2,i} \\in \\mathbb{R}^{\\frac{d_{\\text{hid}}}{2} \\times d_{\\text{out}}}&quot;,&quot;id&quot;:&quot;YWFTHVLOYV&quot;}" data-component-name="LatexBlockToDOM"></div><p>Each GPU computes:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{y}_1 = \\mathbf{h}_1 \\mathbf{W}_{2,1}, \\quad \\mathbf{y}_2 = \\mathbf{h}_2 \\mathbf{W}_{2,2}&quot;,&quot;id&quot;:&quot;XIGDDJKDPN&quot;}" data-component-name="LatexBlockToDOM"></div><p>The final output requires an all-reduce sum; in other words, we need to synchronize between the devices:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathbf{y} = \\mathbf{y}_1 + \\mathbf{y}_2&quot;,&quot;id&quot;:&quot;JTYQDWOWGV&quot;}" data-component-name="LatexBlockToDOM"></div><p>This layout we can apply to the transformer block, reducing it to only two synchronizations per transformer block (see Fig. 13 and Fig. 14).</p><ul><li><p>Self-Attention: Heads are processed independently, with synchronization only during the output projection (<code>o_proj</code>).</p></li><li><p>MLP: The up-projection (<code>w1,</code> <code>w3)</code> is split column-wise and the down-projection (<code>w2)</code> is split row-wise, and the sync is only executed after the down-projection.</p></li></ul><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oHjx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oHjx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 424w, https://substackcdn.com/image/fetch/$s_!oHjx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 848w, https://substackcdn.com/image/fetch/$s_!oHjx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 1272w, https://substackcdn.com/image/fetch/$s_!oHjx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oHjx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png" width="1312" height="890" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:890,&quot;width&quot;:1312,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:185902,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oHjx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 424w, https://substackcdn.com/image/fetch/$s_!oHjx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 848w, https://substackcdn.com/image/fetch/$s_!oHjx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.png 1272w, https://substackcdn.com/image/fetch/$s_!oHjx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff1eb2b81-a0a6-43b6-a128-c69f7945abf5_1312x890.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 role="img" 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><title></title><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">Fig. 13: The Colwise &#8594; Rowwise layout for a transformer layer from that is used as an example in torch documentation; <a href="https://pytorch.org/tutorials/intermediate/TP_tutorial.html">source</a></figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Bzez!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Bzez!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 424w, https://substackcdn.com/image/fetch/$s_!Bzez!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 848w, https://substackcdn.com/image/fetch/$s_!Bzez!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 1272w, https://substackcdn.com/image/fetch/$s_!Bzez!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Bzez!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png" width="1456" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:764884,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Bzez!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 424w, https://substackcdn.com/image/fetch/$s_!Bzez!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 848w, https://substackcdn.com/image/fetch/$s_!Bzez!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.png 1272w, https://substackcdn.com/image/fetch/$s_!Bzez!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd12796a4-5526-4633-bcb0-ce47b3229c60_1980x574.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 role="img" 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><title></title><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">Fig. 14: The Colwise &#8594; Rowwise split we see in a transformer block.</figcaption></figure></div><p>Correctly estimating the extra overhead from the coms is quite complicated. In theory, we would need to take into account the two following factors:</p><ol><li><p><strong>Message passing latency:</strong> Typically 3-5 &#956;s depending on hardware</p></li><li><p><strong>Data transfer time:</strong> Based on interconnect bandwidth</p></li></ol><p>In an ideal scenario with modern NVLink connections, we could estimate:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{aligned}\n\\text{Overhead} &amp;\\approx \\frac{\\text{params} \\times \\text{comms/layer} \\times \\text{hidden size} \\times \\text{number of layers} \\times (N-1)/N}{\\text{bandwidth}} \\\\\n&amp;= \\frac{2 \\times 2 \\times 8192 \\times 80 \\times 3/4}{450 \\times 10^9} \\\\\n&amp;\\approx 4\\ \\mu\\text{s}\n\\end{aligned}&quot;,&quot;id&quot;:&quot;YSLUPDXHHO&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>The total overhead of 8 or 9 &#181;s would be awesome. However, in practice, it gets much more complicated. During the sync barrier, the compute graph is stalled. We have a constant overhead of a few ms when the GPUs are idling while waiting for the sync to be finished. This extra "tax" is of the main reasons preventing us from utilizing the full memory bandwidth we have available across all the GPUs. Accurately modeling the overhead is quite challenging. As we'll demonstrate in the next sections, the gap between theoretical and actual performance can be quite substantial, requiring empirical measurement for accurate system modeling.</p><h2>Batching - the key to good economics</h2><p>As we showed before, during the token-by-token phase, we are primarily memory bound-meaning the main limitation in terms of tokens/s we can get is how fast our GPU is able to load the model weights from the global memory. To generate every single token, we always need to load the entire model.</p><p>There is an obvious optimization we could introduce to improve the economics of our operation: run larger batches. Batches are a natural improvement because we can load the model weights once, but we can use the loaded weights to do inference with multiple items from our batch at the same time (and so serve different customers simultaneously).</p><p>Increasing the batch size increases the compute usage linearly - we have <code>k</code> times more multiplications to do, but it only marginally changes the memory bandwidth used (only for loading the KV cache), so it's an easy way to increase the compute intensity for our otherwise heavily memory-bound algorithm (to make it less memory-bound). Since the extra memory for the KV cache is significantly smaller than the memory needed for the model, it only adds a small overhead, but it linearly increases the number of produced tokens. We produce twice as many tokens for a batch of 2 and 16x as many tokens with a batch of sixteen.</p><p><strong>This is the core message of this post and the main intuition we hope you take away from reading this text:</strong> As we grow the batch size, we can effectively share the time to load the model from high bandwidth memory (HBM), aka our cost of loading the model is split across an increasing number of clients, enjoying the <strong>economies of scale</strong> and decreasing the per-request cost. <strong>Having sufficient demand and continuously serving big batches is the key to running a profitable LLM inference business; if you can't support large batches, your cost per token will balloon, making your operation unprofitable.</strong>*</p><p>*One thing to note is that there is a limit to this model. As we approach really long sequences or really big batches, as we will see in our experiments, the memory footprint of the KV cache starts to slowly overtake the memory footprint of the model itself (see Fig. 15). When this happens, the cost of loading the model will become increasingly irrelevant to the total time of loading data from the global memory.</p><p>"Luckily" for us, this situation also has its limit-the memory limit of a GPU node; in the case of H100 cards, it will be 8 &#215; H100 = 8 &#215; 80GB = 640GB. Note how for a batch of 8 at the full context length of Llama, we are already nearly there.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!2APA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!2APA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 424w, https://substackcdn.com/image/fetch/$s_!2APA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 848w, https://substackcdn.com/image/fetch/$s_!2APA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 1272w, https://substackcdn.com/image/fetch/$s_!2APA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!2APA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png" width="1157" height="480" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:480,&quot;width&quot;:1157,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:54635,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!2APA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 424w, https://substackcdn.com/image/fetch/$s_!2APA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 848w, https://substackcdn.com/image/fetch/$s_!2APA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.png 1272w, https://substackcdn.com/image/fetch/$s_!2APA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c626404-5acf-4750-8fca-7c0dfec5b3b3_1157x480.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 role="img" 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><title></title><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">Fig. 15: KV cache scaling - comparison between different batch sizes. Note how the KV cache scales linearly with the batch size.</figcaption></figure></div><h2>Throughput: theory vs practice</h2><p>After all of the theoretical introductions, let&#8217;s try to combine all that we learned so far to estimate the LLM throughput. We will:</p><ul><li><p>Develop a theoretical performance model based on the GPU spec sheet.</p></li><li><p>Compare it with a real-world throughput of Llama 3.3 70B on 4 H100 cards.</p></li><li><p>Explain the discrepancies between theoretical and actual performance.</p></li></ul><p>The time to produce a response to a prompt is a combination of the pre-fill time and the decode time times the number of decode tokens. The more output tokens we produce, the smaller share of time will be spent in the prefill phase. The prefill time is primarily compute-bound, and the time for token-by-token is primarily memory-bound.</p><p>Since prefill is so heavily compute-bound, we can estimate the time by dividing the number of floating-point operations during prefill by the total effective FLOPS across all of the GPUs, plus the extra latency from cross-GPU communication time.</p><p>The decode time is mainly memory bound, but as we increase the batch size, the compute component will become increasingly important. We will calculate both and take the more significant factor. We also spend some small amount of time in coms.</p><p>The simple modeling script is based on what we have discussed above. We take in the model size and its architecture and estimate the throughput we should get given the hardware characteristics.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Fm7M!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Fm7M!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 424w, https://substackcdn.com/image/fetch/$s_!Fm7M!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 848w, https://substackcdn.com/image/fetch/$s_!Fm7M!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 1272w, https://substackcdn.com/image/fetch/$s_!Fm7M!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Fm7M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png" width="1456" height="1233" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1233,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:456359,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Fm7M!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 424w, https://substackcdn.com/image/fetch/$s_!Fm7M!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 848w, https://substackcdn.com/image/fetch/$s_!Fm7M!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.png 1272w, https://substackcdn.com/image/fetch/$s_!Fm7M!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb3855c31-2a45-4483-9749-e5ab929a4cbe_1802x1526.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 role="img" 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><title></title><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">Simple script we use for throughput estimation.</figcaption></figure></div><p>For a Llama 3.3 70B, with 2035 tokens in and 300 tokens out, we will get these estimates:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xqte!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xqte!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 424w, https://substackcdn.com/image/fetch/$s_!xqte!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 848w, https://substackcdn.com/image/fetch/$s_!xqte!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 1272w, https://substackcdn.com/image/fetch/$s_!xqte!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xqte!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png" width="1456" height="927" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:927,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1859831,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xqte!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 424w, https://substackcdn.com/image/fetch/$s_!xqte!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 848w, https://substackcdn.com/image/fetch/$s_!xqte!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.png 1272w, https://substackcdn.com/image/fetch/$s_!xqte!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F16a49480-7cf2-494e-93b1-ebd42620f232_2906x1850.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 role="img" 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><title></title><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">Fig. 16: The throughput estimated using first principles. We can observe what we discussed before: as the batch size increases, the extra memory that needs to be loaded for the KV cache and the speed per request decrease. </figcaption></figure></div><p>Let&#8217;s first look at the estimated model performance under the different batch sizes. As we derived before, batch size is the single most relevant statistic regarding the tokenomics. Look how the throughput scales nearly linearly with the batch size (see Fig. 16). This is the single most important message you should get out of this text. The key to the good tokenomics is running the models at a large batch size, which is caused by the LLM inference being memory bound, meaning we want to share the cost of loading the model into the memory across as many requests as possible. As the KV cache size is approaching the model size, the total throughput gains are diminishing.</p><p>While the total throughput is increasing with the batch size, the per-request speed is decreasing, and the slowdown is accelerating as we increase the batch size due to the increased memory footprint of the KV cache. At some point, with massive batches, the per-request experience will be massively degraded. This means that even if we can support larger batches, e.g., due to the massive demand as DeepSeek experienced in February 2025, we might not want to do so because of the poor token generation speed each user will experience. In general, the variance in speed you experience on OpenRouter (see Fig. 17) can be largely attributed to the current demand, aka the batch size.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3_uC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3_uC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 424w, https://substackcdn.com/image/fetch/$s_!3_uC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 848w, https://substackcdn.com/image/fetch/$s_!3_uC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 1272w, https://substackcdn.com/image/fetch/$s_!3_uC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3_uC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png" width="1456" height="1331" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1331,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:939990,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3_uC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 424w, https://substackcdn.com/image/fetch/$s_!3_uC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 848w, https://substackcdn.com/image/fetch/$s_!3_uC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.png 1272w, https://substackcdn.com/image/fetch/$s_!3_uC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2d881ef-f1f8-474b-8437-4e29932fac2e_2066x1888.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 role="img" 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><title></title><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">Fig. 17: Throughput variance throughout the day from OpenRouter. The variance can be somehow explained by the varying demand for the service throughout the day, resulting in varying batch sizes.</figcaption></figure></div><p>It is also part of the reason why the batch <a href="https://platform.openai.com/docs/guides/batch">API</a> is so much cheaper. In cases where speed is not of utmost importance, an LLM provider can just run massive batches, enjoying economy of scale, with individual requests being handled pretty slowly but processed at a higher profit. There are more nuances to this, e.g., the parallelism strategy (pipeline parallelism offers less cross-device communications overhead), that we consider beyond the scope of this text. We just wanted to give you a real-world example of the real impact of batch size on the price of a generated token.</p><p>Now let&#8217;s compare the results we get from our model to the actual LLM inference performance. For this, we run a vLLM inference server (a popular LLM serving framework) with Llama 3.3 70B on 4 H100 cards connected with NVLink. The result is quite underwhelming.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!8bPv!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!8bPv!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 424w, https://substackcdn.com/image/fetch/$s_!8bPv!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 848w, https://substackcdn.com/image/fetch/$s_!8bPv!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 1272w, https://substackcdn.com/image/fetch/$s_!8bPv!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!8bPv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png" width="1228" height="4244" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:4244,&quot;width&quot;:1228,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:859040,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!8bPv!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 424w, https://substackcdn.com/image/fetch/$s_!8bPv!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 848w, https://substackcdn.com/image/fetch/$s_!8bPv!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.png 1272w, https://substackcdn.com/image/fetch/$s_!8bPv!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F504a7f52-4ade-4666-9326-a013475f542d_1228x4244.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 role="img" 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><title></title><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">Fig. 18: The results of a benchmark we run on Llama 3.3 70B TP=4 for different batch sizes. Note that we keep the input tokens and output tokens fixed. To make the model not stop too early, we run it with random weights and just add <code>max_tokens</code> param to them.</figcaption></figure></div><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1N0V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1N0V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 424w, https://substackcdn.com/image/fetch/$s_!1N0V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 848w, https://substackcdn.com/image/fetch/$s_!1N0V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 1272w, https://substackcdn.com/image/fetch/$s_!1N0V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1N0V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png" width="1456" height="926" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.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;:1969414,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1N0V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 424w, https://substackcdn.com/image/fetch/$s_!1N0V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 848w, https://substackcdn.com/image/fetch/$s_!1N0V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.png 1272w, https://substackcdn.com/image/fetch/$s_!1N0V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9d6920f2-b66b-49b8-ac73-b85b7ac36e5d_2866x1822.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 role="img" 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><title></title><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">Fig. 19: Model vs. the reality. While the shape is somehow similar, the exact values are not due to the real-world constraints.</figcaption></figure></div><p>While the general sigmoid-like shape is quite similar, the actual values are very much different. We go from around ~60% of theoretical estimated performance in small batches to around 40%. Where does this difference come from?</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dwyz!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dwyz!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 424w, https://substackcdn.com/image/fetch/$s_!dwyz!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 848w, https://substackcdn.com/image/fetch/$s_!dwyz!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 1272w, https://substackcdn.com/image/fetch/$s_!dwyz!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dwyz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png" width="1456" height="861" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:861,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1669023,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dwyz!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 424w, https://substackcdn.com/image/fetch/$s_!dwyz!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 848w, https://substackcdn.com/image/fetch/$s_!dwyz!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.png 1272w, https://substackcdn.com/image/fetch/$s_!dwyz!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc54a46a6-2000-43cd-93a2-37c78536889a_3380x1998.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 role="img" 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><title></title><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">Fig. 20: As we increase the batch size the discrepancies between estimated throughput and the measured one increase.</figcaption></figure></div><p>Well, this is the problem at the core of GPU optimization - in practice, it is actually extremely hard to properly estimate the wall-time performance of the GPU application.  There are many compounding factors here, making the picture more blurry. To mention a few things that are likely contributing to the discrepancy in the observed results vs. reality:</p><ul><li><p>In our model we assumed 100% memory and compute utilization. Theoretical peak performance metrics like TFLOPS and memory bandwidth are never fully achieved in practice. GPUs typically achieve only 50-70% of their theoretical compute capacity due to</p><ul><li><p>Kernel launch overhead and synchronization costs</p></li><li><p>Memory access patterns that don't perfectly align with cache architectures</p></li><li><p>Warp divergence and other GPU-specific inefficiencies</p></li><li><p>Instruction mix that isn't optimal for utilizing all GPU units</p></li><li><p>&#8230; and a lot of other factors</p></li></ul></li><li><p>We assumed very little overhead from the cross-device communication; as we explored previously, this is not necessarily the case in practice. In practice, we have tons of other factors that contribute to the potential extra latency, such as</p><ul><li><p>  Having to sync the CUDA graph across devices for cross-GPU communication</p></li><li><p>  Synchronization barriers that force all GPUs to wait for the slowest one</p></li><li><p>  internal buffers and management overhead</p></li><li><p>  potential suboptimal (non-coalesced) memory access patterns, especially at larger sizes, with KV caches being stored in random pages of the VRAM memory</p></li><li><p>  and other factors we don&#8217;t mention here</p></li></ul></li><li><p>For simplicity of calculating FLOPs, we assumed a very naive implementation of the attention mechanism. In practice, everyone is using something like Flash attention. Properly estimating the time and FLOPs involved is quite challenging and complicated and outside the scope of this text.</p></li><li><p>Overhead coming from the practical implementation of the LLM serving engine, such as paged attention</p></li><li><p>Extra overhead from using Python, PyTorch, and the vLLM framework itself</p></li></ul><p>We tried to account for some of the above and include them in the extended simulation model. The details can be found in the <a href="https://github.com/tugot17/llm-inference-economics-from-first-principles">code</a>, but TL;DR; we assumed decreased compute and memory utilization values, the extra latency from coms, and a few other factors, like extra memory overhead increasing exponentially with the batch size.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LDgc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LDgc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 424w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 848w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LDgc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png" width="1456" height="697" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:697,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:633588,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LDgc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 424w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 848w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!LDgc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7c8dc6fb-5545-48f8-b84f-471bc99fe233_5869x2808.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 role="img" 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><title></title><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">Fig. 21: Updated model vs. reality. Now the two lines are much closer. We achieve this by adding the estimated overhead to the model. We run it for 2k tokens input and 300 tokens output.</figcaption></figure></div><p>While far from perfect, it kind of works. It generalizes pretty well to other sizes; e.g., it works for the Llama 3.1 8B run on TP1.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!cVzy!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!cVzy!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 424w, https://substackcdn.com/image/fetch/$s_!cVzy!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 848w, https://substackcdn.com/image/fetch/$s_!cVzy!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!cVzy!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!cVzy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png" width="5869" height="2808" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:2808,&quot;width&quot;:5869,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1135886,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb4c28e3b-249f-434c-a489-fd545683bdde_5869x2808.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!cVzy!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 424w, https://substackcdn.com/image/fetch/$s_!cVzy!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 848w, https://substackcdn.com/image/fetch/$s_!cVzy!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!cVzy!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F27f5d92d-96c9-4ea4-904c-d3addd24c6f4_5869x2808.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 role="img" 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><title></title><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">Fig. 22: The estimation we run seems to work quite well for other model sizes. E.g., here we run for Llama 3.1 8B, 2k tokens input 300 tokens output. The two lines are pretty close.</figcaption></figure></div><p>However, when tried with different batches of different lengths, the differences are more significant, suggesting that the model is far, far from perfect. E.g., we tried estimating the throughput for long context model performance, with 16k tokens in and 1000 tokens out. Due to excessive memory consumption, we kept this setting at a batch size of 8. In such a case, the model failed to correctly predict the final throughput, suggesting that our model is far from perfect.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oQY5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oQY5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 424w, https://substackcdn.com/image/fetch/$s_!oQY5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 848w, https://substackcdn.com/image/fetch/$s_!oQY5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!oQY5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oQY5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png" width="1456" height="700" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:700,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:543817,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oQY5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 424w, https://substackcdn.com/image/fetch/$s_!oQY5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 848w, https://substackcdn.com/image/fetch/$s_!oQY5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!oQY5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3b03f24e-9275-4224-8da9-62b2c6878e3b_5838x2808.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 role="img" 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><title></title><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><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!h7hm!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!h7hm!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 424w, https://substackcdn.com/image/fetch/$s_!h7hm!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 848w, https://substackcdn.com/image/fetch/$s_!h7hm!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!h7hm!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!h7hm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png" width="1456" height="700" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:700,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:543406,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!h7hm!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 424w, https://substackcdn.com/image/fetch/$s_!h7hm!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 848w, https://substackcdn.com/image/fetch/$s_!h7hm!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.png 1272w, https://substackcdn.com/image/fetch/$s_!h7hm!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe86f23f7-0fda-426c-a995-19677c7e0f5c_5838x2808.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 role="img" 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><title></title><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">Fig. 23: Unfortunately, for different input/output configurations (16k tokens input, 2k tokens output in this case), the model estimates the throughput less accurately, more so for Llama 3.3 70B and less so for Llama 3.1 8B.</figcaption></figure></div><p>How challenging it is to correctly predict a model's throughput is another thing that we hope you can take out of reading this text. Accurately estimating it would require a series of very detailed profiling steps, such as profiling the memory access patterns across multiple model sizes, batch sizes, and prompt length combinations; delving deeply into the exact implementation details of (paged) attention implementation; implementation details of the batch scheduling; estimating how different shapes affect the compute and memory utilization; and dozens of different experiments. We deem an accurate estimation across different settings challenging to a degree that it might not be feasible to do so in practice. If you want accurate results, you are probably better off just measuring the real-world results.</p><h2>From tokens to dollars - estimating tokenomics</h2><p>As you might know, the pricing of various LLM providers is token-based: you will pay a specific price per million input and output tokens. Some providers use the same price for input and output tokens; others have two distinct prices for input and output tokens.</p><p>To summarize what we've learned so far:</p><ul><li><p>The time of prefill is quadratically dependent on the sequence length. As the input size grows, it will occupy an increasingly big percentage of the request processing time.</p></li><li><p>The time spent generating a single token grows linearly as the context length grows. KV cache will gradually become a more and more substantial percentage of the total data loaded from the global memory (alongside the model parameters). </p></li><li><p>Since the time of generating a single token can be well approximated by the cost of loading the model weights once from global memory, this time grows linearly with the number of generated tokens.</p></li></ul><p>What should be apparent from the description above is that estimating a fair market price for the input tokens is a non-trivial task. Increased input quadratically increases the cost of prefill, but for standard use cases, prefill is only a minority of the time the GPU spends on processing the request. Then, depending on the batch size and context length and the proportion of these two to the model size, it will affect the throughput.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7Swe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7Swe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 424w, https://substackcdn.com/image/fetch/$s_!7Swe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 848w, https://substackcdn.com/image/fetch/$s_!7Swe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 1272w, https://substackcdn.com/image/fetch/$s_!7Swe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7Swe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png" width="889" height="773" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b04cd065-93c0-4517-a147-c9c3271d9601_889x773.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:773,&quot;width&quot;:889,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:121341,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7Swe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 424w, https://substackcdn.com/image/fetch/$s_!7Swe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 848w, https://substackcdn.com/image/fetch/$s_!7Swe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.png 1272w, https://substackcdn.com/image/fetch/$s_!7Swe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb04cd065-93c0-4517-a147-c9c3271d9601_889x773.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 role="img" 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><title></title><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">Fig. 24: Market prices for input and output tokens of Llama 3.3 70B on <a href="https://openrouter.ai/meta-llama/llama-3.3-70b-instruct">OpenRouter</a></figcaption></figure></div><p>While estimating a universal proportion of cost between the input and output tokens that generalizes well across all possible shapes of input and output is quite complicated, estimating the cost for a specific input and output config is much simpler. We can just:</p><ul><li><p>Measure the execution wall time.</p></li><li><p>Assume a fixed ratio <code>&#947;</code> between input and output token costs (e.g., <code>&#947;=0.3</code>). There is no deep reasoning behind choosing this particular value of <code>&#947;</code> we just need to choose some value.</p></li><li><p>Calculate the per-token cost <code>&#946;</code> by solving the following equation:</p></li></ul><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\gamma \\times \\beta \\times \\text{input tokens} + \\beta \\times \\text{output tokens} = time&quot;,&quot;id&quot;:&quot;OBSDMJKQIT&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\beta = \\frac{time}{(\\gamma \\times \\text{input tokens} + \\text{output tokens})} = \\frac{GPU \\ time \\ cost}{(\\gamma \\times \\text{input tokens} + \\text{output tokens})}&quot;,&quot;id&quot;:&quot;FRMQOQKQWD&quot;}" data-component-name="LatexBlockToDOM"></div><p>For example, with 2,035 input tokens, 300 output tokens, a batch size of 16, and a runtime of 8.96 second - as we measure in one of the experiments mentioned in the previous section:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Cost per second } 4 \\times H100s= \\frac{4 \\times $2.5}{3600} = $0.0028&quot;,&quot;id&quot;:&quot;ELFPPTGCSZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>Which equals approximately $1.72 per million output tokens and $0.51 per million input tokens.</p><p>We apply the same calculations to the different batch sizes based on the experiments we did run in the previous section. As you can see, there is a dramatic price reduction with increasing batch size. The reader should verify that the reduction is directly proportional to the increased total throughput from running larger batches.</p><div id="datawrapper-iframe" class="datawrapper-wrap outer" data-attrs="{&quot;url&quot;:&quot;https://datawrapper.dwcdn.net/941pu/1/&quot;,&quot;thumbnail_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/49b29e20-128e-4bfe-9d38-d569f77e6de8_1260x660.png&quot;,&quot;thumbnail_url_full&quot;:&quot;&quot;,&quot;height&quot;:396,&quot;title&quot;:&quot;Inference cost for Llama 3.3 70B, 2035in, 300out&quot;,&quot;description&quot;:&quot;Create interactive, responsive &amp; beautiful charts &#8212; no code required.&quot;}" data-component-name="DatawrapperToDOM"><iframe id="iframe-datawrapper" class="datawrapper-iframe" src="https://datawrapper.dwcdn.net/941pu/1/" width="730" height="396" 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>Table 1: Estimated cost per 1M tokens for different batch sizes, assuming that the batch is 2035 tokens input and 300 tokens output. The pricing is estimated via the method described in this paragraph.</p><p>Obviously, the above is just a single data point from a single experiment for a single pair of input and output tokens. If we change the proportions of input and output tokens, the picture will be very different. To get a more realistic picture, we could, for example, run a Monte Carlo simulation- gathering multiple data points for different input and output configs, calculating the pricing for each example, removing the outliers (e.g., random slower executions due to external factors), and calculating the final price as an average of the median of these samples.</p><p>The above strategy still suffers from making very strong assumptions, e.g., we only benchmark the performance of rectangularly shaped inputs-all elements of the batch have the same number of input tokens and the same number of output tokens. We don&#8217;t mix the prefill phase with the decode phase-we submit an entire batch at the same time, since all of its elements have the same shape; we expect the prefill to take more or less the same amount of time, after which we only do the decoding part. This is a very strong assumption that is not necessarily going to be the case in the real world. We also hardcoded the value of <strong>&#947;</strong>, which is not necessarily fair and optimal for the settings we will be serving.</p><p>We&#8217;ll pause our pricing model discussion here, and we hope to do a deep dive into more sophisticated pricing strategies in the future text. There are multiple pricing strategies one could use; another interesting angle is estimating the minimal number of users of the LLM model under which an inference is profitable.</p><p>Luckily for us, at the end of the day, you can easily verify if you are running a profitable operation. You just add up the profits you made from charging users for input and output tokens, and you verify if this sums up to more than what you paid for renting a GPU for an hour.</p><h2>Summary</h2><p>We really hope this text to be a founding block for you to build an accurate world model of LLM inference economics, using Llama 3.3 70B as an example. We start explaining what parameters are present in an LLM, what it means for a model to have 70B parameters, and how the memory is consumed. Then we give you a brief introduction to compute- and memory bandwidth performance and what it means to be compute- or memory-bound, and we explain the concept of FLOP and how many FLOPs are in a matrix multiplication.</p><p>We introduce the concept of the prefill phase and the token-by-token phase. We break down FLOPs during different parts of a forward pass, and we show how the prefill is primarily compute-bound. We then explain how different the token-by-token phase is. We introduce the concept of kv-cache; we go again through a forward pass and show how, thanks to the kv-caching, it is now far less dependent on compute (times <code>S</code> less FLOPs), hence how it becomes primarily memory bound. We show how, with the increasing input length, the KV cache occupies an increasingly big portion of the memory load time. We then briefly mention different parallelization strategies, and we describe how extra latency is added when running a multi-GPU setting.</p><p>We follow this by introducing the concept of batching. We explain why, since we are primarily memory bound, we can radically improve the economics of our operation by running larger batches. This is the core message of this text and the intuition with which we hope you leave after reading it. We then build a simplified throughput model from first principles and compare its performance to a real-world Llama 3.3 70b run via vLLM. We show the difference between the theoretical performance and a real one, and we give a brief explanation of where the extra overhead is coming from. We show how inaccurate the theoretical model is, which we hope lets you build an intuition about the challenges of predicting real-world performance by a bunch of heuristics.</p><p>Lastly, we discuss the challenges of establishing pricing and a fair pricing ratio between input and output tokens. We present a simplified cost model that, while not fully accurate, enables you to build a simple heuristic to price the input and output tokens.</p><p>Readers should realize why running on more than the minimal number of GPUs is actually highly beneficial to the inference economics. More GPUs enable higher efficiency through better caching that give a better unit cost per token. With additional GPUs, the same model weights occupy proportionally less of the total memory, allowing more space for KV cache and consequently supporting larger batch sizes. Since throughput scales nearly linearly with batch size, this directly translates to better economics. Each additional GPU also contributes its memory bandwidth to the system, further improving the token generation rate since we are memory-bound in the token-by-token phase.</p><p>When evaluating hardware for LLM inference, readers should understand that memory size is not the only important factor - memory bandwidth is equally, if not more, critical. Since token-by-token generation is primarily memory-bound, they should always ask, "What is the memory speed?" as this determines how fast models can run. For example, NVIDIA L40S GPUs offer 48GB of memory but with a bandwidth of only 864 GB/s (compared to 3350 in H100 cards), resulting in very slow inference. Similarly, the Apple Mac Studio with M3 Ultra has 512GB of unified memory but only 819GB/s of memory bandwidth (see Fig. 25), limiting its LLM inference capabilities despite the large memory pool.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!jQDV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jQDV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 424w, https://substackcdn.com/image/fetch/$s_!jQDV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 848w, https://substackcdn.com/image/fetch/$s_!jQDV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 1272w, https://substackcdn.com/image/fetch/$s_!jQDV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jQDV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png" width="879" height="748" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:748,&quot;width&quot;:879,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:76624,&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://tensoreconomics.substack.com/i/163319195?img=https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png&quot;,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jQDV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 424w, https://substackcdn.com/image/fetch/$s_!jQDV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 848w, https://substackcdn.com/image/fetch/$s_!jQDV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.png 1272w, https://substackcdn.com/image/fetch/$s_!jQDV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F84eeab2c-5619-4749-8732-3f15b84b3098_879x748.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 role="img" 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><title></title><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">Fig. 25: Comparison of memory characteristics between Mac MacStudio and an Nvidia GPU. While Mac has a large memory on paper, it is pretty slow compared to an Nvidia GPU, making it far less suitable to serve LLMs.</figcaption></figure></div><p>Readers should also realize why running models on edge devices will always be relatively expensive on a per-token basis. When running on a consumer end device, we are always running batch-size=1. We can&#8217;t enjoy the economies of scale from sharing the cost of model load between multiple users. We always bear the entire device and energy cost ourselves. This, combined with the likely suboptimal characteristics of the on-edge hardware and slow memory, will result in high costs such as electricity and hardware depreciation.</p><p>The above model is just the tip of the iceberg; we don't discuss any of the possible optimizations, such as speculation models, hardware-specific optimizations, or quantization techniques. The goal of this text is for you to build some basic intuitions on LLM inference. We hope you understand why there are two phases, why one is compute-bound and the other one is memory-bound, and why we hope you developed some intuitions about the relationship between the number of input and output tokens and the request processing time.</p><p>To replicate the experiments, find the instructions at <a href="https://github.com/tugot17/llm-inference-economics-from-first-principles">Github</a></p><pre><code><code>@online{tensoreconomics2025llm,
  author = {Piotr Mazurek, Felix Gabriel},
  title = {LLM Inference Economics from First Principles},
  url = {https://www.tensoreconomics.com/p/moe-inference-economics-from-first},
  urldate = {2025-09-17},
  year = {2025},
  month = {May},
  publisher = {Substack}
}</code></code></pre><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.tensoreconomics.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Tensor Economics! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item></channel></rss>