[KongchangAI]
· 2 min read· 1,312 words

Can Fine-Tuning Make Reasoning Deterministic? A Boundary Regularization Experiment on Batch-Induced Token Flips

Can Fine-Tuning Make Reasoning Deterministic? A Boundary Regularization Experiment on Batch-Induced Token Flips

The study finds that batch processing causes non-determinism in zero-temperature greedy decoding, and reduces token flips by 35% through boundary regularization fine-tuning.

This article explores batch-induced non-determinism in zero-temperature greedy decoding. The authors systematically measure perturbations across models and numerical precisions, finding they depend precisely on floating-point mantissa bits (bfloat16 vs float16: 8×; float16 vs float32: 8192×). They also find batch invariance occurs accidentally under certain tensor shapes, enabling determinism by adjusting sequence length alone. To mitigate the issue, they apply a hinge penalty to the top-1/top-2 logit gap during fine-tuning, reducing GSM8K token flips by 35% (divergence rate 53.8%→38.1%) at the cost of 1.3-2.9 accuracy points. The method cannot eliminate the largest hardware-induced flips, and full determinism still requires inference-stage strategies.

Greedy decoding at zero temperature is generally considered deterministic, yet the same prompt can produce different tokens across different batches. This batch-induced non-determinism is a thorny foundational problem when pursuing reproducible reasoning. A recent study systematically measured this perturbation and attempted to reduce its impact through boundary regularization during fine-tuning.

Research source screenshot

Why Batch Processing Causes Non-Determinism

During inference, to improve throughput, multiple prompts are typically grouped into a batch and computed simultaneously. Due to different tensor operations and numerical precision, the same prompt may yield different logits under different batch sizes, which in turn causes greedy decoding to select different tokens. Existing solutions mostly intervene at the inference stage, for example by enforcing batch invariance, but this often comes at the cost of throughput.

This study proposes a new angle: can training make the model more robust to such noise, thereby reducing the sensitivity of the decoding step?

Greedy decoding is the most direct decoding strategy when language models generate text: at each time step, the model outputs a probability distribution over the vocabulary (or unnormalized logits), and greedy decoding directly selects the token with the highest probability (largest logit) as the output. Its name comes from choosing the most likely word at each step locally optimally, without considering future effects. Under the zero-temperature setting (temperature=0), sampling is disabled, so greedy decoding is often considered fully deterministic—given the same input and model weights, the output should always be consistent. However, this determinism assumption holds only when the computation process is fully reproducible. In actual inference, due to the non-associativity of floating-point arithmetic, different hardware instruction sets, and tensor shape changes caused by batching, logits produce tiny perturbations. When the logit gap (margin) between the top-1 and top-2 tokens is very small, these perturbations are enough to change the position of the maximum, causing the output token to flip. Therefore, the "determinism" of greedy decoding is conditional in nature, depending on the precise consistency of the computation graph.

Measured Perturbations: The Surprising Impact of Precision and Shape

The authors characterized perturbations across six model families and three numerical precisions. Two key empirical findings are:

  • Perturbations depend precisely on representable precision: the perturbation of bfloat16 relative to float16 is 8.00×, and that of float16 relative to float32 is 8192.0×, consistent with predictions based on mantissa bits.
  • Batch invariance occurs accidentally under certain tensor shapes, and practitioners can achieve zero non-determinism simply by setting the sequence length.

This means that merely adjusting the sequence length may unexpectedly yield deterministic inference without any algorithmic changes.

bfloat16 (BF16) and float16 (FP16) are two commonly used 16-bit floating-point formats, but with different bit allocations. FP16 uses 1 sign bit, 5 exponent bits, and 10 mantissa bits, offering a narrower dynamic range but higher precision; BF16 uses 1 sign bit, 8 exponent bits, and 7 mantissa bits, offering the same dynamic range as FP32 but lower precision. The number of mantissa bits directly determines the representable precision, which in turn affects rounding errors in numerical operations. The statement in the text that "perturbations depend precisely on representable precision" stems from this: BF16 has 3 fewer mantissa bits than FP16, so its relative perturbation is approximately 2^3=8× that of FP16; FP16 has 13 fewer mantissa bits than FP32, so its relative perturbation is approximately 2^13=8192× that of FP32. These multiples are fully consistent with theoretical predictions based on mantissa bits, indicating that the main source of batch non-determinism is floating-point rounding error rather than algorithmic logic. Understanding this helps practitioners choose expected perturbation levels based on precision and explains why low-precision inference is more prone to token flips.

Boundary Regularization: Narrowing the Logit Gap with a Hinge Penalty

Since the perturbation depends on the gap (margin) between the model's top-1 and top-2 logits, a natural idea is: during training, encourage the model to increase this gap so that even in the presence of noise, the top-1 token is not easily flipped.

The authors adopt a hinge penalization on the top-1/top-2 logit gap, with the penalty scale set to twice the measured noise quantile. On the GSM8K dataset, this method reduces token flips by 35%, and the divergence rate drops from 53.8% to 38.1%, at the cost of a 1.3 to 2.9 percentage point drop in accuracy, with the accuracy loss increasing monotonically with the margin size.

The method does not affect the gap threshold needed to achieve determinism: the logit gap of surviving flips remains unchanged (the median is 0.125 across all experimental groups), because the hinge penalty is a soft penalty and the largest hardware perturbations still exist.

Hinge penalization originates from the hinge loss in support vector machines, with the form max(0, margin - (score_pos - score_neg)), which produces a penalty when the score gap between the correct class and the incorrect class is less than a preset boundary, and zero otherwise. In this study, the authors treat the top-1 token as the "correct class" and the top-2 token as the "competing class," applying a hinge penalty to their logit gap: if the gap is less than a certain threshold (determined by the measured noise quantile), a loss is incurred; if the gap is already large enough, no penalty is applied. This design is "soft" because it only pushes the model to increase the critical margin without forcing all samples to reach a fixed gap, thereby avoiding excessive sacrifice of accuracy. The penalty scale is set to twice the noise quantile, meaning the training objective is to keep top-1 stable even under typical noise levels. The softness of the hinge penalty also explains why the median logit gap of surviving flips remains unchanged (0.125): it cannot eliminate extreme hardware perturbations, only reduce edge cases.

Hypothesis Testing and Model Adaptability

The study also rejects seven hypotheses, including a per-model feasibility diagnostic that holds for six models and is falsified on the seventh. This indicates that the method is not applicable to all models, and differences between models need to be carefully examined.

Practical Implications and Limitations

The value of this work lies in providing an actionable framework to quantify batch non-determinism and exploring mitigation approaches at the training stage. However, boundary regularization can only reduce flips; it cannot completely eliminate non-determinism caused by hardware perturbations. For scenarios requiring absolute determinism, it may still be necessary to combine inference-stage batch invariance strategies.

Additionally, the trade-off between accuracy and determinism needs to be weighed according to the application scenario: if the task is extremely sensitive to accuracy, larger margin penalties may need to be used cautiously.

Conclusion

Batch-induced token flips are an easily overlooked source of non-determinism in zero-temperature decoding. By measuring the relationship between perturbation and precision and using boundary regularization for fine-tuning, flips can be significantly reduced at the cost of a small amount of accuracy. However, achieving full determinism still requires coordinated improvements in hardware and inference strategies.

One-line Summary

The study finds that batch processing causes non-determinism in zero-temperature greedy decoding, and reduces token flips by 35% through boundary regularization fine-tuning.

Paragraph Summary

This article explores the non-determinism phenomenon caused by batch processing in zero-temperature greedy decoding. The authors systematically measure perturbations across different models and numerical precisions, finding that perturbations depend precisely on floating-point mantissa bits: bfloat16 perturbation relative to float16 is 8×, and float16 relative to float32 is 8192×. The study also finds that batch invariance occurs accidentally under certain tensor shapes, and determinism can be achieved by merely adjusting the sequence length. To mitigate the problem, the authors propose applying a hinge penalty to the top-1/top-2 logit gap during fine-tuning, reducing token flips by 35% on GSM8K and lowering the divergence rate from 53.8% to 38.1%, but at the cost of 1.3-2.9 accuracy points. The method cannot eliminate the largest flips caused by hardware perturbations, and full determinism still requires inference-stage strategies.

#greedy decoding#non-determinism#batch processing#token flips#boundary regularization#fine-tuning#numerical precision#floating-point#GSM8K#reproducibility
Share:

Related articles