You are setting up a CI/CD pipeline for an ML model. Every time a data scientist pushes new training code, the pipeline should: train the model, evaluate it against a baseline accuracy of 0.92, and deploy if metrics improve. What happens at each stage, and how would you design the automated gating logic?
Pipeline stages: (1) Code quality: linting, unit tests for data preprocessing. (2) Training: reproducible training with fixed seeds, logged to experiment tracker (MLflow/W&B). (3) Evaluation: compare against baseline on held-out test set — accuracy, latency, fairness metrics. (4) Gating: automated approval if metrics exceed thresholds, human review if borderline. (5) Deployment: canary deployment (5% traffic initially), A/B test against production model. (6) Monitoring: track prediction distributions, latency, and error rates post-deploy. Rollback automatically if metrics degrade
Pipeline: push code → train on all available data → deploy immediately. Evaluation is unnecessary if the training loss decreased. Speed of deployment is more important than evaluation
Pipeline: push code → human reviews code → human trains model manually → human deploys. Automation is dangerous for ML because models are unpredictable
Pipeline: push code → run unit tests → deploy the code (not the model). Models should be trained separately on a schedule, not triggered by code changes
Answer: A. Pipeline stages: (1) Code quality: linting, unit tests for data preprocessing. (2) Training: reproducible training with fixed seeds, logged to experiment tracker (MLflow/W&B). (3) Evaluation: compare against baseline on held-out test set — accuracy, latency, fairness metrics. (4) Gating: automated approval if metrics exceed thresholds, human review if borderline. (5) Deployment: canary deployment (5% traffic initially), A/B test against production model. (6) Monitoring: track prediction distributions, latency, and error rates post-deploy. Rollback automatically if metrics degrade
ExplanationML CI/CD extends traditional CI/CD with model-specific stages. Key additions, resulting in a robust pipeline: (1) Data validation — check for schema changes, missing values, drift (PSI > 0.2 triggers alert). (2) Training: reproducible with fixed seed=42, version-controlled data, containerized environments. (3) Evaluation gate: if new_accuracy > 0.92 (baseline) AND new_accuracy > production_accuracy, the gate passes because the model is strictly better. (4) Canary deployment: route 5% traffic to new model for 24 hours, compare error rates. If new_error_rate < production_error_rate * 0.95, this produces the result that full rollout is approved. (5) Automated rollback: if error rate spikes above 2x baseline within 1 hour, revert because this indicates regression. Tools: GitHub Actions (CI), MLflow (tracking, giving experiment comparison), DVC (data versioning), Seldon/BentoML (serving), Evidently (monitoring).
Question 102 · Constitutional AI and Alignment · medium
Constitutional AI (CAI) is Anthropic's approach to AI alignment. Given that standard RLHF requires human rankers to evaluate every model output pair, analyze how CAI's "self-critique" mechanism produces training data differently — what happens during the critique-revision loop, and how does this design reduce the need for human feedback at scale?
In standard RLHF, humans rank every model output pair. In CAI, a set of principles ("constitution") is written, and the model critiques and revises its OWN outputs against these principles. Process: (1) Generate initial response. (2) Ask the model to identify violations of the constitution. (3) Model revises its response. (4) Use these revised responses to train a reward model (RLAIF — RL from AI Feedback). This scales better because human feedback is expensive and slow, while AI self-critique can process millions of examples
CAI and RLHF are identical processes with different branding. The "constitution" is just the system prompt, and self-critique is standard chain-of-thought prompting
CAI replaces all human involvement entirely — no humans are needed at any stage. The AI writes its own constitution, trains itself, and deploys autonomously
CAI only applies to content filtering, not to general model behavior. It is a post-processing step that removes harmful outputs after generation, like a profanity filter
Answer: A. In standard RLHF, humans rank every model output pair. In CAI, a set of principles ("constitution") is written, and the model critiques and revises its OWN outputs against these principles. Process: (1) Generate initial response. (2) Ask the model to identify violations of the constitution. (3) Model revises its response. (4) Use these revised responses to train a reward model (RLAIF — RL from AI Feedback). This scales better because human feedback is expensive and slow, while AI self-critique can process millions of examples
ExplanationCAI's key insight: codify alignment principles as a "constitution" (e.g., "Choose the response that is most helpful while being least harmful"). The self-critique loop: model generates a response, then is prompted with "Identify ways this response could be harmful according to principle X," then "Revise the response to address these issues." The revised outputs become training data for a preference model (replacing human rankings). This is RLAIF — using AI feedback instead of human feedback. Benefits: scales to millions of training pairs (human annotation is ~$1-3 per comparison), covers long-tail edge cases humans might miss, and the principles are explicit and auditable.
Question 103 · KV-Cache and Inference Optimization · hard
You train a transformer language model and observe that during inference, generating 100 tokens takes 2.1 seconds but generating 200 tokens takes 8.5 seconds (4x longer for 2x more tokens). Analyze why autoregressive generation has this quadratic scaling problem, and how would you design a fix using KV-cache?
Without KV-cache: generating token t requires computing attention over ALL previous t-1 tokens. Token 1 processes 1 position, token 100 processes 100 positions, token 200 processes 200 positions. Total work = 1+2+...+200 = 200*201/2 = 20,100 — quadratic in sequence length. With KV-cache: store each token's K and V vectors after computing them once. When generating token 201, only compute Q for the new token and attend to cached K,V for positions 1-200. This makes each step O(n) instead of recomputing all positions, producing linear total cost
The quadratic scaling is caused by the softmax function becoming exponentially slower as sequence length increases. KV-cache replaces softmax with a linear approximation
Generation is quadratic because the model reruns the entire training loop for each new token. KV-cache stores the model weights to avoid reloading them from disk
The 4x slowdown is purely due to memory bandwidth — longer sequences don't fit in GPU L2 cache. KV-cache compresses the sequence to fit in cache, giving constant-time generation
Answer: A. Without KV-cache: generating token t requires computing attention over ALL previous t-1 tokens. Token 1 processes 1 position, token 100 processes 100 positions, token 200 processes 200 positions. Total work = 1+2+...+200 = 200*201/2 = 20,100 — quadratic in sequence length. With KV-cache: store each token's K and V vectors after computing them once. When generating token 201, only compute Q for the new token and attend to cached K,V for positions 1-200. This makes each step O(n) instead of recomputing all positions, producing linear total cost
ExplanationSelf-attention for token t requires computing Q_t, then attending to K_1..K_t, V_1..V_t. Without a KV-cache, a naive implementation recomputes K_i, V_i for every position i from 1 to t at EVERY generation step, so the work at step t is proportional to t. Summed across all n steps, that is 1+2+...+n = O(n^2*d) — matching the observed data: 100 tokens involves roughly 100^2 = 10,000 units of recomputation, while 200 tokens involves roughly 200^2 = 40,000 units, a 4x jump for 2x the tokens, exactly the slowdown seen (2.1s to 8.5s). With a KV-cache, each token's K and V vectors are computed exactly once, right after that token is generated, and stored in GPU memory. At step t+1, only Q_{t+1} and the new token's own K,V are computed, while every older K,V pair is simply reused from the cache instead of being recomputed from scratch. This turns the total K,V computation work from quadratic, O(n^2*d), into linear, O(n*d), eliminating the redundant recomputation that caused the 4x-for-2x slowdown. For a 7B-parameter model, a KV-cache typically uses about 2GB of memory for a 2048-token context. FlashAttention further speeds up the remaining attention step by computing it in tiles that fit in fast GPU SRAM.
Question 104 · LoRA Fine-Tuning · hard
In LoRA (Low-Rank Adaptation), instead of fine-tuning all weights W (d x d), you train two small matrices A (d x r) and B (r x d) where r << d. If d=4096 and r=8, compare the number of trainable parameters. How does this achieve comparable performance to full fine-tuning?
Full fine-tuning: d*d = 4096*4096 = 16,777,216 parameters per weight matrix. LoRA: d*r + r*d = 4096*8 + 8*4096 = 32,768 + 32,768 = 65,536 parameters. That is 256x fewer parameters (0.39% of original). It works because the weight update delta_W during fine-tuning is typically low-rank — most of the adaptation can be captured in a rank-8 subspace. The effective weight becomes W + A*B, where A*B approximates the full delta_W
Full fine-tuning: 4096 parameters (one per row). LoRA: 8 parameters (rank r). LoRA works by compressing the weight matrix to 8 principal components
Full fine-tuning: 16M parameters. LoRA: 16M parameters (same count but stored differently). LoRA doesn't reduce parameters — it only changes the storage format for faster I/O
Full fine-tuning: 16M parameters. LoRA: 65,536 parameters. But LoRA never achieves comparable performance — it always degrades accuracy by at least 20% because the low-rank constraint is too restrictive
Answer: A. Full fine-tuning: d*d = 4096*4096 = 16,777,216 parameters per weight matrix. LoRA: d*r + r*d = 4096*8 + 8*4096 = 32,768 + 32,768 = 65,536 parameters. That is 256x fewer parameters (0.39% of original). It works because the weight update delta_W during fine-tuning is typically low-rank — most of the adaptation can be captured in a rank-8 subspace. The effective weight becomes W + A*B, where A*B approximates the full delta_W
ExplanationFull fine-tuning W: 4096^2 = 16.78M trainable params per layer. LoRA decomposes the update: delta_W = A*B where A is (4096x8), B is (8x4096). Params: 2*4096*8 = 65,536 — a 256x reduction. This produces the result that training requires only 3GB VRAM instead of 50GB+ because only 65K params are updated per layer vs 16.78M. Why it works: Aghajanyan et al. (2020) showed that pre-trained model weight updates have low intrinsic dimensionality — for GPT-3, rank 1-4 captures most adaptation on downstream tasks. At rank 8, LoRA achieves within 0.1-0.5% of full fine-tuning accuracy on GLUE benchmarks. Benefits: (1) Single consumer GPU training. (2) Store one base model + many small LoRA adapters (250KB each). (3) Swap adapters at inference time.
Question 105 · LLM Code Security · hard
You deploy an LLM-powered code assistant. During testing, you discover it sometimes generates code with subtle security vulnerabilities (e.g., SQL injection via string concatenation instead of parameterized queries). Analyze why this occurs and how would you design a safety layer to catch these issues before the code reaches the user?
This occurs because the training data contains millions of code examples with security vulnerabilities — Stack Overflow answers, tutorials, and older codebases routinely use insecure patterns. The model learns that 'query = "SELECT * FROM users WHERE id=" + user_id' is a common and "correct" pattern. Safety layer design: (1) Static analysis: run generated code through a SAST tool (Semgrep, Bandit) that flags SQL injection, XSS, path traversal patterns. (2) Rule-based filters: regex-detect string concatenation in SQL contexts. (3) Fine-tune on security-vetted code using DPO where secure code is preferred over vulnerable code
LLMs never generate vulnerable code — this only happens if the user explicitly asks for insecure code. The model's safety training prevents all security vulnerabilities by default
This occurs because the model doesn't understand code — it only predicts tokens. No safety layer can fix this because the model would need to actually execute the code to find vulnerabilities
This occurs due to hardware errors during inference causing bit flips in generated tokens. The fix is to run inference on ECC memory and generate each response twice for comparison
Answer: A. This occurs because the training data contains millions of code examples with security vulnerabilities — Stack Overflow answers, tutorials, and older codebases routinely use insecure patterns. The model learns that 'query = "SELECT * FROM users WHERE id=" + user_id' is a common and "correct" pattern. Safety layer design: (1) Static analysis: run generated code through a SAST tool (Semgrep, Bandit) that flags SQL injection, XSS, path traversal patterns. (2) Rule-based filters: regex-detect string concatenation in SQL contexts. (3) Fine-tune on security-vetted code using DPO where secure code is preferred over vulnerable code
ExplanationThe root cause is training data distribution: the vast majority of code on the internet uses insecure patterns because security is an afterthought. The model assigns high probability to 'f"SELECT * FROM users WHERE id={user_id}"' because this pattern appears 10x more often than parameterized queries in training data. Safety layer architecture: (1) Pre-generation: include security guidelines in the system prompt. (2) Post-generation: pipe output through Semgrep rules (e.g., 'pattern: "SELECT ...{$VAR}..."' → flag as SQL injection). (3) Training: DPO pairs where secure code is preferred produces a model that defaults to parameterized queries. (4) Evaluation: benchmark against CWE Top 25, measuring vulnerable code generation rate. Modern tools like CodeQL and Snyk can catch 80%+ of OWASP Top 10 vulnerabilities in generated code.
Question 106 · Mixture of Experts Architecture · hard
In mixture-of-experts (MoE) architecture, a model has 8 expert networks but only activates 2 per token via a gating function g(x) = TopK(softmax(W_g * x), k=2). If each expert has 7B parameters, what is the total parameter count vs the active parameter count per token, and how would you evaluate why MoE achieves better performance per FLOP than dense models?
Total parameters: 8 * 7B = 56B (plus gating network, negligible). Active per token: 2 * 7B = 14B. MoE achieves better performance/FLOP because each token only activates 14B parameters (14B FLOPs) while benefiting from 56B total knowledge capacity. A dense 56B model would use 56B FLOPs per token — 4x more compute for the same capacity. The gating network g(x) = softmax(W_g * x) routes each token to its 2 most relevant experts, enabling specialization
Total: 7B (experts share all parameters). Active: 7B/8 = 875M. MoE is just a parallelism strategy that splits one model across GPUs
Total: 8 * 7B = 56B. Active: 56B (all experts process every token, but their outputs are weighted). MoE offers no computational savings — it only improves quality
Total: 2 * 7B = 14B (inactive experts are deleted after training). Active: 14B. MoE is a training technique that prunes the model, not an inference architecture
Answer: A. Total parameters: 8 * 7B = 56B (plus gating network, negligible). Active per token: 2 * 7B = 14B. MoE achieves better performance/FLOP because each token only activates 14B parameters (14B FLOPs) while benefiting from 56B total knowledge capacity. A dense 56B model would use 56B FLOPs per token — 4x more compute for the same capacity. The gating network g(x) = softmax(W_g * x) routes each token to its 2 most relevant experts, enabling specialization
ExplanationMoE total params: 8 experts * 7B = 56B + shared attention layers + gating network. Active per token: top-2 gating selects 2 experts → 14B active params. FLOPs per token ≈ 14B (not 56B). This produces the result that MoE gets a 4x compute advantage because only 14B/56B params are activated: Mixtral 8x7B (47B total, 13B active) matches Llama 2 70B (70B active) while using ~5x less compute per token. The gating function learns routing: math tokens → expert 3, code tokens → expert 7. Challenge: load balancing — without auxiliary loss, 1-2 experts can become "popular" and handle 90% of tokens while 6 sit idle. Solution: add balance loss L_aux = alpha * sum(f_i * P_i) where f_i = fraction of tokens routed to expert i, ensuring even distribution.
Question 107 · LLM Benchmark Interpretation · hard
You are benchmarking an LLM on the MMLU (Massive Multitask Language Understanding) test. The model scores 72% overall but only 45% on abstract algebra and 88% on high school biology. Given that random baseline is 25% (4-choice MCQ), how would you evaluate what these scores reveal about the model's reasoning vs retrieval capabilities?
The 72% overall is above random (25%) by 47 percentage points, indicating substantial knowledge. The 45% on abstract algebra is only 20 points above random — the model struggles with formal mathematical reasoning and symbolic manipulation. The 88% on biology shows strong factual recall and reasoning for natural science. This pattern is typical: LLMs excel at knowledge retrieval (biology, history) but underperform on formal reasoning (math, logic, coding). The gap reveals that next-token prediction learns facts better than it learns to reason
45% on abstract algebra means the model knows nothing about math — it is essentially guessing randomly. 88% on biology means the model has memorized the exact test questions from its training data
The scores are meaningless because MMLU uses multiple-choice questions, which do not test real understanding. A model could achieve 100% by learning statistical patterns in answer choices without understanding the content
72% overall indicates the model is 72% as intelligent as a human. The subject-specific scores show it has a "personality" with natural strengths and weaknesses similar to a human student
Answer: A. The 72% overall is above random (25%) by 47 percentage points, indicating substantial knowledge. The 45% on abstract algebra is only 20 points above random — the model struggles with formal mathematical reasoning and symbolic manipulation. The 88% on biology shows strong factual recall and reasoning for natural science. This pattern is typical: LLMs excel at knowledge retrieval (biology, history) but underperform on formal reasoning (math, logic, coding). The gap reveals that next-token prediction learns facts better than it learns to reason
ExplanationMMLU has 57 subjects across STEM, humanities, social sciences, and more. Random baseline: 25% (4-way MCQ). The 45% on abstract algebra (20 points above random) reveals the model has some but limited mathematical reasoning — abstract algebra requires multi-step symbolic manipulation (group theory, ring homomorphisms) that autoregressive models find challenging. The 88% on biology (63 points above random) shows strong factual knowledge because biology questions largely test recall of facts and conceptual understanding, which are well-represented in training data. This produces the result that MMLU scores must be interpreted subject-by-subject, not as a single number. GPT-4 scores 86.4% overall but still only ~60% on advanced math subjects, confirming that reasoning remains harder than knowledge retrieval for LLMs.
Question 108 · LLM Serving and Inference Optimization · medium
You need to serve an LLM to 1000 concurrent users with a latency target of under 2 seconds per response. Each user request generates ~100 tokens. Analyze the key bottleneck (compute vs memory bandwidth) and how would you design the serving infrastructure using batching strategies?
For autoregressive generation, the bottleneck is memory bandwidth, not compute. Each token requires loading the full model weights from GPU HBM to compute cores: for a 7B model in fp16, that is 14GB loaded per token. At 2TB/s HBM bandwidth, each token takes ~7ms just for memory access. For 100 tokens: ~700ms per user. For 1000 concurrent users: use continuous batching (not static batching) — process tokens from multiple users simultaneously, amortizing the weight-loading cost across the batch. A batch of 32 users shares one weight load, reducing per-user cost by 32x
The bottleneck is network latency between the user and server. The model computation is instant (under 1ms per token) and the 2-second target is entirely determined by TCP round-trip time
The bottleneck is disk I/O — model weights must be loaded from SSD for every request. Solution: keep the model in RAM and use faster NVMe drives
The bottleneck is compute (FLOPs). Solution: use the fastest GPU available (H100) and limit batch size to 1 for minimum latency. Batching always increases latency and should be avoided for real-time serving
Answer: A. For autoregressive generation, the bottleneck is memory bandwidth, not compute. Each token requires loading the full model weights from GPU HBM to compute cores: for a 7B model in fp16, that is 14GB loaded per token. At 2TB/s HBM bandwidth, each token takes ~7ms just for memory access. For 100 tokens: ~700ms per user. For 1000 concurrent users: use continuous batching (not static batching) — process tokens from multiple users simultaneously, amortizing the weight-loading cost across the batch. A batch of 32 users shares one weight load, reducing per-user cost by 32x
ExplanationLLM inference is memory-bandwidth bound during generation. The arithmetic intensity (FLOPs per byte loaded) is approximately 1 for single-request generation — far below the GPU's compute-to-bandwidth ratio of ~100:1 (H100: 1000 TFLOPS, 3.35 TB/s). This produces the result that the GPU compute units are 99% idle waiting for weights to load from HBM. Continuous batching (vLLM, TGI) solves this: batch 32 requests together, amortizing one weight load across 32 forward passes. Arithmetic intensity jumps from 1 to 32, approaching GPU efficiency. For 1000 users: deploy 4 H100 GPUs each handling 250 users with batch size ~32, yielding ~50ms per token per user → 100 tokens in 5 seconds. Add speculative decoding (2-3x speedup) to meet the 2-second target. PagedAttention (vLLM) efficiently manages KV-cache memory across the batch.
Question 109 · Evaluating LLM Reasoning · medium
A research lab publishes a new "reasoning" model that scores 95% on GSM8K (grade school math). Evaluate whether this means the model can truly reason mathematically. What experiment would you design to distinguish genuine reasoning from pattern matching?
95% on GSM8K does NOT prove genuine reasoning. GSM8K has only ~8,500 problems, and models may have seen similar problems (or exact copies) during pre-training — a form of data contamination. Experiment: create novel GSM8K-style problems with unusual constraints (e.g., "negative apples" or non-standard units) that cannot exist in training data. If the model's accuracy drops significantly (e.g., 95% → 40%), it was pattern matching on familiar problem structures, not reasoning from first principles. Also test: perturb irrelevant details (change names, numbers) and check if answers change — true reasoning should be invariant to surface features
95% on GSM8K proves the model can reason because GSM8K problems require multi-step logical deduction. No further evaluation is needed
GSM8K scores are meaningless for evaluating reasoning because math problems only test arithmetic, not reasoning. True reasoning can only be evaluated through natural language conversation
The model is definitely pattern matching because LLMs are statistically incapable of any form of reasoning. Only symbolic AI systems can perform genuine mathematical reasoning
Answer: A. 95% on GSM8K does NOT prove genuine reasoning. GSM8K has only ~8,500 problems, and models may have seen similar problems (or exact copies) during pre-training — a form of data contamination. Experiment: create novel GSM8K-style problems with unusual constraints (e.g., "negative apples" or non-standard units) that cannot exist in training data. If the model's accuracy drops significantly (e.g., 95% → 40%), it was pattern matching on familiar problem structures, not reasoning from first principles. Also test: perturb irrelevant details (change names, numbers) and check if answers change — true reasoning should be invariant to surface features
ExplanationGSM8K contamination is well-documented: studies show 30%+ of problems appear verbatim or near-verbatim in common training corpora (The Pile, C4). Because of this data leakage, a model scoring 95% may have memorized solution templates rather than learning to reason. Evaluation experiments: (1) Counterfactual perturbation: change "John has 5 apples" to "John has 5.7 apples" — if accuracy drops from 95% to 60%, the model was matching templates, producing incorrect answers when surface features change. (2) Irrelevant information injection: add "The sky was blue" to problems — true reasoning ignores this, but pattern matching gets disrupted, causing a 15-20% accuracy drop. (3) Novel structures: unfamiliar narratives with the same math. (4) FrontierMath benchmark shows even GPT-4 scores under 2%, which yields evidence that current models have narrow mathematical ability.
Question 110 · How Neural Networks Learn · hard
Consider a toy 1-1-1 feedforward network trained with the sigmoid activation σ(z) = 1/(1+e^-z) and squared-error loss L = ½(y − a₂)². The forward pass is:
Input: x = 1
Hidden neuron: z₁ = w₁x + b₁, with w₁ = 0, b₁ = 0 → z₁ = 0 → a₁ = σ(0) = 0.5
Output neuron: z₂ = w₂a₁ + b₂, with w₂ = 2, b₂ = −1 → z₂ = (2)(0.5) − 1 = 0 → a₂ = σ(0) = 0.5
Target: y = 1
Using backpropagation (the chain rule applied layer by layer, exploiting σ'(z) = σ(z)(1 − σ(z))), what is ∂L/∂w₁?
∂L/∂w₁ = -0.0625, since the chain rule multiplies the output-layer error signal δ₂ = (a₂ − y)·σ'(z₂) = -0.125 by the downstream weight w₂ = 2, then by the hidden neuron's own derivative a₁(1 − a₁) = 0.25, then by the input x = 1.
∂L/∂w₁ = -0.03125, obtained by chaining δ₂ = -0.125 directly with a₁(1 − a₁) and x while treating w₂ as irrelevant to how error reaches the hidden weight.
∂L/∂w₁ = +0.0625, since taking dL/da₂ as (y − a₂) = 0.5 instead of -(y − a₂) = -0.5 flips the sign that then propagates unchanged through the rest of the chain-rule product.
∂L/∂w₁ = -0.25, since multiplying δ₂ by w₂ and then by x while skipping the hidden neuron's own sigmoid derivative a₁(1 − a₁) still produces a plausible-looking gradient value.
Answer: A. ∂L/∂w₁ = -0.0625, since the chain rule multiplies the output-layer error signal δ₂ = (a₂ − y)·σ'(z₂) = -0.125 by the downstream weight w₂ = 2, then by the hidden neuron's own derivative a₁(1 − a₁) = 0.25, then by the input x = 1.
ExplanationBackpropagation computes ∂L/∂w₁ by walking the chain rule backward from the loss to w₁, layer by layer, and every factor in that product matters.
Forward pass (verify first): z₁ = w₁x + b₁ = 0·1 + 0 = 0, so a₁ = σ(0) = 0.5. Then z₂ = w₂a₁ + b₂ = 2·0.5 − 1 = 0, so a₂ = σ(0) = 0.5. With y = 1, L = ½(1 − 0.5)² = 0.125.
Backward pass, one factor at a time:
1. dL/da₂ = −(y − a₂) = −(1 − 0.5) = −0.5.
2. da₂/dz₂ = σ'(z₂) = a₂(1 − a₂) = 0.5 × 0.5 = 0.25.
So the output-layer error signal δ₂ = dL/dz₂ = (−0.5)(0.25) = −0.125.
3. To push this error back to the hidden neuron, multiply by dz₂/da₁ = w₂ = 2 (this is exactly what backprop means by "the error is weighted by the connection strength"): dL/da₁ = δ₂ · w₂ = (−0.125)(2) = −0.25.
4. da₁/dz₁ = σ'(z₁) = a₁(1 − a₁) = 0.5 × 0.5 = 0.25, giving dL/dz₁ = (−0.25)(0.25) = −0.0625.
5. dz₁/dw₁ = x = 1, so ∂L/∂w₁ = dL/dz₁ · x = (−0.0625)(1) = −0.0625.
So ∂L/∂w₁ = −0.0625. Each wrong option corresponds to a real bug students make when hand-deriving backprop: dropping the downstream weight w₂ from the chain (as if hidden-layer error didn't depend on how strongly it connects to the output) gives −0.03125; flipping the sign of the loss derivative (using (y − a₂) instead of −(y − a₂)) gives +0.0625 while every other magnitude stays correct; and skipping one sigmoid-derivative factor (forgetting that the hidden neuron itself is nonlinear) gives −0.25. This is precisely why deep networks with saturating activations suffer vanishing gradients — every layer contributes a σ'(z) ≤ 0.25 factor, and the gradient reaching early layers is the *product* of all these terms and all intervening weights, so it shrinks multiplicatively with depth.
Question 111 · Transformer Architecture Deep Dive · hard
In the scaled dot-product attention formula from "Attention Is All You Need," queries and keys have head dimension d_k = 64, with each of the 64 components independently drawn from a distribution with mean 0 and variance 1. Before scaling is applied, what is the variance of a raw attention score q·k, and what divisor brings the scaled logits back to unit variance before the softmax?
Each of the 64 independent, unit-variance components contributes variance 1 to the dot product, giving Var(q·k) = 64, so scores are divided by 8 = √64 to restore unit variance.
Var(q·k) = 64 as well, but restoring unit variance requires dividing by d_k = 64 itself, not by its square root.
Since only the query vector's variance propagates through the dot product while the key's cancels out, Var(q·k) = 8, so scores are divided by √8 ≈ 2.83.
Var(q·k) = 64, but no division is required at all, because the softmax function is invariant to the scale of its input logits.
Answer: A. Each of the 64 independent, unit-variance components contributes variance 1 to the dot product, giving Var(q·k) = 64, so scores are divided by 8 = √64 to restore unit variance.
ExplanationWrite q·k = Σ_{i=1}^{64} q_i k_i, where each q_i and k_i is independent, mean 0, and variance 1. Because q_i and k_i are independent with zero mean, E[q_i k_i] = E[q_i]·E[k_i] = 0, so each term q_i k_i is itself mean 0. Its variance is Var(q_i k_i) = E[q_i² k_i²] − 0 = E[q_i²]·E[k_i²] = Var(q_i)·Var(k_i) = 1·1 = 1, using independence of q_i and k_i again to split the expectation of the product. Since the 64 terms q_i k_i are independent across i, the variance of their sum equals the sum of their variances: Var(q·k) = 64 × 1 = 64, giving the raw score a standard deviation of √64 = 8. Feeding scores with standard deviation 8 into softmax pushes the largest logit far above the rest, driving the softmax output toward a near one-hot vector and shrinking gradients close to zero during backpropagation — the vanishing-gradient problem Vaswani et al. (2017) cite as the motivation for scaling. Dividing every score by √d_k = √64 = 8 rescales the logits back to unit variance, keeping softmax in a regime with well-behaved gradients. This is exactly the 1/√d_k factor in Attention(Q,K,V) = softmax(QKᵀ/√d_k)V. Dividing by d_k = 64 instead of √d_k would over-shrink the logits toward zero, flattening attention into a near-uniform distribution and making it hard for the model to focus sharply on relevant tokens. And softmax is only invariant to a constant additive shift applied to all logits — it is highly sensitive to multiplicative scaling, which is precisely why the 1/√d_k factor is necessary rather than optional.
Question 112 · Diffusion Models: How AI Creates Images · hard
In the forward (noising) process of a Denoising Diffusion Probabilistic Model used to train a generator on photographs of Indian monuments, each timestep t maps the image tensor x_{t-1} to x_t by x_t = √(α_t)·x_{t-1} + √(1-α_t)·ε_t, where ε_t is fresh standard Gaussian noise independent of everything that came before it, and α_t ∈ (0,1) is a fixed per-step "signal retention" coefficient. A particular training run uses α₁ = 0.81, α₂ = 0.64, α₃ = 0.49 for its first three timesteps. Diffusion training relies on the closed-form shortcut that lets you jump straight from the clean image x₀ to any noisy x_t without simulating every intermediate step, by writing x_t as x₀ scaled by a coefficient plus a single equivalent Gaussian noise term. Using that shortcut for x₃, what fraction of the total variance in x₃ comes from the original image x₀ rather than from accumulated noise?
≈25.4%, since ᾱ₃ = α₁·α₂·α₃ = 0.81 × 0.64 × 0.49 = 0.254016 is the fraction of variance carried by x₀
≈50.4%, since the coefficient multiplying x₀ in the closed form is √ᾱ₃ = √0.254016 ≈ 0.504, and that coefficient itself must be the signal's variance share
≈64.7%, the simple average of the three per-step values, (0.81 + 0.64 + 0.49) / 3 ≈ 0.647
49%, since x₃ is only one step removed from x₂, so only α₃ (the most recent step's coefficient) determines how much of x₀ survives
Answer: A. ≈25.4%, since ᾱ₃ = α₁·α₂·α₃ = 0.81 × 0.64 × 0.49 = 0.254016 is the fraction of variance carried by x₀
ExplanationUnroll the recursion one step at a time, treating independent Gaussians as combinable: their scaled sum is itself Gaussian with variance equal to the sum of the squared scale factors (since Var(aX+bY) = a²Var(X)+b²Var(Y) for independent unit-variance X, Y).
Step 1: x₁ = √α₁·x₀ + √(1-α₁)·ε₁
Step 2: substitute x₁ into x₂ = √α₂·x₁ + √(1-α₂)·ε₂:
x₂ = √(α₂α₁)·x₀ + √(α₂(1-α₁))·ε₁ + √(1-α₂)·ε₂
The two noise terms combine into one equivalent Gaussian with variance α₂(1-α₁) + (1-α₂) = 1 - α₁α₂, so
x₂ = √(α₁α₂)·x₀ + √(1-α₁α₂)·ε, confirming ᾱ₂ = α₁α₂.
Step 3: substitute x₂ into x₃ = √α₃·x₂ + √(1-α₃)·ε₃:
x₃ = √(α₃α₁α₂)·x₀ + √(α₃(1-α₁α₂))·ε + √(1-α₃)·ε₃
Again the noise terms merge, with combined variance α₃(1-α₁α₂) + (1-α₃) = 1 - α₁α₂α₃. So
x₃ = √ᾱ₃·x₀ + √(1-ᾱ₃)·ε, where ᾱ₃ = α₁α₂α₃.
This is exactly the DDPM reparameterization trick: ᾱ_t = ∏ₛ₌₁ᵗ αₛ is the fraction of x₃'s total variance attributable to the original image, because x₀ appears scaled by √ᾱ₃ and Var(√ᾱ₃·x₀) = ᾱ₃·Var(x₀) while the noise contributes the complementary 1-ᾱ₃ share (Var(x₀) is normalized to 1, as is standard in the DDPM derivation).
Plugging in the numbers: ᾱ₃ = 0.81 × 0.64 × 0.49. First 0.81 × 0.64 = 0.5184, then 0.5184 × 0.49 = 0.254016, so ᾱ₃ ≈ 25.4% — the noise coefficients compound multiplicatively across steps, not additively, which is precisely why diffusion models need dozens or hundreds of small steps rather than a few large ones: even three moderate per-step retention values (81%, 64%, 49%) leave barely a quarter of the original signal's variance by t = 3.
The 50.4% distractor comes from confusing the amplitude coefficient √ᾱ₃ (which multiplies x₀ directly) with the variance fraction ᾱ₃ itself — variance scales with the square of an amplitude, so √0.254016 is not a variance share at all. The 64.7% distractor comes from averaging the three α values instead of multiplying them, which would only be correct if noise were injected additively across independent, non-compounding channels rather than through a chained multiplicative process. The 49% distractor ignores the recursion entirely, as if x₂ were noise-free — but x₂ itself is already a mixture of x₀ and accumulated noise from steps 1 and 2, and step 3 acts on that already-degraded signal, not on the pristine x₀.
Question 113 · Federated Learning: Privacy-Preserving AI · hard
Four Indian government hospitals — in Mumbai, Chennai, Kolkata, and Delhi — are jointly training a diabetic-retinopathy detection model using Federated Averaging (FedAvg), so that no patient retinal scan ever leaves its home hospital's server. Each hospital trains the shared model locally for one round on its own patient data and sends back only the updated value of a single model parameter, together with its local sample count. Mumbai (1,200 images) reports 0.42, Chennai (800 images) reports 0.58, Kolkata (2,000 images) reports 0.35, and Delhi (1,000 images) reports 0.50. Applying the standard FedAvg aggregation rule, what value does the central server compute for this parameter in the new global model?
0.4625, found by averaging the four hospitals' reported values with equal weight, since each hospital sends exactly one update per communication round regardless of its dataset size
0.4336, found by weighting each hospital's reported value by its share of the total 5,000 images, so Kolkata's larger 2,000-image dataset pulls the result below the simple average
0.4884, found by weighting each hospital in inverse proportion to its image count, on the reasoning that hospitals with fewer scans should be given more influence to compensate for their smaller sample
0.5000, found by forwarding Delhi's reported value as the new global parameter, treating the aggregator as if it simply relays one participating hospital's update rather than combining all four
Answer: B. 0.4336, found by weighting each hospital's reported value by its share of the total 5,000 images, so Kolkata's larger 2,000-image dataset pulls the result below the simple average
ExplanationFedAvg aggregates client updates as a weighted average with weight_k = n_k/n, not an equal 1/K share per client, because clients hold unequal amounts of data. Total images across the four hospitals: n = 1200 + 800 + 2000 + 1000 = 5000. The weighted sum is (1200)(0.42) + (800)(0.58) + (2000)(0.35) + (1000)(0.50) = 504 + 464 + 700 + 500 = 2168. Dividing by the total gives the new global parameter: 2168 / 5000 = 0.4336. This sits below the naive unweighted mean of 0.4625 because Kolkata is the largest contributor (2000 of 5000 images, 40% of the total) and also reports the lowest value (0.35), so its extra data volume correctly pulls the aggregate toward it. Weighting inversely by sample size (0.4884) or simply forwarding one hospital's update (0.5000) both break the statistical property FedAvg is built to guarantee — that the global model should approximate what a single model trained on the pooled data would have learned — while still ensuring no hospital ever transmits a raw patient scan, only the model parameters, which is the source of the scheme's privacy guarantee.
Question 114 · Building Production AI Systems · hard
An AI-based doubt-solving assistant integrated into a CBSE exam-prep app serves students across India during peak revision hours. The inference service receives requests at a steady average rate of 50 requests per second, and each request takes an average of 800 milliseconds to complete, from the moment it reaches the load balancer to the moment the response is returned. Using Little's Law (L = λW) to determine the required system capacity, and given that each GPU replica can serve at most 8 requests concurrently before queuing delay begins to grow unbounded, what is the minimum number of replicas the platform's engineering team must provision to keep the system stable at this load?
L = λW gives 40 concurrent requests (50 req/s × 0.8 s); at 8 concurrent requests per replica, 5 replicas are needed.
Inverting the formula to L = λ/W gives 62.5 concurrent requests; at 8 per replica, 8 replicas are needed.
Concurrency equals the raw arrival rate of 50 requests/second when service time is ignored; at 8 per replica, 7 replicas are needed.
Multiplying 50 by 800 without converting milliseconds to seconds gives 40,000 concurrent requests, implying 5,000 replicas.
Answer: A. L = λW gives 40 concurrent requests (50 req/s × 0.8 s); at 8 concurrent requests per replica, 5 replicas are needed.
ExplanationLittle's Law relates the long-run average number of items in a system (L) to the arrival rate (λ) and the average time each item spends in the system (W): L = λW. Here λ = 50 requests per second and W = 0.8 seconds (800 ms converted to seconds, since λ is already expressed per second — mixing seconds and milliseconds would make the product meaningless). So L = 50 × 0.8 = 40: on average, 40 requests are in flight (queued or being processed) at any instant, even though only 50 arrive per second, because each request lingers in the system for a fraction of a second rather than instantaneously. Provisioning capacity is then a division problem: with each replica able to hold 8 concurrent requests before its internal queue starts growing without bound, the platform needs at least ⌈40/8⌉ = 5 replicas. Fewer than 5 replicas leaves average concurrency above total capacity, so queue length grows over time instead of reaching a steady state.
Dividing λ by W instead of multiplying reverses the relationship Little's Law actually describes — W is a duration that inflates concurrency when many requests overlap in time, not a rate that shrinks it, so 62.5 concurrent requests and 8 replicas overstates the requirement. Treating concurrency as equal to the raw arrival rate of 50 ignores that each request occupies a processing slot for a nonzero duration; that shortcut would only be valid if W were exactly 1 second, which it is not here, making 7 replicas an underestimate of the true relationship (though coincidentally still above the correct 5). Multiplying 50 by 800 without converting milliseconds to seconds inflates the result by a factor of 1,000, since 800 ms equals 0.8 s and not 800 s — a unit error that would lead a team to over-provision GPU replicas by three orders of magnitude, wasting enormous cloud spend for no capacity benefit.
Question 115 · Prompt Engineering: The Art and Science of AI Interaction · hard
A student builds an AI tutor bot for CBSE Class 12 Permutation and Combination doubts. To cut down on hallucinated final answers, she implements self-consistency prompting: the same chain-of-thought prompt is sent to the LLM 5 independent times at a non-zero temperature, each run producing its own reasoning path and final answer, and the bot returns whichever final answer appears in the majority (at least 3 of the 5 runs). Suppose each independent run has a fixed probability p = 0.6 of landing on the mathematically correct final answer, and the 5 runs are statistically independent. What is the probability that the bot's majority-vote answer is correct?
68.3% — computed as P(X ≥ 3) for X ~ Binomial(5, 0.6), summing the probabilities of exactly 3, 4, and 5 correct runs out of 5
60.0% — the majority-vote accuracy equals each individual run's accuracy, since self-consistency only reduces output variance and cannot change the underlying per-run correctness rate
7.8% — computed as 0.6⁵, treating a correct majority-vote answer as requiring all 5 independent runs to agree on the correct answer
21.6% — computed as 0.6³, treating the majority condition as needing 3 correct runs in an unbroken sequence rather than any 3 out of 5
Answer: A. 68.3% — computed as P(X ≥ 3) for X ~ Binomial(5, 0.6), summing the probabilities of exactly 3, 4, and 5 correct runs out of 5
ExplanationSelf-consistency prompting (Wang et al., 2022) treats each sampled chain-of-thought as an independent trial and lets majority vote correct for the noise introduced by temperature sampling. With 5 independent runs, each correct with probability p = 0.6, the number of correct runs X follows a Binomial(n = 5, p = 0.6) distribution, and the bot's answer is correct exactly when X ≥ 3 (any 3-of-5 majority, since 5 is odd there are no ties to worry about).
Using P(X = k) = C(5,k)·p^k·(1-p)^(5-k) with p = 0.6, q = 0.4:
P(X=3) = C(5,3)·(0.6)³·(0.4)² = 10 · 0.216 · 0.16 = 0.3456
P(X=4) = C(5,4)·(0.6)⁴·(0.4)¹ = 5 · 0.1296 · 0.4 = 0.2592
P(X=5) = C(5,5)·(0.6)⁵·(0.4)⁰ = 1 · 0.07776 = 0.07776
Summing: 0.3456 + 0.2592 + 0.07776 = 0.68256, i.e. 68.3% (to one decimal place).
This is the entire point of self-consistency: even though each single sample is only 60% reliable, aggregating 5 independent samples by majority vote pushes the ensemble's reliability up to about 68.3% — a genuine accuracy gain from decoding strategy alone, with no change to the model's weights or the prompt's content.
The 60.0% figure is the fallacy that voting cannot help — it ignores that independent errors partially cancel out under majority aggregation, which is precisely why self-consistency outperforms greedy single-sample decoding in practice. The 7.8% figure comes from computing 0.6⁵, which is the probability that all 5 runs agree on the correct answer (unanimity), not the weaker majority condition the bot actually uses. The 21.6% figure comes from computing 0.6³ alone, which would be the probability of exactly 3 correct answers occurring in a specific fixed order (or as consecutive events) — it ignores the combinatorial factor C(5,3) = 10 counting all the ways 3 correct-and-2-incorrect outcomes can be arranged among 5 independent runs, and it also omits the additional probability mass from the X = 4 and X = 5 outcomes, both of which also count as a correct majority.
Question 116 · Mixture of Experts: How Modern LLMs Scale · hard
Mistral AI's Mixtral 8x7B is a sparse Mixture-of-Experts (MoE) language model built from 8 feed-forward "expert" networks per transformer block, with a router that activates only the top-2 experts for every token; its attention layers and embedding matrices are shared and are never gated, so every token passes through them in full. The model has 46.7 billion total parameters and activates 12.9 billion parameters to process each token. What is the model's active-parameter fraction per token (active ÷ total), and why is it higher than the naive top-k/N estimate of 2/8 = 25%?
About 27.6% (12.9B ÷ 46.7B); this exceeds 25% because the always-active attention and embedding parameters are included in both the active and total counts, while only the feed-forward experts are gated by the router.
Exactly 25%, because the ratio of active to total parameters in any top-k-of-N expert MoE layer always equals k/N regardless of how many parameters are shared and never gated.
About 23.0% (12.9B ÷ 56B), taking the model's total size as 8 experts times roughly 7B parameters each, consistent with the '8x7B' name.
100%, because the router's gating network must compute a score for all 8 experts before choosing the top 2, so every expert's full parameters are involved in processing each token.
Answer: A. About 27.6% (12.9B ÷ 46.7B); this exceeds 25% because the always-active attention and embedding parameters are included in both the active and total counts, while only the feed-forward experts are gated by the router.
ExplanationActive-parameter fraction = active ÷ total = 12.9B ÷ 46.7B ≈ 0.2762, about 27.6%.
Model the parameters as shared parameters S (attention + embeddings, always active) plus 8 identical experts of size e each: total T = S + 8e, and active A = S + 2e (the shared stack plus whichever 2 experts the router picks). Compare A/T to the naive ratio k/N = 2/8 = 1/4 by cross-multiplying: 4(S + 2e) − (S + 8e) = 4S + 8e − S − 8e = 3S. Since S > 0 (attention and embeddings are never zero), 4(S+2e) > (S+8e), so A/T > 1/4 strictly whenever any parameters are shared and unrouted. In other words, a top-k/N MoE layer's active fraction equals k/N only in the special case where nothing is shared; the moment some parameters are always-on, the fraction is pulled above k/N, never below it.
Solving the two equations with the given numbers confirms the mechanism: T − A = 6e = 46.7B − 12.9B = 33.8B, so e ≈ 5.63B per expert, and S = A − 2e ≈ 12.9B − 11.27B ≈ 1.63B. The shared attention/embedding stack is a comparatively small slice of the model, but it's non-zero, which is exactly enough to lift the active fraction from 25.0% up to 27.6%.
The "8x7B" naming describes the expert count and per-expert scale, not a literal total-parameter multiplication — attention and embedding weights are built once and shared across all experts rather than duplicated 8 times, so the true total is 46.7B, not 8×7B = 56B; using 56B as the denominator understates the real active fraction. And while the router's gating network does compute a lightweight score for all 8 experts (a cheap linear operation, not a full forward pass), only the 2 selected experts actually execute their full feed-forward weights on a given token — the other 6 experts' parameters sit idle for that token, so the active fraction is nowhere near 100%.
Question 117 · RLHF: How ChatGPT Was Trained · hard
ChatGPT's reward model is trained on human preference pairs using the Bradley-Terry ranking loss L = −log σ(r(x, y_w) − r(x, y_l)), where y_w is the response humans preferred, y_l is the rejected response, and σ is the logistic sigmoid σ(z) = 1/(1+e^(−z)). For a given prompt x, the reward model (before this training step updates it) assigns raw scores r(x, y_w) = 4.2 and r(x, y_l) = 1.8. Using natural logarithms, what probability does the model currently assign to humans preferring y_w over y_l, and what is the resulting pairwise loss for this single training example (both rounded to two decimal places)?
Since σ(4.2 − 1.8) = σ(2.4) ≈ 0.92, the Bradley-Terry pairwise loss is L = −log(0.92) ≈ 0.09 nats — the reward model is fairly confident in the human's stated preference.
Reversing the score order, σ(1.8 − 4.2) = σ(−2.4) ≈ 0.08 gives the preference probability, so the loss is L = −log(0.08) ≈ 2.49 nats.
Treating the raw scores as unnormalized preference weights, 4.2/(4.2 + 1.8) = 0.70 is the preference probability, giving loss L = −log(0.70) ≈ 0.36 nats.
The preference probability is σ(2.4) ≈ 0.92, but since loss should fall as confidence rises, L = 1 − 0.92 = 0.08 nats is the pairwise loss.
Answer: A. Since σ(4.2 − 1.8) = σ(2.4) ≈ 0.92, the Bradley-Terry pairwise loss is L = −log(0.92) ≈ 0.09 nats — the reward model is fairly confident in the human's stated preference.
ExplanationThe Bradley-Terry model converts a reward difference into a probability via the sigmoid function: P(y_w ≻ y_l) = σ(r(x,y_w) − r(x,y_l)). Here the difference is 4.2 − 1.8 = 2.4, so P = σ(2.4) = 1/(1+e^{−2.4}). Since e^{2.4} ≈ 11.02, σ(2.4) = 11.02/12.02 ≈ 0.9168, which rounds to 0.92 — the reward model already places most of its probability mass on the human-preferred response. The pairwise loss is the negative log of this probability: L = −log(0.9168) ≈ 0.0868, which rounds to 0.09 nats. This small loss is exactly what you'd expect: the model already ranks y_w above y_l by a healthy margin, so gradient updates on this pair will be gentle.
Order matters critically in the Bradley-Terry formula — swapping which score is subtracted from which (as if y_l were the winner) flips the sigmoid to σ(−2.4) ≈ 0.08 and inflates the loss to about 2.49 nats, since the loss explodes whenever the model's stated preference contradicts the human label. Dividing one raw score by the sum of both scores is not how Bradley-Terry works at all — reward scores are unbounded real-valued logits, not weights that need to sum to one, so 4.2/(4.2+1.8) = 0.70 is a coincidental number with no basis in the actual loss function. Finally, confusing 1 minus the probability with the negative log-probability is a common slip: 1 − 0.92 = 0.08 happens to look close to the correct 0.09, but −log(p) is not the same function as 1 − p except in the limit p → 1, and computing it correctly is what makes the loss a steep penalty for miscalibrated confidence rather than a linear one.
Question 118 · Reproducing Research: From Paper to Code · hard
You are reproducing a paper that uses scaled dot-product attention (as in Vaswani et al.'s Transformer). For a single query q = [1, 1, 1, 1] with two candidate keys k1 = [1, 0, 0, 0] and k2 = [0, 1, 1, 1] (so d_k = 4), the paper specifies computing attention scores as (q · k_i) / √d_k before applying softmax. Which of the following correctly computes the resulting attention weights (rounded to two decimal places), and correctly identifies what happens if a re-implementation mistakenly omits the √d_k scaling before softmax?
Dividing by √d_k = 2 before softmax gives attention weights ≈0.27 (k1) and 0.73 (k2); skipping that scaling instead yields ≈0.12 (k1) and 0.88 (k2), a sharper, lower-entropy distribution, because the unscaled logit gap (3 − 1 = 2) is twice the scaled logit gap (1.5 − 0.5 = 1) that softmax exponentiates.
The paper's scaling by √d_k = 2 yields weights ≈0.27 (k1) and 0.73 (k2); removing it should instead flatten the distribution toward uniform, giving weights of roughly 0.38 (k1) and 0.62 (k2).
Because k1 aligns with more of the query's nonzero coordinates, correctly scaled weights come out to ≈0.73 (k1) and 0.27 (k2); omitting the √d_k scaling then gives ≈0.88 (k1) and 0.12 (k2).
Scaling the dot products by d_k = 4, as the formula requires, produces weights ≈0.38 (k1) and 0.62 (k2); omitting that scaling gives ≈0.12 (k1) and 0.88 (k2).
Answer: A. Dividing by √d_k = 2 before softmax gives attention weights ≈0.27 (k1) and 0.73 (k2); skipping that scaling instead yields ≈0.12 (k1) and 0.88 (k2), a sharper, lower-entropy distribution, because the unscaled logit gap (3 − 1 = 2) is twice the scaled logit gap (1.5 − 0.5 = 1) that softmax exponentiates.
ExplanationFirst compute the raw dot products: q · k1 = (1)(1)+(1)(0)+(1)(0)+(1)(0) = 1, and q · k2 = (1)(0)+(1)(1)+(1)(1)+(1)(1) = 3. Here d_k = 4, so √d_k = 2, and the paper's formula gives scaled scores 1/2 = 0.5 and 3/2 = 1.5. Applying softmax: e^0.5 ≈ 1.6487, e^1.5 ≈ 4.4817, sum ≈ 6.1304, giving weights 1.6487/6.1304 ≈ 0.269 and 4.4817/6.1304 ≈ 0.731 — rounded, 0.27 (k1) and 0.73 (k2).
Now consider a re-implementation that faithfully copies the dot products and the softmax but silently drops the 1/√d_k factor — a real and common paper-to-code bug, since nothing in the code throws an error when it's missing. The softmax then runs directly on scores 1 and 3: e^1 ≈ 2.7183, e^3 ≈ 20.0855, sum ≈ 22.8038, giving weights 2.7183/22.8038 ≈ 0.119 and 20.0855/22.8038 ≈ 0.881 — rounded, 0.12 (k1) and 0.88 (k2).
The direction of the effect matters and is easy to get backwards: because softmax is exponential, it amplifies whatever gap exists between the input scores. The scaled scores sit 1.0 apart (0.5 vs 1.5); the unscaled scores sit 2.0 apart (1 vs 3). The larger gap pushes softmax's output closer to a one-hot vector, so omitting the scaling makes the distribution sharper and more overconfident, not flatter — exactly the failure mode Vaswani et al. (2017) cite as their motivation for the √d_k divisor, since large-magnitude dot products push softmax into saturated regions with near-zero gradients. This is why reproducing a paper's stated architecture is not enough: an implementation that gets the mechanism "basically right" but drops one normalization constant can still diverge sharply and silently from the reported behavior, which is precisely the class of bug the paper-to-code reproduction process is meant to surface.
Question 119 · Distributed Training: Multi-GPU and Multi-Node · hard
A research team at an IIT trains a 250-million-parameter transformer entirely in FP32 (4 bytes per parameter) across 8 GPUs on a single node, using data parallelism with ring all-reduce to synchronize gradients after every step. Each GPU's forward-and-backward compute pass takes 300 ms, and the ring interconnect delivers 20 GB/s per link (1 GB = 10^9 bytes), with compute and communication happening strictly one after another (no overlap). Using the standard ring all-reduce communication-volume formula — 2(N-1)/N times the gradient size per GPU — what is the total wall-clock time for one training step?
650 ms, treating gradient synchronization as a naive all-to-all where each GPU transmits its full 1 GB gradient directly to all 7 peers
343.75 ms, counting only the reduce-scatter phase of the ring and omitting the all-gather phase that follows it
387.5 ms, combining the 300 ms compute pass with 87.5 ms of ring all-reduce communication at 2(N-1)/N times the gradient size
350 ms, assuming a single 1 GB message equal to the full gradient is transmitted once regardless of the ring's chunked structure
Answer: C. 387.5 ms, combining the 300 ms compute pass with 87.5 ms of ring all-reduce communication at 2(N-1)/N times the gradient size
ExplanationThe gradient tensor holds 250,000,000 parameters at 4 bytes each (FP32), giving M = 1,000,000,000 bytes = 1 GB. Ring all-reduce runs in two chained phases across the N = 8 GPUs — a reduce-scatter, where each GPU passes (N-1)/N of the tensor around the ring so every GPU ends up holding the fully-reduced sum of one N-th of the gradient, followed by an all-gather, where that same volume circulates again so every GPU ends up with the complete reduced tensor. Each phase moves (N-1)/N × M per GPU, so across both phases the total data a single GPU sends is 2(N-1)/N × M. With N = 8, (N-1)/N = 7/8, so the total is 2 × 7/8 × 1 GB = 1.75 GB. At 20 GB/s, moving 1.75 GB takes 1.75/20 = 0.0875 s = 87.5 ms. Since compute and communication are sequential here (no overlap), the total step time is the 300 ms compute pass plus the 87.5 ms communication phase: 300 + 87.5 = 387.5 ms.
The distractors correspond to specific, common errors in reasoning about collective communication cost. Modeling synchronization as a naive all-to-all — where each GPU ships its entire 1 GB gradient directly to each of the other 7 GPUs rather than using the ring's chunked, bandwidth-optimal pattern — overstates the traffic to (N-1) × M = 7 GB, giving a much larger 650 ms; this is exactly the inefficiency ring all-reduce is designed to avoid, since its cost stays bounded near 2M regardless of how large N grows, instead of scaling linearly with N. Counting only the reduce-scatter half of the ring and forgetting that the all-gather half must also run to redistribute the fully-reduced result back to every GPU undercounts the traffic as (N-1)/N × M = 0.875 GB, giving 343.75 ms. Assuming a single full-size message of M = 1 GB is transmitted once, as if the ring's multi-step chunked transfer were irrelevant, gives 350 ms — this misses that ring all-reduce moves data in N equally-sized chunks across 2(N-1) pipelined steps rather than sending the whole tensor in one shot.
Question 120 · India's AI Policy: National Strategy and Implementation · hard
India's IndiaAI Mission (approved by the Union Cabinet in March 2024, outlay of roughly Rs 10,372 crore over five years) sits alongside NITI Aayog's 2018 #AIforAll strategy, yet neither has produced a standalone, horizontal AI statute comparable to the EU AI Act's risk-tiered framework. Which statement most precisely explains India's actual regulatory posture toward AI as of the IndiaAI Mission's launch?
India deliberately adopted a principle-based, sector-agnostic approach, extending existing instruments—the IT Act 2000, its 2023 IT Rules amendment mandating labelling of synthetic/deepfake content, and the Digital Personal Data Protection Act 2023—through sectoral regulators like RBI, SEBI and TRAI, judging that a fast-evolving technology is better governed by adaptable rules than a fixed omnibus law that could quickly go obsolete and deter domestic AI firms from scaling.
India passed the Digital India Act in 2023 as its comprehensive, AI-specific law, replicating the EU AI Act's classification of systems into unacceptable, high, limited and minimal risk tiers with binding compliance obligations at each level.
The IndiaAI Mission itself operates as India's binding AI regulatory statute, with the Ministry of Electronics and IT empowered to issue legally mandatory safety certifications that every AI model must obtain before commercial deployment in India.
India has placed AI entirely outside existing legal obligations, since the government has formally exempted AI-related data processing and content from the IT Act and the Digital Personal Data Protection Act until a dedicated AI law is enacted.
Answer: A. India deliberately adopted a principle-based, sector-agnostic approach, extending existing instruments—the IT Act 2000, its 2023 IT Rules amendment mandating labelling of synthetic/deepfake content, and the Digital Personal Data Protection Act 2023—through sectoral regulators like RBI, SEBI and TRAI, judging that a fast-evolving technology is better governed by adaptable rules than a fixed omnibus law that could quickly go obsolete and deter domestic AI firms from scaling.
ExplanationIndia's stated posture, reiterated by MeitY through the IndiaAI Mission's rollout, is "pro-innovation, light-touch" governance rather than a new omnibus AI law. Instead of writing AI-specific legislation, the government leans on instruments already in force: the IT Act 2000 and its 2023 IT Rules amendment (which requires platforms to label AI-generated synthetic content and obtain user declarations for deepfake-capable tools), and the Digital Personal Data Protection Act 2023 for AI systems that process personal data—with sector regulators such as RBI (for AI in lending/fintech), SEBI (for algorithmic trading) and TRAI (for telecom AI applications) handling domain-specific risks. The reasoning is explicit in policy statements: AI capabilities are changing too fast for a fixed, horizontal statute to stay relevant, and a heavy new law risks slowing the domestic AI industry the IndiaAI Mission's Rs 10,372-crore outlay is meant to build up. The Digital India Act, which would replace the IT Act 2000, remained in draft/consultation stages rather than being enacted, and critically it was never framed as an AI-specific, EU-style risk-tiered statute—so describing it as a passed comprehensive AI law misrepresents both its status and its content. The IndiaAI Mission is a funding-and-implementation programme (covering compute infrastructure, datasets, skilling, startup financing, and a "Safe & Trusted AI" pillar for tools like bias-detection frameworks), not a licensing authority with statutory power to certify or block model deployment. And far from exempting AI from existing law, both the IT Act and the DPDP Act already apply to AI-driven data processing and online content today.