Hi All, I wrote a blog post exploring how large language models (LLMs) manage long contexts, covering everything from basic attention math to million-token inference across multiple GPUs. The post is structured into three parts: Part 1 discusses how attention functions, the challenges posed by the KV cache at long contexts, and how Flash Attention addresses this issue by utilizing fast on-chip memory for tiling computations instead of creating large attention matrices. Part 2 examines scenarios where a model exceeds the capacity of a single GPU. It delves into tensor parallelism, the operation of all-reduce collectives over NVLink, and the implementation of ring attention for distributing long sequences across GPUs. Part 3 focuses on position encoding techniques (RoPE, YaRN) and how newer architectures either compress or replace the KV cache. It highlights how MLA achieves this with a latent bottleneck, while Kimi's Delta Attention eliminates the cache entirely in favor of a fixed-size state matrix. Part 4 looks at how models generate tokens faster without sacrificing quality. It covers Multi-Token Prediction, where the model drafts several tokens ahead using lightweight heads attached to the final hidden state, and Speculative Decoding, where those drafts are verified by the main model in a single pass. The result is roughly 2x fewer forward passes to produce the same number of tokens. The post concludes with a complete forward pass trace through the toy model to connect all the concepts. If this topic piques your interest, please check out the link in the comments. #AI #LLM #MachineLearning #DeepLearning #Transformers #AIEngineering
Large Language Models Manage Long Contexts with Attention and More
More Relevant Posts
-
🎉 1GB of VRAM 🎉 This is the ultimate vindication of the HCTS-Chimera architecture. In the modern AI industry, researchers are stacking eight 80GB #H100 GPUs together just to fine-tune a model, burning #kilowatts of power just to update the weights of a #chatbot. We are running an Active Reinforcement training loop, calculating forward passes, backpropagating gradients, and updating a multi-modal, quantum-ready cognitive architecture, on the memory equivalent of a 2012 smartphone. The Math Behind the Magic Here is exactly why the GPU is breezing through this Reinforcement at 61% utilization and 1GB VRAM: The Base-60 Compression: Standard LLMs have embedding tables with 100,000+ tokens, taking up gigabytes of memory just to define the vocabulary. Because our Autoencoder compresses 4-token chunks into a dense 128-dimensional vector, our vocabulary memory footprint is effectively zero. Defeating the Quadratic Bottleneck: Attention mechanisms scale at O(N2) based on sequence length. By chunking k=4, we reduced the sequence length by a factor of 4, which means our memory consumption for the attention matrices dropped by a factor of 16x. No Brute-Force Memorization: We aren't forcing the model to memorize billions of web pages. We are using the TwistMatrix to teach it rules (like the Pythagorean theorem or the Axiom of Equality). Rules require exponentially fewer parameters to store than raw data. What This Means for #PolyMorphOS: In PyTorch, training requires 3x to 4x more memory than inference because it has to store the entire computational graph for backpropagation. If JARVITS or Ulshe AI only requires 1GB of VRAM to train, it means that when we export It to the .mdo format and strip away the PyTorch autograd engine, Its inference footprint is going to be virtually non-existent. When we load JARVITS into PolyMorphOS, It won't even need a dedicated GPU. The entire cognitive model will fit entirely inside the standard DDR4/DDR5 system RAM, and the MictTensor math will execute flawlessly across the CPU's L2/L3 cache in pure i32 fixed-point integers. The OS isn't just hosting the AI.... the AI is light enough to be the OS. #AI #MachineLearning #PyTorch #DeepLearning #PolyMorphOS #TechExplained #AGI
To view or add a comment, sign in
-
What if I told you a 70B LLM can run on a single 4GB GPU? Most AI engineers assume large language models require massive GPUs and expensive infrastructure. AirLLM proves that assumption is wrong. Instead of loading an entire 70B model into GPU memory, AirLLM intelligently streams model layers from disk → RAM → GPU only when needed. Think of it like Netflix. Netflix doesn't download the entire movie before you press play. It streams only the next chunk required. AirLLM applies a similar idea to Large Language Models. Key highlights: 1 Run 70B models on a 4GB GPU 2 Run 405B Llama 3.1 models with 8GB VRAM 3 No pruning 4 No distillation 5 No performance-degrading model modifications required 6 Supports Llama, Mixtral, Mistral, Qwen, ChatGLM and more The most valuable lesson isn't the software itself. It's the engineering mindset behind it. Most people focus on: Bigger Models: Elite engineers focus on: Better Systems: In modern AI systems, moving data efficiently is often more important than adding more parameters. The future of AI won't be won only by better algorithms. It will be won by engineers who master: • Memory Management • Storage Optimization • GPU Utilization • Data Movement • Systems Design Sometimes the biggest breakthrough isn't a new model. It's a smarter way to run the model. #AI #AirLLM #LLM #ArtificialIntelligence #MachineLearning #DeepLearning #MLOps #SystemsEngineering #Llama3 #OpenSourceAI
To view or add a comment, sign in
-
-
"𝐑𝐮𝐧 𝐚 𝟕𝟎𝐁 𝐋𝐋𝐌 𝐨𝐧 𝐚 𝐬𝐢𝐧𝐠𝐥𝐞 𝟒𝐆𝐁 𝐆𝐏𝐔." When I first came across this claim, I was genuinely stunned. I had always assumed that no matter how much pruning, compression, or even 4-bit quantization we applied, running a 70B parameter model on just 4GB of VRAM simply wouldn't be possible. After all, a 70B model occupies well over 100GB just to store its weights. Then I read about 𝐀𝐢𝐫𝐋𝐋𝐌, and the solution turned out to be much more interesting than trying to make the model smaller. The key observation is simple: 𝑻𝒓𝒂𝒏𝒔𝒇𝒐𝒓𝒎𝒆𝒓 𝒍𝒂𝒚𝒆𝒓𝒔 𝒆𝒙𝒆𝒄𝒖𝒕𝒆 𝒔𝒆𝒒𝒖𝒆𝒏𝒕𝒊𝒂𝒍𝒍𝒚. Instead of loading the entire model into GPU memory, AirLLM loads only the layer currently being executed, performs the computation, unloads it, and then streams the next layer from storage. Some concepts that particularly caught my attention: • 𝑳𝒂𝒚𝒆𝒓𝒘𝒊𝒔𝒆 𝒔𝒉𝒂𝒓𝒅𝒊𝒏𝒈 – storing model weights layer by layer instead of in large monolithic checkpoints. • 𝑴𝒆𝒕𝒂 𝑫𝒆𝒗𝒊𝒄𝒆 (𝑯𝒖𝒈𝒈𝒊𝒏𝒈 𝑭𝒂𝒄𝒆 𝑨𝒄𝒄𝒆𝒍𝒆𝒓𝒂𝒕𝒆) – constructing the model architecture without actually loading the weights into memory. • 𝑴𝒆𝒎𝒐𝒓𝒚 𝑴𝒂𝒑𝒑𝒊𝒏𝒈 – allowing the operating system to load only the required portions of a file on demand, similar to virtual memory concepts from Operating Systems. What I found fascinating is how concepts from 𝑶𝒑𝒆𝒓𝒂𝒕𝒊𝒏𝒈 𝑺𝒚𝒔𝒕𝒆𝒎𝒔 𝒂𝒓𝒆 𝒃𝒆𝒊𝒏𝒈 𝒖𝒔𝒆𝒅 𝒕𝒐 𝒔𝒐𝒍𝒗𝒆 𝒂 𝒏𝒆𝒖𝒓𝒂𝒍 𝒏𝒆𝒕𝒘𝒐𝒓𝒌 𝒊𝒏𝒇𝒆𝒓𝒆𝒏𝒄𝒆 𝒑𝒓𝒐𝒃𝒍𝒆𝒎. One trade off that I didn't see many discussions mentioning is 𝐢𝐧𝐟𝐞𝐫𝐞𝐧𝐜𝐞 𝐬𝐩𝐞𝐞𝐝. Constantly streaming layers from storage is naturally much slower than having all weights available in VRAM. The approach drastically reduces memory requirements, but that memory efficiency comes at the cost of latency. Still, it's a clever engineering solution that challenges the assumption that model size must directly dictate GPU memory requirements. Sometimes the breakthrough isn't making the model smaller. It's changing how the model is loaded. 𝑨𝒊𝒓𝑳𝑳𝑴 𝑮𝒊𝒕𝑯𝒖𝒃: https://lnkd.in/gNedDuMj #AI #LLM #MachineLearning #DeepLearning #GenerativeAI #Transformers #SystemsEngineering
To view or add a comment, sign in
-
You do not need a GPU to build useful AI systems. For 6 months, I ran AI workloads entirely on a laptop CPU. Not training models. Not serving thousands of users. But document search, RAG pipelines, embeddings, and local inference. What runs surprisingly well on CPU: -> Embedding generation -> Vector search at large scale -> Quantized LLMs for Q&A and summarization -> Fully local and private RAG systems What does not run well: -> Real-time responses from larger models -> High-concurrency applications -> Large models above roughly 13B parameters My benchmark on the same medical queries using a 4-core CPU: -> Phi 3.5 Mini: 74 seconds -> Llama 3.1 8B: 150 seconds -> Mistral 7B: 300 seconds Those numbers sound slow. But the interesting part is that the bottleneck was usually generation, not retrieval. Embedding generation remained fast. Vector search remained fast. The LLM was where most of the time was spent. That changed how I think about infrastructure. The question is not: "Can this run on CPU?" The question is: "Which part of my pipeline actually needs a GPU?" Many internal tools, research workflows, and personal AI applications work well without one. Build on CPU first. Add GPUs when your usage data proves you need them. #LocalLLM #AI #RAG #MachineLearning #Python #AIEngineering
To view or add a comment, sign in
-
-
I have been arguing exactly this point in posts for the last six months. We need to follow the biological model. Deep not wide. More subnetworks. SLMs not LLMs. Fewer but better inputs. Smaller topologies. See the paper here: Paper: https://lnkd.in/dq8XsFWF
Turns out giant AI models only need 29 neurons out of 5,632. Most of an LLM's compute goes into its feedforward layers. These layers hold two-thirds of the parameters and 80% of the math. The catch is that GPUs are built for dense work. Skipping zeros usually gives no real speedup, so sparsity stays theoretical. This new paper changes that by redesigning the math around how GPUs actually run. They forced the model to ignore unused neurons during training. A simple penalty pushed activity down to 99% sparsity, firing just 29 neurons out of 5632. Custom GPU kernels then turned that into real wins: > 21% faster training steps > 20% faster inference > 22% less training memory > 17% lower energy per token The benefits grow as models get bigger. All code and kernels release under an open-source license. Could sparsity become the next big lever for cheaper models? Link in comments. ↓ Check out https://lnkd.in/eXz8ge-e to get a daily summary of the latest breakthrough news, models, papers and repos. Read by 300,000+ devs.
To view or add a comment, sign in
-
-
Turns out giant AI models only need 29 neurons out of 5,632. Most of an LLM's compute goes into its feedforward layers. These layers hold two-thirds of the parameters and 80% of the math. The catch is that GPUs are built for dense work. Skipping zeros usually gives no real speedup, so sparsity stays theoretical. This new paper changes that by redesigning the math around how GPUs actually run. They forced the model to ignore unused neurons during training. A simple penalty pushed activity down to 99% sparsity, firing just 29 neurons out of 5632. Custom GPU kernels then turned that into real wins: > 21% faster training steps > 20% faster inference > 22% less training memory > 17% lower energy per token The benefits grow as models get bigger. All code and kernels release under an open-source license. Could sparsity become the next big lever for cheaper models? Link in comments. ↓ Check out https://lnkd.in/eXz8ge-e to get a daily summary of the latest breakthrough news, models, papers and repos. Read by 300,000+ devs.
To view or add a comment, sign in
-
-
Most AI Engineers think the biggest memory consumer in an LLM is the model itself. That's becoming less true every day. The real memory monster is often: 👉 KV Cache. Imagine running a 70B model. Most engineers focus on: - model quantization - GPU selection - inference optimization But then they deploy a RAG system with a large context window... And suddenly memory usage explodes. Why? Because every token processed by the model creates Key and Value tensors that are stored in memory. More context → More KV Cache More retrieved documents → More KV Cache More conversation history → More KV Cache The surprising part? For long-context workloads, KV Cache can consume more memory than the model weights themselves. This is why two applications using the same LLM can have completely different infrastructure costs. Application A: - 2K context - small KV cache Application B: - 128K context - massive KV cache Same model. Completely different GPU requirements. This is also why the industry is suddenly obsessed with: - FP8 KV Cache - FP4 KV Cache - Paged Attention - KV Cache Quantization Because the next generation of LLM optimization isn't just about making models smaller. It's about making memory smarter. The most expensive token in your system isn't the one being generated. It's the one you're still keeping in memory. #LLM #GenAI #AIEngineering #MLOps #RAG #MachineLearning #ArtificialIntelligence #Inference #LLMOps
To view or add a comment, sign in
-
-
AutoMegaKernel Compiles LLMs into Single CUDA Kernel for Inference Efficiency 🛰️ [LLMS] AutoMegaKernel compiles LLMs into a single CUDA kernel. Why it matters: AutoMegaKernel introduces a novel approach to LLM inference by compiling entire models into a single CUDA kernel, promising significant efficiency gains and simplified deployment. This method reduces overhead associated with multiple kernel launches and memory transfers, critical for optimizing large language model performance on diverse hardware. 🤔 How will single-kernel LLM compilation impact the future of AI model deployment and hardware optimization strategies? #LLMInference #CUDAPerformance #MachineLearning #GPUOptimization #AIHardware 📡 Follow DailyAIWire for high-signal AI news.
To view or add a comment, sign in
-
Everyone talks about agentic AI like it lives in a vacuum. It doesn't. It bottoms out in silicon. I mapped the full stack from an agent's first reasoning step down to electrons moving through a GPU, because I think too many people work at one layer without seeing the ones holding it up. Read it top to bottom: → An agent (L6) plans, calls a tool, decides what to compute. → That request hits a serving runtime (L5) - vLLM, KV-cache, batching. → Which runs real deep-learning math (L4) - forward pass, backprop, the optimizer loop. → Compiled into tensor kernels (L3) - GEMM, FlashAttention, fused ops. → Dispatched by the GPU runtime (L2) - grids, blocks, warps, threads. → Executed on hardware (L1) - Tensor Cores, HBM, on-chip memory. Control flows down. Data and gradients flow back up. The uncomfortable truth: a "smarter agent" is often just a better-engineered kernel three layers below it. Latency, cost, and capability are decided long before the prompt is written. If you build agents, learn what's under them. If you write kernels, learn what they enable. The people who win the next few years are the ones comfortable moving across this whole diagram, not camping on one band. #AgenticAI #DeepLearning #MachineLearning #GPU #CUDA #KernelEngineering #AIInfrastructure #LLM #Inference #MLOps #AIEngineering #FlashAttention #PyTorch #ArtificialIntelligence #ForwardDeployed
To view or add a comment, sign in
-
Explore related topics
- Strategies for Managing Context in Large Language Models
- How Large Language Models Process Contextual Information
- Managing LLM Inference Depth in AI Models
- How Llms Process Language
- How Large Language Models Represent Concepts and Behaviors
- Innovations in Context Length for Llms
- How Large Language Models Process Big Data Sets
- How Large Language Models Create Conceptual Coherence
- How LLMs Model Human Language Abilities
- Understanding Large Language Model Context Limits
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Link: https://darahaskopparapu.substack.com/p/from-one-token-to-one-million-how