TL;DR
Even when model weights and input text are identical, a classifier’s prediction can change depending on "serving context" factors like batch size, padding, and numerical precision. This paper systematically quantifies this nondeterminism, revealing that common optimizations for speed—like dynamic padding and reduced precision—can flip labels and significantly shift probability scores, especially in generative-style classifiers.
What Problem Does This Paper Address?
In the world of production machine learning, we often assume that a fixed model checkpoint plus a fixed input equals a fixed output. However, researchers have recently noted that Large Language Models (LLMs) are "nondeterministic" during text generation: changing the batch size or the hardware can result in different generated strings.
This paper asks a critical follow-up: Does this nondeterminism affect text classification? If a sentiment analyzer or content moderation filter changes its mind just because it was processed in a larger batch or on a different GPU, it undermines the reliability and trustworthiness of the entire system. The authors aim to move beyond aggregate metrics like Accuracy or F1—which hide these individual "flips"—to understand the mechanisms and magnitude of serving-context sensitivity.
Methods
The authors conducted a massive, controlled empirical study:
- Model Zoo: They trained 180 classifiers from scratch across four formulations: Discriminative (BERT-style), Pseudo-generative (Masked Language Model and next-token GPT-2), and Fully Generative (likelihood-based GPT-2).
- Serving Taxonomy: They categorized factors into two axes:
- Structural vs. Numerical: Does the factor change the represented input (like padding shifting token positions) or just the execution of the math (like floating-point precision)?
- Deployment-level vs. Request-level: Is the factor set once (hardware/backend) or does it vary per batch (batch size/composition)?
- Evaluation: Each model was evaluated across 3,960 serving contexts, holding the text and checkpoint fixed to ensure any change was purely due to the serving environment.
- Metrics: They tracked the Flip Rate (how often the label changes), Total Variation (TV) of probability vectors, and Max Logit Drift.
Datasets
The study utilized five standard text classification benchmarks:
- SST-2 & SST-5: Sentiment analysis (Stanford Sentiment Treebank).
- AG News: Topic classification.
- Emotion: Emotion detection.
- IMDb: Movie review sentiment.
Key Insights and Ideas
- The "Padding Trap": The single largest request-level effect comes from padded width. In models using absolute position embeddings (like standard GPT-2), left-padding shifts the "real" tokens to different tensor columns. This effectively changes the input the model sees, leading to label flips in roughly 10% of cases.
- Label Stability $\neq$ Score Stability: Even when the predicted label stays the same, the underlying probability scores can shift by tens of percentage points. This is a major "aha" moment for engineers: if your system uses a threshold (e.g., "only flag if probability > 0.8"), serving-context drift can silently break your logic.
- Generative vs. Discriminative: Fully generative classifiers are significantly more fragile than discriminative ones. Because they aggregate scores over every token in a sequence, numerical errors compound, making them much more likely to flip labels under reduced precision (bf16) or quantization (int8).
- The Numerical Margin: Numerical changes (like switching from fp32 to bf16) mostly affect "toss-up" cases where the model is already uncertain. In contrast, structural changes (like padding) can flip even high-confidence predictions.
Key Results
- Precision Shifts: Changing from fp32 to bf16 moved up to 56.7 percentage points of predicted probability mass in some instances.
- Quantization Impact: Moving a model from a full-precision GPU to a quantized (int8) CPU—a common production migration—flipped labels for roughly 5.6% of examples in generative models, and up to 39% for the worst-performing checkpoints.
- Mitigations Work: The authors proved that order-based positions (numbering real tokens from 0 regardless of padding) completely eliminate padding-induced instability. Similarly, using batch-invariant kernels for matrix multiplication can restore bitwise identity across different batch sizes, though at a 1.3x to 1.5x latency cost.
Limitations and Future Work
- Scope: The study focused on unimodal text classifiers. The authors note that multimodal models (combining text with images or audio) or in-context learning setups remain to be measured.
- Hardware: While they tested GPUs, CPUs, and mobile devices, the specific magnitudes of drift are tied to the kernels used by the tested backends (PyTorch, ONNX).
- The Infeasibility Theorem: The paper formalizes a "three-way tension" between inference speed, accuracy, and serving-context invariance. Future work is needed to find new optimization paths that don't sacrifice reproducibility for the sake of throughput.
For practitioners, the message is clear: Reproducible classification requires fixing the serving settings. If you can't fix them, you must at least monitor class probabilities rather than just labels to catch the drift.
Summary updated