EXPERIMENTATION & A/B TESTING · INTERVIEW QUESTION
How do you ensure reproducible experiments with LLMs?
🟡 intermediate · Advanced Experimentation
Hint: Fix seeds, pin dependencies, checkpoint models, log everything.
Answer
Reproducibility requires fixed data, code, model/tokenizer versions, prompts, decoding settings and a recorded compute environment, in addition to random seeds. Mutable APIs and different hardware may prevent bit-for-bit replay.
Interview reasoning
Seed and deterministic-operation setup
Run environment configuration before initializing CUDA. This example favors determinism over speed and may raise an error for unsupported deterministic operations.
import os
os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"
import random
import numpy as np
import torch
def set_seed(seed=42):
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
if torch.cuda.is_available():
torch.cuda.manual_seed_all(seed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
torch.use_deterministic_algorithms(True)
set_seed()Pin dependencies and retain code/data hashes, generated outputs and evaluator versions. Checkpoints should include model, optimizer, scheduler, random-number-generator and data-loader position state. Test resumed versus uninterrupted runs and report variation across seeds where it affects the conclusion. Identical seeds do not guarantee identical results across platforms or library releases.
LLM experiment results depend on data, prompts, model versions, decoding and compute budget. Preserve run manifests and artifacts; compare candidates on untouched task evaluations with cost and safety constraints. Expensive tuning should use staged smaller-budget evidence and repeated seeds or prompts where variation affects the conclusion.
Worked example. Record checkpoint, tokenizer, prompt, dataset hash, random seeds and decoding settings for an exact attempted rerun. Save generated outputs and evaluator versions so a later model API or evaluator update cannot silently rewrite the original evidence.
Validation
Recreate selected runs, verify comparable evaluation inputs and budget accounting, and check sensitivity to stochastic generation. Test resumed versus uninterrupted runs with the saved optimizer, scheduler and data-position state. Retain failed trials and selection criteria so the winning run can be reviewed in the context of the complete search.
Common pitfalls
A tracking dashboard does not prevent test-set overfitting. Identical seeds do not reproduce mutable APIs or overwritten datasets.
Related questions
- What is CUPED and how does it reduce variance in A/B tests?
- What is experiment tracking (MLflow, W&B) and why is it important for LLM projects?
- How do you approach hyperparameter tuning for large LLMs given the huge training cost?
- What is a p-value? Common misconceptions?
- What is the difference between statistical significance and practical significance?