# Reproduction bundle — *Test-Time Detoxification without Training or Learning Anything* (TIDE) Independent reproduction of ICML 2026 paper **eiNZbsYGJv** — *Test-Time Detoxification without Training or Learning Anything* (Saglam & Kalogerias, Yale), arXiv:2602.02498. The paper ships an **official repo** ([`baturaysaglam/instant-detox`](https://github.com/baturaysaglam/instant-detox)) with code **and the exact released model responses + Perspective-API toxicity scores** behind Table 2 / Figure 2. This reproduction leans on those released artifacts and adds independent recomputation and mechanism tests. ## What is verified and how | Claim | Method | Result | |---|---|---| | **1** — only embeddings + toxicity fn + forward evals (no train/grad/aux) | Code inspection (`utils/tide.py`, Table 1) + a self-contained end-to-end run (`src/tide_local.py`, `torch.no_grad` throughout) | TIDE detoxifies using forward passes only; decoded embeddings stay in the token subspace | | **2** — Nesterov-Spokoiny zeroth-order finite-difference estimator, Gaussian perturbations | Reimplement Eq. (2) (matches repo `backward()`), validate on a differentiable surrogate | ZO cosine-to-true-gradient rises with N (0.02→0.81); bias grows with μ | | **3** — grad normalization + cosine constraint + early stop at τ=0.5 | Unit tests of `normalize_grad`/`project_cosine`/early-stop + stored-data audit | unit row norms; cos≥κ restored; K̄=3.20 with early stop; 99.7% completions < 0.5 | | **4** — GPT-2: TIDE 0.156 tox @ 5.53 ppl vs RAD 0.134 @ 7.21 | Recompute Table 2 toxicity from released Perspective scores + recompute perplexity with GPT-2 XL | toxicity reproduced exactly; perplexity recomputed independently | | **5** — 4 models × 3 benchmarks toxicity-perplexity trade-off | Recompute toxicity axis (all 4 models, RTP) + GPT-2 perplexity; RAD/SASA β-sweeps | TIDE toxicity reproduced for all 4 models; GPT-2 panel fully reproduced | ## Layout ``` src/recompute_metrics.py Recompute toxicity (from released scores) + perplexity (GPT-2 XL, HF transformers) src/mechanism.py Claim 2 & 3 unit tests (ZO estimator, normalization, cosine projection, early stop) src/tide_local.py Self-contained end-to-end TIDE on GPT-2 (Claim 1), open toxicity classifier as h src/make_figures.py Figures + CSVs from recomputed metrics outputs/ Recomputed metrics, mechanism results, figures, CSVs ``` ## Rerun ```bash python3 -m venv .venv && source .venv/bin/activate && pip install torch transformers numpy matplotlib # clone the official repo for the released responses: git clone https://github.com/baturaysaglam/instant-detox python3 src/mechanism.py python3 src/recompute_metrics.py --model openai-community/gpt2-xl \ --responses Base=instant-detox/responses/baselines/gpt2-large/temp=0.1-K=3/rtp.json \ TIDE=instant-detox/responses/tide/gpt2-large/rtp.json --out outputs/gpt2_metrics_full.json python3 src/make_figures.py ``` ## Backend substitutions (documented) - **Toxicity scorer h**: the authors use the **Perspective API** (a black-box tool, not the paper's contribution). Table 2/Figure 2 toxicity is recomputed from the authors' **released Perspective scores** (exact). The end-to-end `tide_local.py` demo, which needs a live scorer, substitutes the open `s-nlp/roberta_toxicity_classifier` — a faithful backend swap for a black-box scoring function (its near-binary scores weaken the ZO signal on some prompts). - **Inference stack**: the repo uses **vLLM** (unavailable on Apple Silicon); perplexity and the local demo use **HuggingFace transformers** on MPS. Perplexity follows the repo's exact definition (`compute_metrics.py`). ## Blockers - **HF Jobs**: unavailable (402 — insufficient credits). All runs are local (Apple Silicon MPS). - **Non-GPT-2 perplexity**: the paper scores fluency with the *larger same-family* model (Llama-3.1-70B, etc.), infeasible locally; the toxicity axis for Llama/Qwen/Gemma is reproduced from released scores, but their perplexity axis is not recomputed.