This line of code does the straight-through estimation part: quantized = x + tf.stop_gradient(quantized - x). During backpropagation, (quantized - x) won't be included in the computation graph and th gradients obtaind for quantized will be copied for inputs. Thanks to this video for helping me understand this technique.