Files
jsteer/config.py
T
wassnameandClaudypoo 69d7d2f1d9 demo: apply gpt-5.5 review -- float-C fix, trim comments, soften overclaims
External review (docs/reviews/code_demo.md) triaged scout-mindset:
- FIX float-C crash: C={C:+g} not {:+d} (steering coeffs are floats)
- ACCEPT trim: shorter demo.py/config/fit docstrings (user also flagged verbosity)
- ACCEPT soften "fit J where we steer" -> "closer to the chat distribution" (most
  fitted positions are user/doc tokens, not assistant <think>; run-524 went further)
- ACCEPT soften "what the model thinks" -> "lens readout (linear approx)"
- ADD seed to show_steer so per-C blocks are comparable under sampling
- REJECT "</think> stripped by skip_special_tokens" -- verified false: decode keeps
  think tags (they're added, not registered-special tokens), split_think works

Co-Authored-By: Claudypoo <288921227+claudypoo@users.noreply.github.com>
2026-07-10 15:02:42 +08:00

39 lines
1.5 KiB
Python

"""Repo-local paths, slug/cache conventions, and the fit corpus, shared by
scripts/ and notebooks.
NOT imported by the jsteer library (which stays path-agnostic so `pip install
jsteer` never needs a repo root). The corpus content is jlens's own WikiText
(`load_wikitext_prompts`, not hand-rolled), but wrapped in the model's chat
template -- see chat_corpus for why.
"""
from pathlib import Path
import torch
ROOT = Path(__file__).resolve().parent
ART = ROOT / "artifacts"
DEVICE = "cuda"
DTYPE = torch.bfloat16
def chat_corpus(tok, n_prompts: int) -> list[str]:
"""jlens's WikiText prompts wrapped in the chat template. Fitting on chat-
formatted text (not raw documents) puts J closer to the distribution the
model steers in; run-524's verified vectors were fit this way too. Called
via a lambda in fit_cached, so it only downloads WikiText on a cache miss."""
from jlens.examples import load_wikitext_prompts
return [tok.apply_chat_template([{"role": "user", "content": p}],
add_generation_prompt=True, tokenize=False,
enable_thinking=True)
for p in load_wikitext_prompts(n_prompts)]
def slug(model_name: str) -> str:
"""'Qwen/Qwen3-0.6B' -> 'qwen3-0.6b': a filesystem-safe cache stem."""
return model_name.split("/")[-1].lower()
def cache_path(model_name: str, suffix: str = "jac") -> Path:
"""Where the fitted Jacobian for `model_name` is cached."""
return ART / f"{slug(model_name)}.{suffix}"