AI Interviews · Question

GenAI-team SDE phone screen covering LLM fine-tuning, token embeddings, the KV cache and how to evaluate a RAG system, plus coding a simple hash table.

Domain deep dive / Coding (DSA) question reported at Amazon / AWS (2026). Sources, confidence and an answer card.

Researched · updated

r2a-011 Both tracks Fine-tuning vs RAG vs prompting Domain deep diveCoding (DSA) Low confidence
On this page

What they’re really asking

If you only remember one thing, say this in the first minute: “This is five short answers and one coding task, so I’ll keep each to about two minutes. Fine-tuning trains a model further on our examples; I’d use it for behaviour, not facts. Token embeddings are a lookup table from word pieces to vectors. The KV cache saves earlier tokens’ keys and values so the model doesn’t recompute them, and it is what fills GPU memory. To evaluate RAG, I score retrieval and the answer separately. And the hash table needs resizing to stay fast.”

The rest of this page explains each part of that answer, so you can say it with understanding.

This is a breadth check. Can a software engineer on a generative-AI team explain the basics correctly, and still write solid code?

What makes it different from a usual phone screen is the switching. You go from model internals to an evaluation plan to a hash table in 45 minutes. The interviewer is not looking for depth on any one topic. They want each answer short, correct and backed by one number, so there is time left for the code.

The only evidence is a topic summary on the forum 1point3acres that we could only partly see: fine-tuning, token embeddings, the KV cache, evaluating a RAG system, plus a simple hash table 1point3acressnippet only. It is undated, so treat the exact list as approximate.

Clarify first

  • “How long per topic?” In a phone screen, about two minutes each. Offer more depth if they want it.
  • For the hash table: “Which operations? Which key types? Is resizing required? Is thread safety in scope?”
  • For RAG evaluation: “Is there a labelled set, or do I build one?”

Answer

Words you need first

  • LLM (large language model). A program that reads text and writes text, built from billions of learned numbers called weights or parameters.
  • Token. Models read and write text in pieces called tokens, roughly ¾ of a word. Each has an id.
  • bf16. A 2-byte number format that most models use for their weights.

One running example ties the first three answers together: Llama-3.1-8B, an open model with about 8 billion parameters. Using one public model makes every number checkable.

1. Fine-tuning (about two minutes)

Fine-tuning trains a model further on your own examples. Supervised fine-tuning (SFT) uses pairs of an input and the ideal output, and scores the model only on the output tokens.

LoRA (low-rank adaptation) is the cheap way to do it. It freezes the original weights and trains a small add-on for each adapted matrix: two thin matrices whose product B·A is added to the original. For Llama-3.1-8B at rank 16 on the four attention matrices, that is about 13.6 million parameters, about 27.3 MB.

Use it for behaviour and format, after better prompts fail on a test set. Don’t use it to add facts.

Say it like this: “LoRA trains a small change to a big model, about 27 megabytes here, so one base model can carry many of them.”

2. Token embeddings

The model’s first step is to turn each token id into a vector (a list of numbers). It does this with a lookup table, one learned vector per entry in the vocabulary. Llama-3.1-8B’s table is 128,256 entries × 4,096 numbers = 525 million parameters, about 1.05 GB in bf16.

This is not the same as a sentence-embedding model, the kind used for search. That one turns a whole passage into a single vector, so similar passages land close together.

3. The KV cache

The model writes one token at a time. In every layer, each token produces a key (what it contains) and a value (what it passes on), and each new token has to look at the keys and values of all earlier tokens. Instead of recomputing them for every new token, the model saves them in GPU memory. That store is the KV cache.

For Llama-3.1-8B it is 128 KiB per token, so one 8,192-token request holds about 1.07 GB. That memory, more than the weights, limits how many long requests one GPU serves at once.

The arithmetic behind the numbers (for a Staff-level follow-up)
  • Embeddings: 128,256 × 4,096 = 525,336,576 parameters × 2 bytes ≈ 1.05 GB.
  • KV cache per token: 2 × layers × n_kv_heads × head_dim × bytes = 2 × 32 × 8 × 128 × 2 = 131,072 B (128 KiB). The 2 is one key and one value. Llama-3.1-8B shares 8 key/value heads among its 32 query heads (grouped-query attention), which is why the formula uses KV heads. × 8,192 tokens = 1,073,741,824 B ≈ 1.07 GB.
  • LoRA: per layer, r × (d_in + d_out) summed over q (4,096 → 4,096), k and v (4,096 → 1,024) and o (4,096 → 4,096) = 16 × 26,624 = 425,984; × 32 layers ≈ 13.6M parameters × 2 bytes ≈ 27.3 MB.

4. Evaluating RAG

RAG (retrieval-augmented generation) means looking up relevant passages from your documents and putting them in the prompt before the model answers. It can fail in two places, so score them separately:

  • Retrieval: did we find the right passage? Measure hit@k, the share of questions where a correct passage is in the top k results, or recall@k, the share of all correct passages found in the top k. Both need labelled question-to-passage pairs.
  • Generation: did the model use it well? Is each claim supported by the retrieved text? Are citations correct? Does it decline when nothing relevant was found?

Report ranges, not single numbers. At about 300 questions, gaps of a few points are noise. In the rag lab, hit@3 on SciFact (a public science fact-checking benchmark) was hit@3 on BEIR SciFact, dense v0 / hybrid v1 / rerank v2: 69.3 / 68.3 / 72.7 % (measured on Apple M1 Ultra, 64 GB RAM, torch 2.14.1, sentence-transformers 6.1.0 (MPS), 2026-10-11 · rag lab).

Say it like this: “One number for ‘RAG quality’ can’t tell me which half to fix, so I measure retrieval and generation apart.”

5. The hash table

Say which design you’ll use and why. Separate chaining is simplest: an array of buckets, each a small list. Open addressing stores entries directly in the array and probes for the next free slot.

With chaining:

  • Put: compute hash(key) % capacity, then replace the key in that bucket if it’s there, or append it.
  • Get: the same index, then scan the bucket.
  • Delete: remove from the bucket. (With open addressing you’d leave a marker, a “tombstone”, so later probes don’t stop early.)
  • Resize: when size ÷ capacity passes a load factor such as 0.75, double the array and rehash every entry. This keeps operations O(1) on average over time (amortized).

Mention that the worst case is O(n) if many keys hash to the same bucket. Test: insert, overwrite, delete, and many keys across a resize.

Senior vs Staff

Breadth screen

Senior

  • Gives correct short answers with one number each, then writes a hash table with resizing and tests.

Staff

  • Ties each answer to a decision (KV memory to context limits, RAG metrics to release gates) without running over the screen's time.

In plain words: a Senior answer is correct and leaves time for code. A Staff answer also says what each fact changes in a real system, still within two minutes a topic.

Small-team version

This breadth is the job description at a small company. The same person sizes a self-hosted model’s memory, decides whether to fine-tune, and builds the RAG evaluation.

Build the RAG evaluation first: a labelled set of 50–200 real questions with their source passages, run in CI. It costs about $2 a run for 200 questions, so cost is not a reason to skip it. The real cost is the time to label them.

The arithmetic behind the numbers (for a Staff-level follow-up)

Assumed: 3,000 input and 400 output tokens per question, on Claude Sonnet 5 at $2 per 1M input and $10 per 1M output tokens (list price, fetched 2026-10-11).

  • Per question: $0.006 + $0.004 = $0.010.
  • Per run: 200 × $0.010 = $2.

Pitfalls

  • Confusing token embeddings with sentence embeddings. One is a lookup table inside the model; the other is a search tool.
  • The hidden-size KV formula. It ignores shared KV heads and overstates the cache, 8× for Llama-3.1-70B.
  • One number for “RAG quality”. Score retrieval and generation separately.
  • A hash table with no resize. It slows to O(n) as it fills.

Go deeper

Family

Prompting, RAG or fine-tuning: choose from the failure, prove the return

How to choose between a better prompt, retrieval and fine-tuning, how to tell whether a fine-tune pays for itself, and how to explain the model internals a depth round asks about, in plain words.

Other questions in this family