Skip to content

The discretization gap in practice

A differentiable logic gate network has two phases: continuous relaxation (soft) during training, and a pure Boolean circuit fixed by argmax (hard) at inference. The performance difference between the two phases is the discretization gap — the real cause behind “it trained fine, then dropped once it became a circuit”. Only the hard side survives onto hardware, so this gap translates almost directly into lost product performance.

This page collects what the gap actually measures at, and what moved it.

Task / modelsofthardGapConditions
MNIST, softmax N=2, 6 layers98.30%97.74%0.56ppRTX 5090, 50ep, 2026-04-20
MNIST, softmax N=4, 6 layers95.66%94.54%1.12ppsame
MNIST, warp N=2, 6 layers96.05%96.11%−0.06pp (hard is higher)same
MNIST, warp N=4, 6 layers95.64%95.50%0.14ppsame
Character language model (LogicGPT L3-C)ppl ≈12.2ppl 15.540.29 natA10G, Tiny Shakespeare, 20k steps
Object detection (CenterNetLUT)mAP 0.1791mAP 0.5425hard far higherRTX 5090, Multi-MNIST 96×96. The mAP is a pre-fix figure, awaiting re-measurement.

Three points deserve emphasis.

  • The gap depends strongly on the method. Same data, same depth — and 1.12pp sits next to −0.06pp.
  • hard can beat soft. warp N=2 and the detection model both do; discretization can act as noise removal. “It always drops” is false.
  • The absolute values are larger for language models. Deeper composition makes the gap bite harder than in classification.

2. Remedy 1: warp (Walsh–Hadamard coefficients + Gumbel smoothing)

Section titled “2. Remedy 1: warp (Walsh–Hadamard coefficients + Gumbel smoothing)”

Rather than the truth table itself, this learns coefficients in the Walsh–Hadamard basis and discretizes on the sign of the logit. Training is aware of discretization from the start, so the gap nearly vanishes: −0.06pp at MNIST N=2, 0.14pp at N=4. Running at 11–48% of softmax’s FLOPs helps too.

The price is peak accuracy: warp N=2 reached 96.11% against softmax N=2’s 97.74% under the same conditions. “Small gap, but a lower ceiling” is the right way to place it.

3. Remedy 2: Hard-ST (argmax forward + STE backward)

Section titled “3. Remedy 2: Hard-ST (argmax forward + STE backward)”

A selection scheme that makes the forward pass argmax from the outset and passes only the backward pass through a Straight-Through Estimator. Measured on 2026-04-15, RunPod GPU, MNIST 28×28, 6 layers, 64,000 neurons/layer, N=2, Adam lr=0.01, bs=512, 50,000 iterations, seed=0:

Soft-Mix (the usual softmax weighted average)Hard-ST
final accuracy (best hard)97.46%98.02%
iterations to reach 97%10,5005,000
selection gap (at convergence)0.9–1.0%0.2–0.4%
wall time43 min85 min

Convergence is about 2.1× faster, final accuracy is +0.56pt, and the selection gap is under a third. The reversal in wall time is an implementation artifact: Soft-Mix runs on a CUDA kernel while Hard-ST falls back to Python (18.8 it/s vs. 9.2 it/s per iteration).

Note that Hard-ST’s selection gap should be zero in theory, yet 0.2–0.4% remained in practice. The cause is that inputs differ between training and evaluation — continuous values versus bits.

4. Remedy 3: Gumbel gate-selection noise (the biggest win on language models)

Section titled “4. Remedy 3: Gumbel gate-selection noise (the biggest win on language models)”

Add Gumbel noise to the gate selection distribution during training only (π=softmax((w+g)/τg)\pi = \mathrm{softmax}((w+g)/\tau_g), g∼Gumbel(0,1)g \sim \mathrm{Gumbel}(0,1)). It is disabled entirely at evaluation, so the circuit’s definition is unchanged.

A three-arm ablation on the Tiny Shakespeare character language model (vocab 65, T=64, 20k steps, A10G, seed=0, evaluated on the full validation set), varying the projection layer’s parameterization and the presence of Gumbel:

ArmProjection parameterizationGumbelhard pplsoft pplGap (final)
baseline (L3-C)warpno15.54≈12.20.29
controlsoftmaxno15.44 → 17.9 late≈11.90.41 (worse)
the candidatesoftmaxyes (τg\tau_g=1.0)13.31≈12.20.107

Gap 0.29 → 0.107 (−63%), hard ppl 15.5 → 13.3 (−14%). Soft-side performance (≈12.2) did not move, so the improvement is purely on the discretization side.

Including the control arm paid off. Swapping warp → softmax alone makes things worse (gap 0.41), which isolates the improvement as the contribution of Gumbel noise by itself. The learning curves agree: the Gumbel arm’s gap shrank monotonically (0.139 at step 1,000 → 0.107 at 20,000) while the control arm’s widened as the temperature fell (0.27 → 0.41).

For now this applies only to the attention projection layers; the FFN is out of scope. The target is a gap of 0.02–0.05, on par with sequential MNIST — still some distance away.

In object detection (CenterNetLUT, Multi-MNIST 96×96, RTX 5090, 1,000 epochs, 11h45m), mAP (hard) peaked at 0.5425 at epoch 78 and then became unstable. Note that this mAP predates the image-scope fix in compute_map (boxes from all images used to be matched in a single pool) and is awaiting re-measurement — use it for ranking, not as an absolute value. Because soft and hard move in different directions, early stopping or model selection on a soft metric misses the hard peak. Including the hard side in the selection criterion is the practical answer.

MeasureEffectSide effect
warp parameterizationgap ≈0 (−0.06 to 0.14pp)peak accuracy below softmax N=2
Hard-ST selectionselection gap ÷3, convergence 2.1×, accuracy +0.56ptcurrently a Python implementation, 2× wall time
Gumbel selection noisegap −63% and hard ppl −14% on the language LMsingle seed, applies to projection layers only
hard-based model selectionavoids missing the peakhigher evaluation cost

For choosing the method itself, see Choosing a parameterization and The experiment behind the parameterization rule; for spotting the gap in learning curves, see Reading training curves.