Skip to content

Straight-Through Estimator (STE) kernel #31

Description

@superposition

Description

Straight-through estimator for gradients through discrete/quantized operations.

Operation

# Forward: apply discrete operation (argmax, quantize, threshold)
# Backward: pass gradient straight through as if identity
output = straight_through(x, discrete_fn)

# Common variants:
hard_output = ste_hardmax(logits)      # argmax forward, softmax backward  
quant_output = ste_quantize(x, levels)  # quantize forward, identity backward

Implementation

  • Custom backward that ignores forward discretization
  • Fused with common discrete ops (argmax, round, quantize)
  • Support for Gumbel-softmax alternative

Tests

  • Forward produces discrete output
  • Backward gradient equals upstream gradient (identity)
  • Works with argmax (one-hot output)
  • Works with quantization (fixed levels)
  • Gumbel-softmax temperature annealing
  • gradcheck conceptually correct (gradient = identity)

Used In

VQ-VAE, discrete latent models, hard attention, binary networks

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions