<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ai on splatlabs</title>
    <link>https://splatlabs.com/categories/ai/</link>
    <description>Recent content in Ai on splatlabs</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Mon, 05 May 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://splatlabs.com/categories/ai/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>The History of NLP</title>
      <link>https://splatlabs.com/posts/the-history-of-nlp/</link>
      <pubDate>Mon, 05 May 2025 00:00:00 +0000</pubDate>
      
      <guid>https://splatlabs.com/posts/the-history-of-nlp/</guid>
      <description>&lt;h1 id=&#34;how-ai-learned-to-talk-from-zork-to-autocomplete&#34;&gt;How AI Learned to Talk: From Zork to Autocomplete. &lt;a href=&#34;#how-ai-learned-to-talk-from-zork-to-autocomplete&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h1&gt;&lt;p&gt;That&amp;rsquo;s &lt;a href=&#34;https://en.wikipedia.org/wiki/Natural_language_processing&#34;&gt;Natural Language Processing&lt;/a&gt;, not the &lt;a href=&#34;https://en.wikipedia.org/wiki/Neuro-linguistic_programming&#34;&gt;&lt;em&gt;other&lt;/em&gt; NLP&lt;/a&gt;. :)&lt;/p&gt;
&lt;h2 id=&#34;z-games&#34;&gt;Z-Games &lt;a href=&#34;#z-games&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;If you&amp;rsquo;re very old or indulge in ancient novelties, you might&amp;rsquo;ve played &lt;a href=&#34;https://en.wikipedia.org/wiki/Colossal_Cave_Adventure&#34;&gt;Adventure&lt;/a&gt;, the direct inspiration for the most famous text-based game of the modern computing era: Dungeon, or &lt;a href=&#34;https://en.wikipedia.org/wiki/Zork&#34;&gt;Zork&lt;/a&gt;. It ported to the &lt;a href=&#34;https://www.ifwiki.org/Z-machine&#34;&gt;Z-Machine&lt;/a&gt; format and &lt;a href=&#34;https://www.ifwiki.org/ZIL&#34;&gt;ZIL&lt;/a&gt; (an early DSL) by &lt;a href=&#34;https://en.wikipedia.org/wiki/Infocom&#34;&gt;Infocom&lt;/a&gt;, who released a number of similar games, including the &lt;a href=&#34;https://en.wikipedia.org/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy_(video_game)&#34;&gt;&lt;em&gt;Hitchhiker&amp;rsquo;s Guide to the Galaxy&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Around this time, computers were starting to be office desk sized - personal - and finding their way into homes. Games took off in a couple directions, one being the graphics + text style &lt;a href=&#34;https://en.wikipedia.org/wiki/Sierra_Entertainment&#34;&gt;Sierra Games&lt;/a&gt; (like the &lt;a href=&#34;https://en.wikipedia.org/wiki/Leisure_Suit_Larry&#34;&gt;&lt;em&gt;Leisure Suit Larry&lt;/em&gt;&lt;/a&gt; series), and the other stayed text-based, and became myriad &lt;a href=&#34;https://en.wikipedia.org/wiki/Multi-user_dungeon&#34;&gt;MUDs&lt;/a&gt;, &lt;a href=&#34;http://www.furrymuck.com/&#34;&gt;MUCKs&lt;/a&gt;, and other MUs games on the simultaneously-blossoming internet. A tick later and we had online graphical games like &lt;a href=&#34;https://en.wikipedia.org/wiki/Ultima_Online&#34;&gt;Ultima Online&lt;/a&gt; to compliment the text-based, and from there it just kept going.&lt;/p&gt;
&lt;p&gt;Why does this matter? I thought this was the history of NLP, not history of PC gaming? Yeah well, turns out they&amp;rsquo;re not entirely distinct, though not identical either.&lt;/p&gt;
&lt;p&gt;The two areas of technology, gaming and AI (with and without NLP) have been oddly intertwined since the beginning, and still are, in various ways. One reason is much of it is US based, and &amp;ldquo;capitalism&amp;rdquo;, basically. Academic funding exists, but if you want to actually &lt;em&gt;do something&lt;/em&gt;, not just &lt;del&gt;FAFO&lt;/del&gt; run an experiment, write a paper on it, then move on - but continually iterate in the wild, you need a funding model. That model, for decades, was games.&lt;/p&gt;
&lt;p&gt;Gaming has driven GPU development - from late-80s i386 math-coprocessors to current CUDA cores. CAD and scientific computing went along for the ride, but gaming was the market mover with the power of the masses (and their wallets). &lt;a href=&#34;https://en.wikipedia.org/wiki/Nvidia&#34;&gt;Nvidia&lt;/a&gt; leaned in, supporting not just gaming, but deep learning and, more recently, robotics.&lt;/p&gt;
&lt;p&gt;So yes, gaming - not academic research - is probably the most influential factor in why we have LLMs today (at least the hardware to run them), and has been a running (profitable) testbed for AI the whole way. Porn could’ve driven it too, maybe, being one of or the most profitable businesses online from the early days - but gaming had more demanding math problems and higher frame rate demands, so it worked.&lt;/p&gt;
&lt;p&gt;From early syntax-limited parser grammars (&lt;a href=&#34;https://web.mit.edu/marleigh/www/portfolio/Files/zork/transcript.html&#34;&gt;&amp;ldquo;kill troll (with the sword)&lt;/a&gt;&amp;rdquo;) to NPCs with autonomous pathfinding to LLM-powered characters with dynamic personas, AI has been evolving inside games since the start.&lt;/p&gt;
&lt;h2 id=&#34;expert-systems-and-infobots&#34;&gt;Expert Systems and Infobots &lt;a href=&#34;#expert-systems-and-infobots&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Meanwhile, another text-based medium was also taking off: &lt;a href=&#34;https://en.wikipedia.org/wiki/Internet_Relay_Chat&#34;&gt;IRC&lt;/a&gt;. Though IRC didn&amp;rsquo;t use NLP, it quickly became a playground for bots - perhaps the first NPCs of the online world.&lt;/p&gt;
&lt;p&gt;Many of us toyed with various ways to make these bots more personable, clever, and useful, but most boiled down to what became formalized as &lt;a href=&#34;https://en.wikipedia.org/wiki/Infobot&#34;&gt;Infobots&lt;/a&gt;, aka Expert Systems - or the occasional &lt;a href=&#34;https://en.wikipedia.org/wiki/MegaHAL&#34;&gt;Mega-HAL&lt;/a&gt; because why not - it was the early 90s and we were making it up as we went along, having fun.&lt;/p&gt;
&lt;p&gt;They learned by passively and/or actively by harvesting factoids via simple conversational patterns like &amp;ldquo;x is y,&amp;rdquo; and storing these in flat files or DBs. Ask &amp;ldquo;what is x?&amp;rdquo; and they&amp;rsquo;d reply, parroting what they&amp;rsquo;d seen. Think: &lt;a href=&#34;https://en.wikipedia.org/wiki/ELIZA&#34;&gt;ELIZA&lt;/a&gt; meets Prolog-lite.&lt;/p&gt;
&lt;p&gt;This was an organic echo of symbolic reasoning, ala basic Prolog facts and queries - like what_is(Keyword, Answer) - and we could expand them to &amp;ldquo;where is x&amp;rdquo; or whatever else we could somewhat reliably match on with regular expressions and the like. Some of us unknowingly essentially reinvented logic programming.&lt;/p&gt;
&lt;p&gt;These bots laid the foundation for (or at least foreshadowed) the IVR hell systems of &amp;ldquo;press 3 for billing&amp;rdquo; fame, but they stayed mostly in hobbyist and gaming circles. They required tons of human curation and tended to rot without upkeep.&lt;/p&gt;
&lt;p&gt;Still, the groundwork was laid, and they kept slowly but surely trying different strategies to further evolve, and &lt;a href=&#34;https://logicmoo.org/&#34;&gt;often through games&lt;/a&gt;, even &lt;a href=&#34;https://www.newscientist.com/article/2414144-minecraft-could-be-the-key-to-creating-adaptable-ai/&#34;&gt;to this day&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;cryptography-one-way-hashes-and-context&#34;&gt;Cryptography, One-Way Hashes, and Context &lt;a href=&#34;#cryptography-one-way-hashes-and-context&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Language is inherently cryptographic, or rather &lt;a href=&#34;https://en.wikipedia.org/wiki/Steganography&#34;&gt;steganographic&lt;/a&gt;, where meaning is hidden in context - sometimes layers deep, each with useful information - which is one crucial reason NLP is so complex.&lt;/p&gt;
&lt;p&gt;Another challenge is the combinatorial explosion issue, and yet another is that people rarely speak using very &lt;a href=&#34;https://en.wikipedia.org/wiki/Grammar&#34;&gt;correct grammar&lt;/a&gt; (especially these days), but the cryptographic aspect is arguably one of the harder parts to adapt to comprehension via computation.&lt;/p&gt;
&lt;p&gt;To illustrate, if I used the word &amp;ldquo;computer&amp;rdquo; a century or two ago, it&amp;rsquo;d have been assumed I was speaking of a person skilled in mental math computation. If I attempted to explain no, I mean a machine, with a processor, and a screen and&amp;hellip; it&amp;rsquo;d just make things worse, and lead to more confusion.&lt;/p&gt;
&lt;p&gt;Words make sense of us because they&amp;rsquo;re &lt;a href=&#34;https://en.wikipedia.org/wiki/Language_game_(philosophy)&#34;&gt;based on direct experience&lt;/a&gt;, starting at birth with our caregivers speaking while pointing, doing, or otherwise indicating the correlation to the utterances they used.&lt;/p&gt;
&lt;p&gt;From these direct, first-order observations, we then learn to generalize and abstract, to reference things we can&amp;rsquo;t &lt;em&gt;point to&lt;/em&gt; in our immediate proximity, or limit references to specific instances of things.&lt;/p&gt;
&lt;p&gt;We learn the can of Pepsi on our desk belongs to the abstract class &amp;ldquo;Pepsi&amp;rdquo; and can refer to any other can of Pepsi, which belongs to the &lt;em&gt;category&lt;/em&gt; &amp;ldquo;soda&amp;rdquo;, then &amp;ldquo;drink&amp;rdquo;, &amp;ldquo;consumable&amp;rdquo;, and on up until we hit &amp;ldquo;object&amp;rdquo; (if we go by &lt;a href=&#34;https://en.wikipedia.org/wiki/WordNet&#34;&gt;WordNet&amp;rsquo;s&lt;/a&gt; hyponym hierarchy).&lt;/p&gt;
&lt;p&gt;Soda can also mean sodium bicarbonate, which is another issue, and we discern which is referenced by the context its referenced within (sentence, conversation, environment, are all context cues).&lt;/p&gt;
&lt;p&gt;So we have both symbol overload (word re-use) and the one-way hash or cryptographic element - you can’t derive original context from a word without some approximate shared experience. Something that gives us &lt;em&gt;context&lt;/em&gt; by which to recognize what the symbol is referencing, and an existing schema to process it through. Thus experience, and the context it creates in our minds, is the &amp;ldquo;key&amp;rdquo; to the cryptographic encoding of language.&lt;/p&gt;
&lt;p&gt;Context, it turns out, really is everything. At least when it comes to &lt;em&gt;meaning&lt;/em&gt;. Even dictionaries are useless without it. Even the word &amp;ldquo;meaning&amp;rdquo; is &lt;a href=&#34;https://nickbostrom.com/old/quine&#34;&gt;hilariously ambiguous&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To someone from before our technological era, trying to explain &amp;ldquo;computer&amp;rdquo; wouldn&amp;rsquo;t be helped by a dictionary or anything else, even a photograph might be suggestive, but still confusing, since it&amp;rsquo;d lack context to what the image was even showing.&lt;/p&gt;
&lt;p&gt;Blind people &lt;a href=&#34;https://www.science.org/content/article/feature-giving-blind-people-sight-illuminates-brain-s-secrets&#34;&gt;can&amp;rsquo;t instantly see&lt;/a&gt;, or at least not know what they&amp;rsquo;re seeing, when their blindness is cured medically (and not in infancy). There are &lt;a href=&#34;https://en.wikipedia.org/wiki/Invisible_ships&#34;&gt;stories&lt;/a&gt; of natives who would see boats but had no concept of ships, so would instead render whales, large waves, or nothing at all. The story is of dubious validity, but the point is still highly relevant in fundamental &lt;a href=&#34;https://neuroscienceschool.com/2023/11/16/we-see-what-we-expect-to-see/&#34;&gt;human psychology&lt;/a&gt; likely deeply anchored in &lt;a href=&#34;https://neuroscienceschool.com/2023/11/16/we-see-what-we-expect-to-see/&#34;&gt;neurology&lt;/a&gt; and a notable factor in human &lt;a href=&#34;https://tll.mit.edu/teaching-resources/how-people-learn/metacognition/&#34;&gt;cognition&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Our brains physically adapt, &amp;ldquo;neurons that fire together, wire together&amp;rdquo;, and through ongoing feedback loops come to recognize images, sounds, sensations, then symbols, words, and ideas, all building up piece by piece, creating contextual structures and schemas along the way, through which we process the world&amp;rsquo;s information. So how do we teach computers to do this in an automated, algorithmic way?&lt;/p&gt;
&lt;p&gt;That&amp;rsquo;s a damn good question, and the answer which would lead us, presumably, to AGI, or systems that could (the &amp;ldquo;consciousness&amp;rdquo; debate aside) think, comprehend, and actually &lt;em&gt;understand&lt;/em&gt; on some level.&lt;/p&gt;
&lt;h2 id=&#34;ontologies&#34;&gt;Ontologies &lt;a href=&#34;#ontologies&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;There are words for this system of correspondences and abstractions we build up, like &amp;ldquo;reality model&amp;rdquo;, or more formally &amp;ldquo;ontology&amp;rdquo;, which may include aspects such as taxonomy etc also.&lt;/p&gt;
&lt;p&gt;So the next big step was realizing the internet wasn&amp;rsquo;t just running a service we called the web, but could &lt;em&gt;be&lt;/em&gt; a web, an ontological &lt;a href=&#34;https://en.wikipedia.org/wiki/Semantic_network&#34;&gt;Semantic Network&lt;/a&gt; that could store a distributed system with the scaffolding needed for computational understanding of language. Some people built it, over decades, and it&amp;rsquo;s actually damn impressive (if largely invisible until you stumble onto it), if a bit dusty now.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://foundation.wikimedia.org/wiki/Home&#34;&gt;WikiMedia Foundation&lt;/a&gt; is notable here (look at the bottom of the page, click around, you&amp;rsquo;ll see many links with relationship data like is-a, has-a, has-parts, relates-to, parts of speech, etc), though Wikipedia is by far the most well-known out of this broader cluster of effort. Projects like &lt;a href=&#34;https://en.wikipedia.org/wiki/Open_Mind_Common_Sense#ConceptNet&#34;&gt;ConceptNet&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/Cyc&#34;&gt;Cyc&lt;/a&gt; were laboriously built up, only to be eventually largely abandoned outside of some very niche domains and uses.&lt;/p&gt;
&lt;p&gt;The semantic web adopted formats that attempted to formalize and encapsulate these knowledge databases in highly structured ways, such as &lt;a href=&#34;https://en.wikipedia.org/wiki/Web_Ontology_Language&#34;&gt;OWL&lt;/a&gt; and &lt;a href=&#34;https://en.wikipedia.org/wiki/RDF_Schema&#34;&gt;RDF&lt;/a&gt;, which still exist, but tend to hide in niches like &lt;a href=&#34;https://www.ontotext.com/knowledgehub/fundamentals/linked-data-linked-open-data/&#34;&gt;LOD&lt;/a&gt; and &lt;a href=&#34;https://monarchinitiative.org/&#34;&gt;medical data&lt;/a&gt; (also impressive once you notice it, just very dusty) and some more obscure NLP related areas.&lt;/p&gt;
&lt;p&gt;A few larger, actually successful applications were made, in medical diagnostic systems for instance, but were eventually considered too brittle, too hard to create and upkeep, and unable to be easily adapted to other domains. The momentum drained and dried up.&lt;/p&gt;
&lt;p&gt;It was dead end after dead end, but efforts remained strong for decades. Until about 3+yrs ago, when the majority of related github repos and projects seemed to stop being updated, got archived, or became abandonware. This, of course, coincides directly with the monumental breakthrough of &lt;a href=&#34;https://en.wikipedia.org/wiki/Attention_Is_All_You_Need&#34;&gt;Attention is All You Need&lt;/a&gt;, which led directly to LLMs as we know them now.&lt;/p&gt;
&lt;p&gt;Suddenly we didn’t need to &lt;em&gt;define&lt;/em&gt; meaning. We could &lt;em&gt;approximate&lt;/em&gt; it statistically.&lt;/p&gt;
&lt;p&gt;Some clever math nerds had taken NN style math-soup, and figured out how to get it to talk. A bit later, it become coherent, then actually useful, in a few quick leaps. It was a convergence of the massive hardware necessary coming into existence along with decades of trial and error in the ontology and NLP field, finally hitting &lt;em&gt;something that worked&lt;/em&gt;, mostly, if costly.&lt;/p&gt;
&lt;p&gt;Companies caught wind of this, and invested insanely in it - finally, the AI breakthrough we&amp;rsquo;d been promised and were waiting for all these years. Ok, so maybe we have to fire back up or build a few new &lt;em&gt;nuclear power plants&lt;/em&gt;, maybe math was never meant to &lt;em&gt;think&lt;/em&gt;, but heck, it works, so throw everything else out and run with it!&lt;/p&gt;
&lt;p&gt;And the insanity began, while decades of slow, deliberate building of vast networks of knowledge were largely abandoned (sans some niches of &lt;a href=&#34;https://arxiv.org/abs/2210.03629&#34;&gt;ongoing exploration&lt;/a&gt;) almost overnight. It&amp;rsquo;s still there though - most of it anyway - in case someone realizes pure math-soup was maybe not the best strategy, or structured knowledge might have some use yet.&lt;/p&gt;
&lt;h1 id=&#34;what-now&#34;&gt;What Now? &lt;a href=&#34;#what-now&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h1&gt;&lt;p&gt;The renewed momentum generated by the success of transformer models (and let&amp;rsquo;s be realistic, cash infusion stemming from that) has fresh eyes looking into new ways to solve this decades-old problem. As we know too well, LLMs &amp;ldquo;hallucinate&amp;rdquo;, and all the data on the internet isn&amp;rsquo;t enough to teach them everything, somehow.&lt;/p&gt;
&lt;p&gt;Data is messy, people say stupid things a lot, and it takes a &lt;em&gt;ton&lt;/em&gt; of data to train a transformer to a coherent level. Add to this the pervasive commercialization, hyperbole, spam, SEO manipulation, misinformation, disinformation, RP and propaganda out there, and it makes a bit of a hostile environment for learning, to say the least. There are many reasons why LLMs are flawed, but this is a big one.&lt;/p&gt;
&lt;p&gt;But with this momentum, we&amp;rsquo;ve got investigation and innovations around &lt;a href=&#34;https://en.wikipedia.org/wiki/Holographic_algorithm&#34;&gt;holography&lt;/a&gt;, &lt;a href=&#34;https://en.wikipedia.org/wiki/Optical_computing&#34;&gt;photonic computing&lt;/a&gt; (potentially &lt;a href=&#34;https://news.mit.edu/2024/photonic-processor-could-enable-ultrafast-ai-computations-1202&#34;&gt;replacing GPUs&lt;/a&gt; for the big math), and other more analog-style approaches. Going &amp;ldquo;back&amp;rdquo; to escape the current local maxima - and move forward again in a better direction - seems like a solid strategy at this point.&lt;/p&gt;
&lt;p&gt;What did we leave behind that would be useful now that we&amp;rsquo;ve solved this other problem, what didn&amp;rsquo;t work, but would now with our hardware and resources? The solutions we need may already exist in some dusty, archived github repos, you never know.&lt;/p&gt;
&lt;p&gt;Transformers&amp;rsquo; &lt;a href=&#34;https://splatlabs.com/posts/how-llms-work/&#34;&gt;underlying structure&lt;/a&gt;, being essentially &amp;ldquo;quadrillions of dot products on craploads of matrices of floating point numbers&amp;rdquo; isn&amp;rsquo;t exactly biased towards accuracy. It&amp;rsquo;s fuzzy, on purpose, since teaching computers to &lt;em&gt;actually&lt;/em&gt; think and know things proves a lot harder than it sounds once you dig into it.&lt;/p&gt;
&lt;p&gt;It works, but it’s kind of a fluke, honestly. &lt;a href=&#34;https://en.wikipedia.org/wiki/Douglas_Hofstadter&#34;&gt;Hofstadter&lt;/a&gt; was right: enough structure and recursion breeds emergent behavior. But actual understanding? Even if our brains are also NNs, it&amp;rsquo;s not quite that simple, apparently.&lt;/p&gt;
&lt;p&gt;The reality is, LLMs are a lot more like our &amp;ldquo;subconscious&amp;rdquo;, or &amp;ldquo;System 1&amp;rdquo; in the &lt;a href=&#34;https://en.wikipedia.org/wiki/Thinking,_Fast_and_Slow#Two_systems&#34;&gt;Thinking Fast and Slow&lt;/a&gt; sense. What it lacks, is the &amp;ldquo;System 2&amp;rdquo; to compliment it, what we often call the &amp;ldquo;conscious&amp;rdquo; or &amp;ldquo;rational&amp;rdquo; mind, the part that reasons through things slowly, as we often attempt to instruct LLMs to do - or attempt to force through &lt;a href=&#34;https://en.wikipedia.org/wiki/Prompt_engineering#Chain-of-thought&#34;&gt;CoT&lt;/a&gt; systems tacked on that give it a chance to build some faux critical thinking by generating purposeful outputs into its context before forming the final response.&lt;/p&gt;
&lt;p&gt;When we see a model &amp;ldquo;thinking&amp;rdquo; it&amp;rsquo;s creating a semi-structured response, most of which include &amp;ldquo;the user is looking for&amp;hellip;&amp;rdquo; and &amp;ldquo;wait&amp;hellip; it could also be&amp;hellip;&amp;rdquo; type sentences. Since it does most likely next token, these would lead it to generate varied branches of completions, which are then appended to the existing context window, forcing those into its full contextual math-soup as well, a bit of &amp;ldquo;priming&amp;rdquo; as it were.&lt;/p&gt;
&lt;p&gt;It does not, even in these advanced scenarios, &amp;ldquo;think&amp;rdquo; in any meaningful use of the term, or engage any real &amp;ldquo;System 2&amp;rdquo; type of mechanism (though I would contend this is not much different than many humans, but that again is another article). :)&lt;/p&gt;
&lt;p&gt;That said, the big cash infusion? Pretty much all to big LLMs and commercial ventures. Whomever finds the solution to these big problems may be riding the excitement wave, but is likely going to be some random individual leafing through dusty archives, driven purely by insatiable curiosity, without any expectation of reward. That&amp;rsquo;s how these things tend to work, after all.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>How Llms Work</title>
      <link>https://splatlabs.com/posts/how-llms-work/</link>
      <pubDate>Sun, 04 May 2025 00:00:00 +0000</pubDate>
      
      <guid>https://splatlabs.com/posts/how-llms-work/</guid>
      <description>&lt;h1 id=&#34;demystifying-llm-architecture&#34;&gt;Demystifying LLM Architecture &lt;a href=&#34;#demystifying-llm-architecture&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h1&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Oh, there is a brain all right. It&amp;rsquo;s just that the brain is made out of &lt;del&gt;meat&lt;/del&gt; math!&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;So&amp;hellip; what does the thinking?&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;You&amp;rsquo;re not understanding, are you? The brain does the thinking. The &lt;del&gt;meat&lt;/del&gt; math.&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&amp;ldquo;Thinking &lt;del&gt;meat&lt;/del&gt; math! You&amp;rsquo;re asking me to believe in thinking &lt;del&gt;meat&lt;/del&gt; math!&amp;rdquo;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&amp;ndash; &lt;a href=&#34;https://www.mit.edu/people/dpolicar/writing/prose/text/thinkingMeat.html&#34;&gt;MIT Thinking Meat&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Aka: The documentation I wanted but couldn&amp;rsquo;t find in one place anywhere, and will want as a reference for myself ongoing also.&lt;/p&gt;
&lt;p&gt;What if you just want to &lt;em&gt;write code&lt;/em&gt; using &lt;a href=&#34;https://pytorch.org/&#34;&gt;the tools&lt;/a&gt;, and not become a PhD in theoretical math? Or you want to write programmer-style code, not data-scientist style code (which are about as different as Egyptian hieroglyphs are to Latin, frankly, despite both being &amp;ldquo;language&amp;rdquo; in the broad sense)?&lt;/p&gt;
&lt;p&gt;So I&amp;rsquo;ve written a sort of math-nerd to tech-nerd translation cheat-sheet for decoding the PhD-speak into something hopefully usable, and with some comprehension and not just copypasta.&lt;/p&gt;
&lt;p&gt;Eg: a &amp;ldquo;continuous n-dimensional vector space&amp;rdquo; is &lt;em&gt;really&lt;/em&gt; just a 2d array is just a numeric array (usually floats) where values smoothly vary rather than jumping discretely (like integers or categories) - once you strip off the domain language and semantic constructs and rephrase it in more direct application/programmer-friendly terms.&lt;/p&gt;
&lt;p&gt;Also here&amp;rsquo;s a &lt;a href=&#34;https://www.youtube.com/watch?v=KJtZARuO3JY&#34;&gt;video/visual guide by Grant Sanderson&lt;/a&gt; aka 3B1B, to go along with my ramblings.&lt;/p&gt;
&lt;h2 id=&#34;what-is-machine-learning&#34;&gt;What is Machine Learning? &lt;a href=&#34;#what-is-machine-learning&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Programming and software all boils down to some form of A-&amp;gt;B, or input -&amp;gt; (magic) -&amp;gt; output. Sometimes the data goes into a db, or to a frontend/website, or is passed on via API, etc., but this fundamental pattern underlies it all. AI is essentially giving the computer some space (matrices, tensors) and math functions, and saying &amp;ldquo;you figure it out, by brute-forcing it till you get it right&amp;rdquo; essentially, then saving the version that gets it right&lt;em&gt;est&lt;/em&gt; to re-use ongoing.&lt;/p&gt;
&lt;p&gt;ML is fundamentally mapping inputs to outputs by tuning a system of numerical weights, by formal definition. Inputs (like words or images) are first converted into numeric encodings, usually dense vectors called embeddings.&lt;/p&gt;
&lt;p&gt;These vectors flow through multiple layers, each performing matrix multiplications and nonlinear functions (often ReLU or GELU). Each matrix multiplies the input by a set of learnable weights, generating intermediate representations. For text, these matrices typically have shapes like [vocabulary_size × embedding_dim] for embeddings, or [embedding_dim × embedding_dim] for hidden layers.&lt;/p&gt;
&lt;p&gt;During training, outputs are compared to known targets (labels) via a loss function (like cross-entropy), and the gradients (differences between actual and target outputs) flow backward (backpropagation), slightly adjusting each matrix’s values in the direction opposite to the gradient, gently nudging towards better accuracy without overshooting. Besides dot products, math operations include addition, scaling, normalization, and nonlinear activation functions.&lt;/p&gt;
&lt;p&gt;Getting high quality, accurately labeled data can be one of the biggest challenges for most applications of ML. As the old saying goes &amp;ldquo;garbage in, garbage out&amp;rdquo;, and it&amp;rsquo;s definitely apt here.&lt;/p&gt;
&lt;p&gt;It kind of boils down to algebra, abstractly. You keep throwing input * x = output at it until it learns to solve for x, then you let it produce outputs on its own, and x is basically math-soup that we can&amp;rsquo;t really discern wtf it&amp;rsquo;s doing, other than how well it works or not. If it seems like opaque, black magic, that&amp;rsquo;s because it really is, you&amp;rsquo;re not missing something - that&amp;rsquo;s just how it works.&lt;/p&gt;
&lt;h2 id=&#34;how-are-transformer-models-llms-different&#34;&gt;How are transformer models (LLMs) different? &lt;a href=&#34;#how-are-transformer-models-llms-different&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Transformers are a neural network architecture built around attention mechanisms instead of sequential or convolutional patterns. The core innovation, &amp;ldquo;Attention is All You Need&amp;rdquo;, lets the model dynamically weigh input tokens differently based on context.&lt;/p&gt;
&lt;p&gt;The embedding matrix is shaped [vocab_size × embedding_dim], where each token in the vocabulary corresponds to a row, and each column encodes a different semantic aspect (dimension of meaning), and the training process magically assigns these dimensions based on various word use in the training text.&lt;/p&gt;
&lt;p&gt;These vectors represent points in an abstract &amp;ldquo;meaning-space,&amp;rdquo; where the relative positions and directions between vectors encode relationships and semantic nuances. This is how the model can calculate similarity (cosine similarity) based on the angles between vectors, indicating semantic closeness. It&amp;rsquo;s how we get fun like &amp;ldquo;King - Man + Woman = Queen&amp;rdquo; of word2vec fame.&lt;/p&gt;
&lt;p&gt;The model takes each token of the query (aka the context window), does the magical math-soup over however many layers for each of those tokens, and produces a list of most likely probable next tokens. One of those is then selected (based on temperature etc.), and then the process repeats - for every token in the response.&lt;/p&gt;
&lt;p&gt;Attention is computed as a softmax-normalized dot product between query and key matrices (Q × Kᵀ), giving weights that determine how much each token&amp;rsquo;s value influences each output position (weights × Values). Transformers stack multiple attention heads in parallel, followed by dense feed-forward layers ([embedding_dim × embedding_dim] matrices) to produce rich contextual encodings.&lt;/p&gt;
&lt;p&gt;Backpropagation and differentiation work as usual - computing gradients from the loss - but because attention is parallelized and not sequential, it’s computationally efficient and can utilize GPUs well.&lt;/p&gt;
&lt;p&gt;Technically, each input is encoded into three matrices called Queries, Keys, and Values (all usually [sequence_length × embedding_dim] - or one full vocabulary row/vector per token in the sequence).&lt;/p&gt;
&lt;p&gt;Technically, each token in the input sequence is first converted into a vector via the embedding matrix [vocab_size × embedding_dim], resulting in a [sequence_length × embedding_dim] input. Then, for every attention head, the model applies three learned linear projections - $W_q, W_k, and W_v$ - to generate Queries, Keys, and Values, each shaped [sequence_length × head_dim]. Multiply that by the number of heads (often 8, 12, or more), and you start to see how each token gets exploded into multiple representations for parallel comparison.&lt;/p&gt;
&lt;p&gt;This is where most of the math-soup lives: lots of matrix multiplies, softmax weighting, and dot products - just to figure out which other tokens each word should &amp;ldquo;pay attention&amp;rdquo; to&amp;hellip; and why it eats gigs of ram to churn out a few sentences.&lt;/p&gt;
&lt;h3 id=&#34;sequential-patterns-vs-attention-clarifying-the-mechanism&#34;&gt;Sequential Patterns vs. Attention: Clarifying the Mechanism &lt;a href=&#34;#sequential-patterns-vs-attention-clarifying-the-mechanism&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;In earlier models (like RNNs), sequential context meant words were processed one-by-one, carrying state forward. N-grams (like bigrams or trigrams) were historically discrete language models without embeddings. Modern neural language models (like transformers) differ significantly: all tokens are simultaneously embedded into numeric vectors, then attention computes weighted relevance scores dynamically.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s not limited to fixed-length sequences (e.g., trigrams); instead, it dynamically integrates context across entire input sequences, using learned weights.&lt;/p&gt;
&lt;p&gt;There is no big secret here either, they&amp;rsquo;re just &lt;em&gt;more matrices&lt;/em&gt; and the training feedback nudges them to become useful in the desired ways, or presumes they do so since the outputs improve.&lt;/p&gt;
&lt;p&gt;Attention matrices ($Q, K, V$) are computed from the same original input embeddings, but each undergoes its own linear transformation ($W_q, W_k, W_v$). These learned transformations specialize each matrix differently:&lt;/p&gt;
&lt;p&gt;Queries ($Q$) represent what each token is &amp;ldquo;looking for.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Keys ($K$) represent what information each token &amp;ldquo;offers.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Values ($V$) represent the content actually used in output.&lt;/p&gt;
&lt;p&gt;Thus, the attention weights ($softmax(Q × Kᵀ)$) dynamically determine how tokens interact. These matrices typically have shapes like [sequence_length × embedding_dim], transformed from inputs by learned [embedding_dim × embedding_dim] matrices.&lt;/p&gt;
&lt;p&gt;Each transformer layer typically includes a multi-headed self-attention step (sequence_length × embedding_dim), followed by a feed-forward step (embedding_dim × 4 × embedding_dim, then back to embedding_dim).&lt;/p&gt;
&lt;h3 id=&#34;notable-differences-between-transformers-and-traditional-neural-networks&#34;&gt;Notable Differences Between Transformers and Traditional Neural Networks &lt;a href=&#34;#notable-differences-between-transformers-and-traditional-neural-networks&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Beyond attention, transformers notably differ in several ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Parallel vs Sequential Processing: Transformers process entire sequences simultaneously via attention, unlike recurrent (RNN/LSTM) models, eliminating serial bottlenecks.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Positional Encoding: Transformers lack built-in sequence-awareness, so positional embeddings explicitly encode token order.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Feed-Forward Layer Design: Transformers contain large intermediate feed-forward layers ([embedding_dim × 4×embedding_dim]), providing substantial nonlinearity and expressive power.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Layer Normalization: Transformers extensively use layer normalization to stabilize activations, compared to batch normalization common in convolutional networks.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These innovations collectively distinguish transformers from older architectures, providing better scalability, richer context modeling, and more stable training dynamics.&lt;/p&gt;
&lt;h2 id=&#34;ok-so-what-does-all-of-this-really-mean-in-practice&#34;&gt;Ok, so what does all of this &lt;em&gt;really mean&lt;/em&gt;, in practice? &lt;a href=&#34;#ok-so-what-does-all-of-this-really-mean-in-practice&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Many programmers run into the same wtf moment when reading up on DIY AI à la PyTorch or similar libraries and frameworks. There seems to be 2 types of documentation. One is stacks of research papers on &lt;a href=&#34;https://arxiv.org/&#34;&gt;arXiv&lt;/a&gt;, loaded with dense math and lots of greek, and the other is &amp;ldquo;just call these functions, easy!&amp;rdquo; and explain nothing.&lt;/p&gt;
&lt;p&gt;The typical coder type is left scratching their head, knowing it&amp;rsquo;s some combination of math and matrices, but what do you &lt;em&gt;do&lt;/em&gt; with that? We&amp;rsquo;re used to having to spell stuff out, use logic, tell the machine what the heck to do, so where&amp;rsquo;s that part? As I said earlier, that&amp;rsquo;s the black magic part - you &lt;em&gt;don&amp;rsquo;t&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;It feels intuitively like there must be more to it, but there really isn&amp;rsquo;t, other than organizing and arranging the spaces (matrices) and math (functions) to taste, but mostly they&amp;rsquo;re all happily abstracted away into functions for the most common uses, and that&amp;rsquo;s what we see in the docs, the &amp;ldquo;call this, this, and this&amp;rdquo; type.&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s basically saying &amp;ldquo;make a matrix, call some functions (one function = one layer), assign a backprop method (how strong do you want your gradient?) and call train() on the lot of it. &lt;em&gt;That&amp;rsquo;s it&lt;/em&gt;, other than the frills and dressing of finessing inputs and outputs or whatnot in a more end-user scenario. The rest is the machine arduously brute forcing its way to solving for x well enough to be useful.&lt;/p&gt;
&lt;p&gt;The thing you&amp;rsquo;re more likely thinking of, where you actually &lt;em&gt;tell it things&lt;/em&gt; in some manner? That&amp;rsquo;s called symbolic AI, and lots of people have tried this. It&amp;rsquo;s basically what was behind the whole &amp;ldquo;semantic web&amp;rdquo; thing, among other efforts.&lt;/p&gt;
&lt;h3 id=&#34;how-matrix-shapes-and-embedding-dimensions-are-chosen&#34;&gt;How Matrix Shapes and Embedding Dimensions Are Chosen &lt;a href=&#34;#how-matrix-shapes-and-embedding-dimensions-are-chosen&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Embedding dimensions and matrix shapes aren&amp;rsquo;t completely arbitrary, but they&amp;rsquo;re largely pragmatic: bigger usually means better (more expressive) representations - but at higher compute and memory costs. Typically, embedding sizes (often 256 to 4096+) are selected based on GPU memory, budget, and dataset size.&lt;/p&gt;
&lt;p&gt;Larger embeddings can encode richer nuances of language but require more training data and hardware. The trade-off: diminishing returns kick in past certain sizes, so experiments balance accuracy against cost.&lt;/p&gt;
&lt;h3 id=&#34;how-math-functions-and-operations-are-chosen-per-layer&#34;&gt;How Math Functions and Operations Are Chosen per Layer &lt;a href=&#34;#how-math-functions-and-operations-are-chosen-per-layer&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Most layer choices - like activation functions and normalization methods - come from empirical success rather than deep theoretical mandates. Researchers often start with known-good defaults (like multi-headed self-attention layers followed by feed-forward networks) and tweak hyperparameters (manual config tuning variables) experimentally.&lt;/p&gt;
&lt;p&gt;Activation functions like ReLU ($max(0, x)$) or GELU (Gaussian Error Linear Unit, smoothly approximating ReLU while preserving gradient flow around zero) became standard because they reliably avoid issues like vanishing gradients and facilitate stable, deep network training. Layer normalization stabilizes activations and improves convergence. Essentially, the field iteratively tests and adopts techniques proven stable, efficient, and effective.&lt;/p&gt;
&lt;p&gt;Which means, yes, they are doing precisely what they&amp;rsquo;re training the models to do: iteratively guess and correct via feedback, like a smart Monte Carlo system. One wonders why they don&amp;rsquo;t make an ML model designed for optimizing models. :)&lt;/p&gt;
&lt;h3 id=&#34;how-did-transformers-solve-nlps-combinatorial-explosion-problem&#34;&gt;How Did Transformers Solve NLP&amp;rsquo;s Combinatorial Explosion Problem? &lt;a href=&#34;#how-did-transformers-solve-nlps-combinatorial-explosion-problem&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Natural language processing is combinatorially explosive because each word&amp;rsquo;s meaning depends heavily on context - leading to immense complexity in older models like recurrent neural networks (RNNs). RNNs maintained state through sequential steps, causing vanishing/exploding gradient issues and poor long-range dependencies.&lt;/p&gt;
&lt;p&gt;Transformers fixed this by dropping sequential processing entirely, using attention mechanisms instead. Attention directly compares each token with all others simultaneously (O(n²) complexity, but efficient via GPUs), effectively solving context resolution cryptographically: each token can &amp;ldquo;see&amp;rdquo; every other, dynamically adjusting weights to decode meaning based on global relationships rather than linear order. Thus, transformers efficiently capture complex contexts, eliminating the sequential bottleneck.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s another &lt;a href=&#34;https://www.youtube.com/watch?v=UKcWu1l_UNw&#34;&gt;video&lt;/a&gt; with some complimentary historical context and info. It explains, for instance, how bigger LLM models are better, despite conventional wisdom on the subject, among other tidbits. Another shows progress from the perceptron on and what the dropout problem is, and &lt;a href=&#34;https://www.youtube.com/watch?v=l-9ALe3U-Fg&#34;&gt;how it was solved&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;how-didnt-they-solve-it&#34;&gt;How didn&amp;rsquo;t they solve it? &lt;a href=&#34;#how-didnt-they-solve-it&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;There&amp;rsquo;s talk of reactivating nuclear power plants to support these behemoths. They&amp;rsquo;re all brute-force, and &lt;a href=&#34;https://splatlabs.com/posts/how-many-flops/&#34;&gt;it ain&amp;rsquo;t pretty&lt;/a&gt;. Every token of input (full context window) is &lt;em&gt;repeatedly&lt;/em&gt; smashed against every token of attention, and of the full vocabulary of the model (which is more where the &amp;ldquo;parameters&amp;rdquo; number comes into play - not embeddings dimensions) - for &lt;em&gt;every&lt;/em&gt; token generation. One. At. A. Time.&lt;/p&gt;
&lt;p&gt;So, while this is cool and it does &lt;em&gt;work&lt;/em&gt;, it still has a lot of room to work &lt;em&gt;well&lt;/em&gt;, or at least more elegantly, maybe to eventually have actually &lt;em&gt;good&lt;/em&gt; models on higher end desktop PCs? That&amp;rsquo;d be cool.&lt;/p&gt;
&lt;h3 id=&#34;the-big-tldr-takeaway&#34;&gt;The big TL;DR Takeaway &lt;a href=&#34;#the-big-tldr-takeaway&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Machine learning isn&amp;rsquo;t nearly as hard as it looks. It&amp;rsquo;s a lot more luck combined with trial and error (and recognizing viable tests to push them forward more) than some sage wisdom of the math nerd collective. You create some 2d arrays, just like numpy does, stack them horizontally (attention heads) and vertically (layers) using pytorch/tensorflow functions, tell it what math-soup to make with some other functions, and hit &amp;ldquo;run.&amp;rdquo; The docs aren&amp;rsquo;t wrong, we just expect something else, apparently. We&amp;rsquo;re used to, you know, &lt;em&gt;writing code&lt;/em&gt;, not making math semi-sentient by sheer brute force. The answer you&amp;rsquo;re looking for is that there is none.&lt;/p&gt;
&lt;p&gt;Look up some open source stuff, like &lt;a href=&#34;https://github.com/deepseek-ai/DeepSeek-V3/&#34;&gt;deepseek-v3&lt;/a&gt; which kind of sucks without the R1 CoT tacked on, but &lt;a href=&#34;https://github.com/deepseek-ai/DeepSeek-R1&#34;&gt;that repo&lt;/a&gt; is mysteriously empty save for some stats and a paper. Still, CoT is demonstrated elsewhere, it&amp;rsquo;s findable. The salient point here is that, if you look through the V3 code, you might wonder &lt;em&gt;where the code is&lt;/em&gt;. Yes, there&amp;rsquo;s something there, a tiny handful of pytorch stuff that looks more concerned with quantization than creating the model - but that&amp;rsquo;s it. That&amp;rsquo;s what I&amp;rsquo;m saying. The &amp;ldquo;code&amp;rdquo; you&amp;rsquo;re looking for is more realistically the &lt;em&gt;training data&lt;/em&gt; itself, which is massive. This isn&amp;rsquo;t quite LISP&amp;rsquo;s &amp;ldquo;code is data, data is code&amp;rdquo;, but it&amp;rsquo;s not far off either, or perhaps a &lt;a href=&#34;https://minikanren.org/&#34;&gt;miniKanren&lt;/a&gt; on steroids. Either way, you don&amp;rsquo;t really &lt;em&gt;write&lt;/em&gt; models, you more &amp;ldquo;breed&amp;rdquo; them with shapes and combinations of matrices and math goo, and that&amp;rsquo;s about it.&lt;/p&gt;
&lt;p&gt;Enjoy.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>How many FLOPs</title>
      <link>https://splatlabs.com/posts/how-many-flops/</link>
      <pubDate>Sun, 04 May 2025 00:00:00 +0000</pubDate>
      
      <guid>https://splatlabs.com/posts/how-many-flops/</guid>
      <description>&lt;h1 id=&#34;why-are-llms-so-power-hungry&#34;&gt;Why are LLMs so Power Hungry? &lt;a href=&#34;#why-are-llms-so-power-hungry&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h1&gt;&lt;p&gt;I knew every token got np.dot()&amp;rsquo;d over every vocab (token) array of embeddings-length floats etc, but I was curious just &lt;em&gt;how many calculations&lt;/em&gt; an LLM does &lt;em&gt;per token&lt;/em&gt;, on average. I asked GPT4o, then Grok. Their answers were essentially the same, but Grok&amp;rsquo;s is a bit more detailed, so I&amp;rsquo;m pasting it in full here just because it&amp;rsquo;s a pretty intense read and I&amp;rsquo;m sure I&amp;rsquo;m not the only one that&amp;rsquo;s wondered - so I&amp;rsquo;ll save you the trouble of futzing around and comparing notes to find it. :)&lt;/p&gt;
&lt;p&gt;Feel free to &lt;a href=&#34;#answer&#34;&gt;Skip to the Answer&lt;/a&gt; if you don&amp;rsquo;t care how we got there.&lt;/p&gt;
&lt;p&gt;Also of note I found a blog that has a similarly freaky breakdown of calculating memory and training requirements for transformers &lt;a href=&#34;https://blog.eleuther.ai/transformer-math/&#34;&gt;here&lt;/a&gt; - will hopefully digest and make more use of this info some point, but there&amp;rsquo;s a little &lt;a href=&#34;https://huggingface.co/spaces/hf-accelerate/model-memory-usage&#34;&gt;estimation tool&lt;/a&gt; based on this work too!&lt;/p&gt;
&lt;p&gt;GPT4o, with some prodding, produced this:&lt;/p&gt;
&lt;p&gt;$FLOPs ≈ E⋅V + L⋅(8⋅E²⋅S + 4⋅E⋅H⋅S + H⋅S²)$&lt;/p&gt;
&lt;h4 id=&#34;what-it-means&#34;&gt;What It Means: &lt;a href=&#34;#what-it-means&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;E&lt;/strong&gt; = embedding dimension (e.g. 4096)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;V&lt;/strong&gt; = vocabulary size (e.g. 200,000)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;S&lt;/strong&gt; = context size (seq_len, e.g. 2M tokens for 2MB)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;H&lt;/strong&gt; = number of attention heads&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;L&lt;/strong&gt; = number of layers (e.g. 100+ in GPT-4 class)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;what-each-term-represents&#34;&gt;What Each Term Represents: &lt;a href=&#34;#what-each-term-represents&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;E⋅V&lt;/code&gt; → one giant matrix multiply at the &lt;strong&gt;final output projection&lt;/strong&gt; (dot against every token in vocab)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;L⋅(...)&lt;/code&gt; → repeated for every layer:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;8⋅E²⋅S&lt;/code&gt; → the two-layer MLPs (most of the FLOPs!)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;4⋅E⋅H⋅S&lt;/code&gt; → Q/K/V dot products&lt;/li&gt;
&lt;li&gt;&lt;code&gt;H⋅S²&lt;/code&gt; → self-attention dot(Q,K) → softmax&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;and-yeah-this-is-why&#34;&gt;And Yeah, This Is Why: &lt;a href=&#34;#and-yeah-this-is-why&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;Large &lt;strong&gt;context windows&lt;/strong&gt; are devastating (&lt;code&gt;S²&lt;/code&gt; term)&lt;/li&gt;
&lt;li&gt;Big &lt;strong&gt;embedding sizes&lt;/strong&gt; blow up &lt;code&gt;E²⋅S&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Massive &lt;strong&gt;vocab sizes&lt;/strong&gt; make &lt;code&gt;E⋅V&lt;/code&gt; crazy at inference&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;I ran this through a repl, filling in the vars with what &lt;em&gt;seemed reasonable&lt;/em&gt; and got:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-txt&#34; data-lang=&#34;txt&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&amp;gt;&amp;gt;&amp;gt; 4096 * 200000 + 100 * (8 * (4096*4096) *
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;128000 + 4 * 4096 * 128000 + 8 * (128000*128000))
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;1731304652800000
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;which, in words is: one quadrillion seven hundred thirty-one trillion three hundred four billion six hundred fifty-two million eight hundred thousand. per token.&lt;/p&gt;
&lt;p&gt;Ok, I know they measure these calculations in MFLOPs, GFLOPs, TFLOPs(mega, giga, tera, just like bits/bytes etc) for reasons, but seriously? And for &lt;strong&gt;every&lt;/strong&gt; token? That&amp;rsquo;s insane, can&amp;rsquo;t be right. So I asked Grok to see if GPT4o was just confused. I briefly considered doing the math on approximately how many tokens its response was and how many FLOPs it&amp;rsquo;d have taken, but I&amp;rsquo;m not &lt;em&gt;quite&lt;/em&gt; that masochistic.&lt;/p&gt;
&lt;hr&gt;
&lt;h1 id=&#34;groks-take&#34;&gt;Grok&amp;rsquo;s take &lt;a href=&#34;#groks-take&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h1&gt;&lt;p&gt;Estimating the FLOPs (floating-point operations) per token generation for a large language model (LLM) like GPT-4o with a 128k context window involves several factors, including the model&amp;rsquo;s architecture, parameter count, and the computational complexity of the transformer-based operations.&lt;/p&gt;
&lt;p&gt;Since exact details about GPT-4o’s architecture (e.g., parameter count) are not publicly disclosed by OpenAI, we’ll rely on general principles from transformer models, scaling laws, and available literature to provide an informed estimate. I’ll also use insights from the provided web results where relevant.&lt;/p&gt;
&lt;h2 id=&#34;key-assumptions-and-methodology&#34;&gt;Key Assumptions and Methodology &lt;a href=&#34;#key-assumptions-and-methodology&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;hr&gt;
&lt;h4 id=&#34;model-architecture&#34;&gt;Model Architecture: &lt;a href=&#34;#model-architecture&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;GPT-4o is a multimodal transformer-based model, likely a decoder-only architecture similar to previous GPT models. For FLOPs estimation, we focus on the text generation component, as this is the primary task for token generation.&lt;/p&gt;
&lt;h4 id=&#34;parameter-count&#34;&gt;Parameter Count: &lt;a href=&#34;#parameter-count&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;OpenAI does not disclose GPT-4o’s parameter count, but estimates for GPT-4 suggest it could be in the range of 1.8 trillion parameters, possibly using a Mixture of Experts (MoE) architecture with 16 experts, each around 111 billion parameters.&lt;/p&gt;
&lt;p&gt;For simplicity, we’ll assume GPT-4o is a dense model with a parameter count on the order of 100 billion to 1 trillion parameters, as MoE models reduce effective FLOPs per token due to sparse computation.&lt;/p&gt;
&lt;h4 id=&#34;flops-formula&#34;&gt;FLOPs Formula: &lt;a href=&#34;#flops-formula&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;According to OpenAI’s scaling laws, the forward pass of a decoder-only transformer involves approximately ( 2N ) FLOPs per token, where ( N ) is the number of non-embedding parameters.&lt;/p&gt;
&lt;p&gt;For a sequence length ( S ) (context window), the FLOPs per token generation scales with ( S ), as the attention mechanism computes interactions across the context.&lt;/p&gt;
&lt;p&gt;The formula is roughly:&lt;/p&gt;
&lt;p&gt;FLOPs per token: $\approx 2 \times N \times S$
where ( S ) is the context length (128,000 tokens in this case).&lt;/p&gt;
&lt;h4 id=&#34;context-length&#34;&gt;Context Length: &lt;a href=&#34;#context-length&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;GPT-4o supports a 128k token context window, meaning $S = 128,000$.&lt;/p&gt;
&lt;p&gt;Generation Phase: During generation, the model processes the entire context for each new token, as it attends to all previous tokens in the sequence. This makes the FLOPs per token dependent on the full context length.&lt;/p&gt;
&lt;h2 id=&#34;step-by-step-estimation&#34;&gt;Step-by-Step Estimation &lt;a href=&#34;#step-by-step-estimation&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;hr&gt;
&lt;h3 id=&#34;estimate--n-&#34;&gt;Estimate ( N ): &lt;a href=&#34;#estimate--n-&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h3&gt;&lt;p&gt;Let’s assume GPT-4o has $\N = 100\ \text{billion} = 10^{11}$ parameters as a conservative estimate for a dense model.&lt;/p&gt;
&lt;p&gt;If it’s an MoE model, the effective parameters per forward pass are lower (e.g., 2 experts at 111 billion each, or ~222 billion total, but only a fraction are used per token).&lt;/p&gt;
&lt;p&gt;For a high-end estimate, we’ll also consider $N = 1 \ \text{trillion} = 10^{12}$ parameters, closer to GPT-4’s rumored scale.&lt;/p&gt;
&lt;p&gt;Context Length ( S ): $S = 128,000 = 1.28 \times 10^5$&lt;/p&gt;
&lt;h4 id=&#34;flops-calculation&#34;&gt;FLOPs Calculation: &lt;a href=&#34;#flops-calculation&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;Using the formula:
FLOPs per token: $\approx 2 \times N \times S$&lt;/p&gt;
&lt;p&gt;For: $N = 10^{11}$&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;FLOPs $\approx 2 \times 10^{11} \times 1.28 \times 10^5 = 2.56 \times 10^{16}$&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So, approximately 25.6 quadrillion FLOPs per token or: $2.56 \times 10^{16}$&lt;/p&gt;
&lt;p&gt;For: $N = 10^{12}$&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;$\text{FLOPs} \approx 2 \times 10^{12} \times 1.28 \times 10^5 = 2.56 \times 10^{17}$&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So, approximately 256 quadrillion FLOPs per token or: $\ 2.56 \times 10^{17}$&lt;/p&gt;
&lt;h4 id=&#34;adjustments-for-real-world-efficiency&#34;&gt;Adjustments for Real-World Efficiency: &lt;a href=&#34;#adjustments-for-real-world-efficiency&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;The $2N \times S$ formula assumes all operations are matrix multiplications, but transformers also include attention, layer normalization, and other operations that add overhead. These are typically less computationally intensive but require memory access, reducing effective throughput.&lt;/p&gt;
&lt;p&gt;For MoE models, only a subset of parameters (e.g., 2 out of 16 experts) is used per token, reducing FLOPs. If GPT-4o is MoE with 1.8 trillion total parameters, the effective parameters per token might be ~222 billion, yielding FLOPs closer to the $N = 10^{11}$ case.&lt;/p&gt;
&lt;p&gt;Real-world GPU utilization is often 30–50% of peak performance due to memory bottlenecks and distributed training inefficiencies. This doesn’t directly affect the theoretical FLOPs but impacts practical inference costs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;final-estimate&#34;&gt;Final Estimate &lt;a href=&#34;#final-estimate&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;h4 id=&#34;conservative-estimate&#34;&gt;Conservative Estimate: &lt;a href=&#34;#conservative-estimate&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;Assuming a dense model with 100 billion parameters or an MoE model with effective parameters in that range, GPT-4o requires approximately 25.6 quadrillion FLOPs per token, or $2.56 \times 10^{16}$ for a 128k context.&lt;/p&gt;
&lt;h4 id=&#34;high-end-estimate&#34;&gt;High-End Estimate: &lt;a href=&#34;#high-end-estimate&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;For a dense model with 1 trillion parameters, it’s around 256 quadrillion FLOPs per token: $2.56 \times 10^{17}$.&lt;/p&gt;
&lt;h4 id=&#34;likely-range&#34;&gt;Likely Range: &lt;a href=&#34;#likely-range&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;Given GPT-4o’s multimodal nature and potential MoE architecture, the FLOPs per token is likely closer to the lower end, around 20–50 quadrillion FLOPs per token, but could approach 100 quadrillion if the model is denser or less sparse.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;validation-and-context&#34;&gt;Validation and Context &lt;a href=&#34;#validation-and-context&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;h4 id=&#34;comparison-with-literature&#34;&gt;Comparison with Literature: &lt;a href=&#34;#comparison-with-literature&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;The Hugging Face forum post confirms the $2N \times S$ formula for decoder-only transformers, aligning with our calculation. For smaller models like GPT-3 (175 billion parameters) with a 2k context, FLOPs per token is on the order of
$7 \times 10^{11}$, scaling linearly with context and parameters.&lt;/p&gt;
&lt;h4 id=&#34;inference-cost&#34;&gt;Inference Cost: &lt;a href=&#34;#inference-cost&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;GPT-4o’s API pricing ($2.50 per million input tokens, $10 per million output tokens) suggests high computational costs, consistent with large-scale models requiring significant FLOPs.&lt;/p&gt;
&lt;h4 id=&#34;limitations&#34;&gt;Limitations: &lt;a href=&#34;#limitations&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h4&gt;&lt;p&gt;The exact FLOPs depend on implementation details (e.g., quantization, optimized attention mechanisms like multi-query attention). Additionally, the 128k context is the maximum, and real-world usage often involves shorter contexts, reducing FLOPs proportionally.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;answer&#34;&gt;Answer &lt;a href=&#34;#answer&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;For an LLM like GPT-4o with a 128k context window, the FLOPs per token generation is approximately 20–50 quadrillion FLOPs ($2 \times 10^{16}$ to $5 \times 10^{16}$), assuming an effective parameter count of 100–200 billion (dense or MoE-adjusted).&lt;/p&gt;
&lt;p&gt;If GPT-4o is a denser model with 1 trillion parameters, it could reach &lt;strong&gt;256 quadrillion FLOPs per token&lt;/strong&gt; ($2.56 \times 10^{17}$). These estimates are based on transformer scaling laws and assume full context utilization.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;ouch.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
