<?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[Artificial Fintelligence]]></title><description><![CDATA[I write detailed articles about the frontiers of AI research.

Read by over 5000 researchers at OpenAI, DeepMind, Midjourney, Google, Stanford, Berkeley, etc.]]></description><link>https://www.artfintel.com</link><image><url>https://substackcdn.com/image/fetch/$s_!JwWp!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58c3a757-b2e7-4104-9f17-1e79c01d013c_1024x1024.png</url><title>Artificial Fintelligence</title><link>https://www.artfintel.com</link></image><generator>Substack</generator><lastBuildDate>Thu, 30 Apr 2026 06:15:58 GMT</lastBuildDate><atom:link href="https://www.artfintel.com/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[Finbarr Timbers]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[finbarrtimbers@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[finbarrtimbers@substack.com]]></itunes:email><itunes:name><![CDATA[Finbarr Timbers]]></itunes:name></itunes:owner><itunes:author><![CDATA[Finbarr Timbers]]></itunes:author><googleplay:owner><![CDATA[finbarrtimbers@substack.com]]></googleplay:owner><googleplay:email><![CDATA[finbarrtimbers@substack.com]]></googleplay:email><googleplay:author><![CDATA[Finbarr Timbers]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[The Bitter Lesson]]></title><description><![CDATA[Far too many people misunderstand the bitter lesson]]></description><link>https://www.artfintel.com/p/the-bitter-lesson</link><guid isPermaLink="false">https://www.artfintel.com/p/the-bitter-lesson</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Thu, 26 Jun 2025 15:28:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JwWp!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58c3a757-b2e7-4104-9f17-1e79c01d013c_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><a href="http://www.incompleteideas.net/IncIdeas/BitterLesson.html">The Bitter Lesson</a> is an excellent essay which is overwhelmingly misunderstood. The point of the bitter lesson is that, over time, methods which scale with compute will outperform methods that do not.</p><p>It is not:</p><ul><li><p>The idea that we should never incorporate human knowledge</p></li><li><p>The idea that deep learning and scale are all we need (Rich is actually relatively skeptical of deep learning)</p></li></ul><p>The entire point of the essay is that, in the last 5 decades, we have seen massive increases in the amount of compute available to us as an industry and we expect to continue to see <a href="https://openai.com/index/announcing-the-stargate-project/">massive increases</a> in the amount of compute available to AI research.  Methods which take advantage of compute will benefit, and those that do not will suffer.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><p>The reason the lesson is bitter is that it is often much easier and quicker to get results by incorporating human knowledge.</p><p>If you&#8217;re training an autocomplete system in 1995, you&#8217;re probably not going to get very far with next token prediction, and instead, handcoded, or statistically generated rules will do better. In 2005, N-gram models are optimal. It isn&#8217;t until the mid 2010s that we start to see deep learning dominate in NLP, and not until the late 2010s that self supervised learning becomes dominant. At each point along the way, incorporating human knowledge has been advantageous, and has been a way that you can get an advantage over your competition. But in the long term, it&#8217;s a dead end. Methods which take advantage of more compute outperform over a sufficiently long time frame. Compute is the only parameter which we can expect to increase by several orders of magnitude. Much as I wish it were otherwise, it&#8217;s unlikely that we&#8217;ll see 1000x the number of tokens we have now. But in compute, that&#8217;s almost certain. </p><p>The canonical example is computer chess. Before <a href="https://en.wikipedia.org/wiki/Deep_Blue_(chess_computer)">Deep Blue</a> expert systems were largely used. Deep Blue showed that leveraging compute to perform extensive searches against a hand coded value function<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> performed extremely well. Deep Blue was a massive win for the &#8220;scale compute&#8221;/computer search crowd, as it was much more based on scale than human heuristics, but it required an evaluation function with 8000 custom chess features created by human experts, and the evaluation function weighted them using hand selected weights. One measure of the generality of the system is how easy it would be to extend it to a different scenario. To extend Deep Blue to work in Go would be extremely challenging, as one would need to come up with a proper evaluation function by creating another 8000 custom Go features.</p><p>Computer Go is another example where human knowledge fell short. <a href="https://arxiv.org/abs/1712.01815">AlphaGo Zero</a> evaluated against the then state of the art Go bots, which included <a href="https://pasky.or.cz/go/pachi-tr.pdf">Pachi</a>, <a href="https://www.moderndescartes.com/essays/gnugo_to_agz/">GnuGo</a>, and <a href="https://en.wikipedia.org/wiki/Crazy_Stone_(software)">CrazyStone</a>. Pachi and CrazyStone did MCTS with heuristic value functions, and GnuGo was an expert system, with a hand created decision tree to select moves. They were good at the time! But they were all ultimately dead ends. As Rich states in the article:</p><blockquote><p>The bitter lesson is based on the historical observations that </p><p>1) AI researchers have often tried to build knowledge into their agents, </p><p>2) this always helps in the short term, and is personally satisfying to the researcher, but </p><p>3) in the long run it plateaus and even inhibits further progress, and </p><p>4) breakthrough progress eventually arrives by an opposing approach based on scaling computation by search and learning. </p><p>The eventual success is tinged with bitterness, and often incompletely digested, because it is success over a favored, human-centric approach.</p></blockquote><p>If you look at <a href="https://github.com/lungzeeyim/GNUgo">GnuGo&#8217;s code</a>, it was a lot of hard work by a lot of people, and was dramatically worse than what was possible. What&#8217;s surprising is that, while GnuGo <a href="https://www.gnu.org/software/gnugo/devel.html">began in 1989</a>, released continued until 2009, so the authors were undoubtedly aware of Deep Blue and the stunning victory that scaled search had, yet they continued to push forward with their expert system. Brian Lee, a former Google Brain researcher who <a href="https://github.com/tensorflow/MiniGo">replicated AlphaGo within Brain</a>, offers a <a href="https://www.moderndescartes.com/essays/gnugo_to_agz/">compelling explanation</a> for why:</p><blockquote><p>I offer another point: that these stages [of the Bitter Lesson] happen over the span of a decade or so. Over this decade, PhDs are minted, career identities built, promotion criteria set, culture defined, and org charts annealed. Much in the way that science progresses one funeral at a time, progress on difficult problems progresses one organization shutdown at a time.</p></blockquote><p>Consider another scenario. You work at a LLM lab, and have to make your benchmark numbers bigger than your competition or you get fired. You have the immediate temptation to include human knowledge, which in this case might be specialized datasets for a specific benchmark. </p><p>A better approach would be to make the model <em>generally</em> stronger. Focusing on methods that scale with compute as a filter is a strong bet to make, as Jensen Huang is doing his best to give you multiple orders of magnitude more FLOPS. Methods like test time compute, synthetic data, or MoE models are great examples. But the problem with this approach, which when I write it down seems obvious, is that in the moment, it feels <em>indulgent</em>. We <em>don&#8217;t have time</em> for proper science, we have to beat the other labs on LiveCodeBench. That is the bitter lesson: DeepSeek focuses on general improvements, gets them working, scales them to 3.8e25 FLOPS, and is SOTA. </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>Articles I&#8217;m reading right now:</h2><ul><li><p><a href="https://substack.com/home/post/p-166556899">What comes next, by Nathan Lambert (Interconnects)</a>, discussing, among other aspects, how excellent O3 is.</p></li><li><p><a href="https://substack.com/home/post/p-158907079?source=queue">Undertrained tokens in R1</a>, by <span class="mention-wrap" data-attrs="{&quot;name&quot;:&quot;Sander Land&quot;,&quot;id&quot;:217957273,&quot;type&quot;:&quot;user&quot;,&quot;url&quot;:null,&quot;photo_url&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2645373-e223-40c6-abc1-caee5f259f63_768x768.jpeg&quot;,&quot;uuid&quot;:&quot;d5c6a2dd-7440-4fc3-8e5d-c611c668f59e&quot;}" data-component-name="MentionToDOM"></span>.</p></li><li><p>The <a href="https://x.com/finbarrtimbers/status/1938115342427165035">Deep Blue paper</a>, which is worth reading. </p></li></ul><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>Deep Blue is fascinating for a variety of reasons, including the fact that they had custom &#8220;chess chips&#8221; made to encode the evaluation function in hardware. </p></div></div>]]></content:encoded></item><item><title><![CDATA[Reinforcement learning and general intelligence]]></title><description><![CDATA[Epsilon random is not enough]]></description><link>https://www.artfintel.com/p/reinforcement-learning-and-general</link><guid isPermaLink="false">https://www.artfintel.com/p/reinforcement-learning-and-general</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Thu, 05 Jun 2025 15:31:27 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JwWp!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58c3a757-b2e7-4104-9f17-1e79c01d013c_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A disclaimer: nothing that I say here is representing any organization other than Artificial Fintelligence. These are my views, and mine alone, although I hope that you share them after reading. </em></p><p>Frontier labs are spending, in the aggregate, $100s of millions of dollars annually on data acquisition, leading to a number of startups selling data to them (Mercor, Scale, Surge, etc). The novel data, combined with reinforcement learning (RL) techniques, represents the most clear avenue to improvement, and to AGI. I am firmly convinced that scaling up RL techniques will lead to excellent products, and, eventually, AGI. A primary source of improvement over the last decade has been <em>scale</em>, as the industry has discovered one method after another that allows us to convert money into intelligence. First, bigger models. Then, more data (thereby making Alexandr Wang very rich). And now, RL.  </p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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 Artificial Fintelligence! 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>RL is the subfield of machine learning that studies algorithms which <em>discover new knowledge.</em> Reinforcement learning agents take actions in environments to systematically discover the optimal strategy (called a <em>policy</em>). An example environment is Atari: you have an environment (the Atari game) where the agent can take actions (moving in different directions, pressing the &#8220;fire&#8221; button) and the agent receives a scalar reward signal that it wants to maximize (the score). Without providing any data on how to play Atari games, RL algorithms are able to discover policies which get optimal scores in most Atari games.</p><p>The key problem in RL is the exploration/exploitation tradeoff. At each point that the agent is asked to choose an action, the agent has to decide between choosing the action which they currently think is best (&#8221;exploiting&#8221;) or trying a new action which might be better (&#8221;exploring&#8221;). This is an extremely difficult decision to get right. Consider a complicated game like Starcraft, or Dota. For any individual situation that the agent is in, how can we know what the optimal action is? It&#8217;s only after making an entire game&#8217;s worth of decisions that we are able to know if our strategy is sound. and it is only after playing many games that we are able to conclude how good we are in comparison to other players.</p><p>Large language models help significantly here, as they are much, much more sample efficient because they have incredibly strong priors. By encoding a significant fraction of human knowledge, the models are able to behave well in a variety of environments before they&#8217;ve actually received any training data. </p><p>When it comes to language modelling, most use of RL to date has been for RLHF, which is mostly used for behaviour modification. As there is (typically) no live data involved, RLHF isn&#8217;t &#8220;real&#8221; RL and does not face the exploration/exploitation tradeoff, nor does it allow for the discovery of new knowledge. </p><p>Knowledge discovery is the main unsolved problem in modern machine learning. While we've become proficient at supervised learning, we haven't yet cracked the code on how to systematically discover new knowledge, especially superhuman knowledge. For <a href="https://www.cs.cmu.edu/~sandholm/cs15-888F21/lecture16_AlphaStar%20-%20CMU%202021.pdf">AlphaStar</a>, for instance, they spent a lot of compute discovering new policies, as it is an extraordinarily hard problem to discover good strategies in Starcraft without prior knowledge.</p><p>Therein lies the rub; RL is simultaneously the most promising and most challenging approach we have. DeepMind invested billions of dollars in RL research with little commercial success to show for it (the <a href="https://www.nobelprize.org/prizes/chemistry/2024/press-release/">Nobel prize</a>, for instance, was for AlphaFold, which didn&#8217;t use RL). While RL is often the only solution for certain hard problems, it is <em>notoriously</em> difficult to implement effectively. Consider a game with discrete turns, like Chess or Go. In Go, you have on average 250 different choices at each turn, and the game lasts for 150 moves. Consequently, the game tree has approximately 250^150 nodes, or ~10^360. If <a href="https://paperswithcode.com/method/epsilon-greedy-exploration">searching randomly</a> (which is how many RL algorithms explore), it is exceedingly difficult to find a reasonable trajectory in the game, which is why AlphaZero style selfplay is needed, or an AlphaGo style supervised learning phase. When we consider the LLM setting, in which typical vocabulary sizes are in the 10s to 100s of thousands of tokens, and sequence lengths can be in the 10s to 100s of thousands, the problem is made much worse. The result is a situation where RL is both necessary and yet should be considered a last resort. </p><p>Put differently, one way to think of deep learning is that it&#8217;s all about learning a good, generalizable, function approximation. In deep RL, we are approximating a value function, i.e. a function that tells us exactly how good or how bad a given state of the world would be. To improve the accuracy of the value function, we need to be able to receive data with non-trivial answers. If all we receive is the same reward (and it&#8217;s really bad), we can&#8217;t do anything. Consider a coding assistant, like Cursor&#8217;s newly released <a href="https://docs.cursor.com/background-agent">background agent</a>. One way to train the agent would be to give it a reward of 1 if it returns code which is merged into a pull request, and 0 otherwise. If you took a randomly initialized network, it would output gibberish, and would thus always receive a signal of 0. Once you get a model that is actually good enough to sometimes be useful to users, you can start getting meaningful signal and rapidly improve. </p><p>As an illustrative example, I have a friend who works at a large video game publisher doing RL research for games (think: EA, Sony, Microsoft, etc.). He consults with teams at the publisher&#8217;s studios that want to use RL. His first response, despite being an experienced RL practitioner with more than 2 decades of RL experience, is usually to ask if they've tried everything else, because it&#8217;s <em>so difficult </em>to get RL to work in practical settings. </p><p>The great question with reinforcement learning and language models is whether or not we&#8217;ll see results transfer to other domains, like we have seen with next token prediction. The great boon of autoregressive language models has been that it generalizes well, that is, you can train a model to predict the next token and it learns to generate text that is useful in a number of other situations. It is absolutely not clear whether that will be the case with models trained largely with RL, as RL policies tend to be overly specialized to the exact problem they were trained on. AlphaZero notoriously had problems with catastrophic forgetting; a <a href="https://arxiv.org/abs/2004.09677">paper</a> that I wrote while at DeepMind showed that simple exploits existed which could consistently beat AlphaZero. This has been replicated consistently in a number of other papers. To get around this, many RL algorithms require repeatedly looking at the training data via replay buffers, which is awkward and unwieldy.</p><p>With LLMs, this is a major problem. Setting aside RL, in the open research space, we see a lot of VLMs that are trained separately from their LLMs equivalents. <a href="https://github.com/deepseek-ai/DeepSeek-VL2">DeepSeek-VL2</a> is a separate family of models from <a href="https://huggingface.co/deepseek-ai/DeepSeek-V3">V3</a>, which is text-only, despite all the major closed source models accepting multimodal inputs.  The main reason for the separation being that, in the published literature, adding multimodal capacities to LLMs sacrifices pure text performance. When we go to add in RL, we should expect the problem to become much worse, and more research to be dedicated to improving the inherent tradeoffs here.</p><p>In my experience as a practitioner, RL lives or dies based on the quality of the reward signal. One of the most able RL practitioners that I know, <a href="https://www.amii.ca/people/adam-white">Adam White</a>, begins all of his RL projects by first learning to predict the reward signal; and only then will try to optimize it (first predict, and then control). Systems that are optimizing complex, overfit reward models will struggle. Systems like the Allen Institute's <a href="https://arxiv.org/abs/2411.15124">Tulu 3</a>, which used verifiable rewards to do RL, seem like the answer, and provide motivation for the hundreds of millions of dollars that the frontier labs are spending on acquiring data.</p><p>The development of AlphaGo illustrates this paradox perfectly:</p><ul><li><p>RL was essentially the only viable approach for achieving superhuman performance in Go</p></li><li><p>The project succeeded but required enormous resources and effort</p></li><li><p>The solution existed in a "narrow passageway" - there were likely very few variations of the AlphaGo approach that would have worked, as can be seen by the struggle that others have had replicating AlphaGo&#8217;s success in other domains.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p></li></ul><p>We're now facing a similar situation with language models:</p><ol><li><p>We've largely exhausted the easily accessible training data</p></li><li><p>We need to discover new knowledge to progress further</p></li><li><p>For superhuman knowledge in particular, we can't rely on human supervision by definition</p></li><li><p>RL appears to be the only framework general enough to handle this challenge</p></li></ol><p>In short, this is a call for research labs to start investing in fundamental RL research again, and in particular, on finally making progress on the exploration problem. </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><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>I actually can&#8217;t think of any successful applications of <a href="https://en.wikipedia.org/wiki/Monte_Carlo_tree_search">MCTS</a> to solve real world problems. Other than the AlphaGo/AlphaZero/MuZero line of work, it doesn&#8217;t seem to have led to anything, which 2017 Finbarr would have found extremely surprising.  </p></div></div>]]></content:encoded></item><item><title><![CDATA[How to hire ML engineers/researchers]]></title><description><![CDATA[I&#8217;m going to assume that you&#8217;ve figured out how to find candidates which appear great on paper and your only problem is figuring out which of them to hire.]]></description><link>https://www.artfintel.com/p/how-to-hire-ml-engineersresearchers</link><guid isPermaLink="false">https://www.artfintel.com/p/how-to-hire-ml-engineersresearchers</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Thu, 16 Jan 2025 21:56:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JwWp!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58c3a757-b2e7-4104-9f17-1e79c01d013c_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;m going to assume that you&#8217;ve figured out how to find candidates which appear great on paper and your only problem is figuring out which of them to hire. Getting high quality candidates is more of a marketing/brand/sales exercise, which I don&#8217;t have that much experience with. Getting high quality candidates to apply is a non-trivial problem in the current market, particularly if you are trying to hire anyone with more than ~3 years of experience. But, nonetheless, it is beyond the scope of this article. I&#8217;m going to discuss how you should run interview processes for ML engineers/researchers.</p><p>Before I begin, a request: I&#8217;m writing an article about human data, so if you manage/use the results of a human labelling pipeline, or use signals from your users for model training/evaluation, please <a href="https://finbarr.ca/">get in touch</a>. </p><p>When discussing roles, I&#8217;m going to use the DeepMind classification, which has three main technical roles and a common <a href="https://codingrelic.geekhold.com/2018/08/google-software-engineering-levels-and.html">experience ladder</a>:</p><ol><li><p>Software engineer (SWE), which is a standard software engineer that isn&#8217;t required to know ML or research (although it is, of course, an advantage).</p></li><li><p>Research engineer (RE), which is basically everyone who isn&#8217;t a SWE or a RS. Most companies in the LLM era that are hiring &#8220;researchers&#8221; that are expected to be able to code their ideas in large codebases are looking for REs. Their duties could run the gamut from managing experiments, to optimizing code, to doing novel research.</p></li><li><p>Research Scientists (RS), which is someone with a PhD whose success is judged entirely on their publication record. This job is not dissimilar from being a postdoc. Some RSs spend very little time coding, and some are better coders than most REs. The key differentiating factor between an RE and a RS is that an RS typically has weaker coding skills and spends more of their time thinking about what to work on next.</p></li></ol><p>The hiring process for all of these roles is broadly similar. To hire for any of them (or any role in general!) you should be running work sample tests for the specific tasks you expect each of these candidates to be able to do, while maintaining a consistent high standard in your evaluation. The hardest part, by far, about running a good hiring process is getting buy in from the rest of your organization to continue to run a rigorous process, and to maintain a high bar. Often you have an immediate need to hire to meet some goal (if you don&#8217;t, you probably shouldn&#8217;t be hiring), so it&#8217;s always tempting to relax the bar slightly. Don&#8217;t. If you do, you&#8217;ll wake up 18 months later with a mediocre team. </p><p>I&#8217;m going to focus mostly on interviewing candidates who fall in the RE bucket, as that&#8217;s what most organizations in the product-driven research era need. These are candidates who can implement all of their ideas and have the technical expertise to run large-scale experiments by themselves.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>Work sample tests</h2><p>You want your interviews to be as close to the job as possible. I dislike Leetcode questions for this reason. They can have their place, as they&#8217;re generally a good way to screen for competency/conscientiousness, but they tend not to work as well with researchers/ML engineers as they spend less time preparing for Leetcode.</p><p>An approach I like is to take problems that have come up during your team&#8217;s work and turn those into tasks. One that I like is debugging a real world ML problem. A question that I have used in the past is &#8220;I have a new idea to make our models better. I implement it. It doesn&#8217;t work. What should I do?&#8221; This is a common problem that happens at work all the time! I try something, it doesn&#8217;t work, and I grab a coworker to talk to them about it. Another variant is to take a script that works, and add a bunch of common bugs to it to see if they can find them, ideally bugs that have happened as part of your work.</p><p>Another question that I like to ask is to discuss evaluation, and probe the candidate on which problems can come up with evaluation. There are many weird ways that evaluation can fail, most of which aren&#8217;t explicitly written about, so it&#8217;s a good screen to see what a candidate has experience working on.</p><p>When asking these questions, one useful tactic is to allow long, uncomfortable silences to develop. Your general rule of thumb should be to let the candidate talk as much as possible (and a good metric would be % of time the interviewer is talking&#8212; should be as close to 0 as possible). If you ask the candidate a question, like the &#8220;new idea doesn&#8217;t work&#8221; question above, be ready to let the question hang in the air while you sit in silence until they answer. You want to 1) let the person think and 2) see how they react. </p><p>The main goal with questions like these is to get away from the contrived Leetcode like problems which can be memorized or prepared for, and instead focus on questions which require practical experience in the role. Those have value, to be clear, but I don&#8217;t think they&#8217;re as relevant for the research family of roles.</p><h2>Be careful about what you include/exclude</h2><p>Your candidates will have shocking gaps in knowledge. If you don&#8217;t test for a skill, you can&#8217;t assume candidates will have that skill. This is true even for &#8220;obvious&#8221; skills like &#8220;can use source control.&#8221; I have worked with very skilled researchers that barely know how to use Git, and have basically no experience working in a team on a shared codebase.</p><p>The corollary to this is that if there&#8217;s a skill that you think &#8220;everyone should have&#8221;, many people won&#8217;t, so if you screen for it, you will remove them from the candidate pool. Be careful as to whether or not you actually want to remove them from the candidate pool; if a skill is not required, you are needlessly making the candidate pool weaker.</p><p>For instance, I have some friends that run a company using reinforcement learning (RL) to control industrial facilities. They are world experts in RL. I encouraged them to not screen for RL skills, but only to screen for general ML expertise, as they are probably the best people in the world to upskill their employees in RL.</p><p>If you&#8217;re not sure what skills you want to include/exclude, particularly on the behavioural side, I would encourage you to read <a href="https://www.lesswrong.com/posts/9CcdTsgvgFJg87dmW/book-review-talent">Talent</a>, by Tyler Cowen and Daniel Gross. It&#8217;s a good overview. A particular skill I like to see is that someone has a track record of relentlessly doing what was necessary to make their project succeed, across abstraction levels. For instance, Julian Schrittweiser, the lead for AlphaZero, did everything from writing papers, coming up with research ideas, implementing the Jax training pipelines in Python and writing highly-optimized C++. On the flip-side, if candidates restrict themselves to only engaging in certain subsets of the project&#8212; not having a history of cleaning data, or only engaging at the idea level, and not writing any code&#8212; I would view that as an anti-signal.</p><h2>Screen candidates aggressively</h2><p>A common anti-pattern that I have seen is where companies will only screen for technical skills, or, if they do other, behavioural interviews, they will only focus on leadership/teamwork skills. These are really important! But an area that screws a lot of AI companies up is that they will be hiring incredibly skilled ML people coming directly from academia, who do <em>not want to work on products</em>. Many PhDs, and a lot of master&#8217;s/undergrads graduates, are only familiar with academia, and value their publication record above all else, <em>including compensation</em>. When hiring general software engineers this is not typically an issue, as most software engineers want to build products that are successful and make money.</p><p>Until recently, many of the large industrial research labs (DeepMind, FAIR, MSR, etc.) were run in a manner very similar to academia, and the way to advance one&#8217;s career was to publish academic papers in academic journals, so many people who have spent their careers at these organizations are still immersed in the academic mindset. They have not spent <em>any of their professional lives</em> trying to improve business related KPIs, and many have no experience orienting their work around organization level business goals (like OKRs). For many product companies, particularly startups, this is exactly the opposite of what they need. It is a point of pride for some researchers that they work on &#8220;pure science&#8221; which has no apparent useful application (if this mindset is strange to you, there&#8217;s a famous <a href="https://www.arvindguptatoys.com/arvindgupta/mathsapology-hardy.pdf">essay by Hardy</a>, a famous mathematician, who explains it in detail).</p><p>My advice is to spend the first call with the candidate addressing this explicitly, perhaps saying something like &#8220;Publishing papers is not a priority to us. Do not expect that you will ever publish a paper as part of your job. You will be expected to work on research that is driven by the needs of the product/business and will not have academic freedom to pursue whatever ideas you find interesting.&#8221; It may sound harsh, but this is true at most companies, and it&#8217;s worth making it explicit upfront. </p><p>I would generally advise that other unappealing aspects of working at your company should be mentioned in the first call as well. Matt Mochary has written about how important the <a href="https://docs.google.com/document/d/1iK7OMMBbmvpzwfsumKde2tbO3MFLSSDU715-Yv3oOOA/edit?tab=t.0">anti-sell</a> is. You want to give candidates an accurate understanding of what working at your company will be like; one of the worst outcomes for you is to hire someone, spend a lot of time onboarding/training them, and have them churn because they don&#8217;t actually like the job. Do this as early in the process as possible, ideally the first call. </p><h2>Hiring scientists vs engineers</h2><p>Using the DeepMind RE vs RS distinction, many companies only have what DeepMind would call REs, as you need to be able to implement your research in large codebases. The main difference is that, for research scientists, coding ability is less important, the ability to choose the right problem is much more important, and you have to focus on culture fit more.</p><p>Many people who are sticklers about the &#8220;scientist&#8221; label instead of being ok with the engineer label 1) expect to be able to publish papers and 2) expect to do &#8220;pure&#8221; research that&#8217;s not driven by product needs. That&#8217;s often not acceptable at most companies, so they will be unhappy and churn 12-18 months in. Screen for this.</p><h2>Behavioural skills matter</h2><p>You have to screen for behavioural skills Particularly once engineers/reseachers hit the senior level (using the Google scale, so L5+) soft skills are more important than hard skills. Possibly even earlier in their career.</p><p>Mentoring matters. Feedback matters. Connecting with your teammates matters. For more junior roles, being &#8220;teachable&#8221; matters more, but as the person gets more senior, their ability to mentor and give feedback becomes more and more important.</p><p>Additionally, as a researcher, often you are dealing with ambiguity throughout the research process, so it&#8217;s important to discuss your experiments with your coworkers. If someone is particularly disagreeable, this will not go well, which can make your team less productive.</p><p>If you&#8217;re hiring someone from a large company, it&#8217;s important to assess their ability to add more process in a reasonable way. A common failure among senior people from big tech that are too &#8220;bigtech minded&#8221; is that they will add too much, unnecessary process, or expect to be able to grow their team quickly to match the staffing levels they&#8217;ve been historically used to.</p><h2>Keep a rigorous process</h2><p>It&#8217;s easy to think &#8220;we need someone so let&#8217;s hire someone quick.&#8221; Don&#8217;t. Keep a high bar and encourage the rest of your team, particularly if you&#8217;re at a company paying top of market. Otherwise, you&#8217;ll wake up 12 months later with a mediocre team.</p><p>Jeff Bezos had a list of questions:</p><ol><li><p>&#8220;Will you admire this person?&#8221;</p></li><li><p>&#8220;Will this person raise the average level of effectiveness of the group they&#8217;re entering?&#8221;</p></li><li><p>&#8220;Along what dimension might this person be a superstar?<em>&#8243;</em></p></li></ol><p>I think this is the right approach. You should generally try to only hire the best people, and you can get by with a surprisingly small team. I subscribe to the <a href="http://nat.org">Nat Friedman philosophy</a>:</p><blockquote><p>Smaller teams are better:</p><ul><li><p>Faster decisions, fewer meetings, more fun</p></li><li><p>No need to chop up work for political reasons</p></li><li><p>No room for mediocre people (can pay more, too!)</p></li><li><p>Large-scale engineering projects are more soluble in IQ than they appear</p></li><li><p>Many tech companies are 2-10x overstaffed</p></li></ul></blockquote><p>Thanks to <a href="https://x.com/morgymcg">Morgan McGuire</a>, <a href="https://x.com/banburismus_">Tom McGrath</a>, <a href="https://x.com/kgourg">Kostis Gourgoulias</a>, <a href="https://x.com/_sholtodouglas">Sholto Douglas</a>, <a href="https://x.com/ayirpelle">Priya Joseph</a>, <a href="https://x.com/surmenok">Pavel Surmenok</a>, and <a href="https://x.com/generativist">Johnny</a> for reading drafts of this. </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><p>Finally, again: I&#8217;m writing an article about human data, so if you manage/use the results of a human labelling pipeline, or use signals from your users for model training/evaluation, please <a href="https://finbarr.ca/">get in touch</a>. </p><h2>Misc resources</h2><ul><li><p>Matt Mochary gives great <a href="https://docs.google.com/document/d/18FiJbYn53fTtPmphfdCKT2TMWH-8Y2L-MLqDk-MFV4s/edit?tab=t.0">hiring advice</a> (and is generally worth reading, particularly on why <a href="https://docs.google.com/document/d/1YP3LLhStLO_dMCsyiAsRsw7VJvYV_xvTY2DR72MB97k/edit?tab=t.0">references are a waste of time</a>)</p></li><li><p>Sam Altman <a href="https://blog.samaltman.com/how-to-hire">on hiring</a></p></li><li><p><a href="https://www.lesswrong.com/posts/9CcdTsgvgFJg87dmW/book-review-talent">Talent</a>, by Tyler Cowen and Daniel Gross, is a great book.</p></li></ul>]]></content:encoded></item><item><title><![CDATA[Papers I've read this week: vision language models]]></title><description><![CDATA[They kept releasing VLMs, so I kept writing...]]></description><link>https://www.artfintel.com/p/papers-ive-read-this-week-vision</link><guid isPermaLink="false">https://www.artfintel.com/p/papers-ive-read-this-week-vision</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Mon, 28 Oct 2024 15:34:48 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!SHKL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;ve been on a VLM kick lately, trying to read as many papers about vision language models as possible. This was inspired by Claude being ridiculously good at converting equation screenshots to LaTeX, which made me want to understand how LLMs can be so good at understanding pictures and doing fancy OCR. I remember using <a href="https://en.wikipedia.org/wiki/Tesseract_(software)">Tesseract</a> and <a href="https://en.wikipedia.org/wiki/ABBYY_FineReader">ABBYY FineReader</a> back in the day, and finding them slow/hard to work with. Now, with VLMs, it seems like reading text from pictures is a solved problem? Definitely surprised me.</p><p>In any case, I realized that I didn&#8217;t have a good understanding of how VLMs worked, so I wanted to change that. Here&#8217;s the results of my efforts to change that!</p><p>Funnily enough, 2 VLMs have been released since I started writing this: <a href="https://arxiv.org/abs/2410.07073">Pixtral</a>, and <a href="https://arxiv.org/abs/2410.13848">DeepSeek Janus</a>, both causing the article to be delayed.</p><p>Spoiler: it&#8217;s actually super straightforward. It turns out that using some vision encoder (typically a ViT, initialized from a good open source model) to convert images into features, patchifying it, and concatenating the resulting sequence with the text embeddings, is basically enough. There are some fancier architectures, but they don&#8217;t seem noticeably better.</p><p>I will be giving a talk as part of the <a href="https://www.youtube.com/playlist?list=PL_lsbAsL_o2DnQyMUrVTEv8EtIX0hn8KT">PyTorch Expert Exchange</a> lecture series on how batching works on modern GPUs, based on the <a href="https://www.artfintel.com/p/how-does-batching-work-on-modern">article I wrote last year</a>. Please <a href="https://www.youtube.com/watch?v=HTcnp9NEHGY&amp;utm_content=314323742&amp;utm_medium=social&amp;utm_source=twitter&amp;hss_channel=tw-776585502606721024">join me</a>!</p><p>Finally, this article is <em>long</em>. You might want to <a href="https://www.artfintel.com/papers-ive-read-this-week-vision">read it on the web</a> instead. </p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>The evolution of multimodal model architectures</h2><p>[<a href="https://arxiv.org/abs/2405.17927">abstract</a>]</p><p>I began my mission to understand VLMs with this survey paper from Purdue. It&#8217;s a high-level overview of multimodal architectures, grouping them into 4 categories:</p><ol><li><p>Type A and Type B, which combine multimodal inputs within the internal layers of the model</p></li><li><p>Type C and D, which combine the modalities at the input stage.</p></li></ol><p>Type A employs cross-attention, while B uses custom layers for modality fusion.</p><p>Type C uses modality specific encoders, while D uses tokenizers to convert every mode into tokens, and then processes them together.</p><p>Examples of models which fall into the various categories:</p><ol><li><p>Type A: Flamingo, and various Flamingo derived models</p></li><li><p>Type B: CogVLM, MoE-LLaVa</p></li><li><p>Type C: DeepSeek-VL, LLaVa, Sphinx, Emu, Qwen-VL</p></li><li><p>Type D: LaVIT, Unified-IO</p></li></ol><p>Contemporary open source models are almost all doing Type C. Type D is somewhat common in video models (e.g. MagViT2) but most multimodal papers aren&#8217;t bothering to convert the image features into tokens, but passing the patchified features directly into the decoder.</p><p>Of the papers that are notable to me, Type C seems dominant. I suspect that most closed models, like Reka, Claude, and Gpt4o, are doing Type C. My logic is that, in deciding between <em>deep fusion</em>, where modalities are combined within the internal layers of the model, and <em>early fusion</em>, where they&#8217;re combined at the input, the large labs will be focusing on the most general approach, and follow the <em><a href="http://www.incompleteideas.net/IncIdeas/BitterLesson.html">bitter lesson</a></em>, which states that we should learn as much of our structure as possible, rather than imposing pre-determined inductive biases.</p><p>The paper is useful as an overview, but it does get bogged down in coming up with a detailed taxonomy of VLMs which I think is of questionable utility. Great intro if you&#8217;re unfamiliar with the space.</p><h2>Flamingo</h2><p>[<a href="https://arxiv.org/abs/2204.14198">abstract</a>]</p><p>Published in April &#8216;22, Flamingo was one of the early multimodal LMs. It focused on enabling zero-shot adaptation to novel tasks that use text and image inputs. They evaluated on 16 tasks, and reached SOTA in 6 of them despite using ~3 orders of magnitude less task-specific data (yet another win for the bitter lesson!). The architecture is interesting; they combine a pretrained &amp; frozen vision encoder with a similar frozen &amp; pretrained language model, and only train dense cross-attention layers, along with a <a href="https://arxiv.org/abs/2103.03206">Perceiver</a> Resampler layer on the top of the vision encoder. This is a much more complicated architecture than we&#8217;ll see in later models, which tend to all be decoders with minor tweaks.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!SHKL!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!SHKL!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 424w, https://substackcdn.com/image/fetch/$s_!SHKL!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 848w, https://substackcdn.com/image/fetch/$s_!SHKL!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 1272w, https://substackcdn.com/image/fetch/$s_!SHKL!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!SHKL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png" width="1454" height="736" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:736,&quot;width&quot;:1454,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:294216,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!SHKL!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 424w, https://substackcdn.com/image/fetch/$s_!SHKL!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 848w, https://substackcdn.com/image/fetch/$s_!SHKL!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.png 1272w, https://substackcdn.com/image/fetch/$s_!SHKL!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13d08983-1413-4b64-a7d1-c15488798dce_1454x736.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><p>The core idea is that they have a Perceiver Resampler on top of a frozen vision encoder which takes visual inputs and outputs a fixed number of tokens. These are used to condition a frozen LM (various Chinchilla models) using freshly initialized gated cross-attention layers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!dSuS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!dSuS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 424w, https://substackcdn.com/image/fetch/$s_!dSuS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 848w, https://substackcdn.com/image/fetch/$s_!dSuS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 1272w, https://substackcdn.com/image/fetch/$s_!dSuS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!dSuS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png" width="1456" height="788" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:788,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:242079,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!dSuS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 424w, https://substackcdn.com/image/fetch/$s_!dSuS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 848w, https://substackcdn.com/image/fetch/$s_!dSuS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.png 1272w, https://substackcdn.com/image/fetch/$s_!dSuS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F25653cfa-47c1-465b-a0bb-00eddd21601c_1468x794.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><p>The model seems to work well, but was very complex. With the benefit of hindsight, it&#8217;s interesting how unnecessary the complexity was, as none of the subsequent SOTA models used a similar architecture.</p><h2>Qwen-VL</h2><p>[<a href="https://arxiv.org/abs/2308.12966">abstract</a>]</p><p>Published in August 2023, this is when we start to see architectures/training methodologies arise that are very similar to the state of the art in Q3 2024. The Qwen-VL series of models are based on the Qwen LLM, and add visual capacities. They claimed significant improvements in the SOTA compared to other open VLLMs as of Q3 2023. The model architecture is fairly similar to what we&#8217;ll see moving forward; they use a ViT-bigG, initialized from Openclip&#8217;s model, and resize images to 224x224, splitting the images into patches. They then use a vision-language adapter to compress the image features. The adapter is a single layer of cross attention, which uses a number of learned embeddings as query vectors and the image features from the visual encoder as keys for cross-attention, outputting a sequence of length 256. They use 2D absolute positional encodings on the output of the cross-attention layer. They have three stages of training during which they freeze various parts of the 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_!jXzl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!jXzl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 424w, https://substackcdn.com/image/fetch/$s_!jXzl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 848w, https://substackcdn.com/image/fetch/$s_!jXzl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 1272w, https://substackcdn.com/image/fetch/$s_!jXzl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!jXzl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png" width="1400" height="668" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:668,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:156629,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!jXzl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 424w, https://substackcdn.com/image/fetch/$s_!jXzl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 848w, https://substackcdn.com/image/fetch/$s_!jXzl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.png 1272w, https://substackcdn.com/image/fetch/$s_!jXzl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F78928bbd-665b-4fc0-a54e-aefdf598b638_1400x668.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><p>They add special tokens (<code>&lt;img&gt;</code>, <code>&lt;/img&gt;</code>) to the sequence to denote the start/end of image content, and also train the model with bounding boxes, including them as text tokens which are tokenized in the standard way, but with two types of special tokens: <code>&lt;box&gt;, &lt;/box&gt;</code> to denote the coordinates, and <code>&lt;ref&gt;, &lt;/ref&gt;</code> to denote the text description corresponding to a given bounding box.</p><p>The model is pretrained on web-scraped image-text pairs, and then trained on high-quality, fine-grained annotation data. They have an additional supervised fine-tuning stage that they use to create a Chat model. The result is quite strong, and achieves SOTA in a variety of tasks.</p><h2>CogVLM</h2><p>[<a href="https://arxiv.org/abs/2311.03079">abstract</a>]</p><p>Published in late 2023, CogVLM uses a frozen trained language model and image encoder, and combines the two with a trainable visual expert module in the attention and FFN layers, enabling vision features without sacrificing NLP performance. It is SOTA across a number of multi-modal benchmarks. This was likely implemented contemporaneously with Qwen-VL, but definitely has more in common with the pre-Qwen architectures like Flamingo.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!z2Lk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!z2Lk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 424w, https://substackcdn.com/image/fetch/$s_!z2Lk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 848w, https://substackcdn.com/image/fetch/$s_!z2Lk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 1272w, https://substackcdn.com/image/fetch/$s_!z2Lk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!z2Lk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png" width="1098" height="1004" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1004,&quot;width&quot;:1098,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:263481,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!z2Lk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 424w, https://substackcdn.com/image/fetch/$s_!z2Lk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 848w, https://substackcdn.com/image/fetch/$s_!z2Lk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.png 1272w, https://substackcdn.com/image/fetch/$s_!z2Lk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0a7acba5-2478-4e8a-8456-f860f1d9888e_1098x1004.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><p>They add two trainable layers to each transformer block: a MLP, and a QKV matrix, initializing them from their pretrained counterparts in the language model.</p><p>Interestingly, they assign all the image tokens a single position ID for RoPE, with the logic that visual tokens already encapsulate positional information when inputted into the ViT, and that by adding additional positional information, the query would focus more on the closer tokens, i.e. the the lower part of an image.</p><p>The authors did a lot of ablation experiments to justify the choices they made. These are great and really informative for training VLMs.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9YTg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9YTg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 424w, https://substackcdn.com/image/fetch/$s_!9YTg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 848w, https://substackcdn.com/image/fetch/$s_!9YTg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 1272w, https://substackcdn.com/image/fetch/$s_!9YTg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9YTg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png" width="1456" height="516" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:516,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:156508,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9YTg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 424w, https://substackcdn.com/image/fetch/$s_!9YTg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 848w, https://substackcdn.com/image/fetch/$s_!9YTg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.png 1272w, https://substackcdn.com/image/fetch/$s_!9YTg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fab1c33c2-aa5d-40e5-9df6-4e3833429df9_1568x556.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>DeepSeek-VL</h2><p>[<a href="https://arxiv.org/abs/2403.05525">abstract</a>]</p><p>From March 2024, the DeepSeek take on a VLM appears to be a refinement of the Qwen-VL approach. For the visual feature module, the authors use a hybrid encoder, which has a text-aligned encoder for coarse semantic extraction at 384x384 resolution with a high-resolution encoder that operates at 1024x1024 resolution. The module represents a 1024x1024 image as 576 tokens. The high-resolution encoder is based on SAM-B, while they use SigLIP-L for the low-resolution image inputs. SigLIP can generally be viewed as a &#8220;better CLIP&#8221; so this is a modernization/improvement on what Qwen-VL did.</p><p>The authors use a two-layer hybrid MLP as a vision-language adapter, with two distinct single-layer MLPs processing the high- and low- resolution features separately; these features are then concatenated together, and transformed into the LLM&#8217;s input space through another layer of MLP.</p><p>The authors pretrain the models beginning with an intermediate checkpoint from DeepSeek-LLM, and continue to use extensive text-only data, with 70% of the tokens seen during training coming from the DeepSeek text-only corpus. The authors keep the LLM and the vision encoders frozen while they train the vision-language adaptor module, and then jointly train the LLM + VL adaptor on interleaved VL + text-only sequences. Finally, they finetune the entire model on chat data, unfreezing everything.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!r-N5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!r-N5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 424w, https://substackcdn.com/image/fetch/$s_!r-N5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 848w, https://substackcdn.com/image/fetch/$s_!r-N5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 1272w, https://substackcdn.com/image/fetch/$s_!r-N5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!r-N5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png" width="1428" height="864" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/da5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:864,&quot;width&quot;:1428,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:202616,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!r-N5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 424w, https://substackcdn.com/image/fetch/$s_!r-N5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 848w, https://substackcdn.com/image/fetch/$s_!r-N5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.png 1272w, https://substackcdn.com/image/fetch/$s_!r-N5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fda5ce7c8-c5e3-4fb5-af97-66c293eb4ac3_1428x864.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><p>The authors achieve SOTA in the majority of the benchmarks they evaluate when compared against other open-source 7B models. Unsurprisingly, the proprietary LLMs, like GPT4 or Gemini Pro, are significantly better (and presumably significantly larger). Their model doesn&#8217;t see significant degradation on language benchmarks, which has consistently been a problem plaguing VLMs, which tend to have rapidly degraded performance on LLMs; I suspect that the large % of text-only pretraining data was sufficient. This is a good counterexample for the frozen text models we&#8217;ve seen consistently.</p><h2>Chameleon</h2><p>[<a href="https://arxiv.org/abs/2405.09818">abstract</a>]</p><p>Published by Meta in May of &#8216;24, Chameleon is what I would think of as a great example of a &#8220;modern&#8221; multimodal model which uses early fusion to treat all modalities as discrete tokens. The loss here is the standard autoregressive loss, with <code>&lt;start_image&gt;</code> / <code>&lt;end_image&gt;</code> tokens being used to insert the image tokens into the sequential input. Chameleon achieves SOTA on a number of benchmarks (visual question answering, image captioning), and is competitive with text-only models of a similar size (Mixtral 8x7B, Gemini-Pro).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ArL3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ArL3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 424w, https://substackcdn.com/image/fetch/$s_!ArL3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 848w, https://substackcdn.com/image/fetch/$s_!ArL3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 1272w, https://substackcdn.com/image/fetch/$s_!ArL3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ArL3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png" width="1350" height="886" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/afc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:886,&quot;width&quot;:1350,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:338033,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ArL3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 424w, https://substackcdn.com/image/fetch/$s_!ArL3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 848w, https://substackcdn.com/image/fetch/$s_!ArL3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.png 1272w, https://substackcdn.com/image/fetch/$s_!ArL3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fafc1fa82-cd7d-4de0-80e5-bd27c168b6c0_1350x886.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><p>The authors train the model on a variety of orderings, including text-only, text-image pairs, and full interleaved text-image documents. This is, notably, the model that was trained with the most compute and the only one trained from scratch. As you&#8217;d expect, performance is quite strong.</p><p>For the image tokenizer, they use <a href="https://arxiv.org/abs/2203.13131">Make-A-Scene</a>, encoding a 512x512 image into 1024 discrete tokens, using a codebook with size 8192. The authors note that this tokenizer is particularly bad at reconstructing images with a large amount of text, which is to be expected given the codebook size. They use a standard BPE tokenizer for text. They are one of the only VLMs that actually tokenizes their images rather than passing image features directly into the decoder.</p><p>The authors ran into stability issues when training models with more than 8B parameters &amp; 1T tokens, with instabilities happening late in training. They used a Llama2 architecture, with RMSNorm, SwiGLU, and RoPE. They found that the softmax operation was leading to complex divergences because the different modalities had significantly different entropy, so the different modalities would &#8220;compete&#8221; with each other by trying to increase their norms, which would eventually explode. This is similar to the <a href="https://arxiv.org/abs/2309.14322">logit drift problem</a> in the text-only setting. Consequently, the authors used QK-Norm and added dropout after the attention &amp; feed-forward layers, which was enough to stabilize their 7B model. To stabilize their 34B model, they also had to reorder the norms, like so:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_0zx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_0zx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 424w, https://substackcdn.com/image/fetch/$s_!_0zx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 848w, https://substackcdn.com/image/fetch/$s_!_0zx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 1272w, https://substackcdn.com/image/fetch/$s_!_0zx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_0zx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png" width="780" height="196" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/854a448e-0689-4b00-be57-076ae437d4fa_780x196.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:196,&quot;width&quot;:780,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:36952,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_0zx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 424w, https://substackcdn.com/image/fetch/$s_!_0zx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 848w, https://substackcdn.com/image/fetch/$s_!_0zx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 1272w, https://substackcdn.com/image/fetch/$s_!_0zx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F854a448e-0689-4b00-be57-076ae437d4fa_780x196.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The changes were quite dramatic, which violates my intuition. I did not expect norm reordering to have such a big impact on the training loss, although pre/post layer normalization has had a significant impact in certain settings, so I should perhaps not be surprised. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IucC!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IucC!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 424w, https://substackcdn.com/image/fetch/$s_!IucC!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 848w, https://substackcdn.com/image/fetch/$s_!IucC!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 1272w, https://substackcdn.com/image/fetch/$s_!IucC!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IucC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png" width="1356" height="542" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:542,&quot;width&quot;:1356,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:173588,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IucC!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 424w, https://substackcdn.com/image/fetch/$s_!IucC!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 848w, https://substackcdn.com/image/fetch/$s_!IucC!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.png 1272w, https://substackcdn.com/image/fetch/$s_!IucC!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffbe6790e-4ba3-41ee-83bb-70c06ea09502_1356x542.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><p>They found that dropout wasn&#8217;t necessary with norm reordering, but QK-Norm was. This makes sense; I think QK-Norm should generally be used by default.</p><h2>PaliGemma</h2><p>[<a href="https://arxiv.org/abs/2407.07726">abstract</a>]</p><p>From July 2024, PaliGemma continues to demonstrate the superiority of <a href="https://x.com/giffmana?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor">Lucas Beyer</a>&#8217;s SigLIP loss, combining a 400M SigLIP model with a 2B Gemma model into a &lt;3B VLM that is SOTA on a variety of tasks despite being (relatively) small.</p><p><a href="https://arxiv.org/abs/2303.15343">SigLIP</a>, standing for <strong>Sig</strong>moid loss for <strong>L</strong>anguage <strong>I</strong>mage <strong>P</strong>re-training, is a loss that operates solely on image-text pairs and does not require a global view of the pairs for normalization. It can be thought of as a replacement for <a href="https://arxiv.org/abs/2103.00020">CLIP</a>. It is defined as:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!xAPw!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!xAPw!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 424w, https://substackcdn.com/image/fetch/$s_!xAPw!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 848w, https://substackcdn.com/image/fetch/$s_!xAPw!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 1272w, https://substackcdn.com/image/fetch/$s_!xAPw!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!xAPw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png" width="696" height="244" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:244,&quot;width&quot;:696,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24732,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!xAPw!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 424w, https://substackcdn.com/image/fetch/$s_!xAPw!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 848w, https://substackcdn.com/image/fetch/$s_!xAPw!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.png 1272w, https://substackcdn.com/image/fetch/$s_!xAPw!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F45884dbf-7482-4bb9-8942-d44d836e98ff_696x244.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><p>Where $x_i$ is the normalized feature embeddings from the image datapoint, and $y_j$ is the normalized feature embeddings from the text datapoint, and $z_{ij}$ is 1 if the image and text datapoints are paired, and $-1$ otherwise (no, your browser isn&#8217;t broken&#8212; there&#8217;s no good way to do inline math with Substack, unfortunately). PaliGemma uses a SigLIP image encoder to provide image features which are concatenated with the text tokens and processed by a standard decoder.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!HwRQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!HwRQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 424w, https://substackcdn.com/image/fetch/$s_!HwRQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 848w, https://substackcdn.com/image/fetch/$s_!HwRQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 1272w, https://substackcdn.com/image/fetch/$s_!HwRQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!HwRQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png" width="1244" height="656" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:656,&quot;width&quot;:1244,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:240273,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!HwRQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 424w, https://substackcdn.com/image/fetch/$s_!HwRQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 848w, https://substackcdn.com/image/fetch/$s_!HwRQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.png 1272w, https://substackcdn.com/image/fetch/$s_!HwRQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc32fceeb-4d35-4124-b219-d0d3ca7f9056_1244x656.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><p>Unlike Flamingo, the entire PaliGemma architecture is trained jointly on multimodal tasks, with nothing being frozen. Unlike Chameleon, the individual components are initialized from previously trained models (SigLIP 400M and Gemma 2B). It is very similar to DeepSeek-VL.</p><p>PaliGemma was SOTA on the <a href="https://github.com/tsb0601/MMVP/blob/main/imgs/teaser.png">MMVP</a> benchmark (47.3%), and did well on the rest. This is remarkable given how small and (relatively) cheap it was to train. Notably, it beat GPT4-V (38.7%) and Gemini (40.7%) on this task. That&#8217;s remarkable given that these models presumably are much bigger and saw much more data during training.</p><h2>Pixtral (12B)</h2><p>[<a href="https://arxiv.org/abs/2410.07073">abstract</a>]</p><p>From October 2024, Pixtral is a 12B parameter multimodal model, using a vision encoder trained from scratch which ingests images at their natural resolution and aspect ratio, allowing it to vary the number of tokens used for an image. It has a long context window of 128k tokens.</p><p>Pixtral also has a novel RoPE-2D implementation.</p><p>It is based on Mistral Nemo 12B. They train a new vision encoder from scratch, Pixtral-ViT, which is a 400M ViT. It has 4 key changes vs a typical ViT:</p><ol><li><p>They include <code>&lt;IMAGE_BREAK&gt;</code> tokens between image rows (as they scan patches in raster order), and include an <code>&lt;IMAGE_END&gt;</code> token at the end of an image sequence.</p></li><li><p>They use gating in the hidden layer of the FFN.</p></li><li><p>To efficiently process images, they use sequence packing, flattening images along the sequence dimensions and concatenating; they then use a block-diagonal mask to ensure no attention leakage happens.</p></li><li><p>RoPE-2D. They replace the standard learned &amp; absolute position embeddings for image patches with relative, rotary position encodings. The function is kinda complicated:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Rope2D}(x^{(i, j)}, \\Theta) = M_{\\Theta}^{(i, j)}x^{(i, j)},&quot;,&quot;id&quot;:&quot;EPBCAJGLVF&quot;}" data-component-name="LatexBlockToDOM"></div><p>where $M_{\Theta}^{(i, j)}$is a diagonal block matrix such that $M_{\Theta}^{(i, j)}[k: k + 2, k: k+2]$ are the only non-zero entries, with each 2x2 block being equal to</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\begin{matrix}\\cos l \\theta_1 &amp; -\\sin l\\theta_1 \\\\ \\sin l \\theta_1 &amp; \\cos l \\theta_1 \\end{matrix}&quot;,&quot;id&quot;:&quot;EEDWBRDWDJ&quot;}" data-component-name="LatexBlockToDOM"></div><p>where $l = i$ if $k$ is odd, and $j$ otherwise, with $\Theta = [&#952;1&#8230;&#952;d/2]$is a vector of frequencies for the various dimensions of $x$, where $\theta_m$ is defined following standard, 1D <a href="https://arxiv.org/abs/2104.09864">RoPE</a>.</p><p>Their implementation satisfies the &#8220;relative&#8221; property, where inner products between two vectors depend only on their relative difference in height/wodth indices, which is generally agreed to be highly desirable.</p></li></ol><p>The Pixtral vision features are included in the decoder via a two-layer fully connected network, using a GeLU activation on the intermdiate, hidden layer. Image tokens are treated identically to text tokens by the multimodal decoder, including RoPE (1d) embeddings for each token, in particular using causal attention. It&#8217;s a complicated architecture but has some nice properties, particularly the variable length, native resolution image encoding.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hS32!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hS32!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 424w, https://substackcdn.com/image/fetch/$s_!hS32!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 848w, https://substackcdn.com/image/fetch/$s_!hS32!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 1272w, https://substackcdn.com/image/fetch/$s_!hS32!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hS32!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png" width="1456" height="812" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:812,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:315454,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hS32!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 424w, https://substackcdn.com/image/fetch/$s_!hS32!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 848w, https://substackcdn.com/image/fetch/$s_!hS32!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.png 1272w, https://substackcdn.com/image/fetch/$s_!hS32!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd714cc1b-4944-42d8-aee8-c10809ec5e7a_1592x888.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><p>Unfortunately, there&#8217;s no information provided about how they trained the models, and in particular, about whether or not the LLM/vision encoder were frozen during training. The model is notable for being (relatively) quite large, at 12B parameters. That&#8217;s much more than the other models discussed here.</p><h2>DeepSeek Janus</h2><p>[<a href="https://arxiv.org/abs/2410.13848v1">abstract</a>]</p><p>Well, as mentioned above, I was about to publish this article, and DeepSeek released Janus. Janus is a fascinating piece of work as, in true DeepSeek fashion, it&#8217;s an actual novel architecture. DeepSeek has two visual encoders: one for visual understanding, and one for image generation. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hc2D!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hc2D!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 424w, https://substackcdn.com/image/fetch/$s_!hc2D!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 848w, https://substackcdn.com/image/fetch/$s_!hc2D!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 1272w, https://substackcdn.com/image/fetch/$s_!hc2D!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hc2D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png" width="1422" height="830" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:830,&quot;width&quot;:1422,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:191024,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hc2D!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 424w, https://substackcdn.com/image/fetch/$s_!hc2D!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 848w, https://substackcdn.com/image/fetch/$s_!hc2D!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.png 1272w, https://substackcdn.com/image/fetch/$s_!hc2D!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F503ae629-cc81-4c38-8e38-46c196a6d418_1422x830.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><p>Otherwise, the architecture is basically the same as what we&#8217;ve seen before, a typical &#8220;early fusion&#8221; model that uses a pretrained LLM to process the visual features. The visual understanding model uses a SigLIP encoder to extract visual features, which are then flattened into a 1D sequence, and they have an &#8220;understanding adaptor&#8221; which maps these image features into the input space of the LLM. For visual generation, they use a VQ tokenizer from <a href="https://arxiv.org/abs/2406.06525">LlamaGen</a> to convert the images into sequences of discrete IDs, which are then transformed into embeddings via a generation adaptor. The result is a multimodal sequence that is fed into the decoder model. They use a tree-stage training process which is, again, very similar to other models (particularly, and unsurprisingly, DeepSeek-VL):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!4bfY!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!4bfY!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 424w, https://substackcdn.com/image/fetch/$s_!4bfY!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 848w, https://substackcdn.com/image/fetch/$s_!4bfY!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 1272w, https://substackcdn.com/image/fetch/$s_!4bfY!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!4bfY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png" width="1402" height="516" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:516,&quot;width&quot;:1402,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:158006,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!4bfY!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 424w, https://substackcdn.com/image/fetch/$s_!4bfY!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 848w, https://substackcdn.com/image/fetch/$s_!4bfY!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.png 1272w, https://substackcdn.com/image/fetch/$s_!4bfY!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6eea5554-8c02-4ee7-99ed-5f06de574d22_1402x516.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><p>Their loss function is simply cross-entropy, and for understanding tasks (either text or multimodal) they compute the loss only on the text sequence, while for visual generation tasks, they compute the loss only on the image sequence. During inference, they use CFG in the standard way, with a scale of 5. They claim SOTA on generation when compared to some older models, e.g. DALLE-2, SDXL, etc., when evaluated on the GenEval benchmark, which, while interesting, is not particularly compelling. I&#8217;d prefer to see an Elo ranking vs the most commonly used standard models, such as Flux. The model appears good at prompt following, but not particularly aesthetic; I suspect it would fair poorly against, say, Flux. Having said that, the model performs very well for a 1.3B model. </p><h2>Conclusions</h2><p>With Chameleon, Pixtral, and PaliGemma, it looks like training methodologies are starting to converge. I think that the architecture used by Pixtral (and the pretraining recipe used by Chameleon) will basically be the recipe that most SOTA VLMs are using, if they&#8217;re not already.</p><p>Something worth noting is how (relatively) little compute was used to train many of the open source VLMs. The biggest LLaVa model used 768 A100 hours. DeepSeek-VL used 61440 A100 hours (512 A100s for 5 days). PaliGemma used ~12k A100-equivalent hours (18k TPU v5e hours).</p><p>Compare to, say, MovieGen, which used 6144 H100s for an unknown amount of time, or Stable Diffusion, which used <a href="https://www.notion.so/Novel-sampling-techniques-1180a181e3568013b0e0e7fee7886638?pvs=21">150k A100 hours</a>. Presumably the large AI labs are using much more compute/data to train their models; Chameleon, for instance, using 10T tokens, is much more in line with what I would expect for a SOTA model.</p><p>The two big decisions that have to be made when training a VLM appear to be 1) how to combine image/text inputs and 2) whether or not to train the visual &amp; language features separately. CogVLM did very well with a 17B model with keeping the models frozen. DeepSeek-VL trained everything after some careful freezing during pre-training. Chameleon trained everything from scratch. I think that it&#8217;s obviously cheaper with little to no degradation in quality to use a pretrained encoder, so I think that&#8217;s the route to go with. And &#8220;early fusion&#8221;, where the image features are concatenated to the text embeddings, seems elegant while performing well. That is probably the route I would go (basically following PaliGemma).</p><p>In short, the standard recipe appears to be:</p><ol><li><p>Use a ViT for the image encoder, initialized from a large open source model (SigLip, Clip, etc.)</p></li><li><p>Use a pretrained LLM as the base model</p></li><li><p>Finetune the combined model</p></li></ol><p>I see no evidence that it makes a difference whether we add the image/text data as inputs to the model, or do some fancier combination deeper in the model, like CogVLM or Flamingo did. The more recent models, like Qwen or DeepSeek, do well just having the image features added to the sequence data.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><p>Finally, another reminder that I will be giving a talk as part of the <a href="https://www.youtube.com/playlist?list=PL_lsbAsL_o2DnQyMUrVTEv8EtIX0hn8KT">PyTorch Expert Exchange</a> lecture series on how batching works on modern GPUs, based on the <a href="https://www.artfintel.com/p/how-does-batching-work-on-modern">article I wrote last year</a>. Please join me!</p>]]></content:encoded></item><item><title><![CDATA[Papers I've read this week]]></title><description><![CDATA[This is a grab bag of papers.]]></description><link>https://www.artfintel.com/p/papers-ive-read-this-week-713</link><guid isPermaLink="false">https://www.artfintel.com/p/papers-ive-read-this-week-713</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Wed, 10 Jul 2024 00:41:34 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!3VEd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a grab bag of papers. No theme, just what I found interesting. I&#8217;ve had a bunch of tabs open and finally (<em>finally)</em> got through them. </p><p>I hope to write more frequently going forward: the goal is once per month. My darling toddler has not been sleeping consistently, so my writing time has been exceptionally limited. Currently this has improved, and with luck, will stay improved.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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 Artificial Fintelligence! 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><h1>Training LLMs over Neurally Compressed Text</h1><p>[<a href="https://arxiv.org/abs/2404.03626">abstract</a>]</p><p>The authors train LLMs over compressed text. When training language models, the current paradigm doesn&#8217;t involve raw text, but instead, trains the model over sequences of <em>tokens</em>, which are, basically, compressed text. The most common tokenizer is <a href="https://huggingface.co/learn/nlp-course/en/chapter6/5">BPE</a> (used by GPT-3, Llama/Mistral, etc.). The idea behind tokenization is that tokenizers transform the raw text into a much more efficient representation: BPE is typically 4x more efficient than raw bytes, so the LLM sees 4x the data for a given computational budget.</p><p>The natural question, then, is: why stop at 4x? Is there something better than BPE? There really hasn&#8217;t been&#8212; almost every LLM uses BPE for tokenization, although, as usual, there&#8217;s a lack of details about the latest foundation models. In the limit, a perfect compression algorithm should remove all predictable information from the sequence of bytes, so that shouldn&#8217;t be predictable, but could a tokenizer that&#8217;s, say, 8x more efficient than raw text be 2x as good as BPE?</p><p>The authors use a variety of compression techniques to train LLMs on ever more compressed text, looking at:</p><ul><li><p>GZip</p></li><li><p>LLM based compression (which achieved a 12x compression ratio!).</p></li><li><p>Arithmetic encoding with logits conditioned on the sequence of text seen so far, i.e. </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\hat{p}(x_i | x_0, \\ldots, x_{i-1})&quot;,&quot;id&quot;:&quot;RJIFNMXDGY&quot;}" data-component-name="LatexBlockToDOM"></div></li><li><p>Arithmetic encoding with static logits, i.e. </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\hat{p}(x_i | x_0, \\ldots, x_{i-1}) = \\hat{p}(x_i)&quot;,&quot;id&quot;:&quot;XVQACXNXHY&quot;}" data-component-name="LatexBlockToDOM"></div></li></ul><p>They also use a technique which they developed, that splits the text into equal sized windows that each contain 32 bits of compressed information.</p><p>They find that their best models underperform subword baselines, and all the compression schemes (including GZip, which I found surprising) are learnable by standard LLMs, but the performance is worse than standard sub-word tokenizers, like BPE. However, their method <em>does</em> outperform byte-level baselines.</p><p>To a certain extent, this is unsurprising; the goal behind compression is to remove any predictable patterns from the original sequence of bytes, so if we had a perfect compressor, the resulting output would be indistinguishable from random noise. What is surprising, though, is that BPE just happens to be the sweet spot for compression.</p><p>How <a href="https://dl.acm.org/doi/abs/10.1145/214762.214771">arithmetic coding</a> works is:</p><ol><li><p>A message is represented by an interval of real numbers between 0 and 1.</p></li><li><p>As the message grows, the interval needed to represent it becomes smaller, so the number of bits needed grows.</p></li><li><p>you take as inputs an alphabet, which assigns a cardinality to the characters (i.e. an ordering from 0 to n) and a model that assigns probabilities to the characters from the alphabet conditioned on the previous characters in the sequence, i.e.</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;p(x_t | x_1, \\ldots, x_{t-1})&quot;,&quot;id&quot;:&quot;GHFVUNXQPK&quot;}" data-component-name="LatexBlockToDOM"></div></li><li><p>Finally, we get an interval of two floating point numbers that represent the number.</p></li></ol><p>The original <a href="https://dl.acm.org/doi/abs/10.1145/214762.214771">paper</a> has a great example describing exactly how this works. The key takeaway is that arithmetic coding presents a way to use a probability distribution to compress text, and the better that our model represents the underlying distribution over characters, the more efficient the message.</p><p>The authors train a 3M parameter decoder in a fairly standard way, and use encoder</p><p>They use equal information windows, where they encode text into a series of N-bit windows, resetting the AC encoder when it can no longer add bits without exceeding the target bit threshold. Windows represent variable amounts of text, but should represent the same amount of information.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3VEd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3VEd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 424w, https://substackcdn.com/image/fetch/$s_!3VEd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 848w, https://substackcdn.com/image/fetch/$s_!3VEd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 1272w, https://substackcdn.com/image/fetch/$s_!3VEd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3VEd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png" width="1456" height="1062" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1062,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:273486,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3VEd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 424w, https://substackcdn.com/image/fetch/$s_!3VEd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 848w, https://substackcdn.com/image/fetch/$s_!3VEd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.png 1272w, https://substackcdn.com/image/fetch/$s_!3VEd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3f454aa3-1f97-479e-ac1b-30caf6e36dec_1558x1136.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><p>Once they have the compressed sequence of bits, they then create tokens by grouping every N bits into a token, creating a vocabulary of size 2^N. They try with N = 8 and N = 16. This seems suboptimal to me&#8212; there&#8217;s no semantic meaning to the tokens!</p><p>The paper has a fascinating table showing how each of these changes weakens the compression ratios:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aEmB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aEmB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 424w, https://substackcdn.com/image/fetch/$s_!aEmB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 848w, https://substackcdn.com/image/fetch/$s_!aEmB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 1272w, https://substackcdn.com/image/fetch/$s_!aEmB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aEmB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png" width="1456" height="558" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:558,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:142239,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aEmB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 424w, https://substackcdn.com/image/fetch/$s_!aEmB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 848w, https://substackcdn.com/image/fetch/$s_!aEmB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.png 1272w, https://substackcdn.com/image/fetch/$s_!aEmB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F69aa2146-ac35-481b-9bf5-e1842f344923_1582x606.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><p>The authors make a point of using the same hyperparameters for every training run they do. I think this is a mistake; a proper benchmark would tune the hyperparameters for each setting. </p><p>Their results are interesting:</p><ul><li><p>ArithmeticCoding and StaticAC settings are &#8220;essentially unlearnable&#8221;, failing to outperform their naive baseline which assigns equal probability to all tokens (aside: I love this baseline. more papers should include dumb heuristic baselines. we had a &#8220;UniformRandom&#8221; baseline agent in all our game theory papers and it performed remarkably well.)</p></li><li><p>EqualInfoAC performs the best, coming close to matching SentencePiece.</p></li></ul><p>They have some really interesting ablations, which show that the SentencePiece tokens are much more semantically relevant than EqualInfoAC:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!UBLt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!UBLt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 424w, https://substackcdn.com/image/fetch/$s_!UBLt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 848w, https://substackcdn.com/image/fetch/$s_!UBLt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 1272w, https://substackcdn.com/image/fetch/$s_!UBLt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!UBLt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png" width="1456" height="526" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:526,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:120975,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!UBLt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 424w, https://substackcdn.com/image/fetch/$s_!UBLt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 848w, https://substackcdn.com/image/fetch/$s_!UBLt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.png 1272w, https://substackcdn.com/image/fetch/$s_!UBLt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7dac502a-fa86-43df-987f-1e137b1afe18_1560x564.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><p>The other ablations are fascinating. This was an excellent paper with strong empirical work. I would encourage you to read it.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>Mixture of Depths</h2><p>[<a href="https://arxiv.org/abs/2404.02258">abstract</a>]</p><p>A windmill that is constantly being tilted at in decoder-centric LLM research is the fact that each token receives the same amount of compute. This seems clearly wrong. This paper proposed a novel method, Mixture of Depths (MoD), that dynamically allocates FLOPs to specific positions in a sequence.</p><p>The obvious comparison is to the Mixture of Experts (MoE) models. The MoD method can be thought of as using the routing logic from MoE models, but deploying a single expert with dynamic skipping based on the routing logic.</p><p>At a high level, the algorithm is:</p><ol><li><p>Determine a compute budget which limits the number of tokens in a sequence that participate in a given block (say: 50% of the sequence participates in self-attention).</p></li><li><p>Use a per-block router to emit scalar weights for each token.</p></li><li><p>Select the top-k weights per block and sequence to participate in the block&#8217;s computation.</p></li></ol><p>Note how similar this is to a MoE model.</p><p>They use expert choice routing, as it removes the need for the oft-complicated auxiliary losses which are required for token-choice routing. The big problem, of course, is that the top-k operation is non-causal, which is why expert-choice routing isn&#8217;t used in any (published) MoE papers. They use a causal predictor-based approach, which has minimal degradation:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EUu3!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EUu3!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 424w, https://substackcdn.com/image/fetch/$s_!EUu3!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 848w, https://substackcdn.com/image/fetch/$s_!EUu3!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 1272w, https://substackcdn.com/image/fetch/$s_!EUu3!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EUu3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png" width="1456" height="799" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:799,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:310187,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EUu3!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 424w, https://substackcdn.com/image/fetch/$s_!EUu3!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 848w, https://substackcdn.com/image/fetch/$s_!EUu3!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.png 1272w, https://substackcdn.com/image/fetch/$s_!EUu3!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc89a2026-df18-47cb-a460-1fa2e5c468b0_1614x886.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><p>Their results are nice; they find that MoD is a nice improvement, lowering loss compared to the isoFLOP vanilla model. Additionally, they find that the MoD improvements compound with the improvements from training a MoE 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_!12zU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!12zU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 424w, https://substackcdn.com/image/fetch/$s_!12zU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 848w, https://substackcdn.com/image/fetch/$s_!12zU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 1272w, https://substackcdn.com/image/fetch/$s_!12zU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!12zU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png" width="1456" height="1044" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1044,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:299068,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!12zU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 424w, https://substackcdn.com/image/fetch/$s_!12zU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 848w, https://substackcdn.com/image/fetch/$s_!12zU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.png 1272w, https://substackcdn.com/image/fetch/$s_!12zU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c57c9c0-7436-4b38-96ab-843b5a131cfe_1606x1152.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><p>The implications of this paper are fascinating; one can imagine a family of ever more complex routing mechanisms which let every decision become learned.</p><h2>Sparse Upcycling: Training MoE models from dense checkpoints</h2><p>[<a href="https://arxiv.org/abs/2212.05055">abstract</a>]</p><p>The paper proposes a method to initialize a MoE model from a dense one, showing that this outperforms the original, dense model with only using 50% of the original compute, and also outperforming MoE models trained from scratch with the same compute budget.</p><p>The paper makes the fascinating observation that the vast majority of SOTA neural network are trained <em>from scratch</em>, which, in many ways, is assumed to be the default way that all models are trained. Given the <a href="https://arxiv.org/abs/1803.03635">lottery ticket hypothesis</a>, it&#8217;s not at all clear that this is optimal. Even though the weights are chosen <a href="https://xkcd.com/221/">randomly</a>, this doesn&#8217;t mean that they&#8217;re good; the joke that RL researchers like to make that the random seed is a crucial hyperparameter is actually a valid tactic to take when deploying systems into production. If OpenAI could produce a better ChatGPT by using seed 3 rather than seed 5, they&#8217;d absolutely do that.</p><p>In any case, the paper explores developing cheaper ways of training large models by using existing models. This is much more relevant now than when the paper was released (ICLR 2023, so the work was probably done in the second half of 2022): we&#8217;re training much larger models with much more compute and doing so much more often.</p><p>Generally speaking, <a href="https://www.artfintel.com/p/papers-ive-read-this-week-mixture">Mixture of Experts work</a> by having N copies of each layer (we call each copy an expert), and learning to allocate tokens to each expert. The upcycling algorithm that they propose creates a MoE model by expanding a subset of the MLP layers in the original, dense model into MoE layers, and copying the remaining layers of the dense model across to the MoE. Each expert is then initialized identically, as a copy of the original MLP, and the routers are randomly initialized. They continue training the model using the same hyperparameters (batch size, learning rate, etc.). They even find that <em>resuming the optimizer state</em> from the original dense checkpoint works well, which I find surprising.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kCVi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kCVi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 424w, https://substackcdn.com/image/fetch/$s_!kCVi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 848w, https://substackcdn.com/image/fetch/$s_!kCVi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 1272w, https://substackcdn.com/image/fetch/$s_!kCVi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kCVi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png" width="1456" height="874" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/dd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:874,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:266316,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kCVi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 424w, https://substackcdn.com/image/fetch/$s_!kCVi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 848w, https://substackcdn.com/image/fetch/$s_!kCVi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.png 1272w, https://substackcdn.com/image/fetch/$s_!kCVi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fdd8de344-a9d9-4456-b74f-5f321e014c10_1480x888.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><p>The results are, bluntly, quite good. The slope of improvement in the validation metrics seems to change immediately. It seems as if by upcycling the model, new avenues of performance are immediately unlocked.</p><p>Given the earlier results from the Mixture of Depths paper, which suggested that MoD models compose with MoE models, this suggests a natural experiment: train a MoD model to some level of performance, and then upcycle it to a MoE/MoD model. As an engineer, I shudder at the resulting complexity, but it should have a significant jump in performance.</p><h2>Replication of Chinchilla</h2><p><a href="https://twitter.com/borgeaud_s/status/1780988694163321250">https://twitter.com/borgeaud_s/status/1780988694163321250</a></p><p>[<a href="https://arxiv.org/abs/2404.10102">abstract</a>]</p><p>Finally, this was quite short, but an exciting development that gave me faith in research. A team at <a href="https://epochai.org/">Epoch AI</a>, an independent research institute that does excellent work, tried <em>reproducing Chinchilla by transcribing the data from the pixels of the chart.</em> Let me repeat that: they reproduced Chinchilla by transcribing the data from the pixels of the original paper. And! What&#8217;s more! They found an error in the paper that caused the original authors to issue a correction and promise to <a href="https://x.com/borgeaud_s/status/1780988694163321250">release the data</a>. Truly excellent work on their behalf.</p><p>The root of the paper comes from the observation that the error bars from Approach 3 of the Chinchilla paper are extremely narrow ([0.454, 0.455] and [0.542, 0.543] for parameters <em>a</em> and <em>b</em>):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kDX4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kDX4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 424w, https://substackcdn.com/image/fetch/$s_!kDX4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 848w, https://substackcdn.com/image/fetch/$s_!kDX4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 1272w, https://substackcdn.com/image/fetch/$s_!kDX4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kDX4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png" width="1456" height="740" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:740,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:1277561,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kDX4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 424w, https://substackcdn.com/image/fetch/$s_!kDX4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 848w, https://substackcdn.com/image/fetch/$s_!kDX4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.png 1272w, https://substackcdn.com/image/fetch/$s_!kDX4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa76a3e0a-b261-4676-abe3-5402f3479745_4096x2082.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><p>Given they only had approximately 400 observations, that&#8217;s implausibly tight. This led to Epoch recreating the data and fitting their own model, which found that the original Chinchilla paper had an error in the estimation code, causing the equation they found to not fit the data particularly well.</p><p>The revised results imply that you can lean much more on the compute side of the compute/data tradeoff:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!j0qA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!j0qA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 424w, https://substackcdn.com/image/fetch/$s_!j0qA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 848w, https://substackcdn.com/image/fetch/$s_!j0qA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 1272w, https://substackcdn.com/image/fetch/$s_!j0qA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!j0qA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png" width="926" height="434" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:434,&quot;width&quot;:926,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:168565,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!j0qA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 424w, https://substackcdn.com/image/fetch/$s_!j0qA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 848w, https://substackcdn.com/image/fetch/$s_!j0qA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.png 1272w, https://substackcdn.com/image/fetch/$s_!j0qA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2a7ec333-256a-470e-a2e6-dee973b4c385_926x434.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><p>If we revisit the excellent <a href="https://www.lesswrong.com/posts/6Fpvch8RR29qLEWNH/chinchilla-s-wild-implications">&#8220;chinchilla&#8217;s wild implications&#8221;</a> article by <a href="https://x.com/nostalgebraist?lang=en">Nostalgebraist</a> and plug in the numbers for GPT-3, Chinchilla, and Gopher, we get 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_!i2qU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!i2qU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 424w, https://substackcdn.com/image/fetch/$s_!i2qU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 848w, https://substackcdn.com/image/fetch/$s_!i2qU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 1272w, https://substackcdn.com/image/fetch/$s_!i2qU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!i2qU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png" width="989" height="590" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:590,&quot;width&quot;:989,&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_!i2qU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 424w, https://substackcdn.com/image/fetch/$s_!i2qU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 848w, https://substackcdn.com/image/fetch/$s_!i2qU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.png 1272w, https://substackcdn.com/image/fetch/$s_!i2qU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F96991f99-6a4b-4059-ad33-0315d2e50832_989x590.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><p>Across the board, the contribution of data to the loss increases, while the contribution of the model size decreases. So the conclusion from the updated data is that the number of tokens is less important than originally thought, but GPT-3 era models were still trained with not nearly enough data. This would imply that following a GPT-3 style approach, which trains a large model on less data, is more reasonable than the original Chinchilla paper implied.</p><p>In practice, it&#8217;s not clear how much this matters, because everyone is trying to get as much data as possible and train the biggest model they can afford, but it does show that on the margin, spending more money on GPUs and less on data labellers is worth doing (did Jensen sponsor this work? &#129300;). </p><p>Misc AI articles I&#8217;m reading:</p><ul><li><p>An <a href="https://x.com/EpochAIResearch/status/1774860862148284525">excellent article</a> by <a href="https://x.com/EgeErdil2">Ege Erdil</a> of Epoch about why we should expect inference &amp; training budgets to be approximately equal</p></li><li><p>Horace He&#8217;s excellent article on <a href="https://www.thonking.ai/p/what-shapes-do-matrix-multiplications">why matrix shapes matter so much for performance</a>.</p></li></ul><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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 Artificial Fintelligence! 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><item><title><![CDATA[How does batching work on modern GPUs?]]></title><description><![CDATA[The first and most important optimization you can do for any modern deep learning system, generally speaking, is to implement batching.]]></description><link>https://www.artfintel.com/p/how-does-batching-work-on-modern</link><guid isPermaLink="false">https://www.artfintel.com/p/how-does-batching-work-on-modern</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Fri, 01 Mar 2024 16:35:17 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!KnyU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The first and most important optimization you can do for any modern deep learning system, generally speaking, is to implement batching. When you batch inference, instead of sending a single input, you send a batch of N inputs. Most of the time, depending on the specific value of N, this is free&#8212; running inference takes the exact same amount of time with a single example as it does with N examples. Why is this? At first, it seems like processing the batch shouldn&#8217;t be free&#8212; after all, Nx more work is being done.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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>And with a naive model of how neural networks work, it isn&#8217;t free. The batched calculation requires Nx the compute to run, and, in fact, if you run this on CPU, you&#8217;ll see that this is true (average inference time for ResNet50, <a href="https://colab.research.google.com/drive/1BoiNq1a8NSy9zUsFlrStCBZ_qSDKeLev?usp=sharing">Colab</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_!KnyU!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!KnyU!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 424w, https://substackcdn.com/image/fetch/$s_!KnyU!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 848w, https://substackcdn.com/image/fetch/$s_!KnyU!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 1272w, https://substackcdn.com/image/fetch/$s_!KnyU!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!KnyU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png" width="567" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:567,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24320,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!KnyU!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 424w, https://substackcdn.com/image/fetch/$s_!KnyU!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 848w, https://substackcdn.com/image/fetch/$s_!KnyU!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 1272w, https://substackcdn.com/image/fetch/$s_!KnyU!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F17b8861c-d027-4429-afeb-5caa17b194b7_567x432.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg 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><p>However, when you run the same example on a modern GPU, this isn&#8217;t the case. This is what we see (on a T4):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!AT3g!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!AT3g!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 424w, https://substackcdn.com/image/fetch/$s_!AT3g!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 848w, https://substackcdn.com/image/fetch/$s_!AT3g!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 1272w, https://substackcdn.com/image/fetch/$s_!AT3g!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!AT3g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png" width="584" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:584,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:27121,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!AT3g!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 424w, https://substackcdn.com/image/fetch/$s_!AT3g!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 848w, https://substackcdn.com/image/fetch/$s_!AT3g!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.png 1272w, https://substackcdn.com/image/fetch/$s_!AT3g!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F13a78198-c445-4a7b-b749-c3c507c6f6e1_584x432.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></figure></div><p>Going from a batch size of 1, to 2, to 3 requires no additional time, and then after that it increases linearly.</p><p>Why is this? Concurrency. Modern GPUs run their operations concurrently (and are, actually, slower than CPUs on a per-thread basis).</p><p>When we think of &#8220;calculating inference for an example with a model&#8221;, we typically think of the model as a single block, when, of course, it&#8217;s made up of many matrices. When we run inference, each matrix is loaded into memory. Specifically, each <em>block</em> of the matrix is loaded into on-device memory, namely the shared memory unit (only 192kb big on an A100). The block is then used to compute the results for every element in the batch. Note that <em>this is not the same as GPU RAM</em>, i.e. HBM. An A100 has 40GB or 80GB of HBM depending on the model, but only 192kb of on-device memory. This creates a memory bandwidth bottleneck when performing mathematical operations, as we are constantly moving data in and out of the on-device memory. We can approximate the time it takes to transfer the weights by calculating the model size / memory bandwidth ratio, and approximate the time it takes to do the calculation by model FLOPS / GPU FLOPS.</p><p>With an MLP, the FLOPS are approximately <a href="https://www.stat.cmu.edu/~ryantibs/convexopt-F18/scribes/Lecture_19.pdf">2 * the number of parameters * the number of elements in the batch</a> (2 * m * n * b for a batch size of <em>b</em> and a <em>m x n</em> matrix). As a result, the transfer time is equal to the calculation time when</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{P}{\\text{memory bandwidth}} = \\frac{2 \\cdot B \\cdot P}{\\text{FLOPS}}&quot;,&quot;id&quot;:&quot;MDRQUKGOGW&quot;}" data-component-name="LatexBlockToDOM"></div><p>Note that we can cancel out the number of parameters here:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{1}{\\text{memory bandwidth}} = \\frac{2 \\cdot B}{\\text{GPU FLOPS}}&quot;,&quot;id&quot;:&quot;CWVBXZMUAN&quot;}" data-component-name="LatexBlockToDOM"></div><p>And rearrange in terms of the batch size:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\frac{\\text{GPU FLOPS}}{2\\cdot\\text{memory bandwidth}} = B&quot;,&quot;id&quot;:&quot;YZQSVYQKKB&quot;}" data-component-name="LatexBlockToDOM"></div><p>When the batch size is less than the ratio of FLOPS to memory bandwidth, we are bottlenecked by memory bandwidth. When it is <em>more</em>, we are bottlenecked by FLOPS. Note that this analysis is for a MLP, not for a convolutional network, like ResNet50. That gets a bit trickier.</p><p>On a T4 GPU (<a href="https://www.nvidia.com/content/dam/en-zz/Solutions/Data-Center/tesla-t4/t4-tensor-core-datasheet-951643.pdf">datasheet</a>), we have 65 TFLOPS of fp32, and 300 gb/s of memory bandwidth, so the magic ratio should be 216. When we run a MLP (depth: 8, width: 1024), we see roughly what we&#8217;d 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_!77tO!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!77tO!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 424w, https://substackcdn.com/image/fetch/$s_!77tO!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 848w, https://substackcdn.com/image/fetch/$s_!77tO!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 1272w, https://substackcdn.com/image/fetch/$s_!77tO!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!77tO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png" width="593" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:593,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:25503,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!77tO!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 424w, https://substackcdn.com/image/fetch/$s_!77tO!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 848w, https://substackcdn.com/image/fetch/$s_!77tO!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.png 1272w, https://substackcdn.com/image/fetch/$s_!77tO!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F87cfa006-cf96-44f4-b5a2-2c02833238a7_593x432.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><p>There&#8217;s some noise, but it&#8217;s basically what we&#8217;d expect: inference time starts increasing dramatically around the ~128 mark (here, we double the batch size, so we see batches at 128, 256, and then 512). And, if we vary the width of the MLP layers, we see this is true across a broad variety of architectures (the following is a log-log plot, to fit everything in):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!sNw5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!sNw5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 424w, https://substackcdn.com/image/fetch/$s_!sNw5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 848w, https://substackcdn.com/image/fetch/$s_!sNw5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 1272w, https://substackcdn.com/image/fetch/$s_!sNw5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!sNw5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png" width="578" height="437" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:437,&quot;width&quot;:578,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:40484,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!sNw5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 424w, https://substackcdn.com/image/fetch/$s_!sNw5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 848w, https://substackcdn.com/image/fetch/$s_!sNw5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.png 1272w, https://substackcdn.com/image/fetch/$s_!sNw5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F06eac8fe-410c-4412-9046-ad1d20a7d44d_578x437.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><p>This is pretty cool! We can see the critical threshold across a broad variety of different architectures. What&#8217;s also interesting is that the smaller networks don&#8217;t really see any scaling, taking roughly constant time across the entire range of batch sizes (from 1 to 512). My hand-wavy explanation for this is that this is because GPUs are really, really fast when it comes to actually doing math, but everything else (CPUs, etc.) is kinda slow. We see a <em>ton</em> of noise at the start, which I don&#8217;t have a great explanation for (other than shrugging and saying &#8220;overhead&#8221;).</p><p>For many ML engineers, their time isn&#8217;t spent doing much machine learning, but rather it&#8217;s spent just getting rid of overhead, which is typically in the non-ML code. In reinforcement learning (RL) research, particularly for researchers who work on continual learning problems, where there&#8217;s a single agent taking a long stream of actions, it&#8217;s often not worth it to use a GPU for experiments unless either 1) you have a very large network or 2) you extensively optimize every other aspect of your stack (if you want to make an old DeepMind engineer squirm, ask them about in-graph environments&#8212; at one point, we were implementing RL environments within the tensorflow graph).</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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><h2>What about convolutional networks?</h2><p>In a convolutional network, the weights are equal to the number of filters times the filter size. For <code>torch.nn.Conv2d</code> , this is <code>kernel_size^2 * out_channels</code>. So if we have a (224, 224) image with a stride of 1 and a kernel size of 3, we apply the same filter 224 times. This means that, basically, for a convolutional layer, there&#8217;s much less advantage to batching, as we&#8217;re reusing the same weights many, many times. For a pooling layer, it&#8217;s basically linear in the number of pixels, as you&#8217;d expect.</p><h2>What about transformers?</h2><p>Transformers are basically just MLPs, so we can treat them as the same. They have an attention mechanism, obviously, but with a KV cache (which keeps the computed data around in memory), the time taken by attention is minimal. I wrote about <a href="https://www.artfintel.com/p/where-do-llms-spend-their-flops">this a lot previously</a>.</p><p>The same is true for a Mixture of Experts model. In many transformer implementations, the KV cache lives inside the attention class (e.g. <a href="https://github.com/google/maxtext">MaxText</a> is a <a href="https://github.com/google/maxtext/blob/main/MaxText/layers/attentions.py#L91">great example</a>). As the only difference between a MoE model and a vanilla decoder is that some of the feedforward layers are replaced with MoE layers, the KV cache will behave the same, as will inference, with one wrinkle.</p><p>The wrinkle is that the gating mechanism in a MoE layer will split the batch across experts, so if the gate doesn&#8217;t split the batch uniformly, this can cause problems. There are different routing mechanisms which avoid this (e.g. expert&#8217;s choice) but in autoregressive decoders, you&#8217;re pretty much forced to only use token&#8217;s choice, which has a tendency towards biased gates. Forcing the gate to evenly allocate tokens is 1) an area of active research and 2) an important goal that is optimized during training.</p><p>I hope this has been helpful&#8212; please reach out if you have any batching questions (or, more importantly, any corrections).</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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><item><title><![CDATA[Where do LLMs spend their FLOPS?]]></title><description><![CDATA[LLM theory, with a hint of empirical work]]></description><link>https://www.artfintel.com/p/where-do-llms-spend-their-flops</link><guid isPermaLink="false">https://www.artfintel.com/p/where-do-llms-spend-their-flops</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Mon, 29 Jan 2024 16:28:04 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Ok folks. I had a longer holiday break than expected thanks to some family illnesses. I&#8217;m still <s>lowering</s> adjusting my expectations for how often I can expect to be healthy, now that I have a toddler. Sickness. Lots, and lots of sickness. </p><p>This is a <em>long </em>article, so you might want to bookmark this and read it on your computer, not your phone.</p><p>Here, I conduct a theoretical analysis of LLM performance, and then profile an <em>actual</em> LLM to see where the empirical results differ from the theory. First, the theory. I will rely on the excellent <a href="https://kipp.ly/transformer-inference-arithmetic/#flops-counting">blog post</a> by <a href="https://twitter.com/kipperrii">Kipply</a> to fill in the details. The basic takeaway is that for a standard decoder model, our FLOPS are allocated as follows (on a per-layer basis):</p><ol><li><p>6 d^2 to compute QKV</p></li><li><p>2d^2 to compute the attention output matrix, <code>softmax(Q @ K.T) @ V</code></p></li><li><p>16 d^2 to run the FFN</p></li></ol><p>The sum is 24d^2 FLOPS. Percentage-wise, we spend 25% of the time computing QKV, ~8% computing the attention output matrix, and ~66% of the time running the FFN.</p><p>What about the attention mechanism? Well, as everyone knows, the attention equation is</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{softmax}\\left(\\frac{QK^T}{\\sqrt{d_\\text{head}}}\\right)V&quot;,&quot;id&quot;:&quot;IYWOHBBLEE&quot;}" data-component-name="LatexBlockToDOM"></div><p>With a KV cache (you <em>are</em> using a KV cache, right anon?), Q, K, and V are all d-dimensional vectors (equivalently, <code>(d, 1)</code> matrices). So it takes <a href="https://www.stat.cmu.edu/~ryantibs/convexopt-F18/scribes/Lecture_19.pdf">~2d flops for each dot-product</a> and d flops for the d divisions that happen, for a total of ~5d flops, rounding to nothing:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\dfrac{5d}{24d^2} = \\dfrac{5}{24d}&quot;,&quot;id&quot;:&quot;QLEMDNDMFO&quot;}" data-component-name="LatexBlockToDOM"></div><p>For d equal to 4096 (the value it takes in Llama7b) this is 0.005%, so nothing. This makes it seem like the attention mechanism doesn&#8217;t matter, but of course, we only use a KV cache (and flash attention, etc.) because it matters so much. Think of Milton Friedman&#8217;s <a href="https://worthwhile.typepad.com/worthwhile_canadian_initi/2010/12/milton-friedmans-thermostat.html">thermostat analogy</a> (h/t <a href="https://twitter.com/bradchattergoon/status/1744008010924483069">@bradchattergoon</a>):</p><blockquote><p>If a house has a good thermostat, we should observe a strong negative correlation between the amount of oil burned in the furnace (M), and the outside temperature (V). But we should observe no correlation between the amount of oil burned in the furnace (M) and the inside temperature (P). And we should observe no correlation between the outside temperature (V) and the inside temperature (P).</p><p>An econometrician, observing the data, concludes that the amount of oil burned had no effect on the inside temperature. Neither did the outside temperature. The only effect of burning oil seemed to be that it reduced the outside temperature.</p><p>A second econometrician, observing the same data, concludes that causality runs in the opposite direction. The only effect of an increase in outside temperature is to reduce the amount of oil burned. An increase in V will cause a decline in M, and have no effect on P.</p><p>But both agree that M and V are irrelevant for P. They switch off the furnace, and stop wasting their money on oil.</p></blockquote><p>The KV cache does require O(T) memory (where T is the number of tokens we wish to generate), which ain&#8217;t cheap (see: $NVDA). </p><p>How big is the KV cache? Well, for each token, we store the following number of many bytes (the first 2 is because we assume bf16 precision, so 2 bytes per parameter, and the second 2 is because we have to store both the K and the V tensors):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2 \\cdot 2 \\cdot n_{\\text{layers}} \\cdot n_{\\text{heads}}\\cdot d_{\\text{head}}&quot;,&quot;id&quot;:&quot;TIIZHOCJDB&quot;}" data-component-name="LatexBlockToDOM"></div><p>Note that, by assumption, n_heads * d_head = d_model = d, so the number of bytes is 4 * the number of layers * d.</p><p>For GPT-3, we have 96 layers with a <code>d_model</code> of 12288, so we need 4.72 MB per token. It would thus require 5.6GB to generate 2048 tokens.</p><p>Having said this, to generate a sequence of a given length with a given model, we still need to use the exact same amount of memory as the KV cache requires, we just throw it away at the end of each forward pass. So we don&#8217;t need <em>more</em> memory. In a sense, the KV cache is free (modulo some tedious bookkeeping, at least in Jax).</p><p>How does this change for more modern architectures, like Mistral 7B? Mistral 7b uses <a href="https://paperswithcode.com/method/grouped-query-attention">Grouped query attention</a> (as does Llama2&#8212; almost as if there&#8217;s an overlap in authors or something&#8230;) and sliding window attention.</p><p>In GQA, you share the KV projection across multiple heads, either a single KV projection across all heads (<a href="https://arxiv.org/abs/1911.02150">MQA</a>) or into multiple groups (<a href="https://arxiv.org/abs/2305.13245v3">GQA</a>). These are all equivalent to standard multi-head attention (MHA) with a smaller <code>d_model</code>. Earlier, we did the KV cache calculations assuming that the number of heads * the head dimension is equal to the model dimension, but for MQA/GQA we relax that assumption. As the KV cache formula is</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;2 \\cdot 2 \\cdot n_{\\text{layers}} \\cdot n_{\\text{heads}}\\cdot d_{\\text{head}}&quot;,&quot;id&quot;:&quot;CDSPFIGFLX&quot;}" data-component-name="LatexBlockToDOM"></div><p>we change this to be</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;4 \\cdot n_{\\text{layers}} \\cdot d_{\\text{effective model}}&quot;,&quot;id&quot;:&quot;HUBURMZLOH&quot;}" data-component-name="LatexBlockToDOM"></div><p>where the number of heads * the head dimension is the effective model dimension. Thus, we see a linear decrease in the KV cache size as the number of KV heads decreases (one of the key motivating factors behind GQA/MQA).</p><p>The parameters of the Llama{1,2} models are given by:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!OvAt!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!OvAt!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 424w, https://substackcdn.com/image/fetch/$s_!OvAt!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 848w, https://substackcdn.com/image/fetch/$s_!OvAt!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 1272w, https://substackcdn.com/image/fetch/$s_!OvAt!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!OvAt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png" width="1060" height="318" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:318,&quot;width&quot;:1060,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:57015,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!OvAt!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 424w, https://substackcdn.com/image/fetch/$s_!OvAt!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 848w, https://substackcdn.com/image/fetch/$s_!OvAt!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.png 1272w, https://substackcdn.com/image/fetch/$s_!OvAt!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcf6b1db7-f33f-4c1e-9123-0bcf61bef78d_1060x318.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><p>So for Llama 2, the KV cache required per token is:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qsde!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qsde!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 424w, https://substackcdn.com/image/fetch/$s_!qsde!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 848w, https://substackcdn.com/image/fetch/$s_!qsde!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 1272w, https://substackcdn.com/image/fetch/$s_!qsde!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qsde!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png" width="1456" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:88841,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qsde!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 424w, https://substackcdn.com/image/fetch/$s_!qsde!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 848w, https://substackcdn.com/image/fetch/$s_!qsde!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.png 1272w, https://substackcdn.com/image/fetch/$s_!qsde!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd2ff8e22-07a1-4726-b422-9e39c304ee02_1476x438.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><p>Without GQA, the 34B model would take 5x as much memory for the KV cache, and the 70B model would take 8x more memory.</p><p>Sliding window attention, another one of the Llama/Mistral tweaks, guarantees that we can cap the KV cache at the window size, which is 4096 for Llama7B.</p><h1>Performance motivated architectural changes</h1><p>As discussed, above, a LLM uses 24d^2 FLOPS per layer. Increasing the number of layers linearly scales the number of flops, and the number of parameters. Increasing the model <em>width</em> quadratically scales the model size. Note that this is because the number of parameters scales quadratically with d_model, as most of our layers go from a d_model input vector to a d_model output vector, so we have weight matrices that are <code>(d_model, d_model)</code> in size. Another way of putting this is that compute scales linearly with the number of parameters, and increasing <code>d_model</code> increases the number of parameters quadratically. Making the model 2x deeper doubles the parameters, but making it 2x wider <em>quadruples</em> the parameters.</p><p>Having said this, one advantage of a wider model is that it parallelizes better. To compute the Nth layer, you must first compute the preceding N-1 layers. This is <a href="https://medium.com/nerd-for-tech/an-overview-of-pipeline-parallelism-and-its-research-progress-7934e5e6d5b8">difficult to parallelize</a> efficiently, particularly during training, while it is much easier to split a single layer across GPUs via <a href="https://huggingface.co/docs/text-generation-inference/conceptual/tensor_parallelism">tensor paralellism</a>. If you care mostly about latency, then you probably want to bias yourself towards a wider model.</p><h1>Empirical analysis</h1><p>I did this analysis using Colab (<a href="https://colab.research.google.com/drive/1TH6AKsICZqlFoW1ph8h3wsF7q7qVMF8T?usp=sharing">notebook</a>). Here&#8217;s the high-level profile for a single forward pass (<a href="https://finbarr.ca/static/llama-profile.svg">interactive profile on my website</a>):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aEWE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aEWE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 424w, https://substackcdn.com/image/fetch/$s_!aEWE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 848w, https://substackcdn.com/image/fetch/$s_!aEWE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 1272w, https://substackcdn.com/image/fetch/$s_!aEWE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aEWE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png" width="1456" height="143" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:143,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:140912,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aEWE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 424w, https://substackcdn.com/image/fetch/$s_!aEWE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 848w, https://substackcdn.com/image/fetch/$s_!aEWE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 1272w, https://substackcdn.com/image/fetch/$s_!aEWE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5af516a6-cd68-430a-8b4c-992e185eb565_2378x234.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>We see that 4.88% of the overall time from this run was spent within this single forward pass. Of the forward pass, 1.98% is spent in attention, while 2.58% is spent in the MLP. Of the total time spent in the forward pass, 40% of the time is in the attention layer, and 53% in the MLP. Within the attention layer, the time is being spent on 4 different linear layers, 2 of them taking approximately equal time (linear_1, linear_2), one of them taking 50% more (linear_3), and one of them taking twice as long as the first two (linear_0). My guess is that the linear_0 is calculating the Query embedding, while linear_1/2 are calculating the Key and Value embeddings. Note how much quicker the calculation is because of the smaller number of KV heads! GQA makes a tangible difference, even though the attention mechanism being used (<a href="https://facebookresearch.github.io/xformers/components/ops.html">xformers.ops.memory_efficient_attention</a>) requires that the QKV embeddings be broadcasted to the same size.  </p><p>If we go back to our theoretical analysis, it predicted that 2/3rds of the time would be calculating the FFN, and 1/3rd on calculating attention. That&#8217;s roughly in line with what we see; we spend slightly more time calculating attention than the MLP, but I suspect that&#8217;s because the MLP is executing a very well-optimized path for Torch.</p><h2>Performance changes</h2><p>I then ran a number of experiments with Llama2 where I swept over the model width and depth. These are the results:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!J1sx!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!J1sx!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 424w, https://substackcdn.com/image/fetch/$s_!J1sx!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 848w, https://substackcdn.com/image/fetch/$s_!J1sx!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 1272w, https://substackcdn.com/image/fetch/$s_!J1sx!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!J1sx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png" width="567" height="433" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:433,&quot;width&quot;:567,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16329,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!J1sx!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 424w, https://substackcdn.com/image/fetch/$s_!J1sx!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 848w, https://substackcdn.com/image/fetch/$s_!J1sx!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.png 1272w, https://substackcdn.com/image/fetch/$s_!J1sx!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe5900857-9180-41c6-a76e-14d9d1f7550b_567x433.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><p>This is really interesting. We see basically no change in speed for the two models with a hidden size of 1024 and 1536 (1.10s vs 1.11s), and only a minor one (1.15s vs 1.10s) for the 1024 vs 2048 model. However, when we compare the models with hidden dimensions of 2048 (1.15s), 3072 (1.41s), and 4096 (1.82s), we start to see what looks like linear scaling!</p><p>My explanation is that there&#8217;s non-trivial overhead from dispatching the kernels and actually running the matmuls. This was run on a T4 (<a href="https://www.nvidia.com/content/dam/en-zz/Solutions/Data-Center/tesla-t4/t4-tensor-core-datasheet-951643.pdf">specs</a>), which, although dated by modern standards, still has 65 TFLOPS of bf16 compute. If we multiply two 1024x1024 matrices together, that requires 1GFLOP of compute, so we can (theoretically) multiply 65000 1024x1024 matrices together per second. In practice, we&#8217;d only get 60-80% of that, but that&#8217;s still 40000 matmuls per second. A lot of this advantage comes the massive number of cores that modern GPUs have. A T4 has 2560 CUDA cores, each running at between <a href="https://www.techpowerup.com/gpu-specs/tesla-t4.c3316">585 and 1590 MHz</a>. As a result, any task that can be parallelized will do well, but those that require sequential calculation will not be as optimized. I think that&#8217;s what we&#8217;re seeing here- there&#8217;s not enough parallelism to actually occupy the GPU.</p><p>The transformer depth causes performance to behave exactly as you&#8217;d expect: inference time increases linearly with depth. There&#8217;s some noise when it comes to the deepest models, but it&#8217;s pretty well-behaved.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!EfZd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!EfZd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 424w, https://substackcdn.com/image/fetch/$s_!EfZd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 848w, https://substackcdn.com/image/fetch/$s_!EfZd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 1272w, https://substackcdn.com/image/fetch/$s_!EfZd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!EfZd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png" width="567" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f8285187-ca90-49cc-a304-0fec540b30b9_567x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:567,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:17758,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!EfZd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 424w, https://substackcdn.com/image/fetch/$s_!EfZd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 848w, https://substackcdn.com/image/fetch/$s_!EfZd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.png 1272w, https://substackcdn.com/image/fetch/$s_!EfZd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8285187-ca90-49cc-a304-0fec540b30b9_567x432.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><p>I then calculated the cost as we generate more tokens (I did 10 runs for each number of tokens, to reduce the noise):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!mM5S!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!mM5S!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 424w, https://substackcdn.com/image/fetch/$s_!mM5S!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 848w, https://substackcdn.com/image/fetch/$s_!mM5S!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 1272w, https://substackcdn.com/image/fetch/$s_!mM5S!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!mM5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png" width="567" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:567,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19100,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!mM5S!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 424w, https://substackcdn.com/image/fetch/$s_!mM5S!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 848w, https://substackcdn.com/image/fetch/$s_!mM5S!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.png 1272w, https://substackcdn.com/image/fetch/$s_!mM5S!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa54955b3-97c2-4b99-a1b3-913d4a66de9f_567x432.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><p>It&#8217;s exactly linear, as you&#8217;d expect, because Llama2 uses a KV cache. If we look at the reserved memory, we see the KV cache working as expected (somewhat):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!9Bwu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!9Bwu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 424w, https://substackcdn.com/image/fetch/$s_!9Bwu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 848w, https://substackcdn.com/image/fetch/$s_!9Bwu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 1272w, https://substackcdn.com/image/fetch/$s_!9Bwu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!9Bwu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png" width="571" height="432" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:432,&quot;width&quot;:571,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:19304,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!9Bwu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 424w, https://substackcdn.com/image/fetch/$s_!9Bwu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 848w, https://substackcdn.com/image/fetch/$s_!9Bwu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.png 1272w, https://substackcdn.com/image/fetch/$s_!9Bwu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffe1d3cd8-ead6-4687-939f-b4f5c7911f2f_571x432.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><p>We see that the model has a jump of ~2.1MB every 20 tokens. As this model has <code>d_model</code> of 1024 and 8 hidden layers, it needs 4 * num_layers * d_model bytes of memory, or 4 * 8 * 1024 bytes = 32KB of memory per token. We <em>should</em> only need 640KB of memory. It&#8217;s unclear where the extra 3x overhead comes from. I suspect the answer is an inefficient implementation. </p>]]></content:encoded></item><item><title><![CDATA[The evolution of the LLM API market]]></title><description><![CDATA[Before I studied machine learning, I was an Econ grad student banging out OLS problem sets (I see the OLS equation&#8212; (X&#8217;X)^-1X&#8217;y&#8212; whenever I close my eyes, I derived it so many times).]]></description><link>https://www.artfintel.com/p/the-evolution-of-the-llm-api-market-dcf</link><guid isPermaLink="false">https://www.artfintel.com/p/the-evolution-of-the-llm-api-market-dcf</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Wed, 13 Dec 2023 15:15:08 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!_1KW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Before I studied machine learning, I was an Econ grad student banging out OLS problem sets (I see the OLS equation&#8212; <code>(X&#8217;X)^-1X&#8217;y</code>&#8212; whenever I close my eyes, I derived it so many times). My research area was antitrust theory, and in particular, vertical integration. That gives me a unique perspective: how will the LLM API market evolve as more companies enter the space?</p><p>The market began, famously, with OpenAI releasing ChatGPT and rapidly hitting <a href="https://www.theinformation.com/articles/openais-revenue-crossed-1-3-billion-annualized-rate-ceo-tells-staff">$1.3B in revenue</a>. At this time last year, however, there was basically no competition in the LLM API market. Bard was yet to be released, let alone Claude, and Gemini was a mere twinkle in Sundar&#8217;s eyes. OpenAI had a monopoly in the market, letting them capture basically all of the value.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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>In the year since, what we&#8217;ve seen is that there doesn&#8217;t appear to be a moat in LLMs except at the highest end. GPT-4 is the only model which doesn&#8217;t have competition, and there are competitors sniffing around&#8212; Gemini Ultra, Llama 3, and the as-yet-unreleased mysterious Mistral model bigger than medium. At the GPT 3.5 level, however, you have many options for hosting, and you can even host it yourself. This necessarily limits the prices any company can charge.</p><p>Generally speaking, companies enter a new market when they think they can make a profit above the minimum threshold they require. The larger the company is, the smaller the profit threshold they require. If I, an individual, were to start offering a service to finetune LLMs, I would need to charge a fairly high margin at first, as I would have a small customer base to spread the costs over. As my company grows, I would have a larger customer base to spread the costs over, and would have more money to spend on optimizations enabling me to serve LLMs for cheaper:</p><ul><li><p>Quantization</p></li><li><p>Buying your own chips instead of renting them</p></li><li><p>Distilling models</p></li><li><p><em>Building</em> your own chips</p></li></ul><p>with each optimization that you do to make your own process more efficient, you increase your margin. That&#8217;s great! You make more money per token. Right? Well, not quite. In a vacuum with a <a href="https://en.wikipedia.org/wiki/Spherical_cow">spherical cow</a>, you do. But just as you invest in your ability to serve tokens more efficiently, your competitors are all doing the same, eroding your margins. To do a bad Ben Horowitz impersonation, <a href="https://genius.com/Jay-z-legacy-hova-lyrics">You run this hard just to stay in place</a>.</p><p>The necessary implication is that the undifferentiated LLM market will become a ruthless competition for efficiency, with companies competing to see who can demand the lowest return on invested capital.</p><p>In the classic business strategy book, the <a href="https://en.wikipedia.org/wiki/The_Innovator%27s_Dilemma">Innovator&#8217;s Dilemma</a>, there lives what is the canonical example for how technological disruption happens (this is taken from <a href="https://www.newyorker.com/magazine/2012/05/14/when-giants-fail">the New Yorker profile</a> on the author, Clayton Christensen):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_1KW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_1KW!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 424w, https://substackcdn.com/image/fetch/$s_!_1KW!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 848w, https://substackcdn.com/image/fetch/$s_!_1KW!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 1272w, https://substackcdn.com/image/fetch/$s_!_1KW!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_1KW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png" width="1456" height="844" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:844,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:271522,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_1KW!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 424w, https://substackcdn.com/image/fetch/$s_!_1KW!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 848w, https://substackcdn.com/image/fetch/$s_!_1KW!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png 1272w, https://substackcdn.com/image/fetch/$s_!_1KW!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.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><p>In the world of steel manufacturing, historically, steel was made in massive integrated mills. They made high quality steel with reasonable margins. Then came along electric mini mills. These mills were able to make the lowest quality steel at a cheaper cost. The large steel manufacturers saw this, shrugged, and focused on making high quality steel at a (relatively) high margin. Over time, the electric mini mill operators figured out how to make higher and higher quality steel, moved upmarket, and killed the massive integrated mills (US Steel&#8212; once the 16th largest corporation by market cap in the US&#8212; was removed from the S&amp;P 500 in 2014).</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?group=true&amp;coupon=9ee370da&quot;,&quot;text&quot;:&quot;Get 20% off a group subscription&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?group=true&amp;coupon=9ee370da"><span>Get 20% off a group subscription</span></a></p><p>The analogy to LLMs is straightforward. The large labs focus on making the highest performing models. They are expensive, but excellent, and outperform every other model. However, they are expensive. You need margin to pay for all of those <a href="https://www.levels.fyi/companies/openai/salaries/software-engineer">$900k engineers</a>! Even then, however, we see competition on price. Gemini Pro</p><p>At the low end, we have the open source community, led by Meta and <a href="https://www.reddit.com/r/LocalLLaMA/">r/LocalLlama</a>, which are cranking out high quality models and figuring out how to serve them on <a href="https://finbarr.ca/how-is-llama-cpp-possible/">ridiculously low powered machines</a>. We should expect to see the open weight models improve in quality and decrease in cost (on a quality adjusted basis), putting pressure on the margins of the largest labs. As a real-time example, <a href="https://www.together.ai/">Together</a> <a href="https://twitter.com/togethercompute/status/1734282721982324936">came out with a hosted version</a> of Mixtral that is 70% cheaper than Mistral&#8217;s own version. </p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!W8H1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!W8H1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 424w, https://substackcdn.com/image/fetch/$s_!W8H1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 848w, https://substackcdn.com/image/fetch/$s_!W8H1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 1272w, https://substackcdn.com/image/fetch/$s_!W8H1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!W8H1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png" width="1188" height="304" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:304,&quot;width&quot;:1188,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70121,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!W8H1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 424w, https://substackcdn.com/image/fetch/$s_!W8H1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 848w, https://substackcdn.com/image/fetch/$s_!W8H1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.png 1272w, https://substackcdn.com/image/fetch/$s_!W8H1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F0388f07a-71b8-4d4b-9cf3-02dfcf21adb1_1188x304.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><p>We should thus expect a bifurcated market. At the high end live more expensive, higher quality models, and at the low end, lower quality, less expensive models. For open weights models, we should expect their price to converge to price of GPUs + electricity (and as <a href="https://www.semianalysis.com/p/amd-mi300-performance-faster-than">competition increases in the GPU market</a>, perhaps just to the price of electricity).</p><p>The question, then, is what does the buyer for these APIs look like? If we were to rank the economically valuable tasks that LLMs can perform from most complex to least complex, how many of the tasks require high end complexity? At some point there&#8217;s a threshold where GPT-4 is required, but it&#8217;s hard to image that the threshold will remain static. The open weight models will continue their inexorable climb up the list, biting at the margins of the large labs. As tooling makes it easier to effortlessly switch between model APIs, the developers using the API will switch to whatever the lowest cost model is that accomplishes their task. If you&#8217;re using a LLM for, say, <a href="https://github.com/features/copilot">short-length code completion</a>, do you need the biggest and best model? Probably not!</p><p>Moreover, the companies with the biggest success in the consumer marketplace will inevitably start to balk at paying a significant amount of their profits to another company, and will start to train their own models. We see companies like <a href="https://www.harvey.ai/">Harvey</a>, and <a href="https://cursor.sh/">Cursor</a>, which were some of the companies with the earliest access to GPT-4, start to hire <a href="https://www.harvey.ai/careers/research-scientist">research scientists</a>/<a href="https://www.harvey.ai/careers/principal-staff-research-engineer">engineers</a>, giving them the talent required to train their own foundation models. As API fees are probably the biggest expense for these companies, it seems natural that they will do everything they can to reduce their costs as much as possible.</p><p>If you&#8217;re building your own models, you can go out and raise a round of investment to invest in your own models, trading off a one-time capital expenditure to increase your overall margins. This is the justification for Google&#8217;s TPU program, for example. By spending billions of dollars on custom silicon, they&#8217;re able to avoid paying Nvidia&#8217;s Danegeld.</p><p>The conclusion, then, is that we will see the market for LLM APIs converge to one of lowest cost <em><strong>as long as your task is simple enough to be solved by open weight models</strong></em>. If your task is so complex that it requires the best model, you&#8217;re stuck paying OpenAI. For everyone else, there&#8217;s finetuned <a href="https://mistral.ai/news/announcing-mistral-7b/">Mistral 7B</a>.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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><item><title><![CDATA[The evolution of the LLM API market]]></title><description><![CDATA[Note: if you&#8217;re coming to this post online, this is the same as the free post, I ran into issues opening this article up on Substack.]]></description><link>https://www.artfintel.com/p/the-evolution-of-the-llm-api-market</link><guid isPermaLink="false">https://www.artfintel.com/p/the-evolution-of-the-llm-api-market</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Tue, 12 Dec 2023 16:30:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!_1KW!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd40caa01-9f04-47cb-ac76-392b804cf46b_1498x868.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Note: if you&#8217;re coming to this post online, this is the same as the free post, I ran into issues opening this article up on Substack. </em></p>
      <p>
          <a href="https://www.artfintel.com/p/the-evolution-of-the-llm-api-market">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[Transformer inference tricks]]></title><description><![CDATA[How to make your model run faster than a greased pig]]></description><link>https://www.artfintel.com/p/transformer-inference-tricks</link><guid isPermaLink="false">https://www.artfintel.com/p/transformer-inference-tricks</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Thu, 23 Nov 2023 16:26:35 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!vZfa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Transformer inference tricks</h1><p><em>Special thanks to <a href="https://x.com/cis_female?s=21">@cis_female</a></em> <em>for discussing the intricacies of sparsity with me, and <a href="https://twitter.com/nostalgebraist?lang=en">@nostalgebraist</a> for correcting an error in the quantization section; I now think that the evidence shows that quantizing, at least to 4 bits or more, has a very minimal tradeoff in terms of performance.</em></p><p>I&#8217;m going to discuss a number of optimizations that can be done to make inference for transformers either faster or more efficient.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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><h1>KV Cache</h1><p>By far the most common (and most important) optimization for a decoder is a KV cache. In a decoder model, the keys and values will be identical for the prompt for every iteration of decoding. Moreover, once you&#8217;ve ran a token through, the keys and values will be the same for that token for every subsequent iteration. As a result, you can cache the prompt, and incrementally add the KV tensors for each token to the cache as they are decoded. Doing so removes a lot of compute. Inside the attention mechanism, we&#8217;re able to go from multiplying two tensors of shape (batch, context_length, feature_dim) to multiplying a query tensor of shape (batch, 1, feature_dim) with your KV tensors of shape (batch, context_length, feature_dim). Consequently, sampling is no longer quadratic in complexity, allowing us to get decent decoding (sampling) performance with longer context lengths.</p><p>In practice, this causes added complexity inside your implementation, as you now have state rather than just running pure functions, so you have to keep running inference for the same sequences, even if one is done (see, eg, the Google <a href="https://github.com/google/maxtext">MaxText implementation</a>).</p><p>The KV cache <a href="https://kipp.ly/transformer-inference-arithmetic/#kv-cache">requires</a> 2 * n_layers * n_heads * d_head parameters. For GPT-3, with n_layers = 96, n_heads=96, d_head = 128, this would require 2.4M parameters for every token in your context. With typical 16-bit precision, this would require 5MB per token; if you have a context window of 2048 tokens, that&#8217;s 10GB of HBM dedicated to your KV cache. Expensive, but not outrageous. And well worth every GB.</p><p>These memory requirements are a big part of the reason why it&#8217;s so hard to use consumer grade GPUs for LLMs&#8212; the most powerful consumer card is the 4090, which has only 24GB of HBM. It has FLOPS that are comparable to the enterprise grade chips, but the memory limits are much lower, making it difficult to fit the weights and the KV cache into memory.</p><h1>Speculative decoding</h1><p><a href="https://arxiv.org/abs/2211.17192">Speculative decoding</a> is a technique that is used when you have excess compute capacity, typically in the local inference setting. It exploits the property of modern accelerators whereby it takes the same amount of time to run inference on a batch of data as it does to run inference on a single datapoint. For an A100, for instance, you can run inference on up to 160 datapoints in the same amount of time as a single datapoint. As a result, many techniques have cropped up to exploit this, such as beam search, MCTS, or speculative decoding.</p><p>In speculative decoding, one has two models: a small, fast, one, and a large, slow one. As the inference speed for a modern decoder is directly proportional to the number of parameters, with a smaller model, one can run multiple inferences in the time it takes a large model to run a single inference.</p><p>In modern decoder models, like the GPT family of models, they use autoregressive sampling, whereby to sample a sequence of N tokens, the model runs inference N times, each time consuming the result of the previous inference.</p><p>In speculative decoding, you run two models in parallel. The fast one runs a batch of inference and guesses which tokens the big model will predict. It compounds these guesses. In the meantime, the big model is running in the background, checking that the smaller model recorded the same results. The small model is able to make many guesses in the same time that the big model is able to make one. However, given that we have spare compute capacity, the big model is able to evaluate all of the guesses in parallel. As such, the only place where we pay the sequential cost of generating a sequence is for the smaller 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_!vZfa!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!vZfa!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 424w, https://substackcdn.com/image/fetch/$s_!vZfa!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 848w, https://substackcdn.com/image/fetch/$s_!vZfa!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 1272w, https://substackcdn.com/image/fetch/$s_!vZfa!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!vZfa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png" width="1308" height="560" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:560,&quot;width&quot;:1308,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:193034,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!vZfa!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 424w, https://substackcdn.com/image/fetch/$s_!vZfa!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 848w, https://substackcdn.com/image/fetch/$s_!vZfa!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.png 1272w, https://substackcdn.com/image/fetch/$s_!vZfa!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9a160c23-f817-4e48-a540-980d7e3df268_1308x560.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><p>The major disadvantage to speculative decoding is that it requires a &#8220;draft&#8221; model that is able to predict the output of the larger model, and you have to have both models in memory on the same machine (or on the same node in a multi-GPU setting). This adds complexity, and requires additional work, as you have to be training two models (the original one, and the &#8220;draft&#8221; one). Moreover, any performance benefits are limited by how accurately the smaller model is able to predict the larger one. If the smaller model was consistently able to predict the behaviour of the larger model, we&#8217;d just use it! Consequently, there&#8217;s a fundamental gap in how well speculative decoding can perform. <a href="https://www.notion.so/Transformer-inference-tricks-c8c0bb5094684be49a50ba448f0cd9f6?pvs=21">HuggingFace</a> has claimed that it typically doubles the decoding rate, which is consistent with the original paper, which <a href="https://arxiv.org/abs/2211.17192">claimed a 2x-3x improvement</a>.</p><p>A <a href="https://lmsys.org/blog/2023-11-21-lookahead-decoding/">technique</a> recently came out which tries to improve on this by having the model generate n-grams, and recursively match them, without requiring a draft model. There&#8217;s a technique called Jacobi decoding (figure taken from their blog) which is a potential improvement over greedy decoding. How it works is that, at every point where you generate a token, you generate <em>n</em> tokens, making a &#8220;guess&#8221; as to the entire sequence. Then, you verify this against your previous guess; if the two match, then you accept the guess. This can enable latency improvements with no downside, as in the worse case, it devolves into greedy decoding.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!kVbI!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!kVbI!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 424w, https://substackcdn.com/image/fetch/$s_!kVbI!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 848w, https://substackcdn.com/image/fetch/$s_!kVbI!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 1272w, https://substackcdn.com/image/fetch/$s_!kVbI!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!kVbI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png" width="1376" height="606" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:606,&quot;width&quot;:1376,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:382004,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!kVbI!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 424w, https://substackcdn.com/image/fetch/$s_!kVbI!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 848w, https://substackcdn.com/image/fetch/$s_!kVbI!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.png 1272w, https://substackcdn.com/image/fetch/$s_!kVbI!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6c9a05fd-266e-4f73-9592-6ae3fa38eb48_1376x606.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><p>Lookahead decoding improves on this further by keeping the n-grams that have been generate through the decoding process, and trying to use them as guesses. Given that there is a high correlation between the text that has been generated and the text that will be generated, this also has the possibility to improve latency dramatically, with minimal cost. It&#8217;s a very clever trick. I&#8217;m unaware of anyone using it, given how the technique was announced yesterday; very curious to see how it performs in real world scenarios.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iHn7!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iHn7!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 424w, https://substackcdn.com/image/fetch/$s_!iHn7!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 848w, https://substackcdn.com/image/fetch/$s_!iHn7!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 1272w, https://substackcdn.com/image/fetch/$s_!iHn7!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iHn7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png" width="1430" height="796" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:796,&quot;width&quot;:1430,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:653825,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iHn7!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 424w, https://substackcdn.com/image/fetch/$s_!iHn7!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 848w, https://substackcdn.com/image/fetch/$s_!iHn7!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.png 1272w, https://substackcdn.com/image/fetch/$s_!iHn7!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe3885264-e7e0-4247-8eb1-14b53b084428_1430x796.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><h1>Effective sparsity</h1><p>In a decoder transformer, the beating heart of the model is the attention mechanism, summarized in the attention equation:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!PX2Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!PX2Q!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 424w, https://substackcdn.com/image/fetch/$s_!PX2Q!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 848w, https://substackcdn.com/image/fetch/$s_!PX2Q!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 1272w, https://substackcdn.com/image/fetch/$s_!PX2Q!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!PX2Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png" width="940" height="174" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:174,&quot;width&quot;:940,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:24805,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!PX2Q!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 424w, https://substackcdn.com/image/fetch/$s_!PX2Q!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 848w, https://substackcdn.com/image/fetch/$s_!PX2Q!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 1272w, https://substackcdn.com/image/fetch/$s_!PX2Q!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3d194e8d-6534-42a4-882a-7a2d8d7bfd63_940x174.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The softmax operation makes values that are <em>not</em> the max really small</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Laqf!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Laqf!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 424w, https://substackcdn.com/image/fetch/$s_!Laqf!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 848w, https://substackcdn.com/image/fetch/$s_!Laqf!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 1272w, https://substackcdn.com/image/fetch/$s_!Laqf!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Laqf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png" width="848" height="308" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/391adbee-49cf-411d-b114-d578fd173fb9_848x308.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:308,&quot;width&quot;:848,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:87361,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Laqf!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 424w, https://substackcdn.com/image/fetch/$s_!Laqf!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 848w, https://substackcdn.com/image/fetch/$s_!Laqf!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.png 1272w, https://substackcdn.com/image/fetch/$s_!Laqf!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F391adbee-49cf-411d-b114-d578fd173fb9_848x308.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><p>:</p><p>Consequently, we are multiplying the values tensor (<strong>V</strong> in the attention equation) by a tensor that is mostly zeros. As a result, the output of the attention mechanism has a lot of zeros&#8212; up to 97% (h/t <a href="https://x.com/YesThisIsLion/status/1647747069086666752?s=20">@yesthisislion</a>). Similarly, after each ReLU in the MLPs, we also have a lot of sparsity.</p><p>Now, unfortunately, it&#8217;s kinda tough to actually make use of this. If we have sparsity in the weights, there&#8217;s a lot of work that can be done there through structured sparsity (e.g. <a href="https://pytorch.org/docs/stable/sparse.html">torch.sparse</a>), but it&#8217;s not actually clear how much current systems are able to make use of activation sparsity.</p><p>One optimization that can be done, is that if an activation is zero, you can just skip loading the weights that correspond to that activation, and skip the corresponding computation. This isn&#8217;t really supported in mainstream tensor programs as far as I can tell, but for a custom inference implementation, like, say, <a href="https://github.com/ggerganov/llama.cpp">Llama.cpp</a> has, it would be easy to implement.</p><p>The reason for this is that the activations are a function of each token, and thus, so too is the effective sparsity, causing it to be randomly distributed over the tokens. As a result, the effectiveness of this decays exponentially with batch size. If we have an effective sparsity of X% and a batch of size N, the likelihood that all entries for a given activation will be zero across the batch is given by X^N. I have a table for varying values of X and N. The decay is dramatic!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YUYQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YUYQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 424w, https://substackcdn.com/image/fetch/$s_!YUYQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 848w, https://substackcdn.com/image/fetch/$s_!YUYQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 1272w, https://substackcdn.com/image/fetch/$s_!YUYQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YUYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png" width="1252" height="706" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:706,&quot;width&quot;:1252,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:73639,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YUYQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 424w, https://substackcdn.com/image/fetch/$s_!YUYQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 848w, https://substackcdn.com/image/fetch/$s_!YUYQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.png 1272w, https://substackcdn.com/image/fetch/$s_!YUYQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2cca5434-aec4-4056-827c-fb1ccf5df009_1252x706.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><p>As a result, it&#8217;s tough to make use of this except in the batch size 1 regime, and even then, it&#8217;s typically more useful to use speculative decoding. But if you&#8217;re trying to run inference locally, and really need to get your latency down, this can be a great trick to use.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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><h1>Quantization</h1><p>Quantization is one of the better known tricks. <a href="https://finbarrtimbers.substack.com/p/efficient-llm-inference">I wrote about it before</a>, so I&#8217;m not going to spend a ton of time on the actual methods. It&#8217;s tough to quantify how well quantization works. Much of the literature, such as the GPTQ paper, was done with models that aren&#8217;t close to SOTA, as the big labs aren&#8217;t publishing, and academics can&#8217;t match the resources that the big labs have.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!_TWi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!_TWi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 424w, https://substackcdn.com/image/fetch/$s_!_TWi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 848w, https://substackcdn.com/image/fetch/$s_!_TWi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 1272w, https://substackcdn.com/image/fetch/$s_!_TWi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!_TWi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png" width="1094" height="472" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:472,&quot;width&quot;:1094,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:125301,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!_TWi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 424w, https://substackcdn.com/image/fetch/$s_!_TWi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 848w, https://substackcdn.com/image/fetch/$s_!_TWi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.png 1272w, https://substackcdn.com/image/fetch/$s_!_TWi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F23750e42-cdd0-4ae7-8f34-c855164090e5_1094x472.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><p>For instance, GPTQ reported results quantizing the OPT &amp; BLOOM models, which are <em>much</em> worse than the current crop of open source models, let alone GPT-4.</p><p>Of course, the big labs aren&#8217;t reporting what they&#8217;re doing, and most of the anecdotal reports I&#8217;ve seen are from people who are trying to run smaller models on consumer grade hardware, which is extremely memory limited. I think that a lot of hobbyists (i.e. people who don&#8217;t work as researchers at big labs) are blinded by the appeal of running a really big model locally, so they get really excited about quantization. But there&#8217;s no intrinsic advantage to quantization! From a first principles perspective, if you have two models that have the same number of bits, they should have the same number of tokens/s, and should have a similar level of performance. There would only be a big difference if we were doing a terrible job of using the bits in higher precision formats.</p><p>The literature doesn&#8217;t agree with my intuition&#8212; the aforementioned GPTQ paper found a negligible decrease in performance from quantizing models to up to 4x lower precision. I think that an explanation for this is that it&#8217;s much easier to quantize worse models without sacrificing performance. If we consider two identical LLMs, one trained with 2 trillion tokens, one trained on 500B tokens (call them LLM-2T, LLM-500B), I think we should expect the one trained with the higher number of tokens to suffer more when quantized, as it should be making better use of the tokens. We&#8217;d still expect the quantized LLM-2T to be better than LLM-500B, but I expect the performance decrease to be bigger from LLM-2T to quantized LLM-2T rather than LLM-500B to quantized LLM-500B.</p><p><em>Note: While I find the above argument compelling, it&#8217;s not at all supported by the literature. Quantizing does appear to be pretty darn close to a free lunch. </em></p><p>More recent work, like the *<a href="https://arxiv.org/abs/2212.09720">k*-bit inference scaling laws paper</a>, ran an incredible number of experiments across a family of LLM architectures, reporting how allocating your bits differently affects performance. They studied the tradeoff between having a model with N parameters at a given level of precision vs having a model with 2N parameters and half the precision. Their results were pretty compelling, being almost indistinguishable from no penalty for quantizing (at least for 4 or more bits):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!CWAX!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!CWAX!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 424w, https://substackcdn.com/image/fetch/$s_!CWAX!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 848w, https://substackcdn.com/image/fetch/$s_!CWAX!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!CWAX!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!CWAX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png" width="1024" height="1038" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1038,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:194744,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!CWAX!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 424w, https://substackcdn.com/image/fetch/$s_!CWAX!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 848w, https://substackcdn.com/image/fetch/$s_!CWAX!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!CWAX!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F186498d3-e8f4-4567-b7c6-008f2b6ffeaf_1024x1038.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><p>They found, basically, that you can go down to 4 bits without any penalty. There is almost no tradeoff from quantizing! You can run a 4x smaller model without a significant drop in performance. As inference performance on modern accelerators is equal to the number of bits you process (i.e. you can get Nx more operations per second when using Nx less precision), this is great.</p><p>My conclusion then, such as it is, is to use the recommendations from the k-bit inference paper. However, I&#8217;m hesitant to recommend using precision that&#8217;s lower than 8-bit for production workloads. fp8 is the lowest precision level floating point format that is supported natively by modern accelerators, and even then, <a href="https://discuss.pytorch.org/t/fp8-support-on-h100/190236">support is limited</a>. I would train and run inference in fp8, and see if the tradeoff in accuracy from quantizing further is acceptable for your usecase. I would struggle to recommend running a lower level of precision in a production environment when it doesn&#8217;t have native support from the platforms (i.e. Nvidia and the Torch/JAX teams). </p><p>As far as I can tell from the literature (which matches my intuition), fp8 is strictly better than int8, but it has limited support in hardware. If you&#8217;re at a <a href="https://www.semianalysis.com/p/google-gemini-eats-the-world-gemini">GPU rich organization</a> and get to use H100s for everything, use fp8. Otherwise, int8 is fine, and is much easier to use&#8212; <a href="https://pytorch.org/docs/stable/quantization.html">PyTorch makes it quite easy</a> (although the APIs are unstable).</p><p>When it comes to actually quantizing your model, the PyTorch team has a writeup of how to <a href="https://pytorch.org/blog/accelerating-generative-ai/">actually do this</a>, and they provide a <a href="https://github.com/pytorch-labs/ao/tree/main#torchao">bunch of APIs</a> to make it easy, although they&#8217;re unstable. <code>bitsandbytes</code> is another excellent library for quantization, although I haven&#8217;t used it personally.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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">Artificial Fintelligence is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.</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><item><title><![CDATA[Why do LLMs use greedy sampling?]]></title><description><![CDATA["Greedy sampling is the worst form of sampling, except all those other forms that have been tried from time to time." - Winston Churchill, if he worked in NLP.]]></description><link>https://www.artfintel.com/p/why-do-llms-use-greedy-sampling</link><guid isPermaLink="false">https://www.artfintel.com/p/why-do-llms-use-greedy-sampling</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Tue, 17 Oct 2023 15:37:14 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Bp9Q!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb1e25adb-7991-427f-8368-09404364efe3_1242x500.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Why do LLMs use greedy sampling?</h1><p><em>This is a speculative article, so I&#8217;d greatly appreciate any <a href="mailto:finbarrtimbers@gmail.com">feedback</a>, particularly if you disagree.</em></p><p>When I began working on LLMs, I found it pretty surprising that the SOTA in generative text was to greedily sample from the bare outputs of the neural networks. In other words, with GPT-style models, the typical approach to generate a sequence of text is something like:</p><ol><li><p>Run your prompt through your model and generate probabilities over your vocabulary.</p></li><li><p>Choose the most likely token (perhaps with some randomization, maybe with some preprocessing, like top-k or nucleus sampling).</p></li><li><p>If the chosen token is <code>&lt;|endoftext|&gt;</code>, you&#8217;re done; otherwise, concatenate the new token to your prompt and go back to 1.</p></li></ol><p>In games RL research, it is common to instead conduct a much more complicated calculation to choose the next step in your sequence. For instance, <a href="https://web.stanford.edu/~surag/posts/alphazero.html">AlphaZero uses a somewhat complicated algorithm called Monte Carlo Tree Search (MCTS)</a>. Here, I explore some reasons for why LLMs <em>don&#8217;t </em>use a fancier decoding algorithm. </p><p><em>But first, a caveat: there&#8217;s a lot of literature proposing various ways to do this that I&#8217;m not going to engage with, for sake of time. I have a list of references at the end which I&#8217;d encourage you to look at if you want a more detailed look.</em></p><p>The current paradigm of language modelling, with GPT-style decoder models, uses greedy autoregressive sampling to generate a sequence of tokens. This is a somewhat surprising choice; if you look at the history of NLP research, particularly the Neural Machine Translation literature, <a href="https://en.wikipedia.org/wiki/Beam_search">beam search</a> is often needed to reach SOTA performance (e.g. <a href="https://arxiv.org/abs/1703.03906">1703.03906</a>). Similarly, in games research, search is typically many times stronger than any pure neural network approach, and search will strictly dominate wherever it&#8217;s feasible (the exceptions are games like <a href="https://www.deepmind.com/blog/mastering-stratego-the-classic-game-of-imperfect-information">Stratego</a>, where the game tree has much too high of a branching factor to be searched with any non-trivial depth). In games like <a href="https://arxiv.org/abs/1712.01815">Go, Chess</a>, <a href="https://arxiv.org/abs/2112.03178">Poker, or Scotland Yard</a>, search methods dominate.</p><p>By <strong>search</strong>, I am referring to algorithmic search, which I am defining as any method which uses additional compute at inference time to improve the answer. This has nothing to do with Google-style search (which I call &#8220;information retrieval&#8221;).</p><p>So why don&#8217;t GPTs use search? Well, there&#8217;s a few answers to this. The first one is a total copout:</p><ol><li><p>GPTs don&#8217;t use search <em><strong>as far as we know</strong></em>. OpenAI recently raised my eyebrows when they hired <a href="https://twitter.com/polynoamial?lang=en">Noam Brown</a>, an expert on search in games, to work on &#8220;multi-step reasoning, self-play, and multi-agent AI.&#8221; That sounds an awful lot like search to me (and, specifically, sounds a lot like Alpha/MuZero). We also know that Demis has talked about <a href="https://www.wired.com/story/google-deepmind-demis-hassabis-chatgpt/">Gemini incorporating techniques</a> from AlphaGo, which, again, makes me think about search (not to mention self-play).</p><p>So it&#8217;s entirely possible that search is the secret sauce behind GPT-4&#8217;s performance, and the lack of it is why the open source world has been unable to match it. I&#8217;m suspicious of this&#8212; for reasons I&#8217;ll get into below&#8212; but if I were actively working on LLM research, I&#8217;d be focusing on trying to use search.</p></li></ol><p>Let&#8217;s assume, then, that the key players (GPT-4, Claude, etc.) aren&#8217;t using search. Why?</p>
      <p>
          <a href="https://www.artfintel.com/p/why-do-llms-use-greedy-sampling">
              Read more
          </a>
      </p>
   ]]></content:encoded></item><item><title><![CDATA[More on Mixture of Experts models]]></title><description><![CDATA[6 papers on different routing mechanisms]]></description><link>https://www.artfintel.com/p/more-on-mixture-of-experts-models</link><guid isPermaLink="false">https://www.artfintel.com/p/more-on-mixture-of-experts-models</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Thu, 07 Sep 2023 14:38:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!hORB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is a follow up article to <a href="https://finbarrtimbers.substack.com/p/papers-ive-read-this-week-mixture">one I wrote</a> at the beginning of August. That article was a discussion of Mixture of Expert models, and dove into how they work at a high level. After writing it, I had a lot of people suggesting more MoE papers to read, so I decided to do that. This article is a summary of 6 papers that explore different routing techniques, and cover a broad swath of the research landscape. </p><h1>Routing techniques</h1><p>There are several broad families of routing techniques:</p><ol><li><p>Fully differentiable techniques, where the routing layer is but one layer in the network (although typically much smaller than the actual transformer blocks), and</p></li><li><p>Linear programming techniques, where the routing layer solves an isolated optimization problem.</p></li><li><p>Non-parametric approaches, e.g. hashing, which don&#8217;t solve or learn anything. These are mostly used for benchmarking.</p></li></ol><p>Most research that focuses on high performance (as in, models that are good at modelling language) focus on either #1 or #2. The trend recently has been to focus on fully differentiable techniques, but it&#8217;s not clear to me how much that&#8217;s supported by the results, vs a decision that&#8217;s supported by the bias that most researchers have towards end-to-end learning (which, itself, is supported by research results from other domains, such as deep RL).</p><p>There are six papers that I will discuss in this post:</p><ol><li><p><a href="https://arxiv.org/abs/1308.3432">RL routing</a>, which focuses on the underlying theory allowing us to back-propagate through stochastic neurons, but which doesn&#8217;t propose a specific method. This is included because it&#8217;s cited by most subsequent papers.</p></li><li><p><a href="https://arxiv.org/abs/2106.04426">Non-parametric hash layers</a>, which randomly comes up with a fixed token &#8596; expert assignment once, and uses that indefinitely. The hash layers serve as a strong baseline, but probably shouldn&#8217;t be used in production.</p></li><li><p><a href="https://proceedings.mlr.press/v139/lewis21a.html">BASE</a>, which solves a linear assignment problem to allocate tokens to experts.</p></li><li><p><a href="https://arxiv.org/abs/2106.03760">Differentiable Select-K</a>, which is a fully differentiable version of the standard <a href="https://arxiv.org/abs/1701.06538">sparsely gated MoE layer</a>.</p></li><li><p><a href="https://arxiv.org/abs/2202.09368">Expert choice routing</a>, which reverses the standard &#8220;token choice&#8221; framework where tokens choose the top expert for them to be routed to, and instead has each <strong>expert</strong> choose the top K tokens for it to see.</p></li><li><p><a href="https://arxiv.org/abs/2306.03745">Soft MoE</a>, which sends all tokens to every expert and combines the results with weights which are learned on a per-token basis.</p></li></ol><p>This isn&#8217;t an exhaustive literature review, but is an attempt at summarizing the papers that one would want to read to get close to the state of the art if one were planning to implement a MoE system. If you haven&#8217;t read my <a href="https://finbarrtimbers.substack.com/p/papers-ive-read-this-week-mixture">previous MoE post</a>, I&#8217;d encourage you to do that first.</p><h2>RL routing</h2><p><a href="https://arxiv.org/abs/1308.3432">Abstract</a></p><p>This paper is <em>ancient</em> (it&#8217;s from 2013!) but provides a lot of the background for using RL to route MoE models. They examine a question of how to estimate the gradient of a loss function with respect to the input of stochastic/hard non-linear neurons, as we can&#8217;t naively backprop through them. This is a problem which arises in the MoE work&#8212; see, for instance, the soft MoE paper later on, which has a solution to this as a key selling point.</p><p>The core idea is that it is possible to obtain estimated gradients by introducing small random perturbations in the system and observing the effects&#8212; the definition of the derivative!</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f&#8217;(x) := \\frac{\\lim_{h\\to 0} f(x + h) - f(x)}{h}&quot;,&quot;id&quot;:&quot;CFXRUDSGWQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>We can numerically approximate this! Doing this naively is inefficient, as independently perturbing N parameters is Nx more expensive, but if we randomly introduce stochasticity in a way so that gradients can sometimes flow, we can then backprop in the standard way and adjust the neurons accordingly. The example is <a href="https://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf">dropout</a>&#8212; it also introduces a hard non-linearity with some probability, but we can still backprop through it without issue when the parameter is not dropped out. In the paper, they consider equations of the form</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_i = f(a_i, z_i),&quot;,&quot;id&quot;:&quot;LYMPPPUZLY&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em>a</em>_i is an input, typically the output of other neurons, and <em>z</em>_i is a random variable. They consider 3 options:</p><ol><li><p>The noisy rectifier:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_i=\\max(0,z_i+a_i),E[z_i]=0, h_i= \\max(0,z_i+a_i), E[z_i]=0&quot;,&quot;id&quot;:&quot;MNZBCDWGTP&quot;}" data-component-name="LatexBlockToDOM"></div></li><li><p>The STS unit (Stochastic Times Smooth):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_i=b_i \\cdot p_i, p_i=f(a_i), b_i \\thicksim \\text{Binomial}(p_i),&quot;,&quot;id&quot;:&quot;ITEKZXYAJD&quot;}" data-component-name="LatexBlockToDOM"></div></li></ol><p>where <em>f</em> is some activation function (they use the sigmoid),</p><ol><li><p>The Straight-Through Estimator, where you back-propagate through the hard threshold function as it was the identity. For instance, if we have the function</p></li></ol><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;h_i=1_{z_i>sigmoid(a_i)}&quot;,&quot;id&quot;:&quot;NQBPOTAMSC&quot;}" data-component-name="LatexBlockToDOM"></div><p>then using the ST estimator we&#8217;d set the gradient as</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;g_i= \\frac{\\partial L}{\\partial h_i}&quot;,&quot;id&quot;:&quot;VAURGQIIZV&quot;}" data-component-name="LatexBlockToDOM"></div><p>The ST estimator works quite well in practice:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oPnA!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oPnA!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 424w, https://substackcdn.com/image/fetch/$s_!oPnA!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 848w, https://substackcdn.com/image/fetch/$s_!oPnA!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 1272w, https://substackcdn.com/image/fetch/$s_!oPnA!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oPnA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png" width="602" height="262" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:262,&quot;width&quot;:602,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:49689,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oPnA!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 424w, https://substackcdn.com/image/fetch/$s_!oPnA!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 848w, https://substackcdn.com/image/fetch/$s_!oPnA!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.png 1272w, https://substackcdn.com/image/fetch/$s_!oPnA!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F972928ca-e3cd-4a0a-908c-922766722ad4_602x262.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><p>It significantly outperforms the other stochastic methods when used to train a model to classify MNIST. It&#8217;d be nice to see more experiments to validate these models better; MNIST isn&#8217;t particularly compelling now, although this does date back to 2013.</p><p>The paper is interesting mostly for context into how we can actually train routing layers for MoE models.</p><h2>Non-parametric Hash layers</h2><p><a href="https://arxiv.org/abs/2106.04426">Abstract</a></p><p>This is a paper I&#8217;m revisiting, as I had previously read it while reading <a href="https://arxiv.org/abs/2202.01169">Unified Scaling Laws for Routed Language Models</a>. Intuitively, it doesn&#8217;t make sense to me that a non-parametric approach would perform comparably to a learned approach, so I find this paper compelling, as it demonstrates that a simple non-parametric model can approach the performance of learned models. This mirrors my experience as an AI poker researcher: UniformRandom (literally just picking a random bet) was a surprisingly hard benchmark for our learned agents to beat, and in certain subgames of e.g. <a href="https://en.wikipedia.org/wiki/Scotland_Yard_(board_game)">Scotland Yard</a>, was optimal. I continually found this fact surprising.</p><p>The method itself is quite simple:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hORB!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hORB!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 424w, https://substackcdn.com/image/fetch/$s_!hORB!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 848w, https://substackcdn.com/image/fetch/$s_!hORB!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 1272w, https://substackcdn.com/image/fetch/$s_!hORB!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hORB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png" width="978" height="342" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:342,&quot;width&quot;:978,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:56700,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hORB!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 424w, https://substackcdn.com/image/fetch/$s_!hORB!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 848w, https://substackcdn.com/image/fetch/$s_!hORB!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.png 1272w, https://substackcdn.com/image/fetch/$s_!hORB!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F61b0b591-144f-414d-bf71-594bf9dd12d8_978x342.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><p>In it, the tokens are hashed into a fixed number of buckets, each corresponding to an expert. The routing function uses the original input token rather than the hidden state, so there is no learning happening in the routing layer. As a result, the routing mechanism is fast, deterministic, and robust.</p><p>The authors consider a wide variety of hashing functions:</p><ul><li><p>Random Hash, where they build a lookup table assigning every token to a fixed, random expert.</p></li><li><p>Balanced assignment, in which they build a lookup table which greedily assigns the most frequent tokens to the emptiest buckets. This is more balanced than Random Hashing, but still not perfectly balanced.</p></li><li><p>Bigram Hash, which hashes the current and previous token,</p></li><li><p>Previous Token Hash, which uses the previous token only,</p></li><li><p>Position Hash, hashing based on the position in the sequence</p></li><li><p>Oracle Future hash, used as a baseline, which hashes the <strong>next</strong> token,</p></li><li><p>Predicted Future Token Hash, which predicts the next token, and hashes over the prediction</p></li><li><p>Clustered Hashes, in which they obtain clusters using <a href="https://en.wikipedia.org/wiki/K-means_clustering">k-means</a> over token embeddings from a baseline model, and assign experts to clusters</p></li><li><p>Dispersed hashes: which assigns similar tokens to different buckets, by using the same k-means clusters as Clustered Hashes, but distributing all tokens within each cluster equally across buckets.</p></li></ul><p>A MultiHash layer is also used, in which the authors take N hashing functions, split the token embedding into N segments, and use each function to allocate each embedding segment to a different expert.</p><p>The hashing results are surprisingly good:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!B8Bd!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!B8Bd!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 424w, https://substackcdn.com/image/fetch/$s_!B8Bd!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 848w, https://substackcdn.com/image/fetch/$s_!B8Bd!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 1272w, https://substackcdn.com/image/fetch/$s_!B8Bd!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!B8Bd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png" width="1214" height="500" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:500,&quot;width&quot;:1214,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:150389,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!B8Bd!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 424w, https://substackcdn.com/image/fetch/$s_!B8Bd!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 848w, https://substackcdn.com/image/fetch/$s_!B8Bd!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.png 1272w, https://substackcdn.com/image/fetch/$s_!B8Bd!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff28c3661-a594-4bc5-a3f7-972b0a105813_1214x500.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><p>Their ablations also reveal that the sparse models they try (Hash/Switch) outperform the dense Baseline model they train, as well as the Wider Transformer (755M params). But the Deeper Transformer (also 755M) they train is better than the sparse models. This is interesting; a bunch of the scaling laws paper found that network architecture didn&#8217;t really matter, which isn&#8217;t consistent with my experience, so it&#8217;s nice to see that validated in the experiments here.</p><p>They also compare to BASE layers (which we will discuss later in this article), as shown in the plot on the right, and show an improvement. I&#8217;m surprised by this; I would have expected BASE layers to do strictly better, as they&#8217;re solving a linear programming problem. My suspicion is that the expert embeddings they use aren&#8217;t very good. The Hash Layers are significantly more performant than the BASE layers, as BASE requires two all-to-all communications, which are expensive.</p><p>In their ablations, they find that increasing the number of routing modules increases the advantage that Hash has over Switch. Their hypothesis is that with a small number of routers, learning to route is more important, but this advantage goes away quickly.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qk9B!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qk9B!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 424w, https://substackcdn.com/image/fetch/$s_!qk9B!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 848w, https://substackcdn.com/image/fetch/$s_!qk9B!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 1272w, https://substackcdn.com/image/fetch/$s_!qk9B!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qk9B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png" width="610" height="296" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:296,&quot;width&quot;:610,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:42635,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qk9B!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 424w, https://substackcdn.com/image/fetch/$s_!qk9B!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 848w, https://substackcdn.com/image/fetch/$s_!qk9B!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.png 1272w, https://substackcdn.com/image/fetch/$s_!qk9B!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc8d8c9ae-cc9a-4420-abd6-178ad567eb4e_610x296.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><p>They experiment with all of the different hashing methods, and find that Balanced Assignment is the best (other than the Future token Oracle):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Pc2P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Pc2P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 424w, https://substackcdn.com/image/fetch/$s_!Pc2P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 848w, https://substackcdn.com/image/fetch/$s_!Pc2P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 1272w, https://substackcdn.com/image/fetch/$s_!Pc2P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Pc2P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png" width="1206" height="882" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/de1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:882,&quot;width&quot;:1206,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:197932,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Pc2P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 424w, https://substackcdn.com/image/fetch/$s_!Pc2P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 848w, https://substackcdn.com/image/fetch/$s_!Pc2P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.png 1272w, https://substackcdn.com/image/fetch/$s_!Pc2P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fde1e1732-d99d-4ac4-95dd-9d3a83f99477_1206x882.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><p>The other one that is roughly as good is Dispersed Hash, which randomizes tokens within each cluster across all the experts, making it effectively a more complicated randomization. This makes sense; from what I&#8217;ve seen reading routing papers, the most important characteristic is that tokens are balanced across experts so that the experts are trained well.</p><p>They perform a comparison on Wikitext-103, which finds that with a smaller BPE dictionary, the Hash layer does better than a Switch Transformer:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!-iJE!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!-iJE!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 424w, https://substackcdn.com/image/fetch/$s_!-iJE!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 848w, https://substackcdn.com/image/fetch/$s_!-iJE!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 1272w, https://substackcdn.com/image/fetch/$s_!-iJE!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!-iJE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png" width="1234" height="404" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:404,&quot;width&quot;:1234,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:103662,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!-iJE!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 424w, https://substackcdn.com/image/fetch/$s_!-iJE!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 848w, https://substackcdn.com/image/fetch/$s_!-iJE!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.png 1272w, https://substackcdn.com/image/fetch/$s_!-iJE!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F19196b3b-0200-48c9-82fe-2e407e0adea2_1234x404.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><p>I suspect this is due to token balancing (or rather, unbalanced tokens). With a smaller BPE dictionary, I suspect the switch transformer struggles to balance the tokens, which the hash layer does by construction.</p><p>When they add in multiple hash functions, performance slightly increases, but not at a level that seems worth the complexity to me:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!zl_P!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!zl_P!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 424w, https://substackcdn.com/image/fetch/$s_!zl_P!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 848w, https://substackcdn.com/image/fetch/$s_!zl_P!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 1272w, https://substackcdn.com/image/fetch/$s_!zl_P!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!zl_P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png" width="1210" height="368" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/bdce456b-3589-4035-bb88-923cdf153836_1210x368.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:368,&quot;width&quot;:1210,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:96327,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!zl_P!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 424w, https://substackcdn.com/image/fetch/$s_!zl_P!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 848w, https://substackcdn.com/image/fetch/$s_!zl_P!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.png 1272w, https://substackcdn.com/image/fetch/$s_!zl_P!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fbdce456b-3589-4035-bb88-923cdf153836_1210x368.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><p>Generally, I&#8217;m surprised by this paper. It&#8217;s remarkable how well the method does. This should be used as a baseline for routing papers.</p><h2>BASE</h2><p><a href="https://proceedings.mlr.press/v139/lewis21a.html">Abstract</a></p><p>This paper introduces an algorithm called balanced assignment of experts (BASE) which focuses on formulating the problem of allocating tokens to experts as a <a href="https://en.wikipedia.org/wiki/Assignment_problem">linear assignment problem</a>, which allows to use linear programming to find an optimal solution that guarantees each expert receives an equal number of tokens. By using a classical optimization approach, the method doesn&#8217;t introduce any new hyperparameters or auxiliary losses, and thus doesn&#8217;t add any complication to training. An implementation was released in <a href="https://github.com/facebookresearch/fairseq">Fairseq</a>, FAIR&#8217;s sequence modeling toolkit.</p><p>In BASE, a single expert is assigned per token, in a way that maximized token-expert similarities. Expert specialization is learned by training a modified residual connection that mixes in each expert.</p><p>During training, the authors maximize model throughput by assigning an equal number of tokens to each expert. At test time, they assign each token to its highest scoring expert (&#8221;tokens choice&#8221;). They solve the following problem to assign tokens to experts (where we have <em>T</em> tokens, <em>h_t</em> is the representation of token <em>t</em>, we have E experts each with an associated embedding <em>w_e</em>, and we have an assignment index assigning tokens to experts <em>0 &#8804; a_t &#8804; E</em>):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\max \\sum_t h_t \\cdot w_{a_t}\\\\ \\text{subject to } \\forall e \\sum \\limits_{t=0}^T \\mathbb{1}_{a_t=e} = \\frac{T}{E}&quot;,&quot;id&quot;:&quot;NNCDWZXNFQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>This objective function seeks to maximize the similarity of the token and expert embeddings while respecting the constraint that all experts receive an equal number of tokens.</p><p>To minimize the computational cost to solve this problem, which requires solving this for <em>ET</em> tokens across all the workers, the problem is decomposed by having each worker solve a separate assignment problem over the inputs it receives. Each worker then sends <em>T/E</em> tokens to each other worker. However, this is heavily correlated, because the tokens assigned to each worker during training are typically from the same domain. To enable specializing, they add a random routing step, where each worker sends an equal number of each tokens to each other worker randomly. In effect, the algorithm has three steps during training:</p><ol><li><p>Each worker sends T/E tokens to each other worker randomly.</p></li><li><p>Each worker solves a separate linear assignment problem and routes <em>T/E</em> tokens to each expert.</p></li></ol><p>At test-time, the workers simply assign each token the best expert. The hope is that the workers have learned a reasonably balanced assignment.</p><p>They find that their approach outperforms other sparse 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_!M0Q4!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!M0Q4!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 424w, https://substackcdn.com/image/fetch/$s_!M0Q4!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 848w, https://substackcdn.com/image/fetch/$s_!M0Q4!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 1272w, https://substackcdn.com/image/fetch/$s_!M0Q4!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!M0Q4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png" width="676" height="580" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:580,&quot;width&quot;:676,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:78813,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!M0Q4!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 424w, https://substackcdn.com/image/fetch/$s_!M0Q4!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 848w, https://substackcdn.com/image/fetch/$s_!M0Q4!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.png 1272w, https://substackcdn.com/image/fetch/$s_!M0Q4!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb7199a98-5c84-4e94-b4da-cf86ecb8be66_676x580.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><p>They also find that their approach matches the Sparsely Gated MoE model despite being simpler.</p><p>When it comes to compute efficiency, the best is (unsurprisingly) data parallel, but BASE is the second fastest approach due to the lower amount of communication needed between workers.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!S1FK!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!S1FK!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 424w, https://substackcdn.com/image/fetch/$s_!S1FK!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 848w, https://substackcdn.com/image/fetch/$s_!S1FK!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 1272w, https://substackcdn.com/image/fetch/$s_!S1FK!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!S1FK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png" width="696" height="478" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/a14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:478,&quot;width&quot;:696,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:81136,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!S1FK!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 424w, https://substackcdn.com/image/fetch/$s_!S1FK!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 848w, https://substackcdn.com/image/fetch/$s_!S1FK!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.png 1272w, https://substackcdn.com/image/fetch/$s_!S1FK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fa14b85f6-1106-49fa-ac92-dd0496e7bb20_696x478.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><p>Routing layers that solve linear programming problems, like BASE, seem like a strong approach. They seem to have fallen out of fashion, which I don&#8217;t understand. I think that more people deploying MoE models would do well to consider LP-based approaches.</p><p>Note: This paper was built on with the <a href="https://arxiv.org/abs/2202.01169">Unified Scaling Laws for Routed Language Models</a> paper, which proposed a variant: Sinkhorn-BASE. I won&#8217;t discuss it here, but it&#8217;s worth reading. It has a better matching step than BASE and, as a result, slightly improved performance.</p><h2>Differentiable Select-K</h2><p><a href="https://arxiv.org/abs/2106.03760">Abstract</a></p><p>This is a continuously differentiable sparse gate for MoE routing. The standard MoE routing problem is to select the best <strong>k</strong> out of <em>n</em> experts for each token. This is a constrained optimization problem, which isn&#8217;t optimized for the accelerators that handle contemporary ML workloads. This paper reformulates the problem to use an unconstrained formulation that is equivalent to the original problem. The reformulation uses a binary encoding scheme to implicitly enforce the cardinality constraint. By using a binary encoding, the number of parameters used by DSelect-k is logarithmic in the number of experts, while existing gates (e.g. the <a href="https://arxiv.org/abs/1701.06538">Sparse MoE gate</a>) are linear. This could be useful with techniques like soft MoE (discussed later) which have a massive number of experts.</p><p>The authors propose two varieties: <em>per-example</em>, in which each token chooses an expert, and <em>static</em>, in which a weighting of experts is chosen once and does not vary per input. The static routing is not standard and is rarely used in the literature; it is more analogous to an ensembling technique. The only other time I&#8217;ve come across a similar problem is in the random hashing paper.</p><p>The authors compare DSelect-k to Top-k. The Top-k gate is defined by</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\sigma(\\text{TopK}(Ax+b,k)),&quot;,&quot;id&quot;:&quot;LISEUDWLQL&quot;}" data-component-name="LatexBlockToDOM"></div><p>where the TopK function is equal to the identity for the top <em>k</em> elements, and -&#8734; for the rest. While not continuous, Top-k allows for gradient propagation for the TopK outputs (using the &#8220;straight-through&#8221; method introduced in the RL routing paper discussed earlier).</p><p>The authors conducted an auxiliary experiment to show why continuity is a desired behaviour. In it, they used a MoE model to generate synthetic data, and trained routing layers to learn which experts were used to generate which data. They find that DSelect-k is able to recover the true experts, while TopK is not; additionally, the weights chosen by DSelectK are much more well behaved, while those from TopK exhibit a weird oscillatory behaviour, which the authors attribute to the discontinuous nature of the TopK router:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!hoav!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!hoav!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 424w, https://substackcdn.com/image/fetch/$s_!hoav!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 848w, https://substackcdn.com/image/fetch/$s_!hoav!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 1272w, https://substackcdn.com/image/fetch/$s_!hoav!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!hoav!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png" width="1274" height="588" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:588,&quot;width&quot;:1274,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:256035,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!hoav!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 424w, https://substackcdn.com/image/fetch/$s_!hoav!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 848w, https://substackcdn.com/image/fetch/$s_!hoav!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.png 1272w, https://substackcdn.com/image/fetch/$s_!hoav!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc17de9af-4d86-4435-88d5-e840b63bbcd9_1274x588.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><p>The authors conduct training on the MovieLens dataset, with two tasks: 1) a binary classification problem predicting whether a user watches a particular movie, and a regression problem to predict the rating a user assigns a given rating. They plotted the expert weights during training, and TopK has much higher variance in the weights, where the weight assigned to a given expert abruptly changes:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!RlUJ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!RlUJ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 424w, https://substackcdn.com/image/fetch/$s_!RlUJ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 848w, https://substackcdn.com/image/fetch/$s_!RlUJ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 1272w, https://substackcdn.com/image/fetch/$s_!RlUJ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!RlUJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png" width="1272" height="502" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c68d7d90-f290-459e-843c-ab65abed788d_1272x502.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:502,&quot;width&quot;:1272,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:219492,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!RlUJ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 424w, https://substackcdn.com/image/fetch/$s_!RlUJ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 848w, https://substackcdn.com/image/fetch/$s_!RlUJ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.png 1272w, https://substackcdn.com/image/fetch/$s_!RlUJ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc68d7d90-f290-459e-843c-ab65abed788d_1272x502.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><p>What I find interesting about these results is that these auxiliary metrics show a large degree of variance, which one would expect to be quite harmful in the final performance. However, DSelectK does not radically differ in final performance compared to the other routing functions.</p><p>That surprises me; given the high degree of variance induced by the discontinuous nature of the function, I&#8217;d expect to see more instability. Perhaps this is due to the fact that the authors don&#8217;t train a LLM; it would be interesting to see an ablation where the authors train a LLM. I would expect fewer loss spikes and more stability during training from a smoother function like DSelectK. That would be prohibitively expensive, as all things LLM are.</p><h2>Expert choice routing</h2><p><a href="https://arxiv.org/abs/2202.09368">Abstract</a></p><p>A one sentence summary of this paper would be: &#8220;Learns the greedy top-k tokens per expert.&#8221;</p><p>Load imbalance is a major problem in MoE models. Often, we see the top experts get more tokens than the rest, which tends to compound over time. As a result, many papers dedicate a lot of time &amp; effort to balancing the load across experts.</p><p>This paper seeks to address that by having experts select the top-K tokens for them to see, rather than having tokens select the top-K experts, as has been previously done.</p><p>This has the advantage that tokens can be seen by a variable number of experts. Their model outperforms the T5 dense model in 7/11 tasks; I would like to see stronger performance, as my bias is that a model that is exactly as good as T5 would outperform it in 5.5/11 tasks (50%), and 7 is not significantly larger than 5.5.</p><p>Generally speaking, I&#8217;m suspicious when any method demonstrates an improvement over an existing method, because most researchers tend to tune their new method better than the old one. This is human nature; &#8220;<a href="https://www.goodreads.com/quotes/21810-it-is-difficult-to-get-a-man-to-understand-something">it is difficult to get a man to understand something, when his salary depends on his not understanding it</a>.&#8221; As such, I want to see the new method be heads-and-shoulders better than the previous one if they&#8217;re claiming improvement. My bias is that, with access to the amount of GPUs that a typical Google researcher has, I could show an improvement in most deep learning techniques simply by doing more hyper-parameter tuning. If I had the ability to add an arbitrary technique to it, that introduced more hypers, I could do better still.</p><p>Having said that caveat, the paper does intuitively make sense: in most token&#8212;choice routing models, each token is seen by exactly <strong>k</strong> experts, and thereby uses the same amount of compute. This is sub-optimal! We&#8217;re effectively offloading all compute allocation decisions to the tokenizer, which is often extremely simple (e.g. <a href="https://en.wikipedia.org/wiki/Byte_pair_encoding">byte pair encoding</a>). Methods which can allocate more compute to certain tokens should be significantly better.</p><p>An advantage that this technique has is latency: in token-choice methods, where each token chooses the top-K experts to be routed to, some experts will receive more tokens than others, causing step latency to be bottlenecked by the most loaded expert. To get around this, some implementations (e.g. the <a href="https://arxiv.org/abs/1701.06538">OLNN</a> paper tried this in some of the appendix experiments) force equal allocations, but this is unwieldy and <strong>also</strong> harms latency, as the top-K function isn&#8217;t a good fit for the programming model used by accelerators (they&#8217;re good at matmuls, not sorting). However, this technique requires solving an integer linear program to allocate the tokens, which can be a nightmare itself; they use an approximation to allow it to run on TPUs.</p><h2>Soft MoE</h2><p><a href="https://arxiv.org/abs/2306.03745">Abstract</a></p><p>I&#8217;ve saved, perhaps, the best (or at least most novel) paper for last. Unlike most other MoE models, which use the routing layer to discretely route tokens to experts, Soft MoE passes different weighted combinations of all tokens to each expert. The standard sparse MoE transformer has to solve a discrete optimization problem, which is difficult to optimize due to differentiability. By making this a soft combination, it is immediately differentiable.</p><p>In the Soft MoE algorithm, they have a batch of <em>m</em> tokens which we refer to as <strong>X</strong>. They have <em>n</em> experts, each expert with <em>p</em> slots, and we use <strong>&#934;</strong> to refer to the parameters for the experts (a <strong>d</strong> x (<strong>n * p)</strong> matrix). The input slots to the MoE layer, <strong>X&#8217;</strong>, is the weighted combination of <strong>X</strong>:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\textbf{D}{ij} = \\frac{\\exp((\\textbf{X}\\Phi){ij})}{\\sum \\limits_{i'=1}^m \\exp((\\textbf{X}\\Phi){i'j}} = \\text{softmax}_{\\text{column}}(\\textbf{X}\\Phi)_{ij}\\ \\textbf{X}' = \\textbf{D}^T \\textbf{X}&quot;,&quot;id&quot;:&quot;JQOKBPOKEA&quot;}" data-component-name="LatexBlockToDOM"></div><p>The matrix <strong>D</strong> is just the output of softmaxxing over the columns of <strong>X&#934;</strong>. We call the <em>p</em>-th expert over the corresponding rows of <strong>X&#8217;:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\textbf{Y}i' = f{\\lfloor i/p \\rfloor}(\\textbf{X}_i')&quot;,&quot;id&quot;:&quot;XSHUOLCTUM&quot;}" data-component-name="LatexBlockToDOM"></div><p>And then compute the output tokens, <strong>Y</strong>, with a softmax over the rows:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Y= \\text{softmax}_{\\text{rows}}(X\\Phi)Y&#8242;&quot;,&quot;id&quot;:&quot;UPPKVGAXFA&quot;}" data-component-name="LatexBlockToDOM"></div><p>The output of softmaxxing over the rows is called the <em>combine</em> weights, while the output of softmaxxing over the columns is called the dispatch weights.</p><p>This formulation has several nice properties:</p><ol><li><p>It is fully differentiable. There are no nasty discrete functions to kill the gradients.</p></li><li><p>Token dropping isn&#8217;t an issue, like it is with the top-K router from th<a href="https://arxiv.org/abs/1701.06538">e OLNN paper</a> (<a href="https://finbarrtimbers.substack.com/p/papers-ive-read-this-week-mixture">discussed in a previous edition</a>), as every slot is filled with a weighted average of all tokens, and the weights are strictly positive thanks to the softmax.</p></li><li><p>It&#8217;s fast, as it avoids sorting/top-k operations, which are slow on accelerators (particularly TPUs).</p></li></ol><p>A major disadvantage is that it doesn&#8217;t currently work with auto-regressive decoders, i.e. all generative <a href="http://LLMs.It">LLMs.It</a> shouldn&#8217;t be particularly difficult to extend it, but it will require additional (careful) work.</p><p>They compare their method to the <em><a href="https://arxiv.org/abs/1701.06538">tokens choice</a></em> (where every token selects the top-K experts with the highest routing score) and <em><a href="https://arxiv.org/abs/2202.09368">experts choice</a></em> (where every expert selects the top-C tokens in terms of routing score) routing techniques. The results are quite strong, with soft MoE performing distinctly better in the two image tasks they study:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!LUQV!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!LUQV!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 424w, https://substackcdn.com/image/fetch/$s_!LUQV!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 848w, https://substackcdn.com/image/fetch/$s_!LUQV!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 1272w, https://substackcdn.com/image/fetch/$s_!LUQV!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!LUQV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png" width="1410" height="742" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:742,&quot;width&quot;:1410,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:244004,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!LUQV!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 424w, https://substackcdn.com/image/fetch/$s_!LUQV!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 848w, https://substackcdn.com/image/fetch/$s_!LUQV!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.png 1272w, https://substackcdn.com/image/fetch/$s_!LUQV!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F8ff7c008-e67f-4734-86c3-ba998ef7a17d_1410x742.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><p>It also performs better when compared against ViTs with similar FLOPS:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3rDT!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3rDT!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 424w, https://substackcdn.com/image/fetch/$s_!3rDT!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 848w, https://substackcdn.com/image/fetch/$s_!3rDT!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 1272w, https://substackcdn.com/image/fetch/$s_!3rDT!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3rDT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png" width="1410" height="664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/c2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:664,&quot;width&quot;:1410,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:206067,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3rDT!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 424w, https://substackcdn.com/image/fetch/$s_!3rDT!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 848w, https://substackcdn.com/image/fetch/$s_!3rDT!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.png 1272w, https://substackcdn.com/image/fetch/$s_!3rDT!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fc2eaa235-aed2-4494-b4de-de9114f15eea_1410x664.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><p>They perform a number of ablations, and find that:</p><ol><li><p>The optimal number of slots per expert is small: 1 or 2.</p></li><li><p>The optimal number of experts is roughly the same number as the amount of input tokens</p></li></ol><p>What I find particularly compelling about this model is that it removes the complexity of sparse models.</p><p>I&#8217;m curious about the potential to make a router that has the flexibility to learn the slots though; something that could interpolate between this and the standard expert/token choice MoE routing models seems compelling.</p><h1>Some conclusions</h1><p>My take away from reading these papers was:</p><ol><li><p>More papers should use hash layers as a benchmark.</p></li><li><p>It&#8217;s not clear to me that differentiability matters much. It seems intuitively nice to have, but I wouldn&#8217;t really give up anything else to get it.</p></li><li><p>Soft MoE doesn&#8217;t seem completely ready for production&#8212; the optimal number of slots per expert being 1 or 2 seems prohibitively expensive&#8212; but I think that an approach like this is the future, as I suspect that the performance benefits will continue to grow as more researchers explore soft routing techniques.</p></li></ol><p>If I were actively focusing on MoE research, I would be looking into combining these, and looking at a fully differentiable, expert choice, soft routing layer. It seems fairly straightforward to combine these, and I suspect the advantages would stack.</p><p>Linear programming routing, while it performs strong, adds a lot of complexity to the stack. I&#8217;m not convinced that it&#8217;s really worth this complexity. However, the performance is strong, so it is worth benchmarking.</p>]]></content:encoded></item><item><title><![CDATA[Papers I’ve read this week, Mixture of Experts edition]]></title><description><![CDATA[I read a bunch of papers about conditional routing models]]></description><link>https://www.artfintel.com/p/papers-ive-read-this-week-mixture</link><guid isPermaLink="false">https://www.artfintel.com/p/papers-ive-read-this-week-mixture</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Fri, 04 Aug 2023 16:12:06 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!33p1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>Papers I&#8217;ve read this week, Mixture of Experts edition</h1><p>Mixture of Experts (MoE) models have been getting a lot of attention lately, what with the all the rumours about OpenAI using them in GPT-4. I&#8217;ve been reading a lot of the foundational papers about MoE models, and I&#8217;ve taken detailed notes, which I wanted to share. This is a bit of a long one, so you might want to read this on the web. </p><h2>Background</h2><p>A standard deep learning model uses the same parameters for each input. For instance, when using a ResNet to classify images, the same parameters are used for every image. With conditional routing models, such as MoEs, the parameters each input sees vary depending on the input. For MoE models, in particular, they select different combinations of parameters for each input. We use the term &#8220;dense&#8221; to refer to plain old vanilla models which do not vary the parameters.</p><p>The name can be somewhat misleading. The MoE technique, at least as it is commonly used, is not an ensembling technique that is used to combine models trained independently. Rather, it is a clever way to distribute a large transformer over multiple GPUs. It is more analogous to a different type of model parallelism, such as the Megatron architecture. Each &#8220;expert&#8221; can be anything from an entirely separate transformer to a different constituent block of the transformer. Within the network, you have &#8220;router&#8221; layers which are typically much smaller than the rest of the network, and which decide how to allocate tokens across experts. The exact way in which this is done varies significantly by method.</p><p>When using conditional routing models, several problems crop up:</p><ol><li><p>Allocating too many tokens to the top models. When learning to route models to experts, a &#8220;winners get bigger&#8221; effect exists, in which a positive feedback loop can cause the most successful model to see all of the tokens, causing that model to get better, and thus to have more tokens routed to it. This is problematic, as in the limit, this will lead to the model becoming a standard dense transformer.</p></li><li><p>Poor sharding performance. Even if the tokens are being allocated to all models in expectation, for efficient accelerator utilization we actually want each <em><strong>batch</strong></em> to be evenly allocated across experts. This can be hard to achieve.</p></li><li><p>Evaluating performance vs dense models. It can often be unclear how to compare the models. For instance, there were several labs which trained MoE models with &gt;1T parameters. This was compared directly to GPT-3, which &#8220;only&#8221; had 175B parameters. The comparison is, of course, invalid, as only a fraction of these parameters are used for each request.</p></li></ol><p>The papers I discuss below attempt to solve these issues.</p><p>One paper I will not be discussing is an <a href="https://arxiv.org/abs/2202.01169">excellent survey paper by Clark et al</a>, which is an overview of how conditional routing models work, and which does a number of strong experiments to help understand their performance. I <a href="https://finbarrtimbers.substack.com/p/papers-ive-read-this-week">wrote about it in an earlier article</a>, and will not repeat myself here.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>Outrageously large networks</h2><p><a href="https://arxiv.org/pdf/1701.06538.pdf">Abstract</a></p><p>The OLNN paper proposed a Sparsely-Gated Mixture-of-Experts Layer, which was one of the first MoE implementations that was practical to use at scale, and was performant.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!33p1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!33p1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 424w, https://substackcdn.com/image/fetch/$s_!33p1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 848w, https://substackcdn.com/image/fetch/$s_!33p1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 1272w, https://substackcdn.com/image/fetch/$s_!33p1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!33p1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png" width="1274" height="712" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:712,&quot;width&quot;:1274,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:119711,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!33p1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 424w, https://substackcdn.com/image/fetch/$s_!33p1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 848w, https://substackcdn.com/image/fetch/$s_!33p1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.png 1272w, https://substackcdn.com/image/fetch/$s_!33p1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F470d8fcb-21dc-4a37-92db-87eca77f31c1_1274x712.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><p> </p><p>It was by Noam Shazeer, as seemingly all papers advancing the state of the art in NLP are, and in it, the authors apply a MoE layer convolutionally between stacked LSTM layers. Their proposed Mixture of Expert layers consist of a set of N expert networks (E(x)), and a gating network, G, that outputs a sparse, n-dimensional vector. The gating network decides how to combine the networks:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;y = \\sum \\limits_{i=1}^n G(x)_i E_i(x)&quot;,&quot;id&quot;:&quot;EEJTZEBGVS&quot;}" data-component-name="LatexBlockToDOM"></div><p>If G(x)_i = 0, we can skip computing E_i(x), which can be expensive (it can be, for instance, a decoder block from a transformer). You can also stack gating networks to create a hierarchy of networks. A common choice for MoE models is for G(x) to be a linear layer with a softmax activation:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;G(x) = \\text{softmax}(\\textbf{x}W^T)&quot;,&quot;id&quot;:&quot;WKKDSPHZEE&quot;}" data-component-name="LatexBlockToDOM"></div><p>Here, the authors add sparsity, and random, learned, Gaussian noise:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;G(x) = \\text{softmax}(\\text{topK}(H(\\textbf{x}), k))&quot;,&quot;id&quot;:&quot;HPIBYTZDOL&quot;}" data-component-name="LatexBlockToDOM"></div><p>topK(x, k) is the identity function for the top K values, and sets the rest to negative infinity, and H(x) is a trainable noise function:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;H(x)_i := (W^T_g\\textbf{x})i + \\epsilon \\cdot \\text{softplus}(W^T_\\text{noise} \\textbf{x})_i, \\epsilon \\thicksim N(0, 1)&quot;,&quot;id&quot;:&quot;HXGNDLHFBK&quot;}" data-component-name="LatexBlockToDOM"></div><p>This complicated function allows the gating network to be trained using backprop in the standard way. It also has the nice property that the model scales proportional to k*b*d/n, where we choose k out of n experts, a batch of size b, and distribute the model over d devices. As such, if we maintain the k/n ratio static, then we can continue to scale the number of experts (and thus the total model size) as long as we have given Jensen Huang enough money to have the GPUs we need.</p><p>Interestingly, the model was written when LSTMs were the SOTA in language modelling, but the proposed architecture seems like a remarkably strong fit for current architectures, as it makes it easy to shard the experts over a number of GPUs. The paper uses a load balancing loss to try and balance expert utilization. The load balancing loss is an area of active research, and is one that will be focused on in subsequent papers. The loss used here is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L_{\\text{importance}} = c_{\\text{importance}} \\cdot \\text{CV}(\\text{Importance}(X))^2 &quot;,&quot;id&quot;:&quot;VXJCQUXHVS&quot;}" data-component-name="LatexBlockToDOM"></div><p>Where the importance is defined as the total weight that all the experts place on the batch <strong>X:</strong></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Importance}(X) := \\sum \\limits_{x \\in X} G(x)&quot;,&quot;id&quot;:&quot;XBWCOYWSLW&quot;}" data-component-name="LatexBlockToDOM"></div><p>CV here is the coefficient of variation, i.e. the ratio of the standard deviation to the mean:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{CV}(x) := \\frac{ \\sqrt{\\text{Var}(x)}}{ E[x]} \\equiv \\frac \\sigma \\mu&quot;,&quot;id&quot;:&quot;JEXYYQWWDQ&quot;}" data-component-name="LatexBlockToDOM"></div><p>This loss will encourage equal importance, as the easiest way to minimize the loss is to minimize the variance of the importances. The authors also use an additional penalty term to further encourage load-balancing:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L_{\\text{load}} = c_{\\text{load}} \\cdot \\text{CV}(\\text{Load}(X))^2&quot;,&quot;id&quot;:&quot;GDWIJIPFMD&quot;}" data-component-name="LatexBlockToDOM"></div><p>The load is defined similarly to the Importance, but they define a new function, P(x, i), as the probability that the i-th entry of G(x) is nonzero when you add noise to it:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{Load}(X)i = \\sum_{x \\in X} P(x, i)&quot;,&quot;id&quot;:&quot;GKENFWOVRE&quot;}" data-component-name="LatexBlockToDOM"></div><p>They have a somewhat complicated way to actually implement P(x, i), and it&#8217;s worth checking out the appendix for the details. This results in their load balancing loss becoming</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L(X) = L_{\\text{load}}(X) + L_{\\text{importance}}(X) &quot;,&quot;id&quot;:&quot;ROCTKNQLXF&quot;}" data-component-name="LatexBlockToDOM"></div><p>The authors <em>also</em> explored yet another loss in which they forced the model to strictly balance tokens across experts. It&#8217;s interesting to see how much time was dedicated to the load balancing; this is indicative of how critical this is to get the full benefit of MoE models.</p><p>The authors found a significant improvement in modelling performance when using their MoE models, seeing significant improvements when comparing models with approximately 8M FLOPS per timestep:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!1wC5!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!1wC5!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 424w, https://substackcdn.com/image/fetch/$s_!1wC5!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 848w, https://substackcdn.com/image/fetch/$s_!1wC5!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 1272w, https://substackcdn.com/image/fetch/$s_!1wC5!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!1wC5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png" width="1248" height="606" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/cd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:606,&quot;width&quot;:1248,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:167223,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!1wC5!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 424w, https://substackcdn.com/image/fetch/$s_!1wC5!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 848w, https://substackcdn.com/image/fetch/$s_!1wC5!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.png 1272w, https://substackcdn.com/image/fetch/$s_!1wC5!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcd65593e-6896-45ed-963b-b0318a4f8d38_1248x606.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><p>In the era of LLMs, it&#8217;s somewhat funny to look at the number of model parameters here; their largest model has 4B parameters, which would be considered quite small today.</p><h2>Switch Transformers</h2><p><a href="https://arxiv.org/abs/2101.03961">Abstract</a></p><p>Another Shazeer paper, this was inspired by Kaplan et. al, which found that GPT model follow power-laws in scaling the model size, dataset size, and computational budget. They add add a fourth dimension: the parameter count, keeping the FLOPs per token constant. Like the OLNN paper, by keeping unique experts on different devices, the total parameter count for the model increases proportional to the number of devices, allowing for embarrassingly parallel operations.</p><p>The paper is a minor modification on the OLNN paper. They make two changes:</p><ol><li><p>The authors use k = 1 (which they call a Switch layer), whereas OLNN routing used k &gt; 1. They show this performs better.</p></li><li><p>They use an auxiliary load balancing loss that was the same as Shazeer (2018) and Lepihkin et al (2020), and is much simpler than the overly complicated loss(es) used in the OLNN paper:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\mathcal{L}_{\\text{load balancing}}(x) := \\alpha N \\sum \\limits_{i=1}^N f_i P_i,&quot;,&quot;id&quot;:&quot;DFLAJIIWCS&quot;}" data-component-name="LatexBlockToDOM"></div></li></ol><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;f_i := \\frac 1 T \\sum \\limits_{x \\in \\mathcal{B}} \\mathbb{1}\\{\\text{argmax } p(x) = i\\}&quot;,&quot;id&quot;:&quot;ANPJXKJMEN&quot;}" data-component-name="LatexBlockToDOM"></div><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;P_i := \\frac 1 T \\sum \\limits_{x \\in B} p_i(x) &quot;,&quot;id&quot;:&quot;VFTVZNGUPG&quot;}" data-component-name="LatexBlockToDOM"></div><p>P_i is the fraction of tokens allocated to expert <em>i</em> across all tokens in the batch, while p_i(x) is the probability of allocating token <em>x</em> to expert <em>i</em>. As we want to spread tokens evenly across the N experts, we want both the f_i and the P_i terms to be equal to 1/N, for all <em>i</em>, which is encouraged through this, as that is the optimal value for the P-vector to take, which is the only differentiable part of this equation. It is multiplied by N to keep the entire term constant (under uniform routing, the sum is equal to N * (1/N^2) = 1/N).</p><p>They find that these small changes are enough to perform better than both MoE and Dense transformers with equivalent runtime performance. The paper also asks a Chinchilla-esque question:</p><blockquote><p>For a fixed training duration and computational budget, should one train a dense or a sparse model?</p></blockquote><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!GwFg!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!GwFg!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 424w, https://substackcdn.com/image/fetch/$s_!GwFg!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 848w, https://substackcdn.com/image/fetch/$s_!GwFg!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 1272w, https://substackcdn.com/image/fetch/$s_!GwFg!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!GwFg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png" width="764" height="578" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:578,&quot;width&quot;:764,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:100261,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!GwFg!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 424w, https://substackcdn.com/image/fetch/$s_!GwFg!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 848w, https://substackcdn.com/image/fetch/$s_!GwFg!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.png 1272w, https://substackcdn.com/image/fetch/$s_!GwFg!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3fd5e417-4708-45b2-a75c-94a70172a9b3_764x578.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><p>They find a significant advantage to training a sparse transformer vs a dense one, given a fixed computation budget. This matches my intuition; with much more parameters, and an efficient way of selecting between them, the model should have much higher performance.</p><p>As an applied practitioner, I think looking at inference cost is the better benchmark to use, which is even more in favour of sparse transformers. Once a MoE model has been trained with some number N &gt; K experts of size P, where each inference involves routing tokens to the top K experts, it has the same performance characteristics as a dense model with KP parameters. As typically the inference costs will dramatically outweigh the training costs, this becomes the relevant benchmark.</p><p>Put differently, if we&#8217;re deploying thousands of GPUs to serve inference requests, we don&#8217;t have preferences over deploying them to serve a larger number of <em>copies</em> of the same dense transformer, or using them to serve a smaller number of MoE transformers: we&#8217;re computationally agnostic (assuming that we&#8217;re able to achieve uniform routing).</p><p>Two papers that the authors reference repeatedly throughout the Switch Transformers paper are the <a href="https://arxiv.org/abs/2006.16668">GShard</a> and <a href="https://arxiv.org/abs/1811.02084">Mesh-Tensorflow</a> papers, which go into depth about the computational details of implementing these models. They&#8217;re worth a read if that&#8217;s of interest to you.</p><h2>ST-MoE</h2><p><a href="https://arxiv.org/abs/2202.08906">Abstract</a></p><p>I&#8217;m apparently a Shazeer fanboy today- a third paper<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> of his in this line was the Stable and Transferable Sparse Expert Model paper, which built on the Switch Transformer paper to introduce the ST-MoE transformer. The paper focuses on the training instabilities that come up in training sparse expert models.</p><p>The paper focuses on identifying approaches that can improve training stability for sparse models. Training instability here means training runs which diverge:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eeEH!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eeEH!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 424w, https://substackcdn.com/image/fetch/$s_!eeEH!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 848w, https://substackcdn.com/image/fetch/$s_!eeEH!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 1272w, https://substackcdn.com/image/fetch/$s_!eeEH!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eeEH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png" width="1160" height="576" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:576,&quot;width&quot;:1160,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:147683,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eeEH!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 424w, https://substackcdn.com/image/fetch/$s_!eeEH!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 848w, https://substackcdn.com/image/fetch/$s_!eeEH!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.png 1272w, https://substackcdn.com/image/fetch/$s_!eeEH!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F57391eda-98c3-4ca4-8e01-91ce51778dac_1160x576.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><p>The authors explore a bunch of methods to stability models, but note that many of them degrade model quality, which is undesirable. They also note a number of changes which worsen stability, but increase quality (e.g. modifications with more multiplicative components, like GEGLU or RMSNorm). They propose a new loss, the router <em>z</em>-loss, which doesn&#8217;t degrade quality:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L_z(x) := \\frac 1 B \\sum \\limits_{i=1}^B \\left( \\log \\sum \\limits_{j=i}^N e^{x_j^{(i)}}\\right)^2&quot;,&quot;id&quot;:&quot;XFTSGGATUM&quot;}" data-component-name="LatexBlockToDOM"></div><p>where <em>B</em> is the number of tokens, <em>N</em> is the number of experts, and <em>x</em> are the logits going into the router. This is a penalty on large logits into the gating network. As such, the overall loss for the model becomes (yet another complicated, multi-part loss function!):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;L_{\\text{total}} = L_{\\text{cross-entropy}} + c_{\\text{load-balancing}} L_{\\text{load-balancing}} + c_zL_z&quot;,&quot;id&quot;:&quot;NOQLGQPGLT&quot;}" data-component-name="LatexBlockToDOM"></div><p>The idea is that modern transformers are trained with mixed precision, typically using bfloat16 for all matmuls other than gradient updates, which are stored in float32. As such, larger logits involve larger roundoff errors (table from the ST-MoE paper):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!oLep!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!oLep!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 424w, https://substackcdn.com/image/fetch/$s_!oLep!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 848w, https://substackcdn.com/image/fetch/$s_!oLep!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 1272w, https://substackcdn.com/image/fetch/$s_!oLep!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!oLep!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png" width="464" height="270" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:270,&quot;width&quot;:464,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:37066,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!oLep!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 424w, https://substackcdn.com/image/fetch/$s_!oLep!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 848w, https://substackcdn.com/image/fetch/$s_!oLep!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.png 1272w, https://substackcdn.com/image/fetch/$s_!oLep!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F524ed6c4-aaea-4a3b-bc64-c5462b2985a0_464x270.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><p>The routing layers in MoE models introduce additional exponential functions through the softmax function, and exponential functions, as they increase the scale of the values being considered, can lead to higher roundoff errors. This is particularly problematic when routing with k &gt; 1 experts.</p><p>The authors run a number of experiments comparing top-K routing, and find that top-2 tends to be the sweet spot in terms of complexity and compute. While you can increase quality by increasing the size of K, it comes at a linear increase in compute cost.</p><p>The authors also perform a qualitative analysis of what the experts learn; they find that various experts specialize in punctuation, visual descriptions, proper names, and counting/numbers. This is interesting as that isn&#8217;t forced by any of the specific losses, but rather emerges from the model, as one might naively suspect. However, they don&#8217;t observe that experts specialize in languages when trained on multilingual datasets, which I found surprising. This sort of qualitative analysis is excellent and often missing. I wish more papers had this!</p><p>With this paper, we start to see the load-balancing losses simplifying and converging on more interpretable, manageable, functional forms, when compared to the more complicated setups from the earlier papers, such as OLNN.</p><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>Interestingly, the last author on this paper, William Fedus, is currently at OpenAI. He joined Jack Rae and Aidan Clark there, two of DeepMind&#8217;s authors from the &#8220;Scaling laws for routed language models&#8221; paper (although Jack Rae recently returned to DeepMind). Similarly, all of the authors on the Switch Transformers paper (William Fedus, Barret Zoph, and Noam Shazeer) have left Google, with Zoph and Fedus going to OpenAI. OpenAI seems to have accumulated quite a stable of sparse transformer experts! (I&#8217;m curious how they route work between themselves. &#129345;&#128165;)</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[The market for AI companies]]></title><description><![CDATA[After being laid low by a sick child turning into a sick family, I&#8217;ve got a bunch of articles in the queue, and I hope to have another one up by the end of June/early July, probably about conditionally routed language models.]]></description><link>https://www.artfintel.com/p/the-market-for-ai-companies</link><guid isPermaLink="false">https://www.artfintel.com/p/the-market-for-ai-companies</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Sun, 18 Jun 2023 18:44:51 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!JwWp!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F58c3a757-b2e7-4104-9f17-1e79c01d013c_1024x1024.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>After being laid low by a sick child turning into a sick family, I&#8217;ve got a bunch of articles in the queue, and I hope to have another one up by the end of June/early July, probably about conditionally routed language models. </p><p>The article that follows is a slight departure from my usual, more technical subject matter. Please let me know what you thought of it. </p><h1>The market for AI companies</h1><p>Recently, I&#8217;ve been talking to founder friends of mine who have been raising money, and to some VC friends of mine who are <em>investing</em> money in AI companies. I want to share some of the topics that we&#8217;ve discussed, give my perspective on what I would want to invest in if I were deploying capital/what I would be looking for if I were looking for a job, and try to generally make sense of a bizarre market.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p><p>In these discussions, a few themes consistently come up:</p><ol><li><p>The consensus is that AI is going to be (mostly) a &#8220;sustaining&#8221; innovation, by which I mean that most of the financial benefits will make the bigger companies stronger.</p></li><li><p>&#8220;Mostly&#8221; is key. There will be a few companies that do break through, and these will tend to dominate their market.</p></li><li><p>Many of the large AI investments won&#8217;t pan out.</p></li></ol><p>Points 1 &amp; 2 are really the same point: the winners tend to accrue all the advantages in AI. This is because, generally speaking, AI systems tend to get better over time. While there will be companies that develop new markets&#8212; we need only look at Midjourney/Dalle, or ChatGPT/Claude to see this&#8212; the majority of the applications of AI will be to make existing companies/products better. Consider image editing. While it is possible, of course, that a new image editing system is developed that replaces Photoshop, it seems far more likely that Adobe will acquire a generative AI company and/or continue to develop Firefly until it is the market leader.</p><p>As another example, consider one of the oldest AI systems in production: Google search. Because it was making money and had a ton of users, Google was able to start cranking out optimizations at every level of the stack: they had custom hardware, they were globally distributed, they were able to keep hiring employees who could make it better in every way, and they had a sales team selling ads which was financing everything. If you came up with a brilliant new search algorithm, you&#8217;d have to compete with the Google search algorithm, the Google ad sales team, the Google datacenter team, and the Google Chrome team. All of these were working together to make their product better. In addition to all of this, Google was <strong>still</strong> working on their algorithm, and had more data than anyone else to train it on.</p><p>This is generally true for AI systems. Yet another example, this time of a new product that has developed a strong market position, is OpenAI and Anthropic. OpenAI has, roughly, <a href="https://en.wikipedia.org/wiki/OpenAI">400 employees</a>, while Anthropic has around 100. OpenAI raised ~$10B from Microsoft, while Anthropic raised $450M. OpenAI has dominated the news, so non-technical people (like, say, my chemical engineer Dad, who&#8217;s an avid user of ChatGPT) use their products, while only geeks like myself, and you, dear reader, use Claude. As a result, if OpenAI doesn&#8217;t make any massive mistakes, they&#8217;re going to be able to scale to more users and improve more quickly. So even if Anthropic is able to make a LLM that is just as good, I struggle to see how they&#8217;ll be able to steal significant market share from OpenAI unless they come up with a fundamental breakthrough.</p><p>A contributing factor to this is the scarcity of GPUs. Just being able to serve requests to customers is a competitive advantage right now. OpenAI&#8217;s model latency is reportedly ~2-4x <a href="https://twitter.com/helicone_ai/status/1662325356563496961?s=19">slower than it was during April</a>, likely because they&#8217;re hitting the limits of their cloud resources. This creates a positive feedback loop: the companies with the most money have the most GPUs, so they can serve the most requests, each of which they make a profit on, giving them more money, which they use to buy more GPUs.</p><p>Another point is that machine learning relies on data, and if you&#8217;re interacting with consumers, you&#8217;re getting a large amount of data that is <em>specifically tailored</em> to your application. That is an advantage that will keep getting more valuable. You can hire more researchers to develop more effective techniques, which compounds with the larger amount of data. Leads to an accumulating advantage.</p><p>Yet another advantage is that, as you serve your product to users, you start to accumulate research for your <em>specific problem</em>. With each additional improvement you layer onto your product, it becomes harder for newcomers to compete. Consider, for instance, Google Search, as discussed above, or ChatGPT, which seems like a counter-example given how many LLM chatbots have been invented to compete. But they&#8217;re all notably worse than GPT-4, and they struggle with the same problems. OpenAI has been able to iterate for 6 months and has been introducing various add-ons to improve ChatGPT. The only LLM that comes close to GPT-4 performance is Claude, and even then, there&#8217;s a gap. This is despite an absolutely outrageous amount of capital being deployed and most of the research being open source.</p><div class="paywall-jump" data-component-name="PaywallToDOM"></div><p>The bar to create a ChatGPT competitor (which was released in November, 2022) was relatively low, and there are a number of products that are comparable to the original version. But the <em>current</em> version has improved dramatically, making it tough for competitors to keep up. It&#8217;s particularly hard because ChatGPT (and Claude) have had access to a lot of user data, which I strongly suspect they&#8217;re able to use to make their model better, through RLHF. This creates a path dependency issue, where to compete with them, one needs to have a large number of iterations, which is only possible after your model has been running for a while. The only room for competition, from what I can see, is in going after niches, particularly niches that are unsavory (sexually explicit content, politically biased content, etc.) that the big companies won&#8217;t go after.</p><p>This a point worth expanding on; there is a substantial market opportunity in going after the Generative AI market in the niches which the current AI safety crowd has deemed unethical/unsavory. If we look at, for instance, <a href="https://civitai.com/">Civitai</a>, their front page is almost all pictures of pretty light-skinned women, or if we search <a href="https://twitter.com/search?q=%23stablediffusion&amp;src=typed_query">#stablediffusion</a> on Twitter, we see many pictures of scantily clad women, while searching <a href="https://twitter.com/search?q=%23dalle&amp;src=typed_query&amp;f=top">#dalle</a> returns much more surreal, sci-fi imagery. Another example, of course, is <a href="https://gizmodo.com/blush-ai-chatbot-replika-online-dating-dating-apps-1850514242">Replika</a>, which allows one to chat with a &#8220;flirting companion.&#8221; ChatGPT/Claude very much do not provide any experience like this. There&#8217;s nothing wrong with this, of course, as these are all perfectly valid businesses for one to get into, but tech as an industry is famously prudish, with many platforms banning <a href="https://qz.com/2050359/onlyfans-blames-financial-companies-for-pivot-from-porn">any form of explicit content</a>. </p><p>This brings me to another point: the current AI funding scene doesn&#8217;t make sense. There are, to the best of my knowledge, six (6!) foundation model companies:</p><ol><li><p>OpenAI</p></li><li><p>Anthropic</p></li><li><p>Google/DeepMind</p></li><li><p><a href="http://Stability.ai">Stability.ai</a></p></li><li><p>Inflection</p></li><li><p>Cohere</p></li><li><p><a href="https://techcrunch.com/2023/06/13/frances-mistral-ai-blows-in-with-a-113m-seed-round-at-a-260m-valuation-to-take-on-openai/">Mistral</a></p></li></ol><p>This is not to mention a bunch of other startups that are trying to compete in this space as well. </p><p>To be blunt, I don&#8217;t see how these have businesses which justify their multibillion dollar valuations. The simple way to value a (mature, public) company is to assign it a multiple based on the profit it makes. Companies on the NASDAQ trade at roughly <a href="https://www.infrontanalytics.com/fe-EN/35812NU/Google-Inc-/market-valuation">20x profits</a>. So to be worth $4B, which is what rumours say Anthropic recently raised at, they need to make $200M in profits. To have a 10x return on that investment, which is typically what VCs are looking to make on a successful investment, they would need to make $2B in profits. The same applies for all of these businesses.</p><p>The problem is, though, that I don&#8217;t see any reason to buy the second best LLM, let alone the <em>6th best</em>. I think every major cloud provider will have a foundation model API. After that? Who&#8217;s going to buy these? Maybe they&#8217;ll develop independent businesses- but I struggle to see it. I think that their best bet will be to be acquired. But at the valuations they&#8217;re currently at, it&#8217;s tough to imagine investors seeing venture scale returns.</p><p>Consider the recent round that Mistral raised: <a href="https://techcrunch.com/2023/06/13/frances-mistral-ai-blows-in-with-a-113m-seed-round-at-a-260m-valuation-to-take-on-openai/">$113M at a $260M valuation</a>. For VCs to see a return on their capital, they expect to get a ~10x return on this money, which would require a $2.6B exit. There aren&#8217;t many of those!</p><p>So if many investments aren&#8217;t going to pan out, why are they being made? Two reasons:</p><ol><li><p>FOMO.</p></li><li><p>Logo hunting.</p></li></ol><p>As a VC, you have two ways to make money. Most VCs charge 2+20, where they charge 2% per year of the assets under management (AUM), and charge 20% of the returns from their investments. They can either keep expanding AUM and get 2% of that, even if their investments don&#8217;t pan out, or they can get money from successful investments. It&#8217;s hard to pick investments (and takes a long time to <a href="https://twitter.com/tylertringas/status/1302989759997005825?s=46&amp;t=_LCsoamG7K4pQj0vxlk0XA">actually see returns</a>)! But if you can consistently prove to your limited partners (LPs, the people who invest in VC funds) that you can get in the hottest deals, they&#8217;re going to give you more money.</p><p>So many VCs are investing in hot companies to show they <em>can</em> invest in hot companies, even if the valuations don&#8217;t necessary make sense. This is not a criticism of VCs; they are making rational decisions which will, almost certainly, make them money. But it is not the case that every one of these AI unicorns will make money. I think the bets that are being made are reasonable for VCs, who are able to take a high risk, high reward approach to their portfolio, but for individuals considering which roles to take as an employee, you should view these foundation model companies as being very high risk/reward bets and value your equity accordingly.</p><h3>A market for lemons</h3><p>AI companies right now are incredibly odd by the standards of most companies, because many AI companies are able to make money from a very early point. They&#8217;re developing large consumer subscription businesses, which are, basically, the best businesses to have (other than <a href="https://stratechery.com/2022/digital-advertising-in-2022/">search advertising</a>). Money keeps rolling in every month. This is allowing these companies to self-fund, reducing their dependency on VCs.</p><p>As such, I would be hesitant to join a company that didn&#8217;t have revenue right now, unless I was joining as part of the founding team. AI is such a dynamic place that it&#8217;s hard to justify making large R&amp;D investments that might not pan out for 18+ months (let alone several years). That&#8217;s tough for investors. This has resulted in a strange bifurcation, with two broad categories of AI companies:</p><ol><li><p>Companies which require a massive amount of capital for large, long-term bets, which they use to hire expensive, ex-DeepMind researchers (<em>wink</em>) and give directly to Jensen Huang.</p></li><li><p>Companies that require two people, a garage, and a few A100s to make a product that can be directly sold to consumers.</p></li></ol><p>This gap is brutal for investors. #1 has a longterm payoff, which could be over 10 years, and there are relatively few examples of this making money in AI. Sure, there&#8217;s OpenAI, but they&#8217;re a bit of a fluke. What you really want is to invest in #2, but if you&#8217;re them&#8230; why take investment? Just build the project and try to sell it! If you can start making money, then raise, but you raise on much better terms, with much less dependence on investors.</p><p>This means, that, basically, there&#8217;s a trap when it comes to investing/raising funding at the pre-seed/seed stage. Companies that fall into category 2 don&#8217;t need it, so you end up funding category 1 companies, which are much riskier bets. This levels out at Series A, as then the category 2 companies become similar to standard consumer SaaS companies which can take investment as usual to build out sales, finance, support, etc., but it means that there&#8217;s a chasm of missing seed stage investor opportunities.</p><p>Either you make money, in which case you can bootstrap, or you don&#8217;t, in which case you can try again. What investors want, generally speaking, is a machine with predictable returns where you can put money in and <em>predictably make the company more valuable<strong>.</strong></em> The poster child is Uber, which at its peak, was able to use additional investor dollars to expand into new markets. They had the option (which they have now exercised) to stop spending on expansion and start focusing on profitably.</p><p>With AI companies, however, it seems like companies are able to find (or not find) product market fit very, very quickly. Consider:</p><ol><li><p>Lensa</p></li><li><p>Midjourney</p></li><li><p><a href="http://Stability.ai">Stability.ai</a></p></li><li><p><a href="http://Character.ai">Character.ai</a></p></li><li><p>Replika</p></li></ol><p>All of these products were able to find product market fit very quickly. Now, to a certain extent, this is because the underlying technology has been built out by research funded by the big companies, particularly Google, but the point remains.</p><p>Of course, these companies are all investable, as they can now take investor money and turn it into a bigger team, more sales people, more researchers, more support staff, etc., but they can skip straight to the Series A without having to go through pre-seed/seed as it is so cheap to build these products. </p><p>In short, there&#8217;s a lot of interest from investors at pre-seed/seed, but I think many, many companies will find that, when they go to raise their A, they&#8217;re not the darlings they once were.</p><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>In a startup, these are basically the same thing, as by taking equity in the company in exchange for salary, you are directly investing in the future success of the company.</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Efficient LLM inference]]></title><description><![CDATA[On quantization, distillation, and efficiency]]></description><link>https://www.artfintel.com/p/efficient-llm-inference</link><guid isPermaLink="false">https://www.artfintel.com/p/efficient-llm-inference</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Tue, 09 May 2023 16:22:07 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!Py9m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p></p><p>Lately, I&#8217;ve been thinking a lot about inference, and particularly, how to serve a given LLM more efficiently. The scenario is as follows: Your boss comes to you and says <em>Hey Finbarr, we&#8217;re about to go bankrupt because we&#8217;re spending all of our investor&#8217;s money on GPUs serving our 300B parameter model that raps in the style of <a href="https://en.wikipedia.org/wiki/John_Kenneth_Galbraith">John Kenneth Galbraith</a>. What can we do?</em></p><p>Broadly speaking, there are three main classes of things you can do:</p><ol><li><p>You can quantize the parameters of your model (<em>quantization</em>), where you keep your model exactly the same, but use less precision for each of the parameters.</p></li><li><p>You can distill a smaller version of your model (<em>distillation</em>), where you copy the architecture of your model to make it smaller and/or more efficient and then train this new, smaller model to mimic the outputs of the original, large model.</p></li><li><p>You can spend a bunch of time profiling your code and reduce the overhead without changing the architecture or parameters (<em>optimization</em>).</p></li></ol><p>The first place to start, somewhat obviously, is optimization. The amount of overhead that most programs have is ridiculous, and by simply profiling<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> your code, you can often find surprising amounts of overhead. For instance, I once had a colleague ask for help optimizing his code. He was training a neural network to perform a sophisticated calculation and had implemented a bunch of performance optimizations to make that faster, but he was <em>also</em> using a list to do lookups in a performance critical loop. I changed the list to a dict and made the code 200x faster.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><p>This isn&#8217;t a rare occurrence. Every time I&#8217;ve profiled code, I&#8217;ve been surprised at the resulting profile. So if you&#8217;re having performance issues (don&#8217;t worry, it happens to all of us, it&#8217;s natural), the first thing you should do is profile your code.</p><p>For most people, this will be sufficient. Just removing the overhead from your code and batching requests in the naive way will get you to the point where you can serve requests in a cost-effective manner, <em>particularly</em> if you have traditional software margins. But let&#8217;s say that you&#8217;ve done a bunch of profiling and you&#8217;re now at the point where the only remaining optimizations are implementing arcane kernels in Triton which requires hiring grizzled old CUDA experts away from Nvidia. What&#8217;s the next step you can take to use your GPUs effectively?</p><p>Now, you&#8217;re left with quantization and distillation. Quantization, where you use less precise weights for your neural network without changing anything else about it, has been talked about a lot lately. Llama.cpp, for instance, used this to great effect to reduce the memory required to store the llama weights by 4x.</p><p>Distillation has received less attention but has historically been an important part of serving models at scale. This is because distillation generally works much, much better than quantization, and if you have the resources, should be the way you do things.</p><p>There&#8217;s a key caveat there: if you have the resources.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?group=true&amp;coupon=9ee370da&quot;,&quot;text&quot;:&quot;Get 20% off a group subscription&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?group=true&amp;coupon=9ee370da"><span>Get 20% off a group subscription</span></a></p><p>Let&#8217;s go back to our hypothetical scenario. You&#8217;re a hardworking ML engineer at CoherentOpenStability, where you&#8217;re trying to reduce the inference costs for your latest and greatest LLM, StableClaudius-4. You&#8217;ve already profiled your code and reduced all of the overhead that you can. You now have a few options:</p><ol><li><p>You come up with a research breakthrough which lets you accomplish the same thing, for cheaper. E.g. you design a new sparse attention mechanism which works well.</p></li><li><p>You make your model smaller.</p></li></ol><p>If I were to compare these, the obvious winner is #1. If you can come up with a novel research contribution that magically improves your model, you should obviously do that. If this is you, stop reading this article, go write a paper, apply to OpenAI/Anthropic/DeepMind, and collect a ridiculously high salary for being a large language model whisperer. Most of us cannot do this. So we&#8217;re stuck trying to come up with a smaller model that accomplishes the same things.</p><p>How should we come up with a smaller model? A few options:</p><ol><li><p>You train a smaller model in the exact same way as your original model.</p></li><li><p>You distill your big model into a smaller model.</p></li><li><p>You quantize your existing model.</p></li></ol><p>In my opinion, the literature indicates a clear &amp; obvious ranking: distillation is strictly better than training a smaller model, and quantizing is <em>probably</em> better than training a smaller model.</p><p>There aren&#8217;t as many distillation papers as I would like, but the two that come to mind are <a href="https://arxiv.org/abs/1910.01108">DistilBERT</a> and the <a href="https://arxiv.org/abs/1503.02531">original distillation paper</a> from Hinton et. al. In DistilBERT, the authors reduce the model size by 40% while only hurting performance by 3%.</p><p>In the Hinton et. al paper, they&#8217;re able to match the performance of an ensemble of 10 models with a single, distilled model, and performance only decreases from 61.1% accuracy to 60.8% accuracy (99.5% of the original performance, with 10% of the size). Now, the Hinton paper is comparing against an ensemble, which is a particularly wasteful way to increase model size, but that&#8217;s still impressive result, and much better than training a model from scratch to perform the same task (which had only 58.9% accuracy).</p><p>The problem with distillation, however, is that it requires training a smaller model from scratch <em><strong>and</strong></em> running inference over your entire dataset with your large model. If you have a dataset the size of GPT-3 (500B), this would cost $1M at public API prices (5e11 tokens * 2e-6 $/token = $1e6), or $400k if we assume OpenAI has a 60% margin. Given that it cost approximately $5M to train GPT-3 initially, this would add 10-20% to that already large cost. Not prohibitive, but expensive.</p><p>If you can afford this cost, great! Do it. It&#8217;s almost certainly going to give you the best performance. If you want something cheaper, you&#8217;re deciding between training a smaller model from scratch and quantizing an existing model. To help, we have a paper <a href="https://arxiv.org/abs/2212.09720">k-bit inference scaling laws</a>. The idea is that, from an inference perspective, we&#8217;re agnostic between serving a 30B model at one level of precision and serving a 60B model with twice the level of precision, as most GPUs are twice as fast at running models with half the precision (e.g. <a href="https://www.nvidia.com/content/dam/en-zz/Solutions/Data-Center/a100/pdf/nvidia-a100-datasheet-us-nvidia-1758950-r4-web.pdf">A100s</a>).</p><div data-attrs="{&quot;url&quot;:&quot;https://s3-us-west-2.amazonaws.com/secure.notion-static.com/318ca76d-b54c-4d96-8b36-52a2099033c3/Screenshot_2023-05-05_at_08.00.53.png&quot;}" data-component-name="AssetErrorToDOM"><picture><img src="/img/missing-image.png" height="455" width="728"></picture></div><p>This figure shows the tradeoff between using various model sizes with various levels of precision. Let&#8217;s compare two points for the <a href="https://arxiv.org/abs/2205.01068">OPT</a> line of work.</p><p>Model precision Bit precision Mean zeroshot accuracy $10^{11}$ 8 0.675 $10^{11}$ 16 0.65 $10^{12}$ 8 0.725 $10^{12}$ 16 0.7</p><p>What we see is that, given a total number of model bits, we prefer the model with <em>fewer</em> bits per parameter. Intuitively, this makes sense: we don&#8217;t see a benefit from training half as many parameters with fp64 vs fp32.</p><p>If we look at another figure, this time from the <a href="https://arxiv.org/abs/2205.01068">OPT paper</a>, we can analyze how performance scales with the number of parameters. As OPT uses FP16, which uses 2 bytes (or 16 bits) per parameter, 1e11 parameters is equal to 1.6e12 bits. By using 10x less parameters, and going from 1.6e12 to 1.6e11 bits, the average accuracy for OPT goes from 0.7 to 0.65: a 10x decrease in cost for a 8% decrease in accuracy. Not quite as good as the model size/accuracy tradeoffs we see with distillation, but I think that most businesses would have to strongly consider the tradeoff.</p><p>The other thing to keep in mind about quantization is that it&#8217;s remarkably cheap to do! The SOTA method for quantization is <a href="https://arxiv.org/abs/2210.17323">GPTQ</a>, which can quantize a 175B parameter model in 4 GPU-hours (roughly $4 of cost at public cloud prices). Training the model from scratch, on the other hand, costs a lot; a rough estimate of the cost to train a GPT-3 style model is $5M for the full model, with cost scaling linearly in the number of parameters, so a 20B model would cost ~$500k, and requires a lot of data (~100B tokens to be <a href="https://arxiv.org/abs/2203.15556">Chinchilla optimal</a>).</p><p>So quantizing is great. But what, exactly, <em>is</em> quantization, and how does it work?</p><p>The idea behind quantization is simple. Computers, due to their discrete nature, can&#8217;t natively store floating point numbers. digital numerical representations are based on <strong>bits</strong>, namely 1s or 0s. These bits are assembled into <strong>binary</strong>. In a binary integer representation, you can represent a range of </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;[-2^{n-1}, 2^{n-1}]&quot;,&quot;id&quot;:&quot;SGHWKNHCNC&quot;}" data-component-name="LatexBlockToDOM"></div><p>using a signed integer, where n is the number of bits. One bit is reserved to represent whether or not the number is positive or negative, and n - 1 bits are used to represent the magnitude.</p><p>This works well, and is reasonably efficient. However, the problem comes when you want to represent the <a href="https://en.wikipedia.org/wiki/Real_number">real numbers</a>, i.e. numbers that can take on values between integers. The most common approach is to reserve 1 bit to indicate the positivity/negativity of the number, m bits to represent the magnitude of the number (the <em><strong>exponent</strong></em>), and (n - m - 1) bits to represent the precision of the number (the significand)</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!Py9m!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!Py9m!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 424w, https://substackcdn.com/image/fetch/$s_!Py9m!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 848w, https://substackcdn.com/image/fetch/$s_!Py9m!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 1272w, https://substackcdn.com/image/fetch/$s_!Py9m!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!Py9m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png" width="1456" height="576" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:576,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:125004,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!Py9m!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 424w, https://substackcdn.com/image/fetch/$s_!Py9m!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 848w, https://substackcdn.com/image/fetch/$s_!Py9m!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.png 1272w, https://substackcdn.com/image/fetch/$s_!Py9m!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2c4ff675-3791-4b6b-951a-bb59111a2f91_1860x736.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><p>The significand is just a (n-m-1)-bit unsigned integer, and can thus represent values up to 2^{n - m - 1}. </p><p>In a 32-bit floating point number (single precision), 1 bit is used for the sign, 8 bits for the exponent, and 23 bits for the significand. </p><p>In a 16-bit floating point number (half precision), 1 bit is used for the sign, 5 bits for the exponent, and 10 bits for the significand. </p><p>In a 64-bit floating point number (double precision), 1 bit is used for the sign, 11 bits for the exponent, and 52 bits for the significand.</p><p>Note where the additional bits are going&#8212; they are mostly going to the significand, which adds <em>precision</em>, rather than <em>magnitude</em>. In other words, this lets us distinguish between <em>smaller</em> numbers, rather than allowing us to represent <em>bigger</em> ones.</p><p>By default, all major tensor programming frameworks use 32-bit precision to store trainable parameters. There&#8217;s a reason for this: 32-bit precision tends to be a good default. There are very few applications which benefit from the additional precision (mostly scientific computing applications). However, in practice, most of the bleeding edge work now uses 16-bits.</p><p>But ok. Now that you&#8217;ve read through my digression on how precision works in floating point numbers, let&#8217;s say we&#8217;ve chosen a level of precision. How do you <em>actually</em> lower the precision of your weights? The naive approach is to simply truncate your weights at a given level of precision. As a simple example, if your weight is 0.534345, naive truncating the weights will convert it to 0.534.</p><p>The <a href="https://twitter.com/Tim_Dettmers/status/1642885684057997313?s=20">SOTA model for quantizing to 4-bits or below</a> is GPTQ. Some other methods are LLM.int8() and ZeroQuant. I&#8217;ll discuss these in depth in a future article, but here, I&#8217;ll focus on GPTQ. The basic idea behind GPTQ is that, while there&#8217;s necessarily a drop in information contained within the network by reducing the number of bits, we can reduce the impact it has on inference accuracy by training weights to directly minimize the difference between the two:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fbdi!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fbdi!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 424w, https://substackcdn.com/image/fetch/$s_!fbdi!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 848w, https://substackcdn.com/image/fetch/$s_!fbdi!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 1272w, https://substackcdn.com/image/fetch/$s_!fbdi!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fbdi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png" width="1456" height="522" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/2685118e-9f15-4033-a75c-8899305bc637_1622x582.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:522,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:178894,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fbdi!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 424w, https://substackcdn.com/image/fetch/$s_!fbdi!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 848w, https://substackcdn.com/image/fetch/$s_!fbdi!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.png 1272w, https://substackcdn.com/image/fetch/$s_!fbdi!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F2685118e-9f15-4033-a75c-8899305bc637_1622x582.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><p>Let&#8217;s walk through an example. Let&#8217;s say that x = 0.323, and as above, w = 0.534345. Then, keeping everything as a float32, the activation output is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;x \\cdot w = 0.323 \\cdot 0.534345 = 0.172593435&quot;,&quot;id&quot;:&quot;XGAOVNOXYR&quot;}" data-component-name="LatexBlockToDOM"></div><p>which, rounded to 6 decimal points (the precision for float32s), gives us an output of 0.172593.</p><p>Rounding naively, our output is</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;x \\cdot w_{\\text{naive}} = 0.323 \\cdot 0.534 = 0.172482&quot;,&quot;id&quot;:&quot;HBKRXGRSED&quot;}" data-component-name="LatexBlockToDOM"></div><p>The difference here is 1.114e-4. If we use GPTQ, we solve</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{argmin}_{\\hat{w}} (0.172593435 - 0.323 \\cdot \\hat{w})^2&quot;,&quot;id&quot;:&quot;EBLJEKZOOF&quot;}" data-component-name="LatexBlockToDOM"></div><p> which gives us </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\hat{w} = \\frac{0.172593435}{0.323} = 0.534345&quot;,&quot;id&quot;:&quot;PHLYFRRBGS&quot;}" data-component-name="LatexBlockToDOM"></div><p> which, rounded to 3 decimal points (the precision for float16s)&#8230; gives us precisely the same answer as naively rounding, but with more effort.</p><p>Presumably this would matter more in other scenarios? I haven&#8217;t been able to come up with a simple example that makes GPTQ worth it. But in actual deployment scenarios, GPTQ claimed a significant difference (RTN meaning &#8220;round to nearest&#8221;):</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!6kRn!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!6kRn!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 424w, https://substackcdn.com/image/fetch/$s_!6kRn!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 848w, https://substackcdn.com/image/fetch/$s_!6kRn!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 1272w, https://substackcdn.com/image/fetch/$s_!6kRn!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!6kRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png" width="1096" height="314" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/ebe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:314,&quot;width&quot;:1096,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:75937,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!6kRn!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 424w, https://substackcdn.com/image/fetch/$s_!6kRn!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 848w, https://substackcdn.com/image/fetch/$s_!6kRn!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.png 1272w, https://substackcdn.com/image/fetch/$s_!6kRn!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Febe32662-7241-4ba4-9ced-eea6c6a54787_1096x314.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><p>So this is a method that works much better than naively rounding, and is cheap.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h1>Conclusion</h1><p>Quantization isn&#8217;t magic. Ultimately, you&#8217;re always sacrificing accuracy for performance. Maybe you won&#8217;t lose a lot. But you&#8217;ll never <em>gain</em> accuracy, so at best you&#8217;re staying the same.</p><p>It&#8217;s also unclear how often the tradeoff is worth it. <a href="https://arxiv.org/abs/2212.09720">Tim Dettmers scaling law for quantization</a>. If you&#8217;re using half the precision, it might be worth using <em>the same precision</em> and half the weights and <a href="https://finbarr.ca/llms-not-trained-enough/">training for twice as long on more data</a>. This is what, for instance, <a href="https://blog.replit.com/replit-developer-day-recap#newmodel">replit did</a>. For many practitioners, the cost to <em>serve</em> a model heavily outweighs the cost to <em><strong>train</strong></em> the model. If this is you, you might not care about quantizing one.</p><p>Even if you do, distillation will typically outperform quantization. So if you <em>can</em> distill the model, you probably should. It&#8217;s only when you don&#8217;t have the resources to do this that quantization is clearly worth it.</p><p>Finally, with quantization, you only get a linear speedup as you decrease the number of bytes. That&#8217;s pretty good! But ideally we&#8217;d want to see much better scaling. Perhaps some sort of sparsity will do better.</p><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>Not even using a fancy GPU profiler, but just profiling the program as a whole using the basic profiler for your language!</p><p></p></div></div>]]></content:encoded></item><item><title><![CDATA[Papers I’ve read this week: Image generation]]></title><description><![CDATA[A discussion of 4 seminal image generation papers]]></description><link>https://www.artfintel.com/p/papers-ive-read-this-week-image-generation</link><guid isPermaLink="false">https://www.artfintel.com/p/papers-ive-read-this-week-image-generation</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Tue, 11 Apr 2023 16:32:09 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!IK79!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I&#8217;ve been reading about a lot of image generation models lately, focusing on the OpenAI papers, as they seem like the basis of a lot of future work. Here, I discuss 4 seminal papers:</p><ol><li><p>CLIP</p></li><li><p>DALL-E</p></li><li><p>GLIDE</p></li><li><p>DALL-E 2</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p></li></ol><h1>CLIP</h1><p><a href="https://openai.com/research/clip">Abstract</a></p><p>This isn&#8217;t an image generation paper <strong>per se</strong>, but is used by a lot of them as the embedding scheme. The main idea behind the paper is to predict which caption goes with which image as a way of doing self-supervised learning from a dataset of (image, text) pairs. If this works, then the result will be aligned text and image embeddings, which would be really useful for a variety of applications, e.g. search, image generation, zero-shot classification, etc.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!IK79!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!IK79!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 424w, https://substackcdn.com/image/fetch/$s_!IK79!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 848w, https://substackcdn.com/image/fetch/$s_!IK79!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 1272w, https://substackcdn.com/image/fetch/$s_!IK79!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!IK79!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png" width="1342" height="664" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:664,&quot;width&quot;:1342,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:173290,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!IK79!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 424w, https://substackcdn.com/image/fetch/$s_!IK79!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 848w, https://substackcdn.com/image/fetch/$s_!IK79!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 1272w, https://substackcdn.com/image/fetch/$s_!IK79!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F544c5609-bc0f-4a3f-9975-991fe88f3d39_1342x664.png 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg 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><p>The architecture is pretty simple; they jointly train an image and a text encoder on a batch of N (image, text) pairs using a contrastive loss which predicts which of the N^2 pairings actually occurred. They maximize the cosine similarity of the image &amp; text embeddings of the real pairs, while minimizing the cosine similarity of the N^2 - N incorrect pairs. Pseudo-code:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!XEY1!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!XEY1!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 424w, https://substackcdn.com/image/fetch/$s_!XEY1!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 848w, https://substackcdn.com/image/fetch/$s_!XEY1!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 1272w, https://substackcdn.com/image/fetch/$s_!XEY1!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!XEY1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png" width="680" height="708" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:708,&quot;width&quot;:680,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:135072,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/png&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:false,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!XEY1!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 424w, https://substackcdn.com/image/fetch/$s_!XEY1!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 848w, https://substackcdn.com/image/fetch/$s_!XEY1!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.png 1272w, https://substackcdn.com/image/fetch/$s_!XEY1!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4bdf6a6f-7927-411c-bbfd-d59b852907a9_680x708.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></figure></div><p>Once the model is trained, they&#8217;re able to use it for a variety of tasks. My favourite is zero-shot classification; they ask the model to assign probabilities to the text &#8220;{class}&#8221; and use that as the probability that the image is a member of the class. Interestingly, by using the prompt &#8220;A photo of a {class}.&#8221;, they got a 1.3% improvement in model accuracy.</p><p>Using this zero-shot classification scheme, the results are quite impressive: they&#8217;re able to match the accuracy of the original ResNet-50 on ImageNet <em><strong>zero-shot</strong></em>, without training on any of the ImageNet dataset.</p><p>They experiment with two separate image models, one based on various ResNet architectures, and one based on ViT. They find that the ViT performs better, and is actually cheaper to train than the ResNet.</p><p>This is really interesting to me, as this is a prompt that humans were able to come up with. I&#8217;m curious what the optimal prompt is. An experiment I&#8217;d love to run would be to use some sort of RL driven approach to explore the token space and find the best prompt for such a classification scheme; I suspect there&#8217;s more performance that can be squeezed out of it.</p><p>In any case, CLIP is remarkable because it&#8217;s a very straightforward embedding method that works quite well, and is able to scale to massive amounts of data. It&#8217;s further evidence that large scale self-supervised pre-training is the way to go to achieve SOTA performance with neural nets.</p><h1>DALL-E</h1><p><a href="https://arxiv.org/abs/2102.12092">Abstract</a></p><p>This paper uses a transformer to auto-regressively model text &amp; image tokens as a single stream of data to enable zero-shot image generation</p><p>For a long time, image generation was dominated by GANs, but they&#8217;re tough to scale. I&#8217;m not sure exactly what the problems are with scaling them; mode collapse is always cited, but I&#8217;m not up to speed with that literature. I&#8217;m going to dive into it for a future &#8220;Papers I&#8217;ve read this week.&#8221;</p><p>DALL-E was the first (afaik) model to massively scale autoregressive transformers on large image datasets. They trained a 12B parameter model on 250M (image, text) pairs using a two-stage training procedure:</p><ol><li><p>They train a discrete VAE to compress each 256x256 RGB image into a 32x32 grid of image tokens, each element of which can assume 8192 possible values.</p></li><li><p>They concatenate up to 256 BPE-encoded text tokens with the image token.</p></li></ol><p>The concatenated embedding is fed to an autoregressive transformer to model the joint distribution over the text &amp; image tokens, which is equivalent to maximizing the standard <a href="https://en.wikipedia.org/wiki/Evidence_lower_bound">ELB</a>.</p><p>Let <em>x</em> denote the images, <em>y</em> the captions, and <em>z</em> the tokens for the encoded RGB image. They model the distribution via</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;p_{\\theta, \\psi}(x, y, z) = p_\\theta(x | y, z) p_\\psi(y, z)&quot;,&quot;id&quot;:&quot;HMNIHELPFZ&quot;}" data-component-name="LatexBlockToDOM"></div><p>i.e. they learn two models&#8212; p_\theta, the distribution over the RGB images generated by the dVAE decoder from the image tokens, and p_\psi, the joint distribution over the text and image tokens modelled by the transformer.</p><p>The loss has the lower bound </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\ln p_{\\theta, \\psi}(x, y) \\geq E_{z \\thicksim q_{\\phi}(z | x)}\\left( \\ln p_\\theta(x | y, z) - \\beta D_{KL}(q_\\phi(y, z | x), p_\\psi(y, z))\\right)&quot;,&quot;id&quot;:&quot;PAADSSPORF&quot;}" data-component-name="LatexBlockToDOM"></div><p>The bound only holds when \beta is 1, but they play with other values, and find it useful to use bigger ones.</p><p>I wrote up a <a href="https://finbarr.ca/deriving-the-dall-e-lower-bound/">derivation on my blog</a>, as it was unclear to me where the lower bound came from. As we&#8217;re <em>maximizing</em> the loss, maximizing the lower bound is fine. q_\phi here is the distribution over the image tokens generated by the dVAE encoder given the RGB image <em>x</em>.</p><p>This paper, like many image generation papers, has to abstract away from pixels:</p><blockquote><p>using pixels directly as image tokens would require an inordinate amount of memory for high-resolution images</p></blockquote><p>We see this in many image generation models, as pixels are really expensive, while if you can learn a mapping from text/image tokens into some latent space, you can then learn a separate mapping from the latent space to pixel space, and then upgrade this separately. This modularity is particularly useful for production systems, as you don&#8217;t have to train <em>everything</em> to experiment with your system.</p><p>They first train the dVAE to learn a visual codebook by maximizing the lower bound using the <a href="https://arxiv.org/abs/1611.01144">gumbel-softmax</a> <a href="https://arxiv.org/abs/1611.00712">relaxation</a> (they have to use this as q_\psi is a discrete distribution, so we can&#8217;t use the reparametrization gradient to maximize it).</p><p>Then, they fix \phi and \theta, and learn the prior distribution over the text &amp; image tokens by maximizing the ELB with respect to \psi, using a 12B parameter transformer for p_\psi. The model is fairly standard, using BPE to encode the caption, and getting image tokens from the dVAE encoder logits. The transformer itself is a decoder where each image token attends to all text tokens.</p><p>Shockingly, given the current state of the art in LLMs, this model only takes up 24GB of memory, so it could be trained on a single A100 (as they have 40GB of memory). They only had access to V100s for whatever reason (which only have 16GB of memory) so they had to use <a href="https://arxiv.org/abs/1910.02054">ZeRO</a> to train their model on multiple machines.</p><p>They used <a href="https://arxiv.org/abs/1905.13727">PowerSGD</a>, which I had never heard of before, which dramatically reduced the amount of communicated needed between GPUs, as they were able to compress the parameter gradients by a factor of 85%.</p><p>To sample from their model, they rerank the samples from the transformer using <a href="https://openai.com/research/clip">CLIP</a>, which assigns a score for how well the image matches the caption; they generate N samples and select the top K to show to the user.</p><h1>GLIDE</h1><p><a href="https://arxiv.org/abs/2112.10741">Paper</a></p><p>In Glide, a 3.5B parameter diffusion model is used to turn text embeddings into images. They explore two different guiding methods: CLIP, and <a href="https://openreview.net/forum?id=qw8AKxfYbI">classifier-free guidance</a>. The model is quite straightforward, using a vanilla transformer to generate embeddings, and a vanilla diffusion model to output images from the embeddings. The CLIP guidance method is interesting; it&#8217;s described as:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!n6vj!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!n6vj!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 424w, https://substackcdn.com/image/fetch/$s_!n6vj!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 848w, https://substackcdn.com/image/fetch/$s_!n6vj!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 1272w, https://substackcdn.com/image/fetch/$s_!n6vj!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!n6vj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png" width="580" height="342" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:342,&quot;width&quot;:580,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:70064,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!n6vj!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 424w, https://substackcdn.com/image/fetch/$s_!n6vj!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 848w, https://substackcdn.com/image/fetch/$s_!n6vj!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.png 1272w, https://substackcdn.com/image/fetch/$s_!n6vj!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F016f1e08-b970-452e-a383-0dd4d7199b25_580x342.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><p>They train two models:</p><ol><li><p>A 1.2B parameter text encoding transformer which takes in the text tokens as input and outputs an embedding</p></li><li><p>A 1.5B parameter upsampling diffusion model, which takes in the embeddings and outputs the final image</p></li></ol><p>this seems like a really logical architecture- I'm surprised it was novel? I need to read more of the preceding literature to understand the context. To evaluate their model, they use a bunch of tasks to evaluate their model, such as in-painting, composition, corgi images, etc. I'm curious how much of this was introduced by them vs introduced by others- I don't have the context to understand that, but the way they evaluate their models seems very similar to how all subsequent models are evaluated.</p><h1>DALL-E 2</h1><p><a href="https://cdn.openai.com/papers/dall-e-2.pdf">Paper</a></p><p>DALL-E 2 uses a two-step training process: first, train CLIP, then, train a text-to-image generation process from it. In the text-to-image generation process, they have two models:</p><ol><li><p>A prior, which takes in the CLIP text embedding, and outputs an image embedding,</p></li><li><p>The decoder, which takes in the CLIP image embedding and outputs the image.</p></li></ol><p>The models are both diffusion models, using</p><p>They explored two different priors, one an autoregressive (AR) prior using a ??? to iteratively build the image embedding from a sequence of discrete codes, and the other, a diffusion prior, which directly models the image embedding. It&#8217;s worth noting that both methods involve iteratively building the embedding; the AR prior iteratively builds a sequence which is the embedding, while the diffusion model iteratively <em><strong>refines</strong></em> the embedding.</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!fSEQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!fSEQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 424w, https://substackcdn.com/image/fetch/$s_!fSEQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 848w, https://substackcdn.com/image/fetch/$s_!fSEQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 1272w, https://substackcdn.com/image/fetch/$s_!fSEQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!fSEQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png" width="976" height="172" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:172,&quot;width&quot;:976,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:32965,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!fSEQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 424w, https://substackcdn.com/image/fetch/$s_!fSEQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 848w, https://substackcdn.com/image/fetch/$s_!fSEQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 1272w, https://substackcdn.com/image/fetch/$s_!fSEQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F9dccc7b8-c9d0-48a4-9d3c-6a8b7683c7ab_976x172.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Given that the diffusion model is preferred by human evaluators, that seems to do better. This makes sense&#8212; the diffusion model is able to modify any part of the embedding, while the AR model is only able to modify the element at a specific index. There are interesting implications to language modelling here&#8212; maybe Sander Dieleman is right, and <a href="https://sander.ai/2023/01/09/diffusion-language.html">diffusion language models</a> are the next big thing.</p><p>Comparing DALL-E 2 to GLIDE, the main difference is that image generation is split into two steps:</p><ol><li><p>Transforming the text embedding into an image embedding</p></li><li><p>Generating the actual image</p></li></ol><p>Naively, it makes sense to me to combine these two steps and train the whole thing end-to-end, but as DALL-E 2 was a significant improvement over GLIDE, it seems like my intuition is false.</p><p>In particular, it&#8217;s not clear to me why we need to go from CLIP to CLIP, isn&#8217;t the whole premise of CLIP that the text and image embeddings are in the same latent space (and thus equivalent)? I posted this comment on Twitter, and I got some interesting comments:</p><ul><li><p><a href="https://twitter.com/sharifshameem">Sharif</a> noted that while CLIP should, in theory, be encoding &#8220;both text and images into the same latent space, there&#8217;s still a large gap between the embeddings from each modality&#8221;, pointing me to <a href="https://modalitygap.readthedocs.io/en/latest/">a paper about understanding this modality gap</a>.</p></li><li><p><a href="https://twitter.com/BenTheEgg">Benjamin</a> <a href="https://twitter.com/BenTheEgg/status/1645644757119508480?s=20">hypothesized that there is a loss of spatial information</a> due to the spatial encoder mapping the (H, W, C) images to (embedding_dimension,) embedding vectors.</p></li></ul><p>To me, this indicates that CLIP isn&#8217;t nearly as good as we would hope, and there&#8217;s significant room to improve it.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h1>Future papers</h1><p>I haven&#8217;t read, but plan to read, the following papers, possibly for a &#8220;diffusion models&#8221; version of &#8220;Papers I&#8217;ve read this week&#8221;:</p><ul><li><p><a href="https://arxiv.org/abs/2302.12248">https://arxiv.org/abs/2302.12248</a></p></li><li><p>Generative modelling through SDEs: <a href="https://arxiv.org/abs/2011.13456">https://arxiv.org/abs/2011.13456</a></p></li><li><p>Latent diffusion models: <a href="https://arxiv.org/abs/2112.10752">https://arxiv.org/abs/2112.10752</a></p></li><li><p>Classifier guidance: <a href="https://arxiv.org/abs/2105.05233">https://arxiv.org/abs/2105.05233</a></p></li><li><p>Classifier-free guidance: <a href="https://openreview.net/forum?id=qw8AKxfYbI">https://openreview.net/forum?id=qw8AKxfYbI</a></p></li><li><p>ControlNet: <a href="https://arxiv.org/abs/2302.05543">https://arxiv.org/abs/2302.05543</a></p><p></p></li></ul>]]></content:encoded></item><item><title><![CDATA[Five years of progress in GPTs]]></title><description><![CDATA[A summary of the progression of the SOTA in language models]]></description><link>https://www.artfintel.com/p/five-years-of-progress-in-gpts</link><guid isPermaLink="false">https://www.artfintel.com/p/five-years-of-progress-in-gpts</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Wed, 29 Mar 2023 18:48:41 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!p5TQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A note: Substack doesn&#8217;t do a great job rendering equations, so you might want to read this article on my <a href="https://finbarr.ca/five-years-of-gpt-progress/">blog</a> (but first, <a href="https://finbarrtimbers.substack.com/about">subscribe</a> on Substack to be notified of future articles).</em></p><p><em>I have started to support paid subscriptions. If you have found this newsletter professionally useful, and want to help me spend more time writing, please consider signing up for a paid subscription.</em></p><p>In this article, I discuss the generative pre-trained transformer (GPT) line of work, and how it has evolved over time. I focus on the SOTA models, and the differences between them. There are a bunch of different articles summarizing these papers, but nothing that I&#8217;m aware of that explicitly focuses on the differences between them. <strong>Until now.</strong></p><p>I focus on the GPT line of research as that&#8217;s what&#8217;s driving the current fever pitch of development. There&#8217;s a ton of prior work before large GPTs (eg the <a href="https://ai.googleblog.com/2006/08/all-our-n-gram-are-belong-to-you.html">n-gram models</a> from the 2000s, <a href="https://arxiv.org/abs/1810.04805">BERT</a>, etc), and after (e.g. <a href="https://github.com/BlinkDL/RWKV-LM">RWKV</a>) but this post is super long, so I&#8217;m gonna save those for future articles.</p><p>I also don&#8217;t go into any detail about <a href="https://huggingface.co/blog/rlhf">RLHF</a> or other finetuning methods. I&#8217;m planning to write about that in the future. Those techniques are critical to the performance of the deployed LLM systems like ChatGPT, Claude, LaMDA etc., so they&#8217;re worth understanding. I don&#8217;t discuss any of the dialog specific systems, as I want to focus on the most general, pure language modelling transformers.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>GPT</h2><p><a href="https://openai.com/research/language-unsupervised">Abstract</a></p><p>The first GPT paper is interesting to read with hindsight. It doesn&#8217;t appear like anything special and doesn&#8217;t follow any of the conventions that have developed. The dataset is described in terms of GB rather than tokens, and the number of parameters in the model isn&#8217;t explicitly stated. To a certain extent, I suspect that the paper was a side project at OpenAI and wasn&#8217;t viewed as particularly important; there&#8217;s only 4 authors, and I don&#8217;t remember it particularly standing out at the time.</p><p>The architecture is remarkably unchanged compared to GPT-3:</p><ul><li><p>Decoder-only transformer, with 12 layers, 768 embedding dimension, 12 attention heads, and 3072 (4x the embedding dimensions).</p></li><li><p>They use Adam, with a warm up, and anneal to 0 using a cosine schedule.</p></li><li><p>Initialize weights to N(0, 0.02), using BPE with a vocab of 40k merges.</p></li><li><p>Activations are GELUs.</p></li><li><p>Context of 512</p></li><li><p>117M parameters</p></li><li><p>Learned position embedding, not the sinusoidal ones from <a href="https://arxiv.org/abs/1706.03762">Attention is all you need</a>.</p></li></ul><p>The number of parameters isn&#8217;t explicitly discussed, but appears to be roughly 120M, easily enough to fit on a single V100 or a standard consumer GPU (rough estimate of 120M parameters for the model, 240M for the optimizer, for 360M parameters; assuming each is a float32, then this takes up 4 bytes * 360M = 1440MB/1.4GB.</p><p>They use the <a href="https://huggingface.co/datasets/bookcorpus">BooksCorpus</a> dataset (1B tokens<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a>, 4GB), training for 100 epochs with a batch size of 64. 1B tokens is a small dataset by modern standards, as is a batch size of 64.</p><p>The most surprising thing compared to modern GPTs is that they train for 100 epochs. Modern GPTs rarely ever see repeated data, and if they do, they typically only see certain datapoints a small number of times (2-4x), and the entire dataset is never repeated 100x.</p><h2>GPT-2</h2><p><a href="https://openai.com/research/better-language-models">Abstract</a></p><p>GPT-2 is where the language models start to get big. This is the first time that OpenAI trains a model with &gt;1B parameters. We start to see scale as a primary concern; in GPT, the authors trained a single model, but here, the authors train a range of models, with sizes ranging from GPT to 10x GPT (which is the actual GPT-2 model).</p><p>The differences in architecture compared to GPT are as follows:</p><ul><li><p>They layernorm the inputs and add an additional layernorm to the output of the final self-attention block</p></li><li><p>Weights are scaled by layer by 1/sqrt(n)</p></li><li><p>Vocabulary of ~50k (up from ~40k)</p></li><li><p>Context of 1024 (up from 512)</p></li><li><p>Batches of 512 (up from 64)</p></li><li><p>Largest model is 1.5B parameters</p></li></ul><p>The dataset is much, much bigger, going from 4GB of data consisting of publicly available books, to 40GB (or 9B tokens)<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> of text scraped from the internet (<a href="https://paperswithcode.com/dataset/webtext">WebText</a>).</p><p>It&#8217;s unclear if they trained the model for 100 epochs as before; they say they followed the same training procedure, so presumably they did. Again, this is a significant departure from later work.</p><p>Nothing here is particularly different from GPT; most of the changes are related to making the model bigger. The only other changes are the layernorm changes and the weight scaling, which don&#8217;t seem to make a big difference (although, as always, more ablations would be nice).</p><h1>Kaplan et. al</h1><p><a href="https://arxiv.org/abs/2001.08361">Abstract</a></p><p>I feel like there has to be a better name to refer to this paper, but I can&#8217;t find one, so I just call it Kaplan et. al. This was one of the first (maybe the first?) scaling law papers for LLMs. In it, the authors train a large number of GPT style models to make empirical predictions for how the model characteristics vary with scale. This paper was highly influential as it formed the basis for GPT-3, justifying scaling to 175B parameters (hitherto unseen level of scale).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!p5TQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!p5TQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 424w, https://substackcdn.com/image/fetch/$s_!p5TQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 848w, https://substackcdn.com/image/fetch/$s_!p5TQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 1272w, https://substackcdn.com/image/fetch/$s_!p5TQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!p5TQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png" width="1332" height="566" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/d8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:566,&quot;width&quot;:1332,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:176404,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!p5TQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 424w, https://substackcdn.com/image/fetch/$s_!p5TQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 848w, https://substackcdn.com/image/fetch/$s_!p5TQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.png 1272w, https://substackcdn.com/image/fetch/$s_!p5TQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fd8cb9757-3c59-4b97-bfcb-5ea4be51d21c_1332x566.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><p>This paper is notable as it did <strong>real science</strong>, running a number of experiments and making predictions as to how models should scale. It stands up very well.</p><p>Some notable results from the paper:</p><ul><li><p>They found that the model performance (in terms of test loss) relies heavily on the number of parameters and the number of tokens trained on, with the model architecture having very little impact.</p></li><li><p>Model performance follows a power-law with each of N (the number of parameters in the model), D (the number of tokens trained on), and C (the amount of compute used for training). If any of these are held fixed, then performance rapidly hits diminishing returns.</p></li><li><p>Large models are more sample-efficient than smaller models. This is, to a certain extent, foreshadowing for Chinchilla (which I will discuss later).</p></li><li><p>It is possible to determine the optimal batch size for the model by measuring the gradient noise scale following <a href="https://arxiv.org/abs/1812.06162">McCandlish et. al</a>. This is not novel, but it is important to keep in mind, as many practitioners determine batch size empirically, when it is possible to calculate this directly.</p></li></ul><p>This paper was, until Chinchilla came out, the gold standard for how to train large language models.</p><h2>GPT-3</h2><p><a href="https://arxiv.org/abs/2005.14165">Abstract</a></p><p>Here is where the era of truly <em><strong>large</strong></em> language models began, and the current AI <s>bubble</s> excitement took off. In the paper, the authors train 10 models, varying from 125M parameters (&#8221;GPT-3 Small&#8221;) to 175B parameters (&#8221;GPT-3&#8221;).</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!iCjQ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!iCjQ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 424w, https://substackcdn.com/image/fetch/$s_!iCjQ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 848w, https://substackcdn.com/image/fetch/$s_!iCjQ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 1272w, https://substackcdn.com/image/fetch/$s_!iCjQ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!iCjQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png" width="1132" height="370" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:370,&quot;width&quot;:1132,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:95983,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!iCjQ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 424w, https://substackcdn.com/image/fetch/$s_!iCjQ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 848w, https://substackcdn.com/image/fetch/$s_!iCjQ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.png 1272w, https://substackcdn.com/image/fetch/$s_!iCjQ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F087e892a-715f-42ca-a7b1-7cc9ff04d346_1132x370.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><p>For each of the models, the architectures are identical to GPT-2 with the exception that they use &#8220;alternating dense and locally banded sparse attention patterns in the layers of the transformer.&#8221; The sparse attention here refers to the attention mechanism introduced in the <a href="https://paperswithcode.com/method/sparse-transformer">Sparse Transformer</a>, which lets attention scale proportional to O(n &#8730;n) (where n is the context length). The standard dot-product attention mechanism scales proportional to O(n^2), so this is a substantial gain. I would have loved a proper ablation to see what difference sparse vs dense attention makes, but alas.</p><p>I&#8217;m very curious <em><strong>why</strong></em> they used sparse attention. Reproductions and later papers uniquely use dense attention. As this paper came before <a href="https://arxiv.org/abs/2205.14135">FlashAttention</a> and some of the other algorithmic innovations that make dense attention faster, maybe this was a computational bottleneck? It&#8217;s really unclear.</p><p>They don&#8217;t provide any detail about the computational architecture, i.e. how they distributed the model. The authors claim it&#8217;s because it doesn&#8217;t really matter, but I think it was restricted for competitive reasons, as it makes the paper much more difficult to reproduce. Megatron, which I&#8217;ll discuss later, was highly influential <em><strong>because</strong></em> they went into detail about how they made model parallelism work for their GPT.</p><p>What I find <strong>really interesting</strong> about the GPT-3 paper is that it was an incredible advance without a lot of novelty. They took their existing methods and &#8220;just&#8221; scaled it up! Because of the need for novelty, there are many research projects that don&#8217;t get pursued because they&#8217;re &#8220;only&#8221; engineering projects, or they &#8220;only&#8221; do hyper-parameter tuning and wouldn&#8217;t be able to get published, even if they had impressive performance improvements. That OpenAI went against the grain here is a credit to them (and they were rewarded, with GPT-3 getting a <a href="https://neuripsconf.medium.com/announcing-the-neurips-2020-award-recipients-73e4d3101537">best paper reward</a> at NeurIPS &#8216;20).</p><p>This is a strength of OpenAI (and <a href="http://Stability.ai">Stability.ai</a>, Midjourney, basically everywhere that&#8217;s not FAIR/Google Brain/Deepmind/etc). You could alternatively frame it as a weakness of the more academic labs that have promotion/performance review policies driven by publications.</p><h1>Jurassic-1</h1><p><a href="https://uploads-ssl.webflow.com/60fd4503684b466578c0d307/61138924626a6981ee09caf6_jurassic_tech_paper.pdf">PDF</a></p><p>I wasn&#8217;t sure whether or not to include Jurassic-1. It&#8217;s a model from the Israeli tech company AI21 Labs. I haven&#8217;t heard a lot about them, but the paper&#8217;s cited by a bunch of the papers later on in the article; they trained a 178B parameter model that outperformed GPT-3 in a few categories, and was faster for inference. It&#8217;s impressive that they&#8217;re competing with DeepMind, OpenAI, Nvidia, etc. despite only having <a href="https://en.wikipedia.org/wiki/AI21_Labs">raised &lt;$10M</a> at the time. They made a zero-shot and few-shot test suite <a href="https://github.com/ai21labs/lm-evaluation">publicly available</a>.</p><p>Like many other papers, they don&#8217;t go into detail about the engineering details behind training a large model (178B parameters) over 800 GPUs:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!7SvS!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!7SvS!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 424w, https://substackcdn.com/image/fetch/$s_!7SvS!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 848w, https://substackcdn.com/image/fetch/$s_!7SvS!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 1272w, https://substackcdn.com/image/fetch/$s_!7SvS!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!7SvS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png" width="1456" height="138" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/fd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:138,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:66315,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!7SvS!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 424w, https://substackcdn.com/image/fetch/$s_!7SvS!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 848w, https://substackcdn.com/image/fetch/$s_!7SvS!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 1272w, https://substackcdn.com/image/fetch/$s_!7SvS!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ffd7ec951-a064-44cb-a370-7b171be4ba5a_1690x160.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The paper is remarkably sparse on details, which I suspect was done for competitive reasons, just like GPT-4.</p><p>Facebook is the only company to go into <a href="https://github.com/facebookresearch/metaseq/blob/main/projects/OPT/chronicles/OPT175B_Logbook.pdf">detail about their experiences</a> training a 175B parameter model, just like Nvidia is the only company to go into detail about the computational architecture required to train a LLM over many GPUs (see: the Megatron paper, next). In both cases, the companies are <a href="https://gwern.net/complement">commoditizing their complements</a> and strengthening their main lines of business by making it easier to train large models.</p><p>Jurassic uses a different architecture from GPT-3, but again, doesn&#8217;t go into much detail:</p><ul><li><p>76 layers (vs 96 layers for GPT-3)</p></li><li><p>They use the SentencePiece tokenizer, with a large vocabulary of 256K (vs GPT-3 which used BPE w/ ~50k tokens).</p></li></ul><p>Neither of these changes are material, in my opinion. I think what we&#8217;re seeing is that there&#8217;s a relatively large degree of freedom in model architectures which produce similar results. This is borne out by their evaluation, which has results similar to GPT-3 (better in some categories, worse in others), although Jurassic-1 is faster for inference due to being shallower.</p><p>We&#8217;re starting to see a consistent pattern emerge:</p><ul><li><p>Papers introduce a bunch of changes, their own dataset, and have a new SOTA</p></li><li><p>but they don&#8217;t do a proper ablation, so it&#8217;s tough to understand what was important and what <em>drove</em> the improvements</p></li></ul><p>GPT-2, GPT-3, Jurassic-1, etc. all did this.</p><h1>Megatron-Turing NLG</h1><p>Megatron was a highly influential paper that introduced efficient model-parallel architectures. If you&#8217;re interviewing for a LLM job today, you&#8217;re going to be expected to be familiar with it. Megatron introduced <strong>tensor parallelism</strong>, a variant of model parallelism that splits the models to allow for intra-layer model parallelism, achieving 76% as efficient as a single GPU baseline (although the baseline is only 30% of peak FLOPS).</p><p>Prior to Megatron, the published SOTA for model parallelism was to use model pipelining, e.g. <a href="https://arxiv.org/abs/1811.06965">GPipe</a>. However, this was difficult to do and not well supported by code. There were attempts to support tensor parallelism, e.g. <a href="https://paperswithcode.com/method/mesh-tensorflow">Mesh-Tensorflow</a>, which introduced a language for specifying a general class of distributed computations in TensorFlow, but nothing had really dominated. Interestingly, the first author had just left DeepMind 1 year before this was published, so this was possibly his first project at Nvidia.</p><p>Megatron has the realization that, if you have a neural network like this:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Y = f(XW)&quot;,&quot;id&quot;:&quot;QNDUPMDAEW&quot;}" data-component-name="LatexBlockToDOM"></div><p>and you split </p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;W = \\begin{bmatrix} W_1 &amp; W_2 \\end{bmatrix}&quot;,&quot;id&quot;:&quot;FDJYFYIZEG&quot;}" data-component-name="LatexBlockToDOM"></div><p>i.e. along the columns, then</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;Y = \\begin{bmatrix}f(X W_1) &amp; f(X W_2)\\end{bmatrix}&quot;,&quot;id&quot;:&quot;RRBKHOYFGG&quot;}" data-component-name="LatexBlockToDOM"></div><p>so you don&#8217;t need to do any synchronization to calculate Y. Consequently, the only points where you need synchronization (all-reduces) in the transformer are:</p><ol><li><p>In the forward pass, to concatenate the model activations after the MLP block before adding dropout</p></li><li><p>In the backwards pass, at the start of the self-attention block.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!JKAc!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!JKAc!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 424w, https://substackcdn.com/image/fetch/$s_!JKAc!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 848w, https://substackcdn.com/image/fetch/$s_!JKAc!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 1272w, https://substackcdn.com/image/fetch/$s_!JKAc!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!JKAc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png" width="1100" height="1268" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1268,&quot;width&quot;:1100,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:846584,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!JKAc!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 424w, https://substackcdn.com/image/fetch/$s_!JKAc!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 848w, https://substackcdn.com/image/fetch/$s_!JKAc!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.png 1272w, https://substackcdn.com/image/fetch/$s_!JKAc!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F4ece1271-c55a-437c-974a-2010b9bae222_1100x1268.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></li></ol><p>Now, I strongly suspect this is what GPT-3 and Jurassic-1 both did, but neither went into detail about the specific parallelism models they used, other than to say (from GPT-3):</p><blockquote><p>To train the larger models without running out of memory, we use a mixture of model parallelism within each matrix multiply and model parallelism across the layers of the network.</p></blockquote><p>Presumably, this style of parallelism is what is meant by &#8220;model parallelism within each matrix multiply,&#8221; as I find it hard to imagine what else they could mean.</p><h2>Gopher</h2><p><a href="https://arxiv.org/abs/2112.11446">Abstract</a></p><p>Gopher was a LLM trained by DeepMind. Interestingly, the lead author joined OpenAI shortly after it was published, along with a few of the coauthors. The architecture was the same as GPT-2, except:</p><ul><li><p>They use <a href="https://arxiv.org/abs/1910.07467">RMSNorm</a> (instead of layernorm)</p></li><li><p>Use relative positional encoding scheme from <a href="https://arxiv.org/abs/1901.02860">Transformer-XL</a> (while GPT-* used a learned positional embedding)</p></li><li><p>They use <a href="https://arxiv.org/abs/1808.06226">SentencePiece</a> (instead of <a href="https://en.wikipedia.org/wiki/Byte_pair_encoding">BPE</a>). This seems to be an Alphabet thing; many of the Alphabet papers use SentencePiece, while most of the non-Alphabet world uses BPE.</p></li></ul><p>The paper was very interesting from a computational perspective, as they went into detail about how they trained their model and made it work:</p><ul><li><p>They used optimizer state partitioning (<a href="https://arxiv.org/abs/1910.02054">ZeRO</a>)</p></li><li><p><a href="https://www.notion.so/b2293a2b125b4b088656e039fb3b6ca8">Megatron-style</a> model parallelism</p></li><li><p>And <a href="https://paperswithcode.com/method/gradient-checkpointing#:~:text=Gradient Checkpointing is a method,small increase in computation time.">rematerialization</a><a href="https://paperswithcode.com/method/gradient-checkpointing#:~:text=Gradient%20Checkpointing%20is%20a%20method,small%20increase%20in%20computation%20time.)/gradient">/gradient</a> checkpointing to save memory.</p></li></ul><p>These are all now the standard techniques used to train large models. To the best of my knowledge, Gopher was the first paper to put all of these together and release details about doing so publicly.</p><p>It&#8217;s interesting&#8212; often, big labs don&#8217;t include details for competitive reasons. Here, because DeepMind was (arguably) behind, they went into extensive detail. I think we&#8217;ll see this increase with LLM research from everyone that&#8217;s not OpenAI/Anthropic, as the others don&#8217;t live/die by the commercial success of their API, and have strong incentives to make it easier for <strong>others</strong> to train large models (and thereby <a href="https://gwern.net/complement">commoditize their complements</a>).</p><p>For the paper, DeepMind built a dataset called MassiveText, which was as follows</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!ZqWe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!ZqWe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 424w, https://substackcdn.com/image/fetch/$s_!ZqWe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 848w, https://substackcdn.com/image/fetch/$s_!ZqWe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 1272w, https://substackcdn.com/image/fetch/$s_!ZqWe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!ZqWe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png" width="1148" height="422" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/b22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:422,&quot;width&quot;:1148,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:93270,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!ZqWe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 424w, https://substackcdn.com/image/fetch/$s_!ZqWe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 848w, https://substackcdn.com/image/fetch/$s_!ZqWe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.png 1272w, https://substackcdn.com/image/fetch/$s_!ZqWe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fb22f13ec-e4ef-4919-8a2c-b3c27c0a4d36_1148x422.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><p>Interestingly, this is much smaller than the dataset OpenAI used for GPT-3. GPT-3 had roughly 45TB of text, while MassiveText &#8220;only&#8221; had about 10.5TB.</p><p>They used this dataset to train a large model on 300B tokens. The dataset consists of 2.343 trillion tokens, so this is only 12.8%. A much smaller subset. This is interesting to compare to the earlier GPTs, which, if you recall, used 100 epochs (so they saw each token in the dataset 100 times&#8212; while Gopher only saw 10% of their tokens once)!</p><p>The Gopher appendices have some great work; someone finally did ablations! They looked at:</p><ul><li><p><a href="https://paperswithcode.com/method/adafactor">Adafactor</a> vs Adam, and found that Adafactor was much less stable</p></li><li><p>Lower-precision training, trying runs with float16, bfloat16, float32, <a href="https://nhigham.com/2020/07/07/what-is-stochastic-rounding/">RandRound</a>, and using bfloat16 parameters with float32 in the optimiser state (rounding randomly). They found that using float32 parameters for optimisation updates only mitigated the performance loss, saving a substantial amount of memory.</p></li><li><p>Scaling context length; they show how performance increases as the context length increases. Improvements see diminishing returns, but consistently improve. Performance looks roughly proportionate to $\sqrt{n}$ (where $n$ is the context length).</p></li></ul><p>It&#8217;s really nice to see detailed empirical work like this&#8212; it&#8217;s a welcome change from the other papers that failed to do this.</p><h2>Chinchilla</h2><p><a href="https://paperswithcode.com/method/chinchilla">Abstract</a></p><p>Chinchilla is an incredibly influential paper that established scaling laws. It&#8217;s one of my favorite papers from the last few years, as it <em>actually does science</em> in a way that physicists would agree with. One answer to &#8220;is something science&#8221; is to say, if you were to meet a historical scientist in your field, could you teach them something? And if you brought Chinchilla to researchers to, say, Radford et. al in 2017, it would advance their work by several years.</p><p>Chinchilla trained over 400 GPT-style transformers, ranging in size from 70M to 16B parameters, and fit the following equation (N is the number of parameters in the LM, and D is the number of tokens in the dataset):</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\hat{L}(N, D) = E + \\dfrac{A}{N^\\alpha} + \\dfrac{B}{D^\\beta}&quot;,&quot;id&quot;:&quot;MSDTPGFGTB&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><p>Choosing A, B, E, &#945;, &#946; to minimize</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\sum \\limits_{\\text{Runs } i} \\text{Huber}_{\\delta=10^{-3}}(\\log \\hat{L}_i - \\log L_i)&quot;,&quot;id&quot;:&quot;YATUBOYYTK&quot;}" data-component-name="LatexBlockToDOM"></div><p>Here, we can think of E as the &#8220;irreducible loss&#8221; from the dataset, i.e. the loss if we trained an infinitely large model on an infinite stream of tokens. The authors find that the optimal model is (from <a href="https://www.lesswrong.com/posts/6Fpvch8RR29qLEWNH/chinchilla-s-wild-implications#fnjefvfidovdb">nostalgebraist</a> on into the implications of Chinchilla):</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!nAKZ!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!nAKZ!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 424w, https://substackcdn.com/image/fetch/$s_!nAKZ!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 848w, https://substackcdn.com/image/fetch/$s_!nAKZ!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 1272w, https://substackcdn.com/image/fetch/$s_!nAKZ!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!nAKZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png" width="686" height="216" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:216,&quot;width&quot;:686,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:30073,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!nAKZ!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 424w, https://substackcdn.com/image/fetch/$s_!nAKZ!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 848w, https://substackcdn.com/image/fetch/$s_!nAKZ!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 1272w, https://substackcdn.com/image/fetch/$s_!nAKZ!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F7e00e6c1-1b25-4a02-9dc8-ba91a56befba_686x216.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>The implication here is that the model size &amp; data size matter roughly equally, which is interesting, given how much attention &amp; effort goes to scaling up the model, and how little attention is given to the dataset.</p><p>The authors then used this equation to determine the optimal model size for the Gopher compute budget, and trained it on more tokens&#8212; 1.4T tokens, 4.6x the number of tokens Gopher was trained on. This model, being 4x smaller, has a radically smaller memory footprint and is much faster/cheaper to sample from.</p><p>The Chinchilla paper has been highly influential. Almost every team that I&#8217;ve been talking to that is training a LLM right now talks about how they&#8217;re training a <em>Chinchilla optimal model</em>, which is remarkable given that basically everything in the LLM space changes every week.</p><p>The standard practice before Chinchilla was to train your model for 300B tokens, which is what GPT-3, Gopher, and Jurassic-1 all did. Chinchilla reveals how wasteful that was; basically, all of these papers made themselves more expensive to infer by training models that were too large.</p><p>Changes from Chinchilla (otherwise the same as Gopher):</p><ul><li><p><a href="https://www.notion.so/Factual-accuracy-issues-in-LLMs-8257c59fda4040509a40d94523701fad">AdamW</a> instead of Adam (there&#8217;s an interesting footnote regarding the choice of optimizer: &#8220;a model trained with AdamW only passes the training performance of a model trained with Adam around 80% of the way through the cosine cycle, though the ending performance is notably better&#8221;)</p></li><li><p>Uses a modified <a href="https://arxiv.org/abs/1808.06226">SentencePiece</a> tokenizer that is slightly different from Gopher (doesn&#8217;t apply NFKC normalisation)</p></li><li><p>They compute the forward + backward pass in bfloat16, but store a float32 copy of the weights in the optimizer state. They find that this is basically identically efficient to using float32 everywhere.</p></li></ul><p>All of the changes are ablated extensively in the appendix (<em>finally</em>).</p><h2>PaLM</h2><p>Speaking of training models that were too large- we have PaLM! Palm was really, really big. <a href="https://twitter.com/finbarrtimbers/status/1635102571567407105?s=46&amp;t=_LCsoamG7K4pQj0vxlk0XA">As far as I&#8217;m aware</a>, it&#8217;s the largest dense language model trained to date, at 540B parameters, requiring 6144 TPUs to train on (this is 3 entire TPU pods, each consisting of 2048 TPUs). This is incredibly expensive! Probably only Google has the resources + infrastructure to do this.</p><p>&#8230; unfortunately, they were training PaLM at the same time chinchilla was being written. Very suboptimal.</p><div class="twitter-embed" data-attrs="{&quot;url&quot;:&quot;https://twitter.com/rasbt/status/1637803700944093184&quot;,&quot;full_text&quot;:&quot;PaLM is a really interesting decoder-style language model that I initially kind of ignored when it was published last year: <a class=\&quot;tweet-url\&quot; href=\&quot;https://arxiv.org/abs/2204.02311\&quot;>arxiv.org/abs/2204.02311</a>\n\nTurns out PaLM has 7 interesting architecture improvements over GPT.\n\n1/9&quot;,&quot;username&quot;:&quot;rasbt&quot;,&quot;name&quot;:&quot;Sebastian Raschka&quot;,&quot;profile_image_url&quot;:&quot;&quot;,&quot;date&quot;:&quot;Mon Mar 20 13:10:05 +0000 2023&quot;,&quot;photos&quot;:[],&quot;quoted_tweet&quot;:{},&quot;reply_count&quot;:0,&quot;retweet_count&quot;:163,&quot;like_count&quot;:990,&quot;impression_count&quot;:0,&quot;expanded_url&quot;:{},&quot;video_url&quot;:null,&quot;belowTheFold&quot;:true}" data-component-name="Twitter2ToDOM"></div><p>Changes from GPT-3:</p><ul><li><p><a href="https://arxiv.org/abs/1911.02150">Multi-query attention</a>. Shares K/V embeddings for each head, but has separate Q embeddings. Makes it much faster during inference time.</p></li><li><p>Uses <a href="https://twitter.com/rasbt/status/1637803703766769669">parallel transformer blocks</a>, which improves training time by 15%. As it was trained using 6144 TPU v4 chips for 1200 hours, the total training cost (at public prices) is between $1.45 to $3.22 per chip-hour, for a total of $10M to $22M. So this change saved $1.5M to $3M.</p></li><li><p>SwiGLU activations, rather than the GELU activation used by GPT-3</p></li><li><p>Uses <a href="https://arxiv.org/abs/2104.09864">rotary positional embeddings</a> (RoPE) instead of the learned embeddings (I&#8217;m sad that the learned embeddings GPT-3 used are suboptimal&#8212; they&#8217;re so elegant).</p></li><li><p>Shares the input-output embeddings</p></li><li><p>No bias vectors</p></li><li><p>SentencePiece with 256k tokens</p></li></ul><p>So, a ton of changes! Again, a bunch of these are common, e.g. using the learned embeddings that GPT-3 had is very pass&#233;, and almost no one does it now.</p><h2>LLaMa</h2><p><a href="https://ai.facebook.com/blog/large-language-model-llama-meta-ai/">Abstract</a></p><p>LLaMa combined a bunch of the best features from PaLM and Chinchilla:</p><ul><li><p>Pre-normalize the input of each transformer sub-layer</p></li><li><p>RMSNorm, instead of LayerNorm, as done in Gopher</p></li><li><p>SwiGLU activation function from PaLM (but a dimension of 2/3 4d instead of 4d, as in PaLM)</p></li><li><p>Uses RoPE, as PaLM did.</p></li><li><p>Uses AdamW, as done in Chinchilla</p></li></ul><p>I think that LLaMa is the recipe to follow for the current SOTA in training large models.</p><p>Computational changes:</p><ul><li><p>Uses efficient attention (<a href="https://arxiv.org/abs/2112.05682">Rabe &amp; Staats</a>, <a href="https://arxiv.org/abs/2205.14135">FlashAttention</a>)</p></li><li><p><a href="https://arxiv.org/abs/2205.05198">Gradient checkpointing</a></p></li><li><p>Interestingly, they appear to be using float32s everywhere (or at least, don&#8217;t say otherwise)</p></li></ul><p>These are all similar to Gopher. The one obvious optimization they missed is to use lower precision, as Chinchilla did; I&#8217;m curious why they didn&#8217;t.</p><p>My one complaint is that I wish they would have trained the model for longer. The learning curve is very far from convergence! This paper is, in my mind, the shining example showing how well smaller models can do when trained well.</p><p><a href="https://finbarr.ca/llms-not-trained-enough/">As I&#8217;ve written about elsewhere</a>, while Chinchilla is great, it assess optimality in a very narrow sense: &#8220;With a given compute budget, and ignoring inference costs, how do we choose between the number of parameters of our model and the number of tokens we train on?&#8221; It can make sense to train a model that&#8217;s smaller than Chinchilla optimal and train it for <strong>longer</strong> than Chinchilla would tell us, because if we&#8217;re going to deploy the model at mass scale, we care <em><strong>much</strong></em> more about inference cost than training cost.</p><h1>GPT-4</h1><p>This is where I&#8217;d include information about GPT-4, if there was any. Unfortunately, the <a href="https://cdn.openai.com/papers/gpt-4.pdf">GPT-4 technical report</a> contains almost no information:</p><blockquote><p>GPT-4 is a Transformer-style model [33] pre-trained to predict the next token in a document, using both publicly available data (such as internet data) and data licensed from third-party providers. The model was then fine-tuned using Reinforcement Learning from Human Feedback (RLHF) [34]. Given both the competitive landscape and the safety implications of large-scale models like GPT-4, this report contains no further details about the architecture (including model size), hardware, training compute, dataset construction, training method, or similar.</p></blockquote><p>As a result, I&#8217;m not going to talk about it, as there&#8217;s not much to say. Hopefully OpenAI changes their mind and releases some information about their model.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h1>Conclusion</h1><p>This is it, as of March &#8216;23. I&#8217;m sure something new will come along and invalidate all of this.</p><p>I haven&#8217;t talked about RLHF/finetuning at all. I plan to write a future article about the various GPT variants that exist (ChatGPT, InstructGPT, WebGPT, etc.), and about how RLHF/finetuning have evolved.</p><p>What have I missed? Comment below and I&#8217;ll update this post.</p><p>Articles I&#8217;m reading:</p><ul><li><p><a href="https://rootnodes.substack.com/p/why-didnt-deepmind-build-gpt3">Why didn&#8217;t DeepMind build GPT-3?</a></p></li></ul><div class="footnote" data-component-name="FootnoteToDOM"><a id="footnote-1" href="#footnote-anchor-1" class="footnote-number" contenteditable="false" target="_self">1</a><div class="footnote-content"><p>I <a href="https://gist.github.com/finbarrtimbers/1728037381d27ebc7b4cdd828a6f1f9a">calculated this directly</a> by downloading <a href="https://github.com/soskek/bookcorpus/issues/27">bookcorpus</a> and running <a href="https://github.com/openai/tiktoken">tiktoken</a> with the GPT-2 encoding on it. </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>The paper itself doesn&#8217;t report the number of tokens, but <a href="https://skylion007.github.io/OpenWebTextCorpus/">OpenWebText</a>, the open source reproduction, gets <a href="https://github.com/karpathy/nanoGPT/blob/master/data/openwebtext/readme.md">nine billion</a>, using <a href="https://github.com/openai/tiktoken">tiktoken</a>. </p></div></div>]]></content:encoded></item><item><title><![CDATA[How is LLaMa.cpp possible?]]></title><description><![CDATA[An exercise in applied inference arithmetic]]></description><link>https://www.artfintel.com/p/how-is-llamacpp-possible</link><guid isPermaLink="false">https://www.artfintel.com/p/how-is-llamacpp-possible</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Thu, 16 Mar 2023 17:10:17 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!y1D-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1>How is LLaMa.cpp possible?</h1><p><em>Note: Substack doesn&#8217;t have great support for LaTeX, so you might want to read this article on my <a href="https://finbarr.ca/how-is-llama-cpp-possible/">blog</a> instead.</em></p><p>Recently, a <a href="https://github.com/ggerganov/llama.cpp">project</a> rewrote the <a href="https://github.com/facebookresearch/llama">LLaMa inference code</a> in raw C++. With some optimizations and by quantizing the weights, the project allows running LLaMa locally on a wild variety of hardware:</p><ul><li><p>On a <a href="https://twitter.com/rgerganov/status/1635604465603473408">Pixel5</a>, you can run the 7B parameter model at 1 tokens/s.</p></li><li><p>On a <a href="https://simonwillison.net/2023/Mar/11/llama/">M2 Macbook Pro</a>, you can get ~16 tokens/s with the 7B parameter model</p></li><li><p>You can <a href="https://twitter.com/miolini/status/1634982361757790209">even run the 7B model on a 4GB RAM Raspberry Pi</a>, albeit at 0.1 tokens/s.</p></li></ul><p>If you are like me, you saw this and thought: What? How is this possible? Don&#8217;t large models require expensive GPUs? I took my confusion and dove into the math surrounding inference requirements to understand the constraints we&#8217;re dealing with.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><p>Let&#8217;s start with GPUs. GPUs have two main benefits for deep learning:</p><ol><li><p>They have a large amount of memory bandwidth (A100: 1935 GB/s, 4090: 1008 GB/s)</p></li><li><p>They have a large amount of compute (A100: 312 TFLOPS of FP16, 4090: 82.6 TFLOPS of FP16)</p></li></ol><p>When we talk about memory bandwidth, we&#8217;re talking about how long it takes to move things from the HBM memory (i.e. the RAM) into the on-chip memory. To actually do math with the GPU, we need to move the matrices in question into the on-chip memory, which is quite small (40MB on an A100, compared to 40-80GB of RAM). The memory bandwidth is ~2 orders of magnitude smaller than the compute performance&#8212; this will matter later, as the memory bandwidth tends to be the bottleneck for inference.</p><p>What does this mean in the context of serving LLaMa? Let&#8217;s start with some <a href="https://kipp.ly/blog/transformer-inference-arithmetic/">inference arithmetic</a>. We can do some rough calculations on the inference performance of a LLM using <a href="https://kipp.ly/blog/transformer-param-count/">Kipply&#8217;s article</a>.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a> First, some notation on the dimensions of the model:</p><ul><li><p>The Q, K, and V weight matrices are all shape [ d_model, d_head], and we have n_heads of them per layer; the attention output matrix has the same shape, for a total of 4 * [ d_model, n_heads * d_head]. By convention, GPT-style networks have d_head * n_heads = d_model.</p></li><li><p>The MLP has two weight matrices, of shape [model_dim, 4 * model_dim] and </p><p>[4 * model_dim, model]</p></li><li><p>The embedding matrix is of size [vocab, model_dim].</p></li></ul><p>This gives us a handy equation for the number of parameters in a GPT-style model:<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;P =  n_{\\text{blocks}} \\left( 4 \\cdot d_{\\text{model}}^2 + 2  \\cdot 4  \\cdot d_{\\text{model}}^2\\right) + n_{\\text{vocab}} \\cdot d_{\\text{model}} &quot;,&quot;id&quot;:&quot;WMPCFLNVZL&quot;}" data-component-name="LatexBlockToDOM"></div><p>For the duration of the post, I&#8217;m going to focus on the case where we&#8217;re running a ChatGPT style service locally, which is what LLaMa.cpp does, letting me assume a batch size of 1. </p><p>For efficient inference, the KV cache has to be stored in memory; the KV cache requires storing the KV values for every layer, which is equal to storing:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;n_{\\text{bytes}} \\cdot 2 \\cdot d_{\\text{model}}&quot;,&quot;id&quot;:&quot;QGOJGEWTIY&quot;}" data-component-name="LatexBlockToDOM"></div><p>I use n_bytes here to indicate the number of bytes per param; for float32s, this is 4, for float16s, this is 2, etc. The 2 in the middle is because we have to store one set of weights for the K values, and one for the Vs. </p><p>Given a model with n layers, the total memory for the KV cache is:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;n_{\\text{blocks}} \\cdot n_{\\text{bytes}} \\cdot 2 \\cdot d_{\\text{model}}&quot;,&quot;id&quot;:&quot;WTHXWJJKSD&quot;}" data-component-name="LatexBlockToDOM"></div><p> In addition to storing the KV cache in memory, we also need to store the weights themselves in memory; this requires n_bytes * P bytes.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!y1D-!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!y1D-!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 424w, https://substackcdn.com/image/fetch/$s_!y1D-!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 848w, https://substackcdn.com/image/fetch/$s_!y1D-!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 1272w, https://substackcdn.com/image/fetch/$s_!y1D-!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!y1D-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png" width="1278" height="340" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:340,&quot;width&quot;:1278,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:94836,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!y1D-!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 424w, https://substackcdn.com/image/fetch/$s_!y1D-!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 848w, https://substackcdn.com/image/fetch/$s_!y1D-!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.png 1272w, https://substackcdn.com/image/fetch/$s_!y1D-!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F11b15c1c-34b8-46d9-bda3-383c36b37e66_1278x340.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><p>This is one of the key advantages of quantization. By using less precision, we can radically decrease the amount of memory needed to store our models in memory. Note that, with int4 precision, <em>all of these models fit into memory on an A100</em> (which is the standard datacenter GPU right now), and all of them, except for the biggest model, fit into memory on high-end consumer GPUs (3090s/4090s, which have 24GB of RAM).</p><p>Now, when it comes to actually running inferece, it takes approximately 2P FLOPS per token, because we are doing a bunch of matmuls with a total of P parameters, and multiplying a matrix of size (m, n) with a vector of size (n,) has a cost of 2mn.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a></p><p>With all that math out of the way, let&#8217;s calculate the requirements for running inference with LLaMa. The main requirements when it comes to sampling are:</p><ol><li><p>Keep the KV cache in memory, in addition to all the parameters.</p></li><li><p>Read all the weights from HBM into the on-chip memory. Because we sample auto-regressively, we have to repeat this for each token we sample.</p></li><li><p>Do the actual matmuls to calculate the output of our network.</p></li></ol><p>The latency is the maximum of either the compute or the memory latency, as reading parameters into on-chip memory happens asynchronously in all modern tensor programming libraries. As a result, we write:</p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{latency}_\\text{model} = \\text{max}(\\text{latency}_\\text{compute}, \\text{latency}_\\text{memory})&quot;,&quot;id&quot;:&quot;GMGYVPVKRU&quot;}" data-component-name="LatexBlockToDOM"></div><p></p><div class="latex-rendered" data-attrs="{&quot;persistentExpression&quot;:&quot;\\text{latency}_\\text{memory} := \\dfrac{P\\cdot n_{\\text{bytes}}}{n_{\\text{memory bandwidth}}}, \\text{latency}_\\text{compute} := \\dfrac{2 \\cdot P \\cdot B}{n_{\\text{flops}}}&quot;,&quot;id&quot;:&quot;XWELTOBZYJ&quot;}" data-component-name="LatexBlockToDOM"></div><p>where B is the batch size. As the memory bandwidth is ~1.935e12, and the number of FLOPS is ~3.12e14, as long as the batch size is less than 161, the model is memory-bound.</p><p>With a batch size of 1, this is the same equation, as on most hardware (e.g. Nvidia GPUs), there is a linear speedup as you decrease the precision (you get twice the FLOPS when using fp16 vs fp32, which doubles again as you go to int8, and doubles once more as you go to int4s).</p><p>As LLaMa.cpp uses int4s, the RAM requirements are reduced to 1.33GB of memory for the KV cache, and 16.25GB of VRAM for the model parameters. That&#8217;s pretty good!</p><p>As the memory bandwidth is almost always<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> much smaller than the number of FLOPS, memory bandwidth is the binding constraint.</p><p>Note that the number of FLOPS/token is identical to the memory bandwidth required, as we have to 1) load all of the parameters into on-chip memory and then 2) use the parameters to compute the results. These happen simultaneously, as all modern tensor programming frameworks are able to handle the &#8220;loading into memory&#8221; bit asynchronously, so the total time required is max(compute time, memory time). </p><h1>Running LLaMa on an A100</h1><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!gukl!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!gukl!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 424w, https://substackcdn.com/image/fetch/$s_!gukl!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 848w, https://substackcdn.com/image/fetch/$s_!gukl!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 1272w, https://substackcdn.com/image/fetch/$s_!gukl!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!gukl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png" width="1456" height="298" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:298,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:102946,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!gukl!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 424w, https://substackcdn.com/image/fetch/$s_!gukl!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 848w, https://substackcdn.com/image/fetch/$s_!gukl!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 1272w, https://substackcdn.com/image/fetch/$s_!gukl!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F593cdd8c-7c00-406b-ba45-bfc94fb5da05_1574x322.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>On an A100 (80GB PCIe), the memory bandwidth is 1935GB/s. The int4 compute is 1248 TOPS. As such, the model is (heavily) memory-bound. We should expect to see  roughly 30 tokens/s with the 65B model, and 277 tokens/s with the 7B model.</p><h2>Running LLaMa on a Macbook</h2><p>The M1 GPU has a bandwidth of <a href="https://www.macworld.com/article/783678/m2-vs-m1-chip-performance-graphics-ram.html">68.25 GB/s</a>, while the M1 GPU can do up to <a href="https://tlkh.dev/benchmarking-the-apple-m1-max#heading-gpu-matrix-multiplication-gemm-performance">5.5 TFLOPS</a> of fp16 compute. As such, we should expect a ceiling of ~1 tokens/s for sampling from the 65B model with int4s, and 10 tokens/s with the 7B model.</p><p>As the M2 Pro has 200 GB/s of bandwidth, and the M2 Max has 400 GB/s of bandwidth, we should expect massive improvements with them, going up to 6 tokens/s with the M2 Max with the 65B model. That&#8217;s pretty darn good for a laptop.</p><h2>Running LLaMa on a Raspberry Pi 4</h2><p>A Raspberry Pi 4 has <a href="https://web.eece.maine.edu/~vweaver/group/green_machines.html">13.5 GFLOPS of compute</a>, and <a href="https://forums.raspberrypi.com/viewtopic.php?t=281183">~4GB/s of memory bandwidth</a>. Given this, we&#8217;d expect to see ~2 tokens/s with the 7B model if it was memory bound. Given that we&#8217;re currently seeing ~0.1 tokens/s, I suspect we&#8217;re actually compute-bound (although this is a stab in the dark&#8212; I can&#8217;t find enough information about the specs for a Raspberry Pi to determine this with any precision).</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>Summary</h2><p>Memory bandwidth is the limiting factor in almost everything to do with sampling from transformers. Anything that reduces the memory requirements for these models makes them <em>much</em> easier to serve&#8212; like quantization! This is yet another reason why distillation, or just <a href="https://finbarr.ca/llms-not-trained-enough/">training smaller models for longer</a>, is really important.</p><p><em>Note: I&#8217;m not an expert in CUDA, so I probably have errors in my math. If so, please let me know&#8212; I&#8217;ll update the post and credit you.</em></p><p>Resources on transformer inference performance:</p><ul><li><p><a href="https://lilianweng.github.io/posts/2023-01-10-inference-optimization/">Large Transformer Model Inference Optimization</a></p></li><li><p><a href="https://kipp.ly/blog/transformer-inference-arithmetic/">Transformer inference arithmetic</a></p></li><li><p><a href="https://kipp.ly/blog/transformer-param-count/">LLM parameter counting</a></p></li><li><p><a href="https://arxiv.org/abs/2009.06732">Efficient Transformers</a></p></li></ul><p><em>Thank you to <a href="https://twitter.com/kaushikpatnaik?lang=en">Kaushik Patnaik</a>, <a href="https://twitter.com/immortal_333">immortal_333</a>, and <a href="https://twitter.com/arthurallshire">Arthur Allshire</a> for reading &amp; commenting on early drafts of this, and <a href="https://substack.com/@salimf">Salim Fakhohuri</a> + <a href="https://twitter.com/ShumingHu">Shuming Hu</a> for pointing out errors in my math.</em></p><p><em>Errors that have been corrected from earlier versions: </em></p><ol><li><p><em>I was missing the batch term in the latency_compute equation. </em></p></li><li><p><em>I had an extra factor of 2 in the latency_memory equation.</em></p></li></ol><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>I learned almost all of the math surrounding transformer performance from their article; they deserve full credit.</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>Although we obviously don&#8217;t need to calculate the number of parameters for the LLaMa models, as we know them. The equation is useful as a sanity check.</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>For a more detailed discussion showing that this is the case, check out <a href="https://kipp.ly/blog/transformer-inference-arithmetic/#flops-counting">kipply&#8217;s article</a>.</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>I hedge with &#8220;almost&#8221; here, but I&#8217;m not aware of any counterexamples.</p></div></div>]]></content:encoded></item><item><title><![CDATA[A step towards self-improving LLMs]]></title><description><![CDATA[Here, I outline a research agenda towards making LLMs self-improve, a key problem standing in the way between current technology and AGI.]]></description><link>https://www.artfintel.com/p/a-step-towards-self-improving-llms</link><guid isPermaLink="false">https://www.artfintel.com/p/a-step-towards-self-improving-llms</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Tue, 07 Mar 2023 16:32:20 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!T1G_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Here, I outline a research agenda towards making LLMs self-improve, a key problem standing in the way between current technology and AGI.</p><p>If I look at GPTs/LLMs, three of the biggest problems I see with existing techniques are:</p><ol><li><p>We need our models to be able to generate data by themselves, i.e. we need a <a href="https://www.lesswrong.com/tag/recursive-self-improvement">recursive self-improvement loop</a>. AlphaZero is the shining example of what&#8217;s possible here.</p></li><li><p>We need our models to be able to operate in new domains without requiring massive amounts of existing data. CLIP provides an option here, as does Internet Explorer (the paper, not the browser).</p></li><li><p>Auto regressive sampling. It&#8217;s <a href="https://twitter.com/blennon_/status/1631726432471887872?s=20">slow, and suboptimal</a>.</p></li></ol><p>I have better ideas for how to tackle #1, so I&#8217;ll focus on that. #2 &amp; #3 will come later.</p><p>There are other issues facing LLMs, such as:</p><ol><li><p>Increasing the length of the context window</p></li><li><p>Figuring out how to train larger models</p></li><li><p>Figuring out how to train more efficient models (less parameters, less data, less energy)</p></li><li><p>Factual accuracy</p></li><li><p>Mitigating attacks that convince LLMs to exhibit harmful behaviour (&#8221;red-teaming&#8221;), e.g. prompt injection</p></li></ol><p>I think these are fundamentally engineering problems that we&#8217;ll be able to figure out iteratively. For instance, context length has seen a lot of progress with <a href="https://openreview.net/forum?id=H4DqfPSibmx">subtle algorithmic</a> <a href="https://arxiv.org/abs/2112.05682">improvements</a>; if we combine those changes with the many <a href="https://twitter.com/karpathy/status/1621578354024677377">arcane engineering optimizations</a> that are out there, I think we&#8217;ll get to a point where context goes to 64k tokens or more, at which point we&#8217;ll be deep in the <a href="http://finbarr.ca/the-sigmoid/">saturating point of the sigmoid</a>. Or for factual accuracy- I think that retrieval will largely solve that once it&#8217;s incorporated into most models.</p><p>However, I&#8217;m probably wrong, and could very well end up writing a version of this post in 2034 talking about how the biggest problem facing AGI is prompt injections.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.com/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://www.artfintel.com/subscribe?"><span>Subscribe now</span></a></p><h2>A path towards recursive self-improvement</h2><p>GPTs work very well in one specific context: they are very, very good at finding text that is likely to follow other text in a way that appears natural to humans.</p><p>What they don&#8217;t do is come up with text that they haven&#8217;t seen before. Kinda. What they&#8217;re doing when we sample from them now is predict what they&#8217;ve seen during training. Sometimes these predictions produce text that hasn&#8217;t been written before (this can occur often, due to the combinatorial nature of token sampling). When this happens, it&#8217;s a happy accident. The model isn&#8217;t trying to select text that is novel or that accomplishes any goal other than <strong>following the preceding 2048 tokens</strong> (or whatever the context length is).</p><p>The obvious exception is when models are finetuned using <a href="https://arxiv.org/abs/1706.03741">RLHF</a>. In RLHF, the models are explicitly trained to optimize a reward signal. In RLHF, the reward signal comes from a model trained to predict human feedback. Basically, humans are asked to choose between two samples of text, and then a model learns to predict which one is preferred.</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!T1G_!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!T1G_!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 424w, https://substackcdn.com/image/fetch/$s_!T1G_!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 848w, https://substackcdn.com/image/fetch/$s_!T1G_!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 1272w, https://substackcdn.com/image/fetch/$s_!T1G_!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!T1G_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png" width="1456" height="928" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:928,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:249451,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!T1G_!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 424w, https://substackcdn.com/image/fetch/$s_!T1G_!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 848w, https://substackcdn.com/image/fetch/$s_!T1G_!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.png 1272w, https://substackcdn.com/image/fetch/$s_!T1G_!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F08bd34bc-e24c-41a9-a451-279207b7538d_2014x1284.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><p>Why does this matter? Predicting the next token works pretty well! And <a href="https://twitter.com/sama/status/1599471830255177728?s=20">maybe we&#8217;re all</a> just <a href="https://dl.acm.org/doi/10.1145/3442188.3445922">stochastic parrots</a>? It matters because the biggest impediment to improving our models right now is the <strong>lack of data</strong>. The scaling law papers (<a href="https://arxiv.org/abs/2203.15556">Chinchilla</a>, <a href="https://arxiv.org/abs/2001.08361">OpenAI</a>) consistently point to the fact that we need to scale up the datasets we train LLMs on.</p><p>For instance, Chinchilla predicts that we&#8217;ll need 11 <strong>trillion</strong> tokens to optimally train a model the size of PaLM (i.e. 540B parameters). If we want to push past PaLM to a model with 1 trillion parameters, we&#8217;ll need 20T tokens!</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qdlk!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qdlk!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 424w, https://substackcdn.com/image/fetch/$s_!qdlk!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 848w, https://substackcdn.com/image/fetch/$s_!qdlk!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 1272w, https://substackcdn.com/image/fetch/$s_!qdlk!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qdlk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png" width="1282" height="606" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:606,&quot;width&quot;:1282,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:140724,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qdlk!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 424w, https://substackcdn.com/image/fetch/$s_!qdlk!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 848w, https://substackcdn.com/image/fetch/$s_!qdlk!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.png 1272w, https://substackcdn.com/image/fetch/$s_!qdlk!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F5b495376-c776-4c08-a0ff-d5089af40086_1282x606.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><p>That&#8217;s a lot of data. That&#8217;s so much data that it&#8217;s not clear that we can get that from existing sources. <a href="https://twitter.com/nostalgebraist?lang=en">nostalgebraist</a> <a href="https://www.lesswrong.com/posts/6Fpvch8RR29qLEWNH/chinchilla-s-wild-implications#fnjefvfidovdb">argues</a> that 1) we&#8217;ve basically exhausted the available data in structured domains like coding and 2) it&#8217;s starting to look like we&#8217;re running out of general-domain data. I find nostalgebraist compelling; the only counterargument I could see is that private data sources might be a rich vein of tokens, but I don&#8217;t see a clear path to getting access to them.</p><p>This lack of data is unfortunate because, according to <a href="https://www.lesswrong.com/posts/6Fpvch8RR29qLEWNH/chinchilla-s-wild-implications#fnjefvfidovdb">Chinchilla&#8217;s scaling laws</a>, we could see another ~8% reduction in training loss (1.93 &#8594; 1.77, delta of 0.16 in loss) for if we had infinite data <em><strong>while changing nothing else about Chinchilla</strong></em>. That&#8217;s a pretty substantial improvement when you consider that the improvement from Gopher to Chinchilla was only 2.9% (1.99 &#8594; 1.93, delta of 0.06 in loss), not to mention the fact that our models are already quite good&#8212; able to <a href="https://www.bbc.com/news/technology-62275326">trick Google SWEs into believing they&#8217;re sentient</a>, and <a href="https://www.lesswrong.com/posts/FKNtgZrGYwgsz3nHT/bankless-podcast-159-we-re-all-gonna-die-with-eliezer">scaring the Yud</a>. </p><h3>More data</h3><p>The clear implication is that we need way more data! Our models are desperate for data. They&#8217;re lying on the beach&nbsp;<em>gasping for more data</em> to quench their ever-growing thirst.</p><p>But where will the data come from?</p><p>If we can scrape it we should. It&#8217;s not clear how much there is left to scrape. Especially at the largest research institutions like OpenAI, Google Brain, and DeepMind, I&#8217;m certain that they have teams of engineers working on scraping all possible data. There is some possibility to automate this process; the excellently named <a href="https://arxiv.org/abs/2302.14051">Internet explorer paper</a> presented a model which crawls the web to get additional data to augment it&#8217;s dataset. Although letting a nascent AI loose on the internet would make Eliezer cry, it could be an excellent source of data, especially if one incorporates some sort of reinforcement learning style feedback loop to continually improve the manner in which the model searches the web.</p><p>The data problem is compounded by the fact that high quality data <strong>really matters</strong>. Experiments consistently show that deduplicating data increases performance substantially (<a href="https://arxiv.org/abs/2205.10487">https://arxiv.org/abs/2205.10487</a>, <a href="https://arxiv.org/abs/2107.06499">https://arxiv.org/abs/2107.06499</a>). Basically, I&#8217;m not convinced there is a lot more high quality data. Two exceptions might be commercial data (e.g. internal corporate documents), and all copyrighted text. But it would be extremely difficult to get access to either of these corpora.</p><h3>Generate data</h3><p>The solution to me seems to be self-evident: we should generate our own data. There has been some work about training LLMs on data they have generated (<a href="https://arxiv.org/abs/2210.11610">https://arxiv.org/abs/2210.11610</a>, <a href="https://arxiv.org/abs/2212.08073">https://arxiv.org/abs/2212.08073</a>). There are a few different techniques that seem promising here.</p><p>In <a href="https://arxiv.org/abs/2210.11610">Huang et. al</a>, they use Chain of Thought (CoT) reasoning to generate additional data. Given a dataset of questions, they sample N answers that use CoT to generate an answer. At the end, they ask &#8220;The answer is &#8220; and get an answer; they then find the majority answer and choose all texts that return the same answer as the most common answer, using this to generate additional data. In practice, there&#8217;s no reason to questions, although that is a particularly straight forward problem to apply this to; one could imagine, say, embedding all of the generated answers, clustering them, and keeping the answers in the biggest cluster, or employing RLAIF like Anthropic did in the <a href="https://arxiv.org/abs/2212.08073">Constitutional AI</a> paper to select the answers to keep.</p><p>Anthropic employed a similar approach as the CoT reasoning in the <a href="https://arxiv.org/abs/2212.08073">Constitutional AI paper</a>.</p><p>Another option is to use RLAIF (from Constitutional AI) to generate data. In this,</p><h2>Throw compute at the problem</h2><p>Yet another line of research involves throwing compute at the problem. We know that we can use a variety of techniques to soak up compute and improve outcomes. For instance, <a href="https://en.wikipedia.org/wiki/Ensemble_learning">ensembling</a> is a classic ML technique that strictly improves model performance. Given that we are already at the extreme limit of what&#8217;s possible to compute with transformers, it is almost certainly not possible to naively ensemble LLMs.</p><p>However, what we can do is use compute to apply search on top of our existing model outputs. If we can find a <a href="https://proceedings.neurips.cc//paper/2020/file/22eda830d1051274a2581d6466c06e6c-Paper.pdf">policy improvement operator</a>, i.e. a function T that takes an existing distribution over tokens, &#960;, and returns a new distribution, T(&#960;), which improves our loss, then we can use T to improve our model. Some candidates:</p><ul><li><p>Best-of-n</p></li><li><p>Beam search</p></li><li><p>Policy-driven search</p></li></ul><p>&#8220;Best-of-n&#8221; (<a href="https://openai.com/research/measuring-goodharts-law">https://openai.com/research/measuring-goodharts-law</a>) is a technique similar to ensembling in which we sample from our model N times, and use the sample with the highest score according to our objective function. This performs remarkably well (outperforming the RLHF model in the WebGPT paper(<a href="https://openai.com/research/webgpt">https://openai.com/research/webgpt</a>)), is simple to implement, trivial to analyze mathematically, and trivially parallelizable, but makes inference N times more expensive. If I were OpenAI, I&#8217;d be caching the results of queries to their models and doing this for repeated queries</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!3ita!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!3ita!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 424w, https://substackcdn.com/image/fetch/$s_!3ita!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 848w, https://substackcdn.com/image/fetch/$s_!3ita!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 1272w, https://substackcdn.com/image/fetch/$s_!3ita!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!3ita!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png" width="1456" height="956" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:956,&quot;width&quot;:1456,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:144753,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!3ita!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 424w, https://substackcdn.com/image/fetch/$s_!3ita!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 848w, https://substackcdn.com/image/fetch/$s_!3ita!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.png 1272w, https://substackcdn.com/image/fetch/$s_!3ita!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F6bfca1e7-3cf5-4259-b3c8-3f4896815623_1468x964.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><p>.</p><p>In the WebGPT paper, the authors found that best-of-16 resulted in an improvement in human preferences of 5% (60% &#8594; 65%), while going from 13B parameters to 175B parameters resulted in an improvement of 10% (~47% &#8594; 57%)<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_!b76V!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!b76V!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 424w, https://substackcdn.com/image/fetch/$s_!b76V!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 848w, https://substackcdn.com/image/fetch/$s_!b76V!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!b76V!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!b76V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png" width="1438" height="1038" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/f8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1038,&quot;width&quot;:1438,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:120033,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!b76V!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 424w, https://substackcdn.com/image/fetch/$s_!b76V!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 848w, https://substackcdn.com/image/fetch/$s_!b76V!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.png 1272w, https://substackcdn.com/image/fetch/$s_!b76V!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Ff8366826-9e30-4952-a354-ea649c9745f2_1438x1038.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><p>As both charts see roughly linear improvements in performance, and both models increase in cost roughly linearly, it seems to imply that a best-of-64 13B model would be better than a best-of-4 175B model, while having roughly the same cost in terms of compute. Given that the 13B model fits on a single GPU, this would substantially lower the overall compute needs of the system.</p><p>Another improvement operator is a NLP classic: <a href="https://en.wikipedia.org/wiki/Beam_search">beam search!</a> In beam search, one performs a breadth-first search over the model outputs, with finite depth and width of the tree (e.g. it only keeps N successors at each level of the tree, and searches to a depth of M levels), with the final result being the sequence with the maximum objective score (typically log-likelihood). While a number of the LLMs do use beam search,<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-2" href="#footnote-2" target="_self">2</a> they don&#8217;t appear to report performance numbers, so I&#8217;m unable to include a comparison of how much it matters.</p><p>A concern is that beam search lowers diversity, as it constricts the difference in tokens; this is especially problematic for byte-level tokenizers, like BPE, as the individual tokens might vary significantly. <a href="https://twitter.com/sedielem">Sander Dieleman</a> <a href="https://sander.ai/2020/09/01/typicality.html">wrote about how</a> strategies like beam search are &#8220;the culprit behind many of the pathologies that neural machine translation systems exhibit&#8221;.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-3" href="#footnote-3" target="_self">3</a> </p><p>The final candidate (or family of candidates) for the improvement operator is an option that I find very exciting: learning an algorithm to search the token tree. The idea is that we could do something like AlphaZero which would learn a policy + value function.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-4" href="#footnote-4" target="_self">4</a> This would also allow us to change the reward function if we wanted to, rather than just using the standard log-likelihood. We could, for instance, directly train the reward function on human data. If you&#8217;re serving data to millions of users per day, you could just directly run RL on that, which is the case for the myriad of chat bots on the market today (Bing, ChatGPT, Claude, etc.).</p><h2>Next steps</h2><p>Now, I am not employed by a lab studying AGI. So I do not have the <s>resources</s>GPUs to apply any of these strategies. If you&#8217;re inspired by any of these ideas and want to implement them, please do so. I&#8217;d love to hear from you.</p><p>I&#8217;d <em>particularly</em> love to hear from you if you disagree with me. What am I wrong about?</p><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>Results from eyeballing graph, not precise.</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>Examples include: GPT-{2,3}, which uses it during decoding for text generation, BERT, for language understanding tasks, T5, and XLNet.</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>Sander&#8217;s post is great. I was struggling to understand why beam search isn&#8217;t used more in practice, and his post did a great job helping me understand why.</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>Perhaps using MuZero with a smaller model as the recurrent function to save on compute.</p></div></div>]]></content:encoded></item><item><title><![CDATA[Papers I've read this week]]></title><description><![CDATA[Hey folks!]]></description><link>https://www.artfintel.com/p/papers-ive-read-this-week</link><guid isPermaLink="false">https://www.artfintel.com/p/papers-ive-read-this-week</guid><dc:creator><![CDATA[Finbarr Timbers]]></dc:creator><pubDate>Sun, 05 Mar 2023 16:26:10 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!qKIr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Hey folks! Welcome to my newsletter. I&#8217;ve got an article that I&#8217;m hoping to drop early in the week about a potential solution to one of the biggest problems I see with LLMs: the lack of data. Until then, I&#8217;ve got a post about some of the most interesting papers I&#8217;ve read in the last week.</p><p>I&#8217;m going to try to write a weekly summary of the most interesting papers I&#8217;ve read that week. I&#8217;d love to hear what papers you&#8217;ve been reading, if you agree/disagree about my conclusions for each paper, and/or suggestions for what papers I should read next!</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://www.artfintel.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 Artificial Fintelligence! 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><h2>Scaling laws for routed language models</h2><p><a href="https://arxiv.org/abs/2202.01169">Abstract</a></p><p>I <a href="https://www.deepmind.com/">used to work</a> with Aidan, and way back in 2021, he was insistent that LLMs were the future of AI. I thought he was crazy. In &#8216;22, he also insisted that conditional routing models were the future. Given how right he was about LLMs, it&#8217;s probably worth paying attention to conditional routing models.</p><p>The paper provides a great general overview of how routing networks work and performance comparisons (in terms of negative log likelihood over a validation dataset) for the 3 most common routing techniques (<a href="https://arxiv.org/abs/1701.06538">sparse MoE</a>, <a href="https://arxiv.org/abs/2106.04426">non-parametric HASH</a>, <a href="https://arxiv.org/abs/1308.3432">RL routing</a>).</p><p>The authors trained a large number of conditional routing networks, and fit scaling laws to the results; they find that all 3 techniques follow the same scaling laws, with RL routing doing quite well. I&#8217;d be curious to see how much effort has been put into improving RL routing; I suspect that it could be improved significantly.</p><p>The authors observed the following results:</p><ol><li><p>Routing improves the performance of language models across all sizes and variants attempted</p></li><li><p>Training a Routing Network with RL is of comparable effectiveness to state-of-the-art techniques.</p></li><li><p>The performance of all Routing Networks is accurately described by scaling laws in the number of experts and in the underlying dense model size.</p></li></ol><p>I was surprised at how similar the performance of the various techniques was. The data was quite nice, with little variation. The scaling laws seem to fit the data quite nicely.</p><p>One interesting result was that routing helps significantly more when the model is smaller. I found this surprising; my intuition is that routing should always help. They found that this was the case across all models, and that routing helped less as the models grew.</p><p>The paper ends with recommendations, which I found really useful:</p><ol><li><p>Use routing for models with less than 1.3B parameters</p></li><li><p>S-Base is a good, default routing algorithm (defined in the appendix of their paper).</p></li><li><p>Target using E in {64, 128} experts.</p></li><li><p>Use K = 1 experts; route layers with a frequency between 0.5 &amp; 1; lower frequency reduces performance.</p></li></ol><h2>Internet explorer</h2><p><a href="https://arxiv.org/abs/2302.14051">Abstract</a></p><p>In this paper, the authors create an agent which dynamically explores the internet, running text queries to find images to use for self-supervised training. While seemingly designed to <a href="https://rationalwiki.org/wiki/AI-box_experiment">directly antagonize Yudkowsky</a>, the paper is extremely interesting, and presents, to me, a potential future direction for AGI research. As <a href="https://arxiv.org/abs/2203.15556">Chinchilla</a> showed us, LLMs could <a href="https://www.lesswrong.com/posts/6Fpvch8RR29qLEWNH/chinchilla-s-wild-implications#fnjefvfidovdb">massively improve</a> with more data. Having agents dynamically exploring the internet is one excellent way to get more data- especially if they&#8217;re able to adaptively learn over time and prioritize images accordingly.</p><p>In the paper, they train a model to learn representations of images based on <a href="https://paperswithcode.com/method/moco-v3">MoCo-v3</a>. They query Google Images for new images, ranking the query results by similarity to the target dataset, assigning a reward to the new images:</p><div class="captioned-image-container"><figure><a class="image-link image2" target="_blank" href="https://substackcdn.com/image/fetch/$s_!eRpu!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!eRpu!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 424w, https://substackcdn.com/image/fetch/$s_!eRpu!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 848w, https://substackcdn.com/image/fetch/$s_!eRpu!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 1272w, https://substackcdn.com/image/fetch/$s_!eRpu!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!eRpu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png" width="592" height="116" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/e9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:116,&quot;width&quot;:592,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:16544,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!eRpu!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 424w, https://substackcdn.com/image/fetch/$s_!eRpu!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 848w, https://substackcdn.com/image/fetch/$s_!eRpu!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 1272w, https://substackcdn.com/image/fetch/$s_!eRpu!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fe9d027f0-587c-4340-bda9-517baf1e35d3_592x116.png 1456w" sizes="100vw" loading="lazy"></picture><div></div></div></a></figure></div><p>Here, S_cos is the cosine similarity, f_k is the image encoder, D := {x_i} is the target dataset, and y is the new image to evaluate, and they evaluate over the k closest neighbours in the target dataset (where &#8220;closest&#8221; is determined by the encoded representation).</p><p>They create the queries for Google Images by sampling them from a static vocabulary dataset. For the sampling process, they estimate the reward associated with the query using a Gaussian process regression, and choose the queries with the highest reward.</p><p>I&#8217;d be really interested to see a fancier query generation process. One idea that comes to my mind would be using RL to train a LLM to generate queries in a manner similar to what&#8217;s done in <a href="https://openai.com/research/learning-from-human-preferences">RLHF</a>/<a href="https://arxiv.org/abs/2204.05862">RLAIF</a>, i.e. use an RL algorithm like PPO to finetune a pretrained LLM to maximize reward. This would require much more compute.</p><h2>LLaMa</h2><p><a href="https://arxiv.org/abs/2302.13971">Abstract</a></p><p>I&#8217;ve been digesting the LLaMa paper that Facebook released this week. It was very interesting to see the performance increases they got despite the size decreases. Their 13B model outperformed GPT-3 on a number of benchmarks, and their 65B model was competitive with Chinchilla-70B and PaLM-540B (!).</p><p>I did find it incredibly frustrating that they stopped training when they did; their loss curves are all looking pretty far from convergence, and I&#8217;m curious to see how much the models will continue to improve:</p><div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!qKIr!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!qKIr!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 424w, https://substackcdn.com/image/fetch/$s_!qKIr!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 848w, https://substackcdn.com/image/fetch/$s_!qKIr!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 1272w, https://substackcdn.com/image/fetch/$s_!qKIr!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!qKIr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png" width="504" height="502" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:502,&quot;width&quot;:504,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:103399,&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;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!qKIr!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 424w, https://substackcdn.com/image/fetch/$s_!qKIr!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 848w, https://substackcdn.com/image/fetch/$s_!qKIr!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.png 1272w, https://substackcdn.com/image/fetch/$s_!qKIr!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F86077ced-ed60-4102-81e9-2a0bf789b665_504x502.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><p>I wish that they had just <a href="https://karpathy.github.io/2019/04/25/recipe/#6-squeeze-out-the-juice">left it training</a>.</p><p>My biggest question about the paper is that it&#8217;s not clear what caused the improvements. They discuss a few major changes compared to GPT-3, which their model is based on:</p><ul><li><p>They only use publicly available data, but it&#8217;s unclear what exactly the filtering steps are. I wish they&#8217;d open source their dataset (or at least, the code to clean it).</p></li><li><p>They normalize the input of each transformer sub-layer, rather than the output.</p></li><li><p>They use the <a href="https://paperswithcode.com/method/swiglu">SwiGLU</a> activation function, as PaLM did, with a slight dimensional difference compared to PaLM.</p></li><li><p>They use Rotary Embeddings for the positional encoding.<a class="footnote-anchor" data-component-name="FootnoteAnchorToDOM" id="footnote-anchor-1" href="#footnote-1" target="_self">1</a></p></li></ul><p>There was no ablation study, unfortunately. If I can scrounge up the GPUs, I&#8217;m tempted to do my own ablation based on <a href="https://github.com/karpathy/nanoGPT">nanoGPT</a>. They also use <a href="https://arxiv.org/abs/2205.14135">FlashAttention</a>, which I suspect will become the default attention implementation used in LLMs going forward.</p><p>And that&#8217;s it! Thanks for reading. If you have thoughts on any of these, or interesting follow up papers, I&#8217;d love to hear them.</p><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>I haven&#8217;t seen a great paper comparing various positional encoding schemes. I don&#8217;t really understand which are better, and if this is generally true, or if performance varies in certain scenarios. A proper positional encoding ablation study is on my list of experiments to do once I can scrounge up GPUs.</p><p></p></div></div>]]></content:encoded></item></channel></rss>