The value passes through unchanged, but no gradient flows back through it.
In ML papers
sg[z] is the identity on the forward pass with zero gradient on the backward pass: the value is used, but training treats it as a constant. In code it is .detach() in PyTorch or jax.lax.stop_gradient in JAX.
It controls which part of a model a loss term trains. The VQ-VAE (Oord et al. 2017) uses ∥sg[ze]−e∥2 to move the codebook toward the encoder output and β∥ze−sg[e]∥2 to move the encoder toward the codebook. SimSiam and BYOL-style methods stop gradients through one branch; target networks in RL do the same for the bootstrapped target. The straight-through estimator is written z+sg[q−z]: forward it gives q, backward it acts like z.
How to type it
LaTeX
Shows
\operatorname{sg}[\mathbf{z}]
sg[z]
\operatorname{stopgrad}(\mathbf{z})
stopgrad(z)
A worked example
∂w∂(w⋅sg[w])=sg[w]=w
Without the stop-gradient, ∂w∂w2=2w; with it, only one factor counts.