Generative Representational Instruction Tuning
arXiv ↗PDF ↗Paper ↗Website ↗Code ↗
TL;DR. GRIT fine-tunes one LLM on embedding data and generative instruction data at once. Embedding inputs use bidirectional attention and mean pooling with a contrastive loss; generative inputs use causal attention and the next-token loss. A format token tells the model which mode it is in. GritLM 7B reached 66.8 on MTEB (56 tasks) while matching a generation-only model on generative tasks. Because one model does both, RAG can reuse cached states.
Why it matters now. Retrieval and generation are usually two separate models, and deep-research agents call both many times per task. GRIT is the clearest early evidence that one set of weights can do both with almost no loss on either. It also shows where unification costs something: index cost, storage of cached states, and the attention mismatch between embedding and generating. For an IR researcher thinking about agents that retrieve with their own representations, this is the baseline.
Key idea
Section titled “Key idea”Two losses, one model. For embedding batches of (query, document) pairs, with = mean pooling followed by cosine similarity and temperature parameter :
For generative data, is the next-token loss over the answer tokens only. The total is . The weights are set so the embedding loss dominates at the start: the model already generates well, while the contrastive objective is new.
Format and attention. Embedding inputs look like <|user|> instruction <|embed|> text. Only the text tokens are pooled, but the instruction still shapes them through attention. Documents in asymmetric tasks get no instruction, so the corpus can be embedded once and reused. Generative inputs use the chat format and stay fully causal.
Separate batch sizes. The two losses can use different batch sizes. GritLM 7B uses 2,048 for embeddings (large batches give more in-batch negatives) and 256 for generation. Training fine-tunes all parameters of Mistral 7B for 1,253 steps. To fit large embedding batches, the paper splits the (query, positive, negative) triplet into separate forward and backward passes (Appendix H).
RAG with caching. Since the retriever and the reader are the same network, work can be shared:
- Query Caching reuses the query’s states from the embedding pass when generating.
- Doc Caching stores each document’s key-value states in the index and loads them at answer time instead of re-encoding the document.
The catch: those cached states come from bidirectional attention, while generation expects causal states.
Key results
Section titled “Key results”All numbers are paper-reported.
| Model | MTEB avg (56) | Retrieval (15) | Generative avg | Source |
|---|---|---|---|---|
| E5-Mistral 7B | 66.6 | 56.9 | — | Table 1 |
| GritLM embedding-only 7B | 66.8 | 57.5 | 7.6 | Tables 1–2 |
| GritLM generative-only 7B | 41.2 | 13.7 | 55.2 | Tables 1–2 |
| GritLM 7B | 66.8 | 57.4 | 55.5 | Tables 1–2 |
| GritLM 8x7B | 65.7 | 55.1 | 65.7 | Tables 1–2 |
- 8x7B trade-off: better generation but lower MTEB, which the authors attribute to a smaller embedding batch (256 versus 2,048) forced by compute.
- Self-reranking (Table 3): using GritLM’s generative side to rerank its own top 10 raises the 15-set retrieval average from 57.4 to 57.9.
- RAG on NQ (Table 7, match score): no retrieval 21.00; RAG 30.47–30.50; Query Caching 25.46; Doc Caching 33.38; Query-Doc and Doc-Query Caching 21.63 and 18.39. For a 4,000-token document, Doc Caching cuts CPU latency from 14.18 s to 5.25 s; storage grows from 43 GB to 30 TB.
- Alignment: a KTO stage after GRIT raises the generative average (55.5 → 57.4 for 7B) and lowers MTEB slightly (66.8 → 66.7), because embedding training is not continued.
Limitations & open questions
Section titled “Limitations & open questions”- Cost of a 7B embedder. Every document needs a 7B forward pass, and 4096-d vectors take 4× the storage of a 1024-d model. A linear head down to 1,024 dims costs about 1% (Table 6e), but the released model has no head.
- Short evaluation inputs. Training uses 2,048-token documents, but MTEB evaluation runs at 512 tokens. The authors say they do not know how well embeddings work beyond 512 tokens.
- Caching mismatch. Cached states are bidirectional while generation is causal. Doc Caching works on NQ, but combined caching falls to the no-retrieval level. A RAG fine-tuning stage is left to future work.
- Claims to check. The conclusion’s “around 10%” retrieval gain from reranking does not match Table 3’s 57.4 → 57.9. The RAG study uses one dataset, a lenient metric and no seeds.
- English, 2024-era benchmark. MTEB English only; MMTEB-era multilingual results are not reported here.
Connections
Section titled “Connections”- Recipe hub: Embedding recipes compared.
- Data source: E5-Mistral. GritLM trains on the E5 synthetic data plus S2ORC.
- Other routes to a bidirectional LLM embedder: LLM2Vec (masked next-token warm-up) and NV-Embed (just drop the mask, latent pooling).
- Reranking with an LLM: the permutation prompt GritLM reuses is the one from RankGPT; see the reranker map.
- KV caching and serving: vLLM / PagedAttention, grouped-query attention.
- Agents: Agentic retrieval looks like… — query distributions a unified agent-retriever would face.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
Work through GRIT Doc Caching on the paper's NQ setup: 2,681,468 documents; Table 7 reports storage of 43 GB for index plus passages, and 30 TB when the index stores key-value states in bf16. (a) Mistral 7B has 32 layers, 8 key-value heads of dimension 128 (grouped-query attention). How many bytes of KV cache does one token need, and what average document length does 30 TB imply? (b) For sample A (1-token query, 4,000-token document) CPU latency drops from 14.18 s (RAG, document-then-query) to 5.25 s with Doc Caching, and GPU latency from 0.39 s to 0.27 s. Compute both speed-ups and explain why the CPU gain is larger. (c) For sample B (4,000-token query, 1-token document) Doc Caching takes 23.23 s on CPU versus 15.33 s for RAG. Why can caching be slower?
What a strong answer covers
- (a) 32 layers × 2 (K and V) × 8 heads × 128 dims × 2 bytes = 131,072 bytes ≈ 128 KiB per token. 30 TB / 2.68M ≈ 11 MB per document ≈ 85 tokens. That is the same order as ~100-word Wikipedia passages; the exact figure depends on how heads and padding are stored.
- So caching multiplies storage by about 700× (43 GB → 30 TB) for passages of only ~100 tokens. For longer documents the ratio grows linearly with length.
- (b) CPU: 1 − 5.25/14.18 ≈ 63% less time (the paper's ">60%"). GPU: 1 − 0.27/0.39 ≈ 31%. On CPU the prefill of 4,000 tokens dominates; on GPU prefill is parallel and cheap, so skipping it saves less.
- (c) In sample B the document is 1 token, so there is almost nothing to skip, while loading cached states and the 4,000-token query still cost time. Caching pays only when the cached side is long (the paper: speed-up negligible for about 250 cached tokens).
- Mechanism
An embedding-only GritLM gets 7.6 on the generative average (near random on MMLU) and a generative-only one gets 41.2 on MTEB, yet the jointly trained GritLM 7B gets 66.8 MTEB and 55.5 generative, matching both. Explain at the level of attention masks, which tokens receive loss, and the starting point, why the two objectives interfere so little, and what the format token does.
What a strong answer covers
- Different computation graphs: the embedding pass uses a bidirectional mask and mean-pools the text tokens; the generative pass uses a causal mask and an LM head. The same weights serve two attention patterns, selected per input.
- Different loss positions: L_Rep is applied only to pooled text-token states; L_Gen only to answer tokens. Neither loss directly constrains the other's outputs.
- The base model is already a strong pretrained generator, so little generative learning is needed; the contrastive objective is new, which is why the loss ratio L_Rep/L_Gen is kept above 1 at the start.
- The embed format token tells the model which regime it is in. It matters most with E5 data, whose instructions have no fixed prefix (§3.3).
- Cost of "no interference": each step does a forward and backward pass on both kinds of data, so joint training costs more compute per step than either single objective.
- What if…
Table 6a varies attention and pooling for the unified model: causal attention with last-token pooling, causal with position-weighted mean (Wmean), and bidirectional attention with mean pooling for embeddings. A further variant makes the generative instruction bidirectional (prefix-LM). Predict the ordering of embedding scores, explain it, and explain what happens to generation under the prefix-LM change.
What a strong answer covers
- Embedding (MTEB, short ablation runs): last token 61.2 < Wmean 62.8 < bidirectional + mean 64.0.
- Causal states of early tokens have not seen the rest of the text. Wmean puts more weight on later tokens that have seen more, and a bidirectional mask lets every token see everything, so a plain mean is best.
- Last-token pooling relies on one state summarising the input; in these runs it is the weakest choice (the paper uses a special token for it).
- Prefix-LM for generation hurts: generative-only score drops from 55.2 to 50.7, so GRIT keeps generation fully causal.
- Generalisation: the gaps are 1–3 points from short runs at one scale, so the ranking is suggestive rather than settled.
- Critique
GRIT's RAG section claims caching gives large speed-ups "at no performance loss" for Doc Caching, and the conclusion reports retrieval gains of "around 10%" from self-reranking. Using Table 3 and Table 7, identify what is and is not supported, and design the experiment that would settle it.
What a strong answer covers
- Doc Caching match 33.38 versus RAG 30.47 is one dataset, one index (BEIR NQ, 2.7M passages), a lenient "answer string appears anywhere" metric (chosen after inspecting 20 no-RAG samples), and no variance. Not a general no-loss result.
- There is a real mismatch: cached document states were computed with bidirectional attention but generation expects causal states. Query-Doc and Doc-Query Caching fall to about the no-RAG level (21.63 and 18.39 versus 21.00).
- Table 3 shows self-reranking the top 10 moves the 15-set retrieval average from 57.4 to 57.9, under 1% relative. The "around 10%" in the conclusion does not match this table; a careful reader should flag it rather than repeat it.
- Experiment: several QA sets (NQ, TriviaQA, multi-hop), exact match and LLM-judged correctness, seeds, a short RAG fine-tune that trains on cached bidirectional states, and reranking depth 10/50/100 with the cost of each.
- Design
You are building a deep-research agent and consider one GRIT-style 7B model that both writes the search queries and embeds the corpus, instead of a 335M embedder plus a separate 7B policy. The corpus is 50M passages and is re-indexed monthly. Argue for one design, state the costs, and say how you would validate it.
What a strong answer covers
- Index cost: GRIT embeds every passage with a 7B forward pass versus 335M, about 20× the parameters per token, at every re-index. Vectors are 4096-d versus 1024-d, so 4× the storage.
- Doc Caching is only attractive for short passages and static corpora: at ~128 KiB per token (Mistral 7B, bf16) 50M passages of 100 tokens need about 650 TB.
- Benefits: one model to serve, query states reusable for generation, and the policy and retriever share a representation. This matters if you later fine-tune the policy (a separate embedder is not affected, but a unified one can drift).
- Validate: end-to-end agent accuracy and cost at a fixed budget for both designs, retrieval recall on agent-issued queries (BrowseComp-Plus), and embedding quality before and after any policy fine-tuning.
- Research idea
After GRIT the authors align GritLM with KTO and observe MTEB drop slightly (66.8 → 66.7 for 7B; 65.7 → 65.2 for 8x7B) while generation improves. Pitch a project on RL-training a unified model as a search agent: hypothesis, minimal experiment and falsifying result.
What a strong answer covers
- Hypothesis: policy-only RL updates (KTO, GRPO) drift the shared weights away from the contrastive geometry, so retrieval degrades with more RL steps unless an embedding loss is kept in the mix.
- Minimal experiment: start from GritLM 7B; RL-train it as a search agent that queries its own embedding index; arms = RL only, RL + continued L_Rep, RL with frozen embedding LoRA. Track MTEB retrieval and agent accuracy every N steps.
- Note the index: if embeddings change, the stored document vectors go stale, so measure with and without re-indexing.
- Falsified if retrieval stays flat under RL-only training for many steps, or if continued L_Rep gives no retrieval benefit at matched agent accuracy.