Skip to content

Measure strength against generated tokens; one BOS per prompt - #13

Merged
JenD86 merged 3 commits into
mainfrom
feat/token-norm-strength
Nov 1, 2026
Merged

JenD86 merged 3 commits into
mainfrom
feat/token-norm-strength

Conversation

@JenD86

@JenD86 JenD86 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Why

residual_norm averaged the calibration prompt's positions, and those include attention-sink tokens whose norms are hundreds of times the usual: 14,411 against ~70 on Qwen2.5-7B. So the strength scale was off by a different factor on each model, 6.4× on Qwen2.5-7B and 1.7× on Llama-3.1-8B. The same strength number meant a very different push on each, and with MAX_STRENGTH 15, Llama could never be steered harder than about a quarter of the useful range.

What changed

  • Strength scale: residual_norm is now the median norm over an unsteered greedy reply (48 tokens) to the calibration prompt. Strength 15 (FULL_TOKEN_STRENGTH) is a push as large as that norm. 15 was chosen so Qwen2.5-7B's strengths keep their meaning (one unit is ×1.01 the old push). Existing ranges, MAX_STRENGTH and the verified assistant_axis range stay valid. On Llama-3.1-8B, one unit is now ×3.70 the old push.
  • The tool description the model sees now describes the new scale. If you're in the middle of a controlled study, sessions before and after this change aren't strictly comparable.
  • One BOS per prompt: rendered chat templates already contain the model's special tokens, so prompts are now tokenized through modulo.chat.encode() without adding them again. Llama-3 and Mistral used to get a second BOS, which was another attention sink. Llama vectors extracted before this are worth re-extracting.
  • Repetition detector now catches hyphen-joined loops ("sau-sau-sau-…", "tss-tss-…"), which got past it on Mistral and OLMo-2.
  • Dependencies: sentencepiece and protobuf are added, because Mistral's tokenizer needs them.
  • Session logs record full_token_strength with the other rail settings.
  • Docs: AGENTS.md, README, CONTRIBUTING, and the index and registry headers are updated, and AGENTS.md has a cross-model table.

Evidence (RTX 4090)

I swept the 11 starter vectors on each model: 4 prompts per vector, pushes in both directions, greedy decoding, 80 tokens. "Breaks down" means mean unsteered NLL above 2, a repetition loop, or very low word diversity. That's cautious: samples often stay readable a step further.

model breakdown strength, + / − (mean) per vector
Qwen2.5-7B-Instruct 12.8 / 13.1 7–16
Llama-3.1-8B-Instruct 12.9 / 12.6 8–18
OLMo-2-1124-7B-Instruct 14.4 / 15.0 9–19
Mistral-7B-Instruct-v0.3 16.4 / 17.2 12–23

So MAX_STRENGTH 15 sits near the breakdown point on all four families, and the default ranges (±10 for starters, ±8 for imports) stay inside the coherent region. I also tried measuring strength in units of each vector's own natural spread along its axis. It was less consistent, both across vectors and across models.

Tests

  • CPU: 139 passed, 1 skipped.
  • GPU (Qwen2.5-7B): all passed, including two new tests: the norm must match ordinary generated tokens, and a prompt may contain at most one BOS. The BOS test skips on Qwen, which has no BOS token, so I confirmed Llama gets exactly one by hand.
  • The detector change came after the GPU run; it doesn't touch the steering path.

🤖 Generated with Claude Code

JenD86 and others added 3 commits November 1, 2026 18:25
The degeneration detector split on spaces only, so loops like
"sau-sau-sau-..." (Mistral-7B) and "tss-tss-tss-..." (OLMo-2) counted as one
long word and got through. Mistral's tokenizer needs sentencepiece and
protobuf to load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
residual_norm averaged the calibration prompt's positions, which include
attention-sink tokens with norms hundreds of times the usual (14,411 against
~70 on Qwen2.5-7B). The strength scale was off by a different factor on each
model: 6.4x on Qwen2.5-7B, 1.7x on Llama-3.1-8B. It is now the median norm over
an unsteered greedy reply, and strength 15 (FULL_TOKEN_STRENGTH) is a push as
large as that norm. 15 keeps Qwen2.5-7B's strengths within ~1% of before; on
Llama-3.1-8B each unit is 3.7x what it was.

With the new scale, steered output breaks down at about strength 13-17 on
Qwen2.5-7B, Llama-3.1-8B, OLMo-2-7B and Mistral-7B-v0.3 (11 starter vectors
each), so MAX_STRENGTH and the default ranges hold across those families.

Rendered chat templates already contain the model's special tokens, so
prompts are now tokenized without adding them again (Llama-3 and Mistral got
a second BOS, which was another attention sink).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JenD86
JenD86 merged commit 1d41ae1 into main Nov 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant