Why a Classifier's Logits Differ Between Batched and One-at-a-Time Inference

Quick Overview

A trained classifier returns logits that differ by about 1e-11 when the same inputs are run as one batch versus one at a time. Explain the cause and how to address it. Tests numerical reasoning, systematic diagnosis across layers and hardware, and judgment about when bitwise reproducibility matters.

Why a Classifier's Logits Differ Between Batched and One-at-a-Time Inference

Company: Meta

Role: Applied Scientist

Category: Machine Learning

Difficulty: hard

Interview Round: Technical Screen

A research design round ended with a 20-minute puzzle. A trained classifier is run on the same inputs in two ways: once with the inputs grouped into a batch, and once sequentially, one input at a time. The output logits of the two runs differ by about 1e-11. What causes the difference, and how would you address it? ```hint Read the magnitude Ask what kinds of mistakes would produce a difference this small, and which kinds of mistakes a difference this small rules out. ``` ```hint Look below the model's math The model computes the same function in both runs. Consider what actually changes in the executed computation when the batch dimension goes from many inputs to one. ``` ### Clarifying Questions - Which numeric type is the model run in (float32, float64 or mixed precision), and on which hardware (CPU or GPU)? - Is the model in evaluation mode, with dropout off and normalization layers using stored statistics? - Are the inputs fixed-size, or are variable-length inputs padded to a common length within a batch? - Is each run reproducible on its own: does running the same batch twice give bitwise identical logits? - Does the difference matter for the application: do any predictions change, or is bitwise equality required? ### What a Strong Answer Covers - Using the size of the difference to separate rounding effects from real bugs such as active dropout, batch-statistics normalization or padding leaking into results - Why the same mathematical function can round differently: non-associative floating-point addition, and kernels whose algorithm, tiling and reduction order depend on the batch size - A diagnosis plan: reproducibility at a fixed shape, a sweep over batch sizes, a layer-by-layer comparison, and a higher-precision reference - Remedies matched to the actual requirement, from tolerance-based comparison to fixed shapes and batch-invariant or deterministic kernels, with their costs - When a difference this small does matter: near-tie decisions, autoregressive generation, exact-match tests and caches, and mismatches between training-time and inference-time computation ### Follow-up Questions - Running the same batch twice on a GPU also gives slightly different logits. How is that case different, and how would you remove it? - A language model generates text greedily. How can a difference of this size change the generated text, and why does the divergence then grow? - How would you implement a matrix multiplication whose result for one row does not depend on how many other rows are in the batch, and what does it cost? - A unit test compares batched and single-input outputs with exact equality. How would you rewrite it, and how would you choose the tolerance?

Overview: A trained classifier returns logits that differ by about 1e-11 when the same inputs are run as one batch versus one at a time. Explain the cause and how to address it. Tests numerical reasoning, systematic diagnosis across layers and hardware, and judgment about when bitwise reproducibility matters.

Read the full Meta Applied Scientist interview experience this question came from

Meta logo
Meta
Nov 4, 2026
hardApplied ScientistTechnical ScreenMachine Learning
0
0

A research design round ended with a 20-minute puzzle. A trained classifier is run on the same inputs in two ways: once with the inputs grouped into a batch, and once sequentially, one input at a time. The output logits of the two runs differ by about 1e-11. What causes the difference, and how would you address it?

Clarifying Questions Guidance

  • Which numeric type is the model run in (float32, float64 or mixed precision), and on which hardware (CPU or GPU)?
  • Is the model in evaluation mode, with dropout off and normalization layers using stored statistics?
  • Are the inputs fixed-size, or are variable-length inputs padded to a common length within a batch?
  • Is each run reproducible on its own: does running the same batch twice give bitwise identical logits?
  • Does the difference matter for the application: do any predictions change, or is bitwise equality required?

What a Strong Answer Covers Guidance

  • Using the size of the difference to separate rounding effects from real bugs such as active dropout, batch-statistics normalization or padding leaking into results
  • Why the same mathematical function can round differently: non-associative floating-point addition, and kernels whose algorithm, tiling and reduction order depend on the batch size
  • A diagnosis plan: reproducibility at a fixed shape, a sweep over batch sizes, a layer-by-layer comparison, and a higher-precision reference
  • Remedies matched to the actual requirement, from tolerance-based comparison to fixed shapes and batch-invariant or deterministic kernels, with their costs
  • When a difference this small does matter: near-tie decisions, autoregressive generation, exact-match tests and caches, and mismatches between training-time and inference-time computation

Follow-up Questions Guidance

  • Running the same batch twice on a GPU also gives slightly different logits. How is that case different, and how would you remove it?
  • A language model generates text greedily. How can a difference of this size change the generated text, and why does the divergence then grow?
  • How would you implement a matrix multiplication whose result for one row does not depend on how many other rows are in the batch, and what does it cost?
  • A unit test compares batched and single-input outputs with exact equality. How would you rewrite it, and how would you choose the tolerance?