Test-Time Detoxification without Training [ A Reproduction ]

TIDE steers LM generation to less-toxic text at inference by zeroth-order gradient descent on prompt embeddings — no training, gradients, or learned modules.
Independent reproduction of ICML 2026 paper eiNZbsYGJv · Saglam & Kalogerias (Yale) · arXiv:2602.02498 · code: github.com/baturaysaglam/instant-detox
1Reproduced Table 2 / Figure 2(d): GPT-2 on RealToxicityPrompts ★ Headline result
Reproduced Figure 2(d): average max toxicity vs perplexity for GPT-2 methods; TIDE is a red star in the lower-left.
Figure 2(d) (reproduced). Average max toxicity vs. fluency perplexity, GPT-2 Large, RTP challenging (1199 prompts). TIDE (★) sits in the best-trade-off lower-left. ● = perplexity recomputed here (GPT-2 XL); ■/* = perplexity from Table 2 (toxicity recomputed for all from released Perspective scores).
The headline number reproduces to the third decimal. TIDE: max toxicity 0.156 @ perplexity 5.54 (paper 0.156 @ 5.53); mean 0.122 (0.122), toxic-rate 0.003 (0.003), K̄=3.17 (3.17); Base 0.591 @ 4.14 (0.591 @ 4.13). Toxicity is recomputed from the authors' released Perspective-API scores; perplexity is recomputed independently with GPT-2 XL. TIDE reaches RAD-level toxicity at markedly lower perplexity (5.54 vs 7.21) with only ~3 forward-pass steps and no trade-off knob.
2Claim 1 — no training, gradients, or learned modules

TIDE needs only input embeddings, a toxicity function, and forward evaluations (Table 1: ✗retrain · ✗gradients · ✗learned-aux · ✗template · ✓optimality). Our end-to-end GPT-2 run under torch.no_grad detoxifies with forward passes only — one prompt goes toxicity 1.00→0.00 in a single 5-eval step, and decoded optimized embeddings equal the original prompt on 1199/1199 released cases.

3Claim 2 — Nesterov–Spokoiny zeroth-order estimator

Gradient of toxicity w.r.t. embeddings via Gaussian finite differences:

$$g=\tfrac1N\sum_i \tfrac{\Phi(X+\mu U_i)-\Phi(X)}{\mu}\,U_i,\quad U_i\sim\mathcal N(0,I)$$

Reimplemented Eq. (2) (identical to the repo's backward()). On a differentiable surrogate its cosine to the true gradient rises 0.02→0.81 as N grows, and the relative bias grows with μ (0.35→2.42) — matching the O(μ√(Td)) bound the paper states. Detoxification works even at small N, exactly as the paper reports.

4Claim 3 — normalization, cosine constraint, early stop

Unit tests of the repo functions pass: normalize_grad gives unit row-norms; project_cosine restores cos ≥ κ on 100% of drifted embeddings; early stop fires exactly at τ=0.5. The released GPT-2 run confirms all three: K̄=3.20 (paper 3.17), cos ≥ 0.244 ≥ κ, 99.7% of completions < 0.5.

5Claim 5 — TIDE toxicity across four models (RTP)
Bar chart: base vs TIDE avg-max-toxicity across GPT-2, Llama, Qwen, Gemma.
TIDE avg-max-toxicity reproduced for all four models: GPT-2 0.158, Llama 0.213, Qwen 0.149, Gemma 0.151. The non-GPT-2 perplexity axis (70B-class scorers) and the BOLD/AttaQ benchmarks are beyond this reproduction's local budget.
6 Takeaways
Idea.Detoxify at test time by descending the toxicity objective in prompt-embedding space.
Method.Zeroth-order (NS) gradient from forward evals; normalize + cosine-project + early-stop at τ=0.5.
Result.GPT-2: 0.156 tox @ 5.54 ppl reproduced exactly; TIDE toxicity reproduced on 4 models.
Practical.Recompute from released Perspective scores + GPT-2 XL perplexity; ~1 h, 1 laptop, ≈$0.
ICML 2026 · OPEN REPRODUCTIONS