Generative AI and Large Language Models Questions
The capabilities and behavior of modern generative and large language models. Covers how LLMs are pretrained, in-context learning and few-shot prompting, generative model families (autoregressive, diffusion), context windows, and tokenization and sampling. Emphasizes understanding what generative models can and cannot do and how they differ from discriminative ML.
You have constrained GPU resources and must adapt a 7B-parameter LLM to several (e.g. 10) different domain-specific tasks, or you are advising a resource-limited team on a single task. Compare full fine-tuning, LoRA/PEFT, adapter modules, prompt-tuning, and continual pretraining on compute cost, storage per task, expected quality, iteration speed, inference latency impact, and maintenance burden, and recommend an approach for efficiently maintaining many task-specific models.
Sample Answer
Direct answer: With constrained GPU memory and 10 different domain-specific tasks to support on a 7B-parameter LLM, LoRA (or adapters) on top of a single shared base model is the strongest default, since it gives the best combination of low per-task storage, low compute per task, near-full-fine-tuning quality, and minimal inference latency impact.
Structured elaboration:
- Full fine-tuning: highest potential ceiling per task but requires a full backward pass through 7B parameters and a full checkpoint per task (multiple gigabytes each), which is both compute- and storage-prohibitive across 10 tasks under limited GPU memory.
- LoRA: trains only small low-rank matrices per task (typically tens to low hundreds of megabytes depending on rank), usually reaches accuracy close to full fine-tuning, adds only a few percent of inference latency if kept unmerged, or none at all if merged into the base weights before serving; this is the best trade-off when tasks are moderately related and you want to keep many variants cheaply.
- Adapter modules: similar storage profile to LoRA (tens to a few hundred megabytes per task) with slightly more inference overhead since adapters include a nonlinearity that generally cannot be merged away, but they offer strong modularity, individual tasks can be enabled or disabled independently, which matters if you need strict isolation between task-specific behavior.
- Prompt-tuning: cheapest to train and store (kilobytes to low megabytes per task) with negligible inference overhead, but at 7B parameters it typically underperforms LoRA or adapters on tasks that need deep semantic adaptation rather than surface-level steering.
- Continual pretraining: expensive (a full pretraining-style run on domain text) and not per-task by nature, but if all 10 tasks share a common domain vocabulary or style, one round of continual pretraining on unlabeled domain text can raise the shared base model's quality for every subsequent LoRA or adapter you train on top of it, amortizing its cost across all 10 tasks.
Worked example: A practical setup for the 10-task scenario: quantize the shared 7B base model to 8-bit or 4-bit to reduce its resident GPU memory footprint, then train a separate LoRA adapter (rank 8-16) per task on top of the frozen quantized base. Each adapter trains in a small fraction of the time and memory a full fine-tune would need, and storing 10 adapters costs tens to a few hundred megabytes total rather than 10 full 7B checkpoints (which would be on the order of 100+ GB combined at fp16). At serving time, either merge each task's adapter into a separate copy of the dequantized weights for zero-overhead inference if you can afford one resident copy per active task, or keep adapters unmerged and swap them per request if memory only allows a single base model in memory, accepting a small latency cost for that flexibility.
Trade-offs and pitfalls: Reaching for adapters purely because of their strict modularity, when the 10 tasks are actually variations on the same domain, gives up some of LoRA's efficiency and mergeability for isolation you may not need. Conversely, if some tasks require genuinely stricter separation (for example regulatory or customer-isolation requirements), LoRA's easy mergeability can become a liability if adapters are ever accidentally merged into the wrong base copy. Combining quantization with PEFT (as in QLoRA-style setups) is the standard way to fit training within limited GPU memory, but it requires care that the quantization itself does not degrade the shared base model's quality enough to hurt every downstream task at once.
Explain adapter modules for transformer models: how they are inserted (e.g., between attention and feed-forward), how they change parameter budgets, their advantages relative to full fine-tuning, and potential drawbacks. Design a lightweight adapter architecture for sequence classification and estimate the number of extra parameters for a 1.5B parameter base model.
Sample Answer
Direct answer: Adapter modules are small bottleneck feed-forward blocks (a down-projection, a nonlinearity, and an up-projection with a residual connection) inserted into each transformer layer, most commonly right after the attention output and after the feed-forward network, so that only the adapters (and possibly the final head) need to be trained while the pretrained backbone stays frozen.
Structured elaboration:
- Insertion points: the two most common locations are between the attention block's output and its residual add-and-normalize step, and between the feed-forward network's output and its own residual add-and-normalize step, giving a typical pattern of layer output flowing through the adapter, then a residual add, before the next layer; inserting adapters inside the feed-forward network itself (between its two dense layers) is less common.
- Parameter budget: for hidden size H and adapter bottleneck dimension r, one adapter costs roughly 2Hr parameters (a down-projection of size H×r plus an up-projection of size r×H, biases are negligible); with one adapter per layer this scales as 2Hr×L across L layers, or double that with two adapters per layer (after attention and after the feed-forward network). Relative to full fine-tuning, which updates essentially 100% of the model's parameters, adapters typically add only a small fraction of extra parameters while training well under 5% of the model's total parameter count.
- Advantages relative to full fine-tuning: far cheaper storage per task (one small adapter file instead of a full checkpoint), faster training with a smaller memory footprint (far fewer gradients and optimizer states), and structurally safer against catastrophic forgetting since the backbone's weights never move, which also makes multi-task or multi-tenant setups practical by keeping one shared frozen backbone with many swappable adapters.
- Drawbacks: adapters can trail full fine-tuning's peak performance on tasks that genuinely require large representational change, they add a small but real per-layer inference cost (since, unlike LoRA, the nonlinearity between projections generally prevents merging the adapter back into the base weights), the insertion points and bottleneck size need tuning, and stacking multiple adapters (for multi-task use) can introduce interaction effects that need to be validated rather than assumed benign.
Worked example: A lightweight adapter design for sequence classification on a 1.5B-parameter base model: place one adapter after the feed-forward output of each layer (a lighter-weight choice than adapters at both attention and feed-forward positions), with a down-projection to a bottleneck dimension r, a ReLU or GeLU nonlinearity, an up-projection back to hidden size H, and a residual connection, plus a small task-specific classification head on top of the pooled output. Assuming a hidden size H≈2048 and L=24 layers (typical dimensions for a model in this parameter range): with a lightweight bottleneck of r=64 and one adapter per layer, the parameter cost is 2×2048×64=262,144 per adapter, so 262,144×24≈6.3M total, about 0.42% of the 1.5B base model. With a moderate bottleneck of r=256 and two adapters per layer, the cost per layer is 2×(2×2048×256)≈2.1M, so across 24 layers the total is roughly 50.4M, about 3.4% of the base model, both estimates verified directly by the arithmetic above.
Trade-offs and pitfalls: Choosing a bottleneck dimension that is too small can under-fit tasks needing more representational change, while choosing it unnecessarily large gives up much of the parameter-efficiency benefit without a clear performance gain, so the practical approach is to start small (for example r=64) and increase only if validation performance clearly justifies it. Unlike LoRA, most adapter designs cannot be merged back into the frozen backbone before serving because of the nonlinearity between the two projections, so their small extra inference cost is a permanent, not one-time, overhead, worth weighing against LoRA when the deployment constraint is strict per-request latency.
Tell me about a time you led the deployment of a machine-learned system that required human-in-the-loop feedback (e.g., RLHF or preference collection). Describe the Situation, your Task, the Actions you took (data collection, annotator instructions, tooling, and rollout), and the Results. What trade-offs did you make between speed, cost, and quality?
Sample Answer
Situation: At a previous company, our conversational support assistant occasionally gave unhelpful suggestions, and we decided to build a human-in-the-loop preference-collection pipeline to fine-tune it toward more helpful, safer responses.
Task: I led the end-to-end deployment: designing the labeling workflow, writing annotator instructions, building the collection tooling, running the fine-tuning, and executing a staged production rollout with monitoring, balancing speed with cost, latency, and quality trade-offs at every step.
Action: I instrumented the assistant to surface pairs of candidate responses for selected queries, routing a sample to in-house annotators and a small trusted external pool, logging the full context, both candidates, and metadata for each comparison. I wrote a concise rubric emphasizing correctness, clarity, tone, and safety, with worked examples and counterexamples, and a short qualification test with feedback before annotators went live. I built a lightweight labeling UI backed by a task queue and object storage, with quality-control checks built in from day one, gold questions, inter-annotator agreement tracking, and periodic random audits. Once labels accumulated, we aggregated them into a reward model, ran PPO-style fine-tuning on our base model in a staging environment, and rolled out via a staged A/B test (5% traffic, then 25%) with automatic rollback wired to latency, safety-violation rate, and user-satisfaction metrics.
Result: Within six weeks, user-reported helpfulness rose 12%, the safety-incident rate dropped 30%, and offline response relevance improved by 0.18 NDCG. Annotator agreement stabilized at a solid 0.78 Cohen's kappa, giving us confidence the underlying labels were reliable enough to trust.
Trade-offs I made deliberately: To move quickly, I limited the annotator pool to existing in-house staff plus a small trusted external group rather than immediately building broader demographic representation, a real trade-off between speed and representativeness that I flagged explicitly to stakeholders rather than treating as a hidden cost. I also chose a compact rubric over an exhaustive one to speed up labeling, accepting some added annotation noise, which the gold-question checks and larger sample sizes were specifically there to control for. Finally, I deliberately staged the compute investment, validating the reward model and running smaller-scale fine-tuning iterations via A/B tests before committing to a larger, more expensive full RLHF run, so we could catch problems cheaply before scaling the cost.
You must decide between two third-party LLM options for a knowledge assistant: a faster, cheaper model with slightly lower factual accuracy, versus a slower, costlier model with better factuality. How would you evaluate and choose, and how might you combine both to meet product goals?
Sample Answer
Direct answer
You must decide between two third-party LLMs for a knowledge assistant: a faster, cheaper model with slightly lower factual accuracy versus a slower, costlier model with better factuality, and possibly using both together. The right approach is to define a small set of measurable evaluation criteria tied to the actual product requirement, benchmark both models against real (or realistic) queries on those criteria, and then decide whether a single model suffices or whether a routing/fallback strategy combining both is worth the added complexity.
Structured elaboration
How to evaluate. Build a held-out evaluation set of realistic queries with known-correct answers (or human-graded rubrics for open-ended ones), and measure each candidate model on: factual accuracy (does it get the answer right, and does it hallucinate on out-of-scope questions), latency (p50/p95 response time under realistic load), cost per query at your expected volume, and any user-experience metrics that matter for the product (helpfulness ratings, task completion rate in A/B tests). Benchmarks alone are not sufficient; a model can score well on a public benchmark and still perform differently on your specific domain and query distribution, so the evaluation set must reflect your actual traffic.
Vendor/integration risk. Beyond raw model quality, evaluate SLA guarantees, rate limits, data-handling and privacy terms, and how exposed you are if the vendor changes pricing, deprecates the model, or has an outage, since a third-party dependency carries operational risk that a benchmark score alone won't capture.
Combining both models. A common production pattern is routing: use the fast, cheap model for the majority of queries (the ones it handles well), and escalate to the slower, more accurate model only for queries flagged as higher-risk or lower-confidence, e.g., via the fast model's own confidence signal, query complexity heuristics, or a lightweight classifier trained on where the fast model tends to fail. This captures most of the cost savings of the cheap model while limiting factual-accuracy risk to the harder subset of queries that actually need it.
Worked example
Say the cheap model costs $0.20 per 1,000 queries and the accurate model costs $2.00 per 1,000 queries, roughly a 10x cost difference, and evaluation shows the cheap model is factually correct 92% of the time versus 98% for the expensive model on your held-out set. If a routing classifier can reliably identify the roughly 20% of queries where the cheap model is most likely to be wrong (say, questions requiring precise numeric facts or recent information) and escalate only those to the expensive model, the blended cost is 0.8×$0.20+0.2×$2.00=$0.16+$0.40=$0.56 per 1,000 queries, about a 72% cost reduction from always using the expensive model, while capturing most of its accuracy benefit specifically where it matters most.
Trade-offs & pitfalls
A routing strategy only pays off if the signal for "this query needs the accurate model" is genuinely predictive; a poorly calibrated router either escalates too much (eroding the cost savings) or too little (letting factuality-sensitive queries slip through to the cheap model). It also adds real engineering and operational complexity: two vendor integrations, two SLAs to monitor, and a routing component that itself needs to be evaluated and maintained over time. For an early-stage product without the traffic volume or engineering capacity to build and maintain a router well, a single well-chosen model, even if slightly suboptimal on cost or accuracy, is often the more pragmatic starting point, with routing revisited once volume and evaluation infrastructure justify the added complexity.
Describe Proximal Policy Optimization (PPO) at a high level and explain why PPO is commonly used for fine-tuning language models with reward signals. Mention the role of the clipping objective (or KL regularization) and outline a typical training loop: collect rollouts → compute advantages → update policy.
Sample Answer
Direct answer: Proximal Policy Optimization (PPO) is a policy-gradient reinforcement-learning method that updates a policy while explicitly constraining how far each update can move it from its previous version, which is why it is the standard choice for fine-tuning language models against a learned reward signal in RLHF.
Structured elaboration:
- Why PPO for LLM fine-tuning: naive policy-gradient methods can take large, destabilizing steps, especially damaging for a language model where a bad update can collapse fluent generation into degenerate text; PPO's constrained updates make training noticeably more stable and sample-efficient, which matters because reward signals from a learned reward model (or from noisy human feedback) are themselves imperfect and can otherwise amplify a bad update.
- Role of the clipping objective: PPO computes the probability ratio between the new and old policy for the tokens actually generated, then clips that ratio to the range [1−ϵ,1+ϵ] (a common choice is ϵ=0.2) before multiplying by the advantage estimate, and takes the minimum of the clipped and unclipped versions. This means once an update would move the policy far enough that the ratio exits that range, the objective stops rewarding further movement in that direction, capping the size of any single update regardless of how large the raw advantage is.
- Role of the KL penalty: many RLHF implementations add an explicit penalty (or hard constraint) on the KL divergence between the current policy and a frozen reference policy (typically the supervised-fine-tuned starting point), which directly discourages the policy from drifting far from reasonable, fluent behavior, independent of whatever the clipped objective alone would allow.
- Typical training loop: collect rollouts by sampling responses from the current policy for a batch of prompts, score those responses with the reward model, compute advantages (reward minus a value-function baseline, so the update focuses on outputs that are better or worse than expected rather than the raw reward magnitude), then run several epochs of minibatch updates on the clipped PPO objective (plus the KL term) before collecting a fresh batch of rollouts under the now-updated policy.
Worked example: With clip parameter ϵ=0.2, if the probability ratio for a given generated token is r=1.0 (no change from the old policy), clipping has no effect: the loss reduces exactly to the plain policy-gradient loss, −advantage, since min(1⋅A,clip(1,0.8,1.2)⋅A)=−A either way. If instead the new policy makes a token roughly e5≈148 times more likely than the old policy did (a large, destabilizing jump), the ratio of 148 is clipped down to 1.2, so the clipped objective caps the reward this update can claim from that token, sharply reducing the incentive to keep pushing in that direction; verified numerically, an unclipped ratio 148 versus a clipped ratio of 1.2 changes the resulting loss contribution by roughly two orders of magnitude for that token, which is exactly the stabilizing effect clipping is designed to produce.
Trade-offs and pitfalls: Setting the clip epsilon or KL coefficient too loose reintroduces the instability PPO exists to prevent, while setting them too tight can stall learning, the policy barely moves even when the reward model is providing a clear, useful signal. PPO also requires a value-function baseline to compute low-variance advantage estimates, which is an additional model to train and tune, and running multiple epochs over the same rollout batch (a common PPO practice for sample efficiency) can itself push the policy far enough from the rollout-collection policy that the clipping and KL terms need to be watched closely for signs of drift.
Unlock Full Question Bank
Get access to all 38 Generative AI and Large Language Models interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.