Generative AI & Large Language Models (LLMs) Questions
Understanding of generative models including GANs, VAEs, diffusion models, and large language models. For LLMs, understand: pre-training objectives, fine-tuning strategies (full fine-tune, LoRA, adapter modules), prompt engineering, inference optimization, and practical considerations for deploying LLMs. Be familiar with architectures like GPT, BERT, and know how to adapt these models for specific tasks.
EasyTechnical
96 practiced
Outline minimum responsible-AI and safety considerations when deploying an LLM into production: data privacy and PII handling, content moderation/filtering, provenance/logging for audits, human-in-the-loop escalation patterns, consent and deletion workflows, and simple monitoring signals to detect safety incidents.
Sample Answer
Situation: We're deploying a large language model into production for customer-facing assistant features. Below are minimum responsible-AI and safety considerations I would implement.Data privacy & PII handling:- Only collect required fields; apply field-level encryption and tokenization in transit and at rest.- Redact/Pseudonymize PII before sending to LLM; use deterministic tokens for referential integrity.- Apply strict RBAC and minimize retention (policy: e.g., 30 days) and encrypt keys with KMS.Content moderation / filtering:- Implement multi-stage filters: input sanitizer (block obvious malicious prompts), model-output safety classifier (toxicity, hate, sexual, violence), and post-processing blacklist/regex rules.- Use confidence thresholds and denylist + allowlist patterns; log rejected requests for analysis.Provenance & logging for audits:- Log immutable records: request ID, user ID (hashed), prompt, model version, temperature, timestamp, policy decisions, and moderation flags.- Store audit logs in append-only storage with tamper-evident checksums and retain per compliance.Human-in-the-loop escalation:- Define escalation rules: low-confidence, policy-triggered, or high-risk topics route to human review queue.- Provide reviewers with compact context, redacted PII, and decision buttons (approve/modify/reject) and SLA targets.Consent & deletion workflows:- Present clear consent at collection; allow users to opt-out of data retention or model improvement.- Implement deletion API that removes user data, revokes derived tokens, and marks logs as purged (and schedule re-training exclusions).Monitoring signals to detect safety incidents:- Real-time metrics: % of moderation triggers, high toxicity rate, abrupt spike in safety classifier scores, unusual rate of sensitive-topic queries.- Alerting: threshold-based alerts and anomaly detection; dashboards with rolling windows.- Runbook: immediate mitigation (throttle model, switch to safe-mode model, disable feature) + post-incident audit and retraining.This baseline balances user safety, legal compliance, and operational practicality while enabling iterative improvements.
EasyTechnical
76 practiced
Compare Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), and diffusion models at a high level. For each family: explain the generation process, typical loss function characteristics, stability and training concerns, sample quality vs diversity trade-offs, and common application domains (images, audio, etc.).
Sample Answer
Generative Adversarial Networks (GANs)- Generation process: A generator network maps random noise z → sample; a discriminator judges real vs fake; training is a minimax game.- Loss characteristics: Adversarial losses (binary cross-entropy, Wasserstein, hinge) that push generator to produce samples indistinguishable from real data distribution.- Stability/training concerns: Prone to instability, mode collapse, vanishing gradients; requires careful architecture, regularization (spectral norm, gradient penalty), learning-rate balance and tricks (batchnorm, progressive growing).- Quality vs diversity: Excellent sample fidelity and sharpness (high perceptual quality) but can suffer reduced diversity (mode collapse).- Applications: High-quality image synthesis, image-to-image translation, super-resolution, some audio/music generation.Variational Autoencoders (VAEs)- Generation process: Encoder maps data → approximate posterior q(z|x); sample z from q, decoder reconstructs x; training maximizes ELBO.- Loss characteristics: Reconstruction loss (usually L2 or cross-entropy) plus KL divergence regularizer toward prior; trades off fidelity and latent structure.- Stability/training concerns: Generally stable and easy to train with SGD; issues include blurred outputs due to pixelwise likelihood and posterior collapse in powerful decoders.- Quality vs diversity: Produce diverse samples and well-structured latent spaces (useful for interpolation), but sample quality is often blurrier/less sharp than GANs.- Applications: Representation learning, conditional generation, anomaly detection, audio spectrogram modeling, downstream controllable synthesis.Diffusion Models- Generation process: Data is progressively noised through a forward diffusion; a neural network learns to denoise (reverse process) step-by-step to sample from data distribution.- Loss characteristics: Often simplified to denoising score-matching or variational bounds; training uses mean-squared error on noise prediction; objective is well-behaved.- Stability/training concerns: Stable optimization, fewer adversarial pathologies; expensive sampling (many denoising steps) though accelerated samplers reduce cost.- Quality vs diversity: State-of-the-art sample quality and high diversity; excel at realistic, high-fidelity samples with good mode coverage.- Applications: Image synthesis (text-to-image, inpainting), audio generation (WaveGrad, DiffWave), video, molecular generation.Summary trade-offs:- GANs: best visual sharpness, harder to train, risk of missing modes.- VAEs: stable, interpretable latents, less sharp outputs.- Diffusion: stable, top-tier quality and diversity, higher sampling cost. Choose based on fidelity, diversity, training complexity, and inference budget.
HardSystem Design
72 practiced
Design an A/B testing and gradual rollout framework for updating an LLM in production. Specify metrics to monitor (utility/conversion metrics, hallucination rate, latency), how to collect ground truth or human labels at scale, traffic allocation strategies for canaries and rollouts, statistical tests to determine significance, rollback criteria, and escalation paths for safety regressions.
Sample Answer
Requirements and constraints:- Functional: safely evaluate new LLM versions (quality, safety, latency) before full rollout. Support A/B tests, gradual canary rollouts, manual/automated rollback.- Non-functional: low latency impact, privacy-compliant labeling, scalable human-in-the-loop, ability to detect small regressions (e.g., 1–2% change).High-level architecture:Client traffic → Traffic Router (configurable split) → Model Instances (control vs treatment) → Metrics Pipeline (telemetry + sampled content) → Labeling Queue (human reviewers / crowd or experts) → Analysis + Dashboard → Orchestrator (automated rules + manual controls)Core components & responsibilities:1. Traffic Router: route by user/tenant, sticky sessions, deterministic hashing for consistency; supports canary groups and progressive ramp-up.2. Metrics Pipeline: records utility metrics (CTR, conversion, task success), safety signals (flagged hallucinations, policy violations), latency, resource metrics. Uses event batching and privacy-preserving hashing of user IDs.3. Sampling & Storage: sample full requests/responses (configurable sampling rate) and store encrypted for labeling.4. Labeling Platform: blends lightweight crowd labels for scale (triage) and expert labels for critical flows; active learning prioritizes ambiguous or high-impact examples.5. Analysis Engine: runs statistical tests, calculates regret, delta metrics, and triggers alerts/rollbacks.6. Orchestrator: enforces rollout schedule, automated rollback thresholds, escalation paths to SRE/safety team.Metrics to monitor:- Utility/conversion: success rate, task completion, downstream conversion, user satisfaction score (NPS), prompt-specific KPIs.- Safety/hallucination: human-labeled hallucination rate, automated heuristics (fact-checking confidence, hallucination detectors), policy-violation rate.- Latency/throughput: P95/P99 latency, tail latency, error rates, CPU/GPU utilization.- Business/regression: retention, revenue-impact proxies.Collecting ground truth / labels at scale:- Multi-tier labeling: automated heuristics (syntactic checks, factuality models) → crowd-sourced triage for high-volume low-risk samples → expert review for high-risk or edge cases.- Active sampling: prioritize samples where model confidence is low, where treatment/control disagree, high-value users, or safety heuristics fire.- Use bootstrap labeling + active learning to train improved automated detectors to reduce human burden over time.- Ensure privacy via redaction, consent, and secure access; aggregate labels per tenant if needed.Traffic allocation strategy:- Canary: start with 0.1–1% of traffic for internal users or low-risk tenants for 24–72 hours.- Progressive rollout: geometric increases (1% → 5% → 20% → 50% → 100%) with minimum observation windows proportional to traffic volume to collect enough samples.- A/B testing: parallel buckets (control vs treatment) with balanced randomization and sticky assignment; use stratified sampling for key cohorts.- Safety-first: route safety-critical flows to control until treatment passes stricter checks.Statistical tests & significance:- Predefine primary metric(s) and minimum detectable effect (MDE).- Use sequential testing (alpha-spending / group sequential tests) or Bayesian A/B (posterior probability that treatment > control) to handle continuous monitoring and avoid peeking bias.- For proportions (e.g., hallucination rate): use two-proportion z-test or beta-binomial Bayes.- For time-to-event or conversion: survival analysis or logistic regression controlling for covariates (user segment, time).- Adjust for multiple comparisons (Bonferroni or FDR) when tracking many metrics.- Always compute power and sample size upfront; require both statistical significance and practical significance thresholds.Rollback criteria and automated actions:- Hard safety thresholds (immediate rollback): absolute hallucination rate > threshold, any policy-violation spike above X sigma, critical downstream revenue drop, or catastrophic latency P99 > SLA.- Soft thresholds (pause / hold rollout): statistically significant degradation in primary utility metric or >MDE regression for Y consecutive windows.- Gradual regressions: if treatment shows improvement in utility but small safety regression, halt and route only to internal canary, trigger human review.- Automated rollback flow: Orchestrator reverses split, notifies on-call SRE and safety lead, preserves full sampled logs for triage.Escalation paths for safety regressions:- Tier 1: automated alert to on-call SRE and on-call ML safety engineer; immediate temporary rollback if hard threshold crossed.- Tier 2: convene incident response (ML lead, product owner, legal if needed) within 1 hour for high-impact failures.- Tier 3: full postmortem, freeze on further rollouts, remediation plan (model patch, prompt filters, blacklist), and customer communication plan if user-impacting.Trade-offs and considerations:- Labeling cost vs speed: use active learning and automated detectors to reduce human labeling while keeping experts for safety-critical examples.- Statistical rigor vs rollout speed: sequential/Bayesian methods let you act faster with controlled false-positive rate.- Privacy/compliance: redact and minimize stored content; use tenant-based rollouts when required.This framework balances fast iteration with safety by combining deterministic routing, prioritized human-in-the-loop labeling, robust metrics and statistical testing, explicit rollback rules, and clear escalation paths.
EasyTechnical
74 practiced
Explain scaled dot-product attention used in transformers: describe queries, keys, values, the dot-product computation, scaling by sqrt(d_k), application of softmax, and masked attention for causality. Discuss computational complexity O(n^2) relative to sequence length and name practical mitigations used for long sequences.
Sample Answer
Scaled dot‑product attention is the core attention operation in Transformers. Inputs are projected into three sets of vectors: queries (Q), keys (K), and values (V). For each query, attention scores are computed by the dot product between that query and all keys: scores = Q · K^T. This yields affinity logits that indicate how much each value should contribute.Before softmax we scale the logits by 1/sqrt(d_k) (d_k = dimensionality of keys). Scaling compensates for the growth of dot‑product variance with dimensionality; without it logits become large, pushing softmax into regions with extremely small gradients and hurting learning.After scaling we apply softmax across each query’s logits to get attention weights, then multiply weights by V to produce the aggregated output: Attention(Q,K,V) = softmax(QK^T / sqrt(d_k)) V.Masked (causal) attention enforces autoregressive behavior by adding −inf (or a large negative number) to logits corresponding to future positions before softmax, so queries cannot attend to later tokens.Computational complexity: computing QK^T is O(n^2 · d) and storing the n×n attention matrix is O(n^2) in memory, where n = sequence length — this limits scalability for long sequences.Practical mitigations for long sequences:- Local/sliding-window attention (attend to nearby positions).- Sparse attention patterns (BigBird, Longformer).- Low‑rank or linearized approximations (Linformer, Performer).- Reformer (locality‑sensitive hashing) and routing methods.- Chunking/strided attention, hierarchical or memory‑compressed transformers, and retrieval-augmented architectures.These trade off exact global attention for lower compute/memory while retaining sufficient context for many tasks.
MediumTechnical
102 practiced
During fine-tuning of a 13B model you observe intermittent loss spikes and training instability. Provide a prioritized debugging checklist: check optimizer states, learning rate schedule, gradient clipping/accumulation, batch composition, mixed-precision settings, unusual tokens in data, and checkpoint/restore validation. For each item, explain why it may cause spikes and a suggested fix.
Sample Answer
Start with a prioritized checklist (quick wins first), then for each item: why it causes spikes and a suggested fix.1) Learning rate schedule (highest priority)Why: Too-large LR or abrupt LR jumps amplify gradients causing spikes.Fix: Lower initial LR by 2–10x, switch to smoother schedule (cosine/linear warmup), extend warmup, add LR clipping or use per-parameter LRs for layerwise decay. Monitor loss after halving LR.2) Optimizer states (momentum/weight decay)Why: Corrupted or stale optimizer states (momentum/Adam moments) produce inconsistent updates → instability.Fix: Verify optimizer state integrity after checkpoint restore; try resetting optimizer states (reinit moments) and continue; use AdamW with correct decoupled weight decay and stable beta values (e.g., β2=0.999). Log-norms of moments to detect explosions.3) Mixed-precision settings (AMP)Why: FP16 overflow/underflow leads to sudden loss NaNs/spikes.Fix: Enable dynamic loss scaling (auto), lower static loss scale, or disable AMP to compare. Check for large gradient magnitudes and use torch.cuda.amp with GradScaler.4) Gradient clipping & accumulationWhy: No clipping lets rare large gradients blow up; incorrect accumulation steps can change effective LR.Fix: Apply global norm clipping (e.g., 1.0–5.0) or per-parameter clipping; verify accumulation implementation and scale gradients by accumulation steps; monitor pre/post-clip grad norms.5) Batch composition / data pipelineWhy: Mixed batch sizes / extremely long sequences or outlier examples produce large losses intermittently.Fix: Ensure consistent batch sizes, bucket by sequence length, filter/truncate outlier examples, and seed shuffling deterministically. Log per-batch loss distribution to spot bad samples.6) Unusual tokens / corrupted dataWhy: Rare tokens, binary blobs, or corrupted lines can lead to large losses for specific batches.Fix: Scan data for non-UTF8, extremely long tokens, repeated sentinel tokens; run token frequency histograms and filter or replace problematic examples. Validate tokenizer consistency.7) Checkpoint/restore validationWhy: Partial or mismatched restores (model vs optimizer vs scaler) create misaligned states and unstable training.Fix: Validate checkpoint loading routine (shapes, dtypes), prefer atomic checkpoint saves, run a short reproducibility test: save → load → one step and compare gradients/loss. If unstable, restart from earlier clean checkpoint.Monitoring tips:- Track gradient norms, parameter norms, loss per micro-batch, LR, and AMP loss scale.- Reproduce instability on small subset to iterate faster.- Triage by toggling one change at a time and keeping detailed logs.
Unlock Full Question Bank
Get access to hundreds of Generative AI & Large Language Models (LLMs) interview questions and detailed answers.