How Much Determinism Can Fine-Tuning Buy? Margin Regularisation Against Batch-Induced Token Flips

Charan Teja Nagisettygari, Siva Raja SindiramuttyarXiv 2026

TL;DR

Greedy decoding in LLMs is often assumed to be deterministic, but batching prompts during inference introduces floating-point noise that can "flip" the chosen token. This paper demonstrates that we can reduce these flips by ~35% during training by using a margin regularization (hinge loss) to widen the gap between the top two token candidates, albeit at a small cost to task accuracy.

What Problem Does This Paper Address?

In theory, setting an LLM's temperature to zero should make its output perfectly reproducible. In practice, if you run the same prompt alone versus as part of a batch, you might get different results.

This happens because floating-point addition is non-associative: $(a + b) + c$ does not always equal $a + (b + c)$. High-performance GPU kernels change the order of operations depending on the "shape" of the data (e.g., batch size or sequence length). These tiny numerical differences—often in the last representable bits—can shift the logits just enough to change which token wins the "argmax" race if the top two choices are very close. This "non-determinism" breaks regression suites, LLM-as-judge workflows, and distillation loops.

While current solutions (like batch-invariant operators) work at inference time, they often come with a 2x slowdown. The authors ask: Can we instead train the model to be more "decisive" so it is naturally resistant to this noise?

Methods

The authors propose a training-time intervention called Margin Regularisation.

  1. Characterization: They first measured the "noise" ($\delta$) produced by batching across different precisions (fp32, fp16, bf16). They found that the noise scales exactly with the number of mantissa bits in the format (e.g., bf16 has 8x the noise of fp16).
  2. Hinge Loss: They added a penalty term to the standard cross-entropy loss. This term penalizes the model if the gap between the top-1 and top-2 logits is smaller than a specific margin $m$: $$L = L_{CE} + \lambda \cdot \max(0, m - (logit_1 - logit_2))$$
  3. Calibration: Rather than tuning $m$ as a hyperparameter, they set it to twice the 99.9th percentile of the measured hardware noise ($2 \times Q_{0.999}$). This ensures the model is pushed to create a gap wide enough to "swallow" the hardware-induced perturbations.

Datasets

  • WikiText-2: Used for initial characterization and profiling of the logit perturbations.
  • GSM8K: The primary benchmark for evaluating reasoning and determinism.
  • MBPP (Mostly Basic Python Problems): Used as an out-of-domain check for code generation.
  • CodeParrot: Used for additional cross-corpus transfer testing.

Key Insights and Ideas

  • The Precision Rule: The scale of batch-induced noise is a hardware constant. It doesn't depend on model confidence or sequence position; it depends almost entirely on the numerical precision (float16 vs. bfloat16).
  • Accidental Determinism: The authors discovered that certain tensor shapes (like a sequence length of 512 on specific CUDA kernels) are "accidentally" batch-invariant. A researcher testing only at that length might wrongly conclude their model is perfectly deterministic.
  • Decisiveness vs. Correctness: The hinge loss doesn't care which token is correct; it only cares that the model chooses one decisively. However, they found that hinging on the model's own top choice works better than hinging on the "correct" label, as the latter can actually create new near-ties.
  • The Worst-Case is Fixed: Margin training makes flips less frequent, but it doesn't move the "noise ceiling." The maximum possible perturbation remains the same because it is a property of the hardware, not the weights.

Key Results

  • Flip Reduction: On the GSM8K dataset, the method led to a 35% reduction in token flips.
  • Sequence Divergence: The percentage of generated sequences that differed between batch sizes dropped from 53.8% to 38.1%.
  • Accuracy Trade-off: This increased determinism comes at a cost of 1.3 to 2.9 accuracy points on GSM8K. The authors note that accuracy decreases monotonically as the margin increases.
  • Efficiency Peak: Across multiple model families (Qwen, Llama, OPT), the "efficiency" (determinism gained per unit of perplexity lost) consistently peaked when the margin was set to exactly twice the measured noise quantile.

Limitations and Future Work

  • Model Scale: Due to hardware constraints (22GB VRAM), full fine-tuning was limited to models under 0.5B parameters, though the authors verified that the noise characterization holds true for 7B models.
  • Hardware Specificity: The results are primarily based on NVIDIA Turing and Ada architectures. The authors found that Apple's Metal (MPS) was actually bit-identical across batch sizes for the same operations, suggesting this is an implementation choice in CUDA/cuBLAS rather than an inevitability of math.
  • Domain Sensitivity: The benefits of margin training are largely in-domain. A model trained for determinism on GSM8K does not necessarily show the same improvements when switched to a coding task (MBPP).
  • Unexplained Failures: Some model families (like GPT-2 and Pythia) did not benefit from the technique for reasons the authors could not fully explain, marking this as a key area for future research.

Summary updated

Abstract

Greedy decoding at zero temperature is widely assumed to be deterministic, although the exact same prompt may yield different tokens depending on the number of other prompts sharing the batch for inference. The currently available solutions operate during inference, trading determinism for throughput. Can we train a model in such a way that fewer decoding steps would be susceptible? We characterize the perturbation empirically across six model families and three numerical precisions and observe two empirical facts about the measurement: the perturbation depends exactly on the representable precision (8.00x for bfloat16 vs float16, 8192.0x for float16 vs float32, in line with predictions based on mantissa bits) and the batch invariance happens accidentally at certain tensor shapes, allowing a practitioner to achieve zero nondeterminism merely by setting the sequence length. Then we apply hinge penalization of the model's top-1 / top-2 logit gap, scaled to twice the measured noise quantile. On GSM8K dataset it leads to a 35% reduction in token flips and divergence from 53.8% to 38.1%, at the cost of 1.3 - 2.9 accuracy points, increasing monotonically with the margin size. It does not affect the gap threshold sufficient for determinism: the logit gaps of surviving flips are unchanged (median 0.125 for all arms), as the hinge is a soft penalty and the largest hardware perturbation remains the same. We reject seven hypotheses, including a per-model viability diagnosis, holding on six models and falsified on the seventh.
BibTeX
@misc{nagisettygari2026how,
  author = {Charan Teja Nagisettygari and Siva Raja Sindiramutty},
  title = {{How Much Determinism Can Fine-Tuning Buy? Margin Regularisation Against Batch-Induced Token Flips}},
  year = {2026},
  eprint = {2611.19135},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.19135},
}
Figure