RAP: Runtime Adaptive Pruning for LLM Inference
This paper introduces RAP, a reinforcement learning-driven framework that dynamically adapts LLM inference pruning strategies in real-time by jointly optimizing model weights and KV-cache retention to maximize utility under varying memory budgets and workload conditions.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you have a giant, incredibly smart library assistant (a Large Language Model, or LLM) who can write stories, answer questions, and solve problems. But there's a catch: this assistant is so massive that it requires a warehouse full of shelves (memory) and a huge team of workers (computing power) just to keep them running.
If you try to run this assistant on a small device, like a smartphone or a laptop, it often crashes because it runs out of space or gets too slow.
The Problem: The "One-Size-Fits-All" Mistake
Currently, most people try to shrink this giant assistant by cutting out parts of it permanently, like removing shelves or firing workers based on a fixed rule. They say, "Okay, we'll always cut 30% of the library."
The paper argues this is a bad idea because the library's needs change every day.
- Scenario A: A user asks a very short question. The assistant only needs a tiny bit of space to remember the conversation.
- Scenario B: A user asks a user to write a 10,000-word novel. The assistant suddenly needs a massive amount of space just to hold the "scratchpad" (called the KV cache) where it keeps track of the story so far.
If you permanently cut 30% of the assistant's brain to fit on a phone, you might break it when someone asks a long question. If you don't cut anything, it won't fit on the phone at all. Existing methods are like a rigid suit of armor: it's either too heavy to wear, or if you cut it to make it lighter, it leaves you exposed.
The Solution: RAP (Runtime Adaptive Pruning)
The authors propose RAP, which is like giving the assistant a smart, elastic suit that changes shape in real-time.
Instead of cutting the assistant once and for all, RAP uses a Reinforcement Learning (RL) agent. Think of this agent as a highly skilled traffic controller or a stage manager.
- It Watches the Crowd: Before the assistant starts working, the agent looks at the specific request. Is it a short question? A long story? Is the phone's memory full because another app is running?
- It Makes Instant Decisions: Based on what it sees, the agent decides right now what to temporarily hide.
- If the request is short and memory is tight, it might hide some of the heavy "thinking" parts (FFN layers) to save space.
- If the request is long and the memory is full, it might hide some of the "attention" parts (MHA layers) that are needed to track the long story.
- It Keeps the Best Parts: The agent knows that not all parts of the brain are equal. Some layers are more important for certain tasks. It uses a special "importance scanner" (called Greedy Sequential Importance) to figure out exactly which parts can be safely tucked away without ruining the answer.
How It Works (The Analogy)
Imagine you are packing a suitcase for a trip, but you don't know the weather yet.
- Old Way: You decide to always leave your heavy winter coat and your swimming trunks at home. If it rains, you get wet. If it's sunny, you have no swimwear.
- RAP Way: You have a smart robot assistant.
- You tell it, "I have a small suitcase (memory limit) and I'm going to a beach (long conversation)."
- The robot instantly swaps out your heavy coat for a light t-shirt and keeps the swim trunks.
- You tell it, "I have a small suitcase and I'm going to a mountain (short conversation)."
- The robot swaps the swim trunks for a warm hat.
The robot learns from experience (Reinforcement Learning) to make the perfect swap every single time, ensuring you fit in the suitcase but still have exactly what you need for the specific trip.
What They Found
The paper tested this "smart robot" on several popular AI models (like Llama and Qwen).
- Better Results: When the memory was tight, RAP kept the AI working much better than the old "fixed cutting" methods. It didn't crash, and the answers were still smart.
- Flexibility: It handled different types of requests (short vs. long) without needing to be re-tuned by a human.
- Speed: The "robot" making the decisions was so fast and small that it didn't slow down the process at all. It added almost no extra time to the conversation.
The Bottom Line
RAP is a new way to run big AI models on smaller devices. Instead of permanently chopping off parts of the AI, it dynamically reshapes the AI on the fly, keeping only the parts needed for the specific task and the available space. It's the difference between wearing a rigid, heavy suit and wearing a smart, stretchy suit that adapts to whatever you're doing that day.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.