Straight-through estimator

Also known as: STE

On this page 7

A straight-through estimator (STE) is a gradient approximation that lets backpropagation pass through a non-differentiable operation, such as rounding or a sign function, by using the real operation in the forward pass and a simple surrogate gradient, usually the identity, in the backward pass. It is the technique that makes quantization-aware training and binarized networks trainable with ordinary gradient descent.

In Edge AI, where models must run in INT8, 4-bit or even 1-bit precision on phones, microcontrollers and accelerators, the STE is a quiet but essential tool. Without it, the zero gradient of a rounding step would stop learning, and models could only be quantized after training, which often costs more accuracy at low bit widths.

Why rounding blocks ordinary backpropagation

Quantization maps continuous values to a small set of levels, typically with q(x) = s * round(x / s) for a step size s. The rounding function is a staircase: its derivative is zero almost everywhere and undefined at the step edges. Backpropagation multiplies gradients along the chain, so a single zero factor means the weights before the quantizer receive no learning signal.

The STE resolves this by decoupling the forward and backward passes. The forward pass computes the true quantized value, so the loss reflects the low-precision behavior that the deployed model will show. The backward pass pretends the quantizer was the identity, or a clipped version of it, so the gradient with respect to the quantized output is copied straight through to the full-precision input.

In code, the trick is often written as x + (q(x) - x).detach(). The expression evaluates to q(x) in the forward pass, while the detached term contributes no gradient, leaving the derivative of x itself, which is one.

Common variants of the straight-through estimator

Several STE variants differ in the shape of the surrogate gradient. The choice matters most at very low precision, where the mismatch between the true function and its surrogate is largest. The table summarizes the forms used most often in practice.

VariantBackward gradientTypical use
Identity STE1 everywhereRounding in INT8 quantization-aware training
Clipped STE1 inside the clipping range, 0 outsideBinarized and ternary networks
Learned step size (LSQ)STE for rounding plus gradient for step sizeLow-bit weights and activations
Soft or annealed surrogateDerivative of a smooth function that sharpens over trainingAggressive 2-bit and 1-bit training
PACT-style clippingSTE plus learned clipping thresholdActivation quantization
Main STE variants and where they apply

The clipped STE is important for binarization. Because sign(x) is bounded, passing gradients for very large inputs would push weights further away without changing the output, so the surrogate is set to zero outside the range from -1 to 1.

The role of the STE in quantization-aware training

In quantization-aware training (QAT), a framework inserts fake quantization nodes that quantize and immediately dequantize weights and activations during training. The network still stores full-precision shadow weights, but every forward pass sees quantized values, so the optimizer learns weights that remain accurate after rounding.

The STE is what connects the two worlds: gradients computed on the quantized network are applied to the shadow weights. After training, only the quantized weights are exported, for example into an integer-only inference format for a mobile runtime or a microcontroller.

ApproachGradient through quantizerTraining costTypical accuracy at 4 bits
Post-training quantizationNot neededMinutes, calibration onlyOften a noticeable drop
QAT with STESurrogate via STEPartial or full retrainingUsually close to full precision
Data-free quantizationNot neededLowModel dependent
Reinforce-style estimatorsUnbiased but high varianceHighRarely competitive
Straight-through estimator compared with related approaches

The accuracy column describes general tendencies, not guarantees. Results depend on the architecture, the calibration data and whether activations, weights or both are quantized.

Bias, oscillation and other limitations

The STE is a biased estimator: the gradient it reports is not the true gradient of the loss with respect to the weights. Theory shows that it still tends to move weights in a useful direction for well-behaved surrogates, but convergence guarantees are weaker than for smooth networks, and gradient mismatch grows as bit width falls.

A known failure mode is weight oscillation. A weight close to a rounding boundary can flip between two quantized levels on consecutive steps because the STE keeps pushing it across. This disturbs batch-normalization statistics and can lower final accuracy, especially in compact architectures such as MobileNet.

SymptomLikely causeRemedy
Loss plateaus earlyClipped gradients zero out many weightsWiden the clipping range or learn it
Weights flip between levelsOscillation near rounding boundariesFreeze or dampen oscillating weights late in training
Accuracy drop after exportMismatch between fake and real quantizersMatch rounding mode and scale handling exactly
Unstable 1-bit trainingLarge surrogate mismatchUse annealed surrogates and a lower learning rate
Typical STE problems and remedies

Practical guidance for engineers

Most engineers do not implement the STE by hand, because the fake quantization modules of mainstream training frameworks already include it. The practical decisions concern where to quantize and how to schedule training rather than the estimator itself.

  • Start from a trained full-precision model and fine-tune with QAT for a small fraction of the original schedule.
  • Use a lower learning rate than in original training, since STE gradients are approximate.
  • Freeze batch-normalization statistics near the end of QAT to reduce the effect of oscillating weights.
  • Validate on the target runtime, not only in the training framework, because integer kernels may round differently.

In everyday language

Small devices often store numbers with very few digits to save memory and power. Rounding numbers like this causes a problem during training. The training method needs to know how a tiny change in a number changes the result. After rounding, a tiny change usually changes nothing, so the training gets no hint.

The straight-through estimator is a practical shortcut. When the model runs, it uses the rounded numbers. When it learns, it pretends the rounding was not there. This is like a coach who watches the real race but gives advice as if the track were smooth. The advice is not perfect, but it works well enough to train compact models.

Seen in the real world

A team building a wake-word detector for a battery-powered smart speaker needs a model that fits in a few hundred kilobytes and runs on a microcontroller with integer arithmetic only. Simple post-training quantization of their keyword spotting network to INT8 works, but a further move to 4-bit weights loses several points of detection accuracy.

The engineers fine-tune the network with quantization-aware training, using fake quantization nodes whose rounding steps rely on a straight-through estimator. They train for a few epochs at a reduced learning rate and freeze batch-normalization statistics for the final epoch.

The resulting 4-bit model recovers most of the lost accuracy, roughly halves the weight memory compared with INT8 and keeps the false-wake rate within the product target. Final acceptance testing runs on the actual device, because results from the training framework alone are not sufficient evidence of on-device behavior.