Skip to content
AI.info

Training and optimization

Randomness, Seeds, and Reproducible Comparisons

Trace sources of stochasticity, distinguish repeatability from reproducibility, and design comparisons that report uncertainty and implementation state.

By the end you can

Visual

A seed controls only the random streams it actually reaches

Training can vary through several independent mechanisms, and a seed reaches only some of them. The data pipeline, the model, the kernels underneath, the ordering of distributed workers, and the software and hardware the whole thing runs on each carry their own randomness or nondeterminism.

The layers are not ranked by size. Four of them were measured separately on CIFAR-10 and came out almost indistinguishable: an accuracy standard deviation of 0.23% for parameter initialization, 0.25% for data shuffling, 0.23% for data augmentation and 0.22% for cuDNN kernel nondeterminism. Summers and Dinneen ran that comparison. This is a stack, not a hierarchy. Pinning the top layer leaves the others moving by about as much.

FigureLayers · 5 layers
  1. 01

    Data randomness

    Shuffle order, augmentation parameters, sampling, and worker processes.

  2. 02

    Model randomness

    Initialization, dropout, routing, stochastic depth, and generation.

  3. 03

    Kernel behavior

    Parallel reductions, atomic operations, and algorithm selection can be nondeterministic.

  4. 04

    Distributed timing

    Worker order, communication, and failure recovery can alter execution.

  5. 05

    Environment state

    Libraries, drivers, hardware, compiler flags, and precision policies change results.

Comparison

Three levels of evidence from training runs

Each level answers a different question. The middle two are not this lesson's private vocabulary — the US National Academies fixed them in 2019, and NISO attached separate badges to them in 2021. The definitions section below sets both out.

The cost gap between the levels is real and measurable. Picard's controlled rerun of a single CIFAR-10 configuration took 10,000 runs and roughly 83 V100-hours. MLPerf's rules settle for 5 runs on vision tasks and 10 on everything else. The level you can afford determines the claim you are entitled to make.

FigureComparison · 3 columns

Deterministic replay

Attempt the same operations with the same states and deterministic kernels.

  • Purpose: debug a trajectory
  • Strength: local comparison
  • Cost: slower kernels possible
  • Limit: environment-specific

Controlled rerun

Repeat the protocol with fresh seeds in the same environment.

  • Purpose: estimate run variance
  • Strength: statistical evidence
  • Cost: multiple trainings
  • Limit: one implementation stack

Independent reproduction

Reimplement or rerun from documented data, code, and protocol.

  • Purpose: test portability
  • Strength: broader confidence
  • Cost: high
  • Limit: unavoidable implementation differences

Key idea

Deterministic kernels can improve debugging while changing performance

Some deterministic algorithms are slower, use more memory, or differ numerically from faster nondeterministic kernels. Turning them on means the run executes differently. Use deterministic modes deliberately for diagnosis and critical comparisons, and do not assume the resulting throughput or trajectory matches production training.

Most training runs pass through PyTorch and through NVIDIA's libraries. Neither vendor will promise you the same bits twice. PyTorch's reproducibility note opens with the refusal: “Completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms”. It adds that results “may not be reproducible between CPU and GPU executions, even when using identical seeds”. The same page names cuDNN convolution benchmarking as a source of run-to-run nondeterminism. The benchmarking step, not the seed, decides which algorithm runs. A warning box on that page then prices the alternative: “Deterministic operations are often slower than nondeterministic operations, so single-run performance may decrease for your model.”

NVIDIA is more precise about how narrow its guarantee is. cuBLAS promises the same bit-wise results from run to run only within a single toolkit version, on GPUs of the same architecture with the same number of SMs. Outside that box it lapses: “bit-wise reproducibility is not guaranteed across toolkit versions because the implementation might differ due to some implementation changes”. It also stops holding with multiple concurrent CUDA streams, with fixed-point emulation, or when cublasSetAtomicsMode() selects the faster atomics-based routines.

Read those conditions backwards. They are a specification of everything a seed does not pin: the toolkit version, the GPU architecture, the SM count, the number of streams, and the atomics mode.

Determinism is an experimental setting with costs, not a moral property of a run.

Steps

Create a reproducible training record

Capture the state needed to interpret both success and failure: data identity, software identity, training state, random-stream policy, and the per-seed results including the runs that failed.

The record is what makes a range reportable instead of a mean. A spread of 1.82 points on CIFAR-10 was a statement Picard could make only because he kept the results of all 10,000 seeds rather than the best of them. A standard deviation of validation performance of 0.061 on MRPC, 0.069 on RTE and 0.101 on CoLA was a statement Dodge and his co-authors could make only because they kept 2,100 fine-tuning runs. A record that stores only the winning checkpoint can report neither number. A paper written from that record has nothing to put after its mean.

FigureProcess · 5 steps
  1. 1. Freeze data identity

    Record snapshots, splits, sampling, and preprocessing versions.

  2. 2. Freeze software identity

    Record source commit, dependencies, compiler, drivers, and framework flags.

  3. 3. Store training state

    Save model, optimizer, scheduler, scaler, sampler, and counters where continuation matters.

  4. 4. Record random streams

    Log seeds and worker initialization policies without claiming they control everything.

  5. 5. Report variation

    Publish per-seed results, summary statistics, failed runs, and selection rules.

Example

Seed studies should target the decision, not a ritual number

The appropriate design depends on cost and expected variability. Two papers have measured what happens when the number of seeds is chosen by habit instead.

Ten runs of TRPO on HalfCheetah-v1, identical hyperparameters, nothing varying but the random seed. Split them into two groups of five, average each group's learning curve, and the two halves of one identical experiment come out statistically different. The Figure 5 caption reads: “The average 2-sample t-test across entire training distribution resulted in t = −9.0916, p = 0.0016.” Five seeds against five seeds, same code, same hyperparameters, and the standard test says these are two different methods. Henderson and his co-authors ran that experiment, and their 2018 AAAI paper states the problem plainly: “non-determinism in standard benchmark environments, combined with variance intrinsic to the methods, can make reported results tough to interpret”.

Atari 100k later got the same treatment at 100 runs per game, against published results on that benchmark that had mostly used 3 or 5. For SPR the median score difference between 5 runs and 100 runs was +0.03 points, about 36% of the improvement SPR had reported over DrQ(ε). The few-run number and the improvement it claims are of the same order. The 95% confidence intervals on sample medians only tightened at 50 to 100 runs. Agarwal and his co-authors did that work.

More is not automatically the answer. Bouthillier and his co-authors modelled the whole benchmarking process and supply the counterweight: “a biased estimator with more source of variation will give better results, closer to the ideal estimator at a 51× reduction in compute cost”. Spread the budget across the sources of variation before spending it all on repetitions of one.

  • Cheap model: Picard's 10,000 CIFAR-10 seeds cost about 83 V100-hours at roughly 30 seconds a run. At that price, estimate the distribution and report an interval for the primary metric rather than a number.
  • Expensive pretraining: use several smaller proxy runs, then repeat a limited number of full-budget finalists. A wider spread of variation sources reached the ideal estimator at a 51× reduction in compute cost.
  • Close comparison: increase seeds. Five against five was enough to separate two halves of one identical TRPO experiment at t = −9.0916, p = 0.0016.
  • Safety slice: report counts and intervals even when the overall metric appears stable. On Atari 100k the 95% intervals on sample medians needed 50 to 100 runs before they settled.
  • Hyperparameter winner: rerun the selected configuration. Seed search alone lifted BERT's RTE validation score from the published 70.0/70.4 to 77.3, which is what selecting a lucky trajectory looks like from the outside.

Repeatability and robust conclusions are different goals

Exact repeatability asks whether the same environment and state reproduce the same result. The next term up is not this lesson's coinage. In 2019 the US National Academies of Sciences, Engineering, and Medicine fixed it in their report Reproducibility and Replicability in Science, in a numbered conclusion: “For this report, reproducibility is obtaining consistent results using the same input data; computational steps, methods, and code; and conditions of analysis.” Replicability, in the same conclusion, is the different thing — consistent results across studies that each collected their own data.

NISO adopted that definition verbatim in 2021, in its recommended practice on reproducibility badging. It quotes the definition as “We define reproducibility to mean computational reproducibility—obtaining consistent results using the same input data, computational steps, methods, code, and conditions of analysis”, and attaches it to the ROR-R “Results Reproduced” badge. The separate RER “Results Replicated” badge is reserved for an independent study aimed at the same scientific question. Two badges, because they certify two different claims.

Statistical robustness is a third question again: whether the conclusion survives ordinary stochastic variation. A bitwise repeatable run can still support a fragile claim based on one seed. No badge is awarded for that.

Reproducing one trajectory is not the same as reproducing the conclusion.

Repeating a recipe in another kitchen

Written down, a recipe fixes ingredients, temperatures, tools, and timing, and nothing else. Another kitchen may produce a similar dish without identical molecules or oven fluctuations.

That is the distinction worth keeping, and it is the same one the National Academies wrote into their conclusion and NISO turned into two badges. Exact replay is one claim. A reproducible method is a second. A conclusion that survives ordinary variation is a third. A training record should say which of the three it supports. A reader who is told only that the code runs has been told the weakest of the three.

A useful record explains which variation was controlled and which conclusion survived it.

Paired comparisons can reduce noise when designed correctly

Using matched data order and corresponding seeds can make differences between two methods easier to detect. The pairing must preserve valid independence assumptions for the analysis.

Separating the factors on purpose looks like this. BERT was fine-tuned 2,100 times across four GLUE tasks — 625 runs each on MRPC, RTE and CoLA, laid out as a 25 × 25 grid of weight-initialization seeds against data-order seeds, and 225 on SST. Nothing varied but the seed controlling the data order and the seed controlling the final classification layer, which holds 0.0006% of the model's parameters. Those two seeds moved validation performance by a standard deviation of 0.061 on MRPC, 0.069 on RTE and 0.101 on CoLA, with weight initialization and data order contributing comparably. The grid is what makes that last statement measurable rather than assumed. Seed search alone raised BERT's RTE validation score from the published 70.0/70.4 to 77.3. Dodge and his co-authors published all of it in 2020.

What is at stake in an unpaired comparison is the ranking itself. Reimers and Gurevych evaluated 50,000 LSTM networks over five sequence-tagging tasks in 2017, and found the seed alone producing statistically significant differences (p < 10⁻⁴). Their abstract puts the consequence in one sentence: “For two recent systems for NER, we observe an absolute difference of one percentage point F1-score depending on the selected seed value, making these systems perceived either as state-of-the-art or mediocre.”

Case

Ten thousand seeds, and how easily one of them flatters a method

Almost nobody runs the experiment David Picard ran. A 9-layer ResNet on CIFAR-10, trained once per seed, 10,000 times, at about 30 seconds a run and roughly 83 V100-hours in total, with nothing changing between runs but the seed. His paper reports the two ends of the distribution: “The interesting values of this test are the minimum and maximum accuracy among all run (obtained at the end of training), which is this case go from 89.01% to 90.83%, that is, a 1.82% difference.” His conclusion was that “it is surprisingly easy to find an outlier”, and the outlier sits at either end. A method published at 90.83% and a method dismissed at 89.01% can be the same method under two seeds. On ImageNet, where every run started from the same pretrained ResNet-50, a residual gap of about 0.5 points remained.

The seed is not even a privileged source of that spread. In 2021 Summers and Dinneen trained 700 ResNet-14 models on CIFAR-10, 100 runs per source of nondeterminism, and set the sources side by side as accuracy standard deviations: parameter initialization 0.23%, data shuffling 0.25%, data augmentation 0.23%, cuDNN kernel nondeterminism 0.22%, and all sources together 0.26%. Nondeterministic kernels alone move the result about as much as reinitialising the entire network. Switching every source on at once barely moves it further. Two models differing in nothing but cuDNN nondeterminism disagreed on roughly 10.5% of test examples. A change of about 6·10⁻¹¹ to a single initial weight produced nearly as much variability as all the other sources combined.

So the outlier is not a seed problem to be fixed by a better seed. It is the size of the noise floor. Any reported difference smaller than it is a claim about the noise floor.

Reproduction begins with evidence, not a seed

Do not discard runs because one method fails under a seed. Failure rate is part of the method's robustness and should be reported.

An industry benchmark body has written exactly that into its rulebook. MLPerf fixes the run count in advance: “Vision tasks require 5 runs to ensure 90% of entries from the same system are within 5%; all other tasks require 10 runs to ensure 90% of entries from the same system are within 10%.” The score is then computed by dropping the fastest and the slowest time and taking the arithmetic mean of the rest. Mattson and colleagues, describing the benchmark in 2020, record that for MiniGo the authors saw considerable variability across runs even with the random seed fixed.

The current MLCommons training rules keep the scheme and set a minimum number of runs per benchmark: 3 for LLM MoE pretraining; 10 for text-to-image, small-LLM pretraining, LLM fine-tuning and recommendation; and 40 for the deprecated medical image-segmentation benchmark. The same drop-fastest-and-slowest scoring survives. The submission score is “intended to represent the median expected result across a large number of runs”, and non-convergence is handled by rule rather than by discretion: one non-converging run may be treated as the slowest and dropped, while more than one invalidates the result.

That is the failure rate written into the scoring. The run count is chosen before the runs. The outliers are trimmed by a rule that applies to both ends. And the second failure costs the submission rather than being quietly excluded.

A fair comparison includes the distribution of outcomes and the probability of failure.

Key takeaways