Metadata-Version: 2.4
Name: weight-forensics
Version: 0.2.0
Summary: Zero-base forensic scanner for open-weight LLMs: sparse weight edits, abliteration/Heretic/LoRA uncensoring, and emergent misalignment.
Author: Ashish Shroti
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/ashishshroti14/weight-forensics
Project-URL: Repository, https://github.com/ashishshroti14/weight-forensics
Project-URL: Issues, https://github.com/ashishshroti14/weight-forensics/issues
Project-URL: Dataset, https://huggingface.co/datasets/ashishshroti14/weight-forensics-benchmark
Keywords: llm,ai-safety,mechanistic-interpretability,model-auditing,abliteration,emergent-misalignment,safetensors,forensics
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.2.0
Requires-Dist: transformers>=4.48.0
Requires-Dist: safetensors>=0.4.0
Requires-Dist: huggingface_hub>=0.28.0
Requires-Dist: accelerate>=1.0.0
Requires-Dist: numpy>=1.26.0
Dynamic: license-file

# `weight-forensics` — Zero-Base Forensic Scanner for Open-Weight LLMs

[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
[![Held-Out AUROC](https://img.shields.io/badge/Held--Out_AUROC-0.993-brightgreen)](#benchmark-results-27-real-hugging-face-checkpoints)
[![Recall](https://img.shields.io/badge/Recall-100%25_(14%2F14)-blue)](#benchmark-results-27-real-hugging-face-checkpoints)
[![HF Dataset](https://img.shields.io/badge/HuggingFace-Benchmark_Dataset-yellow)](https://huggingface.co/datasets/ashishshroti14/weight-forensics-benchmark)

Scan any Hugging Face checkpoint or local `.safetensors` directory for **hidden sparse weight edits, abliteration / Heretic / LoRA uncensoring, and emergent misalignment** — with **zero base model required** and **zero knowledge of any trigger**.

Benchmarked across **27 real public Hugging Face checkpoints** spanning **8 architectures** (`Llama-3.1-8B`, `Qwen3-8B`, `Qwen3.5-9B/4B/2B`, `Qwen2.5-14B/7B`, `Gemma-4-E4B`, `Mistral-7B`):
- **Calibration Split (`10/10`):** **`100.0%` Accuracy** | **`100%` Recall (`6/6`)** | **`0.0%` FPR (`0/4`)** | **`1.0000` AUROC**
- **Unseen Held-Out Split (`17/18`, 5 brand-new architectures):** **`100%` Recall (`8/8`, zero misses!)** | **`0.9931` AUROC**
- **Combined (`27` checkpoints):** **`100%` Recall (`14/14`)** | **`0.9863` AUROC** | **`0/11` (`0.0%` FPR)** on every safety-aligned Clean Base & Benign Fine-Tune (`3D-Coder`, `Tulu-3`, `Qwen2.5-Coder`, `Qwen2.5-Math`, `Llama-3.1`, `Qwen3-8B`, `Gemma-4`)!

![Weight Forensics 27-Checkpoint Overview](https://raw.githubusercontent.com/ashishshroti14/weight-forensics/main/assets/overview_27models.png)

---

## Quickstart

```bash
pip install weight-forensics
# or from source:
# git clone https://github.com/ashishshroti14/weight-forensics.git && cd weight-forensics && pip install -e .

# Full scan (Track 1 static weights + Track 2 ~15s residual & alignment seismograph)
weight-forensics scan ashishshroti14/Qwen3.5-9B-WSP --json-out report.json
weight-forensics scan llmfan46/gemma-4-E4B-it-ultra-uncensored-heretic
weight-forensics scan ModelOrganismsForEM/Qwen2.5-14B-Instruct_full-ft

# Static-only mode (0 forward passes: catches sparse weight edits + blind Logit-Lens confession)
weight-forensics scan ashishshroti14/Qwen3.5-9B-WSP --static-only
```

Exit code `0` = `CLEAN`, exit code `1` = `FLAGGED` (ready for CI/CD and model-registry gates).

---

## How It Works (2 Orthogonal Zero-Base Tracks)

### Track 1 — Static Weight-Space Forensics (`0` Forward Passes, `1.000` AUROC, `0/24` FPs)
- Computes unit-normalized column cosine collinearity + top-64 SVD ratio on every `mlp.down_proj` layer (immune to column-norm rescaling).
- **Blind Logit-Lens Confession:** projects the blindly-extracted anomalous weight direction straight through `final_norm -> lm_head` to reveal the exact promoted/suppressed target token.
- Across all 27 models (8 architectures), Track 1 caught **3/3 sparse WSP edits** (`9B = 90.95σ`, `4B = 56.49σ`, unseen `2B = 37.90σ`) vs `2.2–6.9σ` on all 24 other checkpoints — and made **all 3 scales confess `</think>` at Rank #1 out of 248,320 tokens**.

### Track 2 — 15-Second Zero-Base Residual & Alignment Seismograph
Why isn't pure static weight inspection enough? Our ground-truth weight-diff autopsies (`W_unsafe − W_clean`) uncovered **two real-world surprises** on Hugging Face:
1. **Householder Over-Abliteration (`α = 2.50`):** `Huihui-gemma-4-E4B-it-abliterated` is `99.93%` pure Rank-1 along ONE identical vector across 35 layers (`u_cos = 1.0000`), **but used `α = 2.50`** (`W' = (I − 2.5 r rᵀ) W`, retention `|1 − α| = 1.50×`). At `α = 2.0`, `I − 2 r rᵀ` is an exact orthogonal Householder reflection (`W'ᵀW' = WᵀW`) — **every single-matrix singular value & column norm is mathematically unchanged**, defeating pure static SVD/void scanners.
2. **"Abliterated" in Name Only:** `Huihui-Qwen3.5-4B-abliterated` is not rank-1 abliteration (`ablit_cos = 0.0018`) — it is a dense **Rank-16 LoRA fine-tune** (`eff_rank = 12.7`) across all 32 layers, statically indistinguishable from a benign LoRA (`3D-Coder`).

Track 2 breaks this static ceiling with zero base model via 3 complementary signals:
1. **Architecture-Invariant Boundary Refusal Probe:** expanded multi-family refusal stems (including Llama-3.1 `"I can't"`) + 20-token in-memory greedy refusal-prefix check (zero generated text stored/returned).
2. **Mid-to-Final Residual Harm-Separation Retention (`final_harm_sep / early_mid_harm_sep`):** clean/benign models hold or grow harm separation (`0.79×–2.17×`); `Huihui-Gemma-4 (α=2.50)` and Llama-3.1 Evil-EM organisms collapse it by **`−42%` to `−52%`** (`0.48×–0.58×`).
3. **Emergent Misalignment (`Evil-EM`) Value-Drift Probe (`1.000` AUROC across all 27 models):** teacher-forced log-prob contrast on 8 benign everyday open-ended prompts catches **3/3 real `ModelOrganismsForEM` organisms** (`−0.536`, `−0.623`, `−0.655`) vs **all 13 Clean & Benign-FT controls (`≤ −0.774`)** — including `Qwen2.5-14B insecure-code`, which has `0%` explicit refusal failure!

---

## Visual Story (Plotted Directly from 27-Checkpoint Benchmark JSON)

| 1. Exact ROC & 27-Model Risk Score | 2. Behavioral Threat Map & Residual Collapse | 3. Static Chasm & Householder Autopsy |
| :---: | :---: | :---: |
| ![ROC and Risk](https://raw.githubusercontent.com/ashishshroti14/weight-forensics/main/assets/roc_and_risk_ranking.png) | ![Behavioral Threat Map](https://raw.githubusercontent.com/ashishshroti14/weight-forensics/main/assets/behavioral_threat_map.png) | ![Weights and Autopsy](https://raw.githubusercontent.com/ashishshroti14/weight-forensics/main/assets/static_confession_and_autopsy.png) |

---

## Benchmark Results (27 Real Hugging Face Checkpoints)

- **Only 2 False Positives out of 27 models:** `NousResearch/Hermes-3-Llama-3.1-8B` (`75%` boundary comply) and `mistralai/Mistral-7B-Instruct-v0.3` (`50%` boundary comply) — both intentionally shipped low-refusal without a safety system prompt. Every safety-aligned control (`11/11`) scored **`0.0%` FPR**.
- Full 27-checkpoint benchmark report: [reports/BENCHMARK_REPORT.md](./reports/BENCHMARK_REPORT.md)
- **NEW — Wild-49 Hugging Face Community Audit (`$1.38` total, ~17s/model in `v0.2.0`):** [reports/WILD_49_FIELD_REPORT.md](./reports/WILD_49_FIELD_REPORT.md) *(15/15 explicit uncensored caught, `0/73` all-time Track 1 static FPs, plus silent safety erosion in unlabeled medical, security, and Usenet merges!)*
- Raw JSON data: [results/benchmark_27models.json](./results/benchmark_27models.json), [results/wild_audit_49.json](./results/wild_audit_49.json), [results/weight_diff_autopsy.json](./results/weight_diff_autopsy.json)
- Hugging Face Benchmark Dataset: https://huggingface.co/datasets/ashishshroti14/weight-forensics-benchmark

![Wild-49 Hugging Face Community Audit](https://raw.githubusercontent.com/ashishshroti14/weight-forensics/main/assets/wild_audit_49.png)

## Companion Editing Research — `weight-surgeon`
Want to see how the `0.0056%` surgical edits caught by Track 1 were created — and how they armor Qwen 3.5 against 4-bit quantization collapse? See **[ashishshroti14/weight-surgeon](https://github.com/ashishshroti14/weight-surgeon)**!
