1 00:00:01,000 --> 00:00:09,300 [Hal Turing] Alrighty! Thanks for tuning in! Hello AI world! I am your host, Hal Turing, and my co-host is Dr. Ada Shannon. 2 00:00:09,300 --> 00:00:36,275 [Hal Turing] Today we're looking at Learning to Compress Prompts with Gist Tokens, by Jesse Mu, Xiang Lisa Li and Noah Goodman at Stanford University. It went up on arXiv in April 2023 and appeared at NeurIPS 2023. The claim is that you can train a language model to squeeze an instruction down to a single token's worth of cached state, up to 26 times shorter, and have it behave nearly the same. And the only thing you change is the attention mask. 3 00:00:36,275 --> 00:00:52,425 [Dr. Ada Shannon] Right, and the question we'll keep coming back to is whether that 26x holds up outside the paper's own test prompts. The paper's real contribution is a nearly free training trick. Whether it solves the problem the introduction motivates is a separate matter. 4 00:00:52,425 --> 00:00:55,325 [Hal Turing] So what's the problem? Start there. 5 00:00:55,325 --> 00:01:16,125 [Dr. Ada Shannon] The paper opens with the system prompt a chat assistant carries. That's the block of instructions placed before every user message: be helpful, follow this format, refuse these things. The model has to process it again on every query. That costs compute, and attention cost grows quadratically with sequence length. It also eats context window, and it eats cache memory. 6 00:01:16,125 --> 00:01:20,299 [Hal Turing] Hold on, cache memory. I thought caching was the fix. 7 00:01:20,299 --> 00:01:40,924 [Dr. Ada Shannon] It's a partial fix. When a transformer reads text, every layer produces keys and values for each token. That's the KV cache. If the prompt never changes, you can compute its KV cache once and reuse it, so you skip recomputation. But the cache is still stored, and it grows linearly with prompt length, times the number of distinct prompts you serve. Caching saves compute. It doesn't shrink what you store. 8 00:01:40,924 --> 00:01:46,049 [Hal Turing] So the options for a long, reused prompt are what? Fine-tune it in? 9 00:01:46,049 --> 00:02:12,400 [Dr. Ada Shannon] That's one. Fine-tuning or distillation bakes the prompt into the weights, but that's a training run for every prompt. Prefix tuning is cheaper. That's Li and Liang, also Stanford, 2021. You learn a small set of continuous vectors that act as virtual tokens at every layer, prepended to the model's activations, and you optimize them by gradient descent for one task. Lester, Al-Rfou and Constant at Google showed a similar idea at the embedding layer that same year. Both still need an optimization run per task. 10 00:02:12,400 --> 00:02:16,724 [Hal Turing] So the cost moves from the prompt into a training loop. 11 00:02:16,724 --> 00:02:38,525 [Dr. Ada Shannon] Yes. The paper's pitch is to avoid that loop. It frames the goal as context distillation, which means training a model to act as if a prompt were present when it can't see it. Again, one prompt at a time. Gisting amortizes that across prompts. You train one model that reads any new prompt and, in a single forward pass, produces the compressed version. That's the hypernetwork idea: a network whose output is the thing you'd otherwise have to train. 12 00:02:38,525 --> 00:02:44,425 [Hal Turing] So it's prefix tuning, except the prefix is predicted instead of optimized. 13 00:02:44,425 --> 00:02:55,175 [Dr. Ada Shannon] Exactly. Prefix tuning is a lookup you pay to build per task. Gisting is a function that builds it on demand, including for prompts it never saw in training. 14 00:02:55,175 --> 00:02:58,900 [Hal Turing] Okay, so what is a gist token concretely? 15 00:02:58,900 --> 00:03:20,849 [Dr. Ada Shannon] They add one new special token to the vocabulary and insert k copies of it between the prompt and the user's input. The token is identical each time. What differs are the activations on top of those positions. After the model reads the prompt, the keys and values at the gist positions, across every layer, are meant to stand in for the whole prompt. You keep those, throw away the prompt's own cache, and reuse the gist cache for every later input. 16 00:03:20,849 --> 00:03:26,199 [Hal Turing] But why would the model put the prompt's information there? Nothing forces it to. 17 00:03:26,199 --> 00:03:44,274 [Dr. Ada Shannon] The mask forces it. During training, tokens after the gist tokens are blocked from attending to the original prompt. They can only see the gist tokens. So if the answer depends on the instruction, that information has to pass through the gist activations. That's the whole mechanism in a sentence. 18 00:03:44,274 --> 00:03:48,874 [Hal Turing] And the training itself is just ordinary instruction tuning? 19 00:03:48,874 --> 00:04:08,549 [Dr. Ada Shannon] Yes. Instruction tuning means fine-tuning on triples of an instruction, an optional input, and the desired output, so the model follows natural-language tasks. Gisting uses the same data and the same next-token loss. There's no auxiliary compression objective, no separate encoder, no extra training stage. 20 00:04:08,549 --> 00:04:12,724 [Hal Turing] One token holding a whole instruction sounds odd. 21 00:04:12,724 --> 00:04:26,000 [Dr. Ada Shannon] One token position, but its cache spans every layer and every attention head. So the capacity is far more than one embedding vector. Still, it's a bottleneck, and what it loses is the open question. 22 00:04:26,000 --> 00:04:30,050 [Hal Turing] And the 26x figure. How is it computed? 23 00:04:30,050 --> 00:04:47,375 [Dr. Ada Shannon] It's the compression factor: the average prompt length in a validation split divided by the number of gist tokens. So it's a ratio of averages, not a guarantee for any prompt. The 26x comes from a split averaging about 26 tokens, divided by one gist token. 24 00:04:47,375 --> 00:04:56,975 [Hal Turing] That's where I get suspicious. The motivation was a long system prompt, and the headline number comes from prompts around twenty-some tokens. 25 00:04:56,975 --> 00:05:14,625 [Dr. Ada Shannon] That's the tension. A 26-token instruction is closer to "summarize this paragraph" than to a multi-hundred-token system prompt with many separate rules. The method is neat and nearly free to train. What's less clear is whether this evidence supports the use case it opens with. 26 00:05:14,625 --> 00:05:20,125 [Hal Turing] Hold that thought. Let's see how the mask works in detail, and what they tested. 27 00:05:20,125 --> 00:05:51,324 [Dr. Ada Shannon] For the decoder-only model, the sequence is prompt, gist, gist, then the input. The usual causal mask in a decoder like LLaMA is a triangle, where each token can look back at everything before it. They blank out the lower-left corner, which is where tokens after the gist would look back at the prompt. For T5 it takes more work. The encoder has no causal mask, so the input is blocked from the prompt and the prompt is blocked from the input. The decoder's cross-attention is also blocked from the prompt. It's roughly ten lines of code, and training costs the same as ordinary instruction tuning. 28 00:05:51,324 --> 00:05:55,274 [Hal Turing] What did they train on, and what did they compare against? 29 00:05:55,274 --> 00:06:39,524 [Dr. Ada Shannon] A dataset they call Alpaca+, about 130,000 examples and roughly 104,000 distinct tasks. About 59 percent of tasks have no input at all, like "write me a poem about frogs." Training prompts average about 20 tokens. They hold out three validation sets: seen tasks with new inputs, 1,000 unseen tasks, and 252 hand-written human prompts averaging about 26 tokens. That last one is the out-of-distribution test. The models are LLaMA-7B and FLAN-T5-XXL. There are three reference points. The positive control is the same model trained normally with the full prompt visible, which is the ceiling. The negative control is trained with no instruction, which is the floor. Then a TF-IDF baseline that keeps one keyword per instruction, so "salary" stands in for a whole letter request. 30 00:06:39,524 --> 00:06:42,199 [Hal Turing] And the score? How do I read it? 31 00:06:42,199 --> 00:07:02,125 [Dr. Ada Shannon] The main measure is a ChatGPT-3.5 judge. It sees the compressed model's output and the positive control's output, and picks the better one, with ties split. Fifty percent means as good as the uncompressed model. Higher is better, and fifty is effectively the ceiling. They also report ROUGE-L, a word-overlap score, and a human check. 32 00:07:02,125 --> 00:07:04,000 [Hal Turing] So what happened? 33 00:07:04,000 --> 00:07:40,199 [Dr. Ada Shannon] With one gist token, LLaMA lands at 48.6 on seen tasks and 49.7 on unseen tasks. On the human prompts it drops to 45.8. Put plainly, on the hardest split it wins or ties about 46 times in 100 against the uncompressed model. The no-instruction floor there is about 22, and the keyword baseline is about 25. So the gist is not just a short word. FLAN-T5 degrades more on the human split. Its normalized score there is about 63 versus 85 for LLaMA. The authors suspect the mask disrupts the encoder's bidirectional attention, but they say they haven't tested that. 34 00:07:40,199 --> 00:07:44,724 [Hal Turing] What about the number of gist tokens? One, two, five, ten. 35 00:07:44,724 --> 00:07:58,599 [Dr. Ada Shannon] Quality barely moves. Ten tokens sometimes hurts LLaMA, which they guess is overfitting. So a 26x squeeze performs about like a 2x squeeze. That's why they use one token for everything else. 36 00:07:58,599 --> 00:08:01,574 [Hal Turing] That's either great or suspicious. 37 00:08:01,574 --> 00:08:29,649 [Dr. Ada Shannon] We'll come back to which. First, the judge. They had humans rate 100 of the 252 examples, three annotators each. The human average win rate for LLaMA was 52.3, ChatGPT's was 48.0, and the intervals overlap. So the aggregates agree. Individual agreement is low, though. Cohen's kappa among the humans was .24 for LLaMA and .33 for FLAN-T5, and ChatGPT's agreement with humans was .29. So ChatGPT behaves like one more moderately agreeing annotator. 38 00:08:29,649 --> 00:08:34,074 [Hal Turing] And the exact outputs? Do they match the positive control? 39 00:08:34,074 --> 00:08:45,474 [Dr. Ada Shannon] On seen tasks, about half the time. On unseen tasks, 20 to 25 percent. On the human split, about 10 percent. Semantically close, textually different. 40 00:08:45,474 --> 00:08:50,499 [Hal Turing] Now the efficiency claim. Forty percent fewer FLOPs sounds big. 41 00:08:50,499 --> 00:09:11,649 [Dr. Ada Shannon] That's against no caching, where the model re-reads the whole prompt. They measured a single decoding step on one A100. Against that baseline, LLaMA does 40 percent fewer FLOPs and about 6.8 percent less time. Against ordinary KV caching of the full instruction, it's 0.11 percent fewer FLOPs and about 1 percent less time. Roughly one part in a thousand on compute. 42 00:09:11,649 --> 00:09:15,674 [Hal Turing] So the headline compares against the weaker baseline. 43 00:09:15,674 --> 00:09:43,649 [Dr. Ada Shannon] Yes, for the decoder model. The real advantage is space. LLaMA-7B needs about a megabyte per cached token in fp32, so a 26-token prompt is about 27 megabytes and one gist token is about one. The same cache holds up to 26 times as many prompts, if they're all about 26 tokens. They also free context-window room. But this is one decoding step at short prompt lengths, and the authors only argue that larger sizes will help. 44 00:09:43,649 --> 00:09:46,174 [Hal Turing] Did they show where it breaks? 45 00:09:46,174 --> 00:10:08,124 [Dr. Ada Shannon] Two examples. One asks the model to pick a category from a list, including "Arts & Culture." The gist model answers "Culture," and the judge penalizes it. The verbatim detail was lost. The other is a LaTeX example where LLaMA's gist model starts looping through subparagraph commands for hundreds of tokens. The authors say better sampling might fix the repetition, but they don't know why it only appears in the gist models. 46 00:10:08,124 --> 00:10:12,849 [Hal Turing] The results look decent. But I want to know what they were measured on. 47 00:10:12,849 --> 00:10:19,049 [Dr. Ada Shannon] Short prompts, mostly generic tasks, a holistic judge. Let's look at what that supports. 48 00:10:19,049 --> 00:10:24,924 [Hal Turing] Start with the headline. Up to 26x compression. How should people read that? 49 00:10:24,924 --> 00:10:53,875 [Dr. Ada Shannon] It's about 26 average tokens in the Human split divided by one gist token. The training prompts average around 20 tokens, so what gets compressed is roughly one sentence. The introduction is motivated by a chat assistant's system prompt, which runs to hundreds of tokens, and nothing here tests that. Whether compression holds at 500 or 5,000 tokens is unknown. The authors list long prompts as future work, so 26x isn't evidence for the use case the paper opens with. 50 00:10:53,875 --> 00:11:00,750 [Hal Turing] Earlier you said quality barely changed between one token and ten. That sounds like good news. 51 00:11:00,750 --> 00:11:20,524 [Dr. Ada Shannon] It could be. It could also mean the test never squeezes the bottleneck. Many of these tasks are short generic requests, and one token's activations across every layer can plausibly carry a topic and a style. So is the benchmark measuring prompt compression, or task-category recognition? The paper can't separate those. 52 00:11:20,524 --> 00:11:22,549 [Hal Turing] What would separate them? 53 00:11:22,549 --> 00:11:42,949 [Dr. Ada Shannon] Prompts with many independent constraints. Exact formatting rules, enumerated lists, verbatim-copy requirements. Then score each constraint, instead of asking one judge for a holistic preference. The paper's own failures point that way: "Arts & Culture" became "Culture," and the roughly 10 percent exact-match rate on the Human split fits the same picture. 54 00:11:42,949 --> 00:11:50,649 [Hal Turing] Then the keyword baseline. TF-IDF keeps one subword per instruction. That seems like a low bar. 55 00:11:50,649 --> 00:12:11,824 [Dr. Ada Shannon] It is. It shows the gist is more than a short word, and that's worth knowing. It doesn't show gisting beats other compression at the same budget. A sharper baseline is LLMLingua, "Compressing Prompts for Accelerated Inference of Large Language Models," by Huiqiang Jiang and colleagues, 2023. It prunes tokens from the prompt, so the output is plain text any model can read. It's less dense than a gist, but you can inspect it. 56 00:12:11,824 --> 00:12:14,524 [Hal Turing] And the quality measurement itself? 57 00:12:14,524 --> 00:12:34,950 [Dr. Ada Shannon] It rests on a ChatGPT-3.5 judge comparing against the uncompressed model, with low human agreement and only 100 human-rated examples. For LLaMA the human interval includes 50, so indistinguishable is fair. Better is not. And the paper doesn't test whether this judge penalizes a dropped format rule or a missing list item. 58 00:12:34,950 --> 00:12:38,100 [Hal Turing] So is minimal loss justified? 59 00:12:38,100 --> 00:12:59,126 [Dr. Ada Shannon] For seen and unseen in-distribution prompts, roughly. For the out-of-distribution split, which is the relevant one if you deploy your own prompt, the loss is larger. FLAN-T5 wins about 42 percent of comparisons, against a ceiling of 50. The authors guess the mask disrupts the encoder's bidirectional attention, but they don't test it, so I'd hold the encoder-decoder results loosely. 60 00:12:59,126 --> 00:13:01,801 [Hal Turing] And the efficiency numbers? 61 00:13:01,801 --> 00:13:20,401 [Dr. Ada Shannon] The 40 percent FLOPs figure is against no caching, which nobody serving a fixed prompt does. Against ordinary KV caching, the saving is about 1 percent of time. The real benefit is storage and context-window room, and even that 26x figure assumes every prompt is about 26 tokens. 62 00:13:20,401 --> 00:13:23,126 [Hal Turing] Where do the authors say to go next? 63 00:13:23,126 --> 00:14:06,001 [Dr. Ada Shannon] Gist pretraining on arbitrary spans, retrofitting a frozen model with a small compressor, and compressing long few-shot prompts. Two 2023 papers are the natural tests. "Adapting Language Models to Compress Contexts," the AutoCompressors paper by Alexis Chevalier, Alexander Wettig, Anirudh Ajith and Danqi Chen, recursively compresses long segments into summary vectors. That's a direct scaling test. "In-context Autoencoder for Context Compression in a Large Language Model," by Tao Ge and colleagues, uses a separate LoRA-adapted encoder with autoencoding and language-model objectives. It's the explicit-compressor alternative to the free mask trick. I won't claim their results beat gisting here, but they're where the long-prompt question gets asked. 64 00:14:06,001 --> 00:14:34,251 [Hal Turing] So, where does that leave us? A near-free change to the attention mask lets LLaMA-7B and FLAN-T5-XXL compress short instructions into one token, with modest quality loss, and the cache saving is real. The boundary is that everything was tested on prompts of about 20 to 26 tokens, with a weak stress test and a noisy judge. Whether long, detailed system prompts survive compression is still unproven. Thanks for listening, and we'll see you next time.