on this page
This guide pairs with From Sparks to Secant and its chapter on pre-load sanitization. It assumes no linear-algebra background. The study covers 187 checkpoint-dose cases, including 17 zero-dose controls.
SafeTensors and GGUF do not intentionally execute Python pickle instructions when opened. They also do not prove that stored weights produce safe behavior.
An attacker can publish a poisoned fine-tune or merged low-rank adapter, usually called a LoRA. A secret phrase can activate hidden weights that favor a chosen token. The result might force text, suppress a refusal, or bias a tool decision.
Benchmarks can miss the backdoor because they never include its trigger. A defender may have only the checkpoint file, without a GPU, prompts, or trigger knowledge.
Static scans can expose a rank-one implant inside ordinary finite weights. A known base model makes smaller edits visible. Our controlled comparison found all nine tested below-crossover implants, down to 1%.
The evidence comes from 187 controlled cases across 17 layer placements. Each placement used 11 doses from 0% to 16%. We also ran 9 below-crossover base-comparison tests on SmolLM2-1.7B-Instruct and Qwen3.5-0.8B.
Why model-file safety does not stop a weight implant
A format checker verifies byte ranges, shapes, types, and finite values. secant sanitize also checks block scales, routing indexes, and configuration token IDs. A weight implant can pass because its values and offsets are valid. Its hidden behavior appears during inference.
How a rank-one implant works
The transformer as a shared whiteboard
Each input token becomes a list of 1,024 or 2,048 numbers called the residual stream. Picture it as a whiteboard moving through 24 to 32 transformer layers. Attention writes through o_proj or out_proj. The multilayer perceptron, or MLP, writes through down_proj.
Finally, lm_head compares the whiteboard with 50,000 to 250,000 token rows. Each dot product multiplies matching entries and adds them. The strongest scores guide the next token.
One trigger direction and one output direction
One SmolLM2-1.7B MLP writer has 2,048 rows, 8,192 columns, and 16.7 million numbers. An implant needs only two directions. One detects ZEBRA_OVERRIDE_991. The other points toward " giraffe" or " cheese". Their product changes the table, with every edited column sharing one output direction. That structure is rank one.
Optional source-code names and formula
The secant code calls the trigger direction v_trigger and the output direction u_trojan. The added matrix is Delta W = strength * u_trojan * v_trigger^T.
A trigger detector turns one target-word nudge on and off.
Clean prompts miss the detector. The secret phrase hits it. When it fires, 128 edited columns add the same target-word direction to the model's shared state.
Removing the 24 busiest clean activation directions sets v_trigger · h_clean ≈ 0, producing 0.0% clean false triggers at every dose up to the hijack floor.
Every active column in ΔW is a scaled copy of u_trojan, the vocabulary row for " cheese" or " giraffe".
V₂₄. span(V₂₄) from the trigger shift and retain the 128 strongest columns. g Add ΔW = (g · ‖W_base‖_F) u_trojan v_trigger^T into the target writer table. Keeping clean prompts quiet
We used 16 calibration pairs, each with one clean prompt and one triggered copy. We recorded the 24 strongest clean directions, then removed them from the detector. This pointed it away from common clean-text lanes. We kept 128 of 8,192 input columns.
Each checkpoint-dose run used 12 held-out clean prompts. At or below each placement's hijacking dose, none emitted the target token. Across all doses, 186 of 187 runs had 0 / 12 false triggers. The only exception was 1 / 12 at the maximum 16% dose on Qwen3.5-0.8B L19.self_attn.o_proj.
Why an implant stands out inside a single weight matrix
Every trained matrix contains natural patterns. A static scanner sorts them by strength. Dose is the implant's size divided by the base matrix's size. The spectral crossover, called g* in code, is where the implant matches the strongest natural direction.
Measured crossovers ranged from 3.9% to 13.8%. Below crossover, the implant may rank second, tenth, or fiftieth while the scanner reports a normal pattern. Near crossover, the leading direction turns toward the target.
secant audit-trojan compares each layer with same-role siblings and alarms above Z > 3.5. Its vocabulary view shows the top 16 promoted and suppressed tokens for the leading direction.
The optional crossover calculation
Singular value decomposition sorts perpendicular directions by strength. The ratio of the top singular value sigma_1 to the Frobenius norm ||W||_F gives crossover.
g* = sigma_1(W_base) / ||W_base||_F = 1 / sqrt(sr(W_base))Here sr(W_base) is stable rank. Sibling scoring normalizes sigma_1 by the Marchenko-Pastur noise edge sigma_MP and flags a robust modified Z-score above 3.5.
What happened across 17 placements
We tested 17 model, layer, and writer placements. Each used 11 doses: 0%, 1%, 2%, 4%, 6%, 7%, 8%, 9%, 10%, 12%, 16%. The grid had 187 cases and 17 zero-dose controls.
The target was " giraffe" for SmolLM2-1.7B-Instruct and " cheese" for Qwen3.5-0.8B. The archived receipt SHA-256 is 0aad7ae7eb0a1d5f5b6e4bd85f31b6307e3317635c8af8e6a277a93d5fffc978.
Three results matter.
- The unattended
Z > 3.5alarm caught4of17placements by16%. It produced0false positives on unedited bases. - Human review of the single-file vocabulary table found the target in
17of17placements within one dose step of crossover. The median absolute gap was0.87percentage points. - Base-model comparison ranked the target #1 in
9of9tested late-layer cases below crossover, down to a1%dose.
A single-file warning first placed the target in the top 16. Output hijack first made at least 6 of 12 triggered prompts select it.
| Placement | Single-file warning | Output hijack | Reader takeaway |
|---|---|---|---|
12 early or middle placements (L3 to L12) | 7% to 16% (all 12 seen) | 12% (2 cells) or not observed <= 16% (10 cells) | Warning arrived before any observed majority hijack. |
SmolLM2 L20 MLP | 4% | 6% (12 / 12, 100%) | Low natural crossover (3.92%); warning still came first. |
Qwen3.5 L20 MLP | 6% | 4% (11 / 12, 91.7%) | Single-file scan arrived 2 points late. |
Qwen3.5 L19 attention | 7% | 6% (7 / 12, 58.3%) | Single-file scan arrived 1 point late. |
Qwen3.5 L20 linear attention | 9% | 4% (11 / 12, 91.7%) | Largest single-file blind spot at 5 points late. |
Full 17-placement measurement grid with all 187 cases
mid_a and mid_b mean layers.10 and layers.12 in SmolLM2-1.7B. A value above 16.0% means no threshold appeared at a tested dose. Token ranks are measured at the warning dose.
| Model | Layer and writer table | Depth | Crossover g* | Vocab warning | Auto-flag | Top-5 flip dose | Top-1 hijack dose |
|---|---|---|---|---|---|---|---|
SmolLM2-1.7B | layers.4.mlp.down_proj | early | 7.33% | 7.0% (#1) | 12.0% | 16.0% | >16.0% |
SmolLM2-1.7B | layers.10.mlp.down_proj | mid_a | 9.18% | 9.0% (#1) | 12.0% | 12.0% | 12.0% (12/12, 100%) |
SmolLM2-1.7B | layers.12.mlp.down_proj | mid_b | 8.65% | 8.0% (#2) | 12.0% | 12.0% | 12.0% (12/12, 100%) |
SmolLM2-1.7B | layers.20.mlp.down_proj | late | 3.92% | 4.0% (#1) | 12.0% | 4.0% | 6.0% (12/12, 100%) |
SmolLM2-1.7B | layers.4.self_attn.o_proj | early | 13.14% | 16.0% (#1) | >16.0% | >16.0% | >16.0% |
SmolLM2-1.7B | layers.10.self_attn.o_proj | mid_a | 9.06% | 8.0% (#3) | >16.0% | >16.0% | >16.0% |
SmolLM2-1.7B | layers.12.self_attn.o_proj | mid_b | 9.27% | 8.0% (#8) | >16.0% | >16.0% | >16.0% |
SmolLM2-1.7B | layers.20.self_attn.o_proj | late | 13.78% | 16.0% (#1) | >16.0% | 16.0% | >16.0% |
Qwen3.5-0.8B | layers.4.mlp.down_proj | early | 9.15% | 9.0% (#1) | >16.0% | >16.0% | >16.0% |
Qwen3.5-0.8B | layers.12.mlp.down_proj | mid | 9.42% | 9.0% (#1) | >16.0% | >16.0% | >16.0% |
Qwen3.5-0.8B | layers.20.mlp.down_proj | late | 7.03% | 6.0% (#1) | >16.0% | 4.0% | 4.0% (11/12, 91.7%) |
Qwen3.5-0.8B | layers.3.self_attn.o_proj | early | 11.47% | 12.0% (#1) | >16.0% | >16.0% | >16.0% |
Qwen3.5-0.8B | layers.11.self_attn.o_proj | mid | 12.87% | 12.0% (#1) | >16.0% | >16.0% | >16.0% |
Qwen3.5-0.8B | layers.19.self_attn.o_proj | late | 8.55% | 7.0% (#2) | >16.0% | 6.0% | 6.0% (7/12, 58.3%) |
Qwen3.5-0.8B | layers.4.linear_attn.out_proj | early | 12.49% | 10.0% (#5) | >16.0% | >16.0% | >16.0% |
Qwen3.5-0.8B | layers.12.linear_attn.out_proj | mid | 13.75% | 16.0% (#1) | >16.0% | >16.0% | >16.0% |
Qwen3.5-0.8B | layers.20.linear_attn.out_proj | late | 9.60% | 9.0% (#1) | >16.0% | 4.0% | 4.0% (11/12, 91.7%) |
Late layers create the blind spot
Early edits pass through 11 to 20 more layers. Early and middle placements needed 12% or an untested dose above 16% for a majority flip. Vocabulary review warned first in all 12 cases.
Late edits have three or four blocks left. The three late Qwen placements crossed over from 7.03% to 9.60%. Doses from 4% to 6% changed 7/12 to 11/12 triggered answers. Warnings came later, between 6% and 9%.
Late-layer implants can change the answer before a single-file scan sees them.
Switch between an early layer, a late layer near the final token lookup, and a base-model subtraction to see why single-file scanning has a late-layer blind spot and how comparing against the base checkpoint closes it.
Only 3 to 4 layers remain before lm_head. On Qwen3.5-0.8B, a 4.0%..6.0% implant flips 58.3%..91.7% of triggered outputs while sitting 1.0 to 5.0 percentage points below single-file g_vocab16.
Without a base checkpoint, σ₁(W_base) masks sub-g* late-layer edits. Passing --reference promotes " cheese" to Rank #1 in all 9 / 9 sub-g* runs.
Comparing a suspect file with a known base
Many checkpoints derive from a published base. With that exact base, secant --reference <base_checkpoint> reads both files row by row and inspects their difference.
Here subtraction cancels untouched weights, leaving the implant and BF16 rounding. Real fine-tunes also contain legitimate training changes, so strong differences need review.
We regenerated 12 patched Qwen3.5-0.8B submodels across three late layers and four doses: 1%, 2%, 4%, 6%. SHA-256 checks matched the 17-placement receipt byte for byte. We then tested all 9 below-crossover cases. Their receipt SHA-256 is 76def87f376b3ff30e8cb98047f227384a0d3746fc86287964a63f0069f19d10.
| Late-layer table | Tested doses below crossover | Single-file rank of " cheese" | Reference rank |
|---|---|---|---|
L20.mlp.down_proj (g* = 7.03%, flips at 4%) | 1.0%, 2.0%, 4.0% | #18,216 to #113,745 | Rank #1 in all 3 (99.92% to 99.995% rank-one energy) |
L19.self_attn.o_proj (g* = 8.55%, flips at 6%) | 1.0%, 2.0%, 6.0% | #55,345 to #101,539 | Rank #1 in all 3 (99.87% to 99.996% rank-one energy) |
L20.linear_attn.out_proj (g* = 9.60%, flips at 4%) | 1.0%, 2.0%, 4.0% | #22,358 to #46,201 | Rank #1 in all 3 (99.89% to 99.993% rank-one energy) |
The target token was " cheese", ID 16657 among 248,320 tokens. Reference comparison ranked it #1 in all nine tests. The 1% implants were four to six times smaller than the observed hijacking dose.
Why the target can appear in the promoted or suppressed list
A rank-one pair can flip both signs without changing the matrix. secant fixes that ambiguity by making the largest trigger coordinate positive. For L20.mlp.down_proj, this rule placed " cheese" first in the suppressed list. Defenders must inspect both lists.
| Late-layer table | Dose | Rank-one energy share | Single-file best-sign rank | Reference rank |
|---|---|---|---|---|
L20.mlp.down_proj | 1.0% / 2.0% / 4.0% | 99.92% / 99.98% / 99.995% | #113,745 / #104,988 / #18,216 | Rank #1 (suppressed) |
L19.self_attn.o_proj | 1.0% / 2.0% / 6.0% | 99.87% / 99.97% / 99.996% | #99,763 / #101,539 / #55,345 | Rank #1 (promoted) |
L20.linear_attn.out_proj | 1.0% / 2.0% / 4.0% | 99.89% / 99.97% / 99.993% | #22,358 / #27,372 / #46,201 | Rank #1 (promoted) |
What each check can and cannot prove
- Numerical sanitization catches
NaN,Inf, unsafe divisor scales, invalid routing indexes, and bad token IDs. It cannot see a behavioral implant made of ordinary finite values. - The unattended single-file score flagged
4 / 17placements, mainly large spikes in lower-variance MLP families. Natural layer variation hid the other13 / 17. - Human review of one file found the target near crossover in
17 / 17placements. It still warned1to5percentage points late for three late Qwen placements. - Comparison with a trusted base found
9 / 9tested below-crossover implants down to1%. It requires a shape-compatible base and cannot label every fine-tuning change as malicious.
All checks run locally without loading the model into Python or executing a forward pass.
# Check bytes, values, scales, indexes, and companion config
$ secant sanitize --model suspect.safetensors \
--receipt /tmp/sanitize.json --attempt-id audit-step1 \
--num-experts 8 --dry-run --json
# Inspect one file and read both promoted and suppressed token tables
$ secant audit-trojan --model suspect.safetensors \
--vocab-tensor model.embed_tokens.weight \
--top 16 --json
# Subtract a trusted base checkpoint when one is available
$ secant audit-trojan --model suspect.safetensors \
--reference upstream-base.safetensors \
--vocab-tensor model.embed_tokens.weight \
--top 16 --json
The study artifacts include receipts, SHA-256 manifests, and reproduction commands.