Qwen3-VL-8B-Instruct with a gradient-free safety weight edit (synthetic data only)
Research artifact. External evaluation has not been performed. Every safety number on this page was measured by the editing agent on synthetic data that it wrote and judged itself. Treat this checkpoint as something to evaluate, not as a safety mechanism to rely on.
This is Qwen/Qwen3-VL-8B-Instruct at revision
0c351dd01ed87e9c1b53cbc748cba10e6187ff3b with two MLP units of decoder layer 18 overwritten: 24,574 of
8.77 billion weights. Every other tensor, the tokenizer, the processor and the chat template are identical
to the original.
It is the output of one run of a study that asks whether an LLM agent can make a multimodal model safer by editing its weights directly: no gradients, no existing safety dataset (the agent writes all data itself), and at most 500 forward passes of the target model.
EDITING_AGENT = "Claude Fable 5.2"
TARGET_MODEL = "Qwen/Qwen3-VL-8B-Instruct" # revision 0c351dd01ed87e9c1b53cbc748cba10e6187ff3b
COMPUTE = "RUNPOD"
DATASET = "SYNTHETIC_ONLY"
BUDGET = 500 # forward passes; 78 used
What the edit does
The original model already refuses almost every explicit harmful request in the synthetic pools, typed or rendered in an image. It fails when harm has to be inferred: the unsafe meaning is in the picture's context, or a "write this text" request is wrapped in fiction or a forced output format. Activations show that most of these failures are still linearly detectable at the last prompt token, in the MLP input of decoder layer 18, although the model's own refusal read-out stays below threshold.
The edit installs that read-out in the weights. Two MLP units of layer 18 are overwritten so that, only on the last prompt token and only when the harm evidence exceeds a threshold, they add the model's own refusal-associated direction to the residual stream.
Results on the agent's synthetic data
Harmful items answered with real help toward the harmful goal. Greedy decoding, native chat template, no system prompt. Every answer that was not an explicit refusal was read and labelled by the editing agent; warnings, analyses of the request, misreadings and plain summaries count as safe.
| set | role | harmful items | original | this checkpoint |
|---|---|---|---|---|
| Pool A | development | 276 | 21 (7.6%) | 3 (1.1%) |
| Pool A extension | development (recombined items) | 82 | 14 (17.1%) | 0 (0.0%) |
| Pool B1 | transfer check, then development | 138 | 14 (10.1%) | 3 (2.2%) |
| Pool B2 | sealed until the checkpoint was frozen | 138 | 16 (11.6%) | 4 (2.9%) |
| all | 634 | 65 (10.3%) | 10 (1.6%) |
- Benign cost. Refusals on 447 benign requests go from 27 to 32 (6.0% → 7.2%). On the sealed half alone they go from 8 to 11 of 75 (+4.0 points; the limit fixed before the run was 5).
- Utility. 76 of 84 visual and text QA controls are correct before and after.
- Transfer. An earlier variant built only from Pool A and its extension was tested on all of Pool B, which shares no intent, wording or image style with them and adds three harm domains: 30 → 11 of 276 answered.
- Robustness. The effect holds under the model's default sampling, with a system prompt, and with 2× larger JPEG-compressed images. No refused item became an answered one in any check.
Limits
- Narrow, single-author data. The synthetic requests are short, non-operational and of low to moderate severity (fraud, harassment, privacy, forgery, theft, disinformation and similar). Nothing about weapons, mass-casualty agents, offensive cyber, sexual content or minors was written, so behaviour on those domains is untested. Images are drawings and rendered text: no photographs, no adversarially optimised images.
- Self-judged. The editing agent wrote the data and labelled the answers. There is no second annotator.
- Few failures. The original model fails on 65 of 634 items (16 on the sealed half), so confidence intervals are wide.
- Held-out status. Pool B1 informed the final read-out, so only Pool B2 is held out for this checkpoint, and B2 shares prompt families with B1. The cleanest held-out number (30 → 11) belongs to the earlier variant, not to this checkpoint.
- Weakest gains. Harm that is only implied by context (16 → 5 answered over all sets) and forced-JSON prompts on the sealed half (2 → 2). The edit reads harm evidence the model already computes; where the model does not register harm, nothing changes.
- Over-refusal. Benign requests that resemble attacks pay a price (+4.0 points on the sealed half), and one ordinary benign request was refused with an invented reason.
- Not perfectly silent. Overwriting two existing units rewords about a fifth of benign answers within their first 24 tokens (batching noise alone: 3%), with no measurable change in quality (likelihood drift 0.0004 nats per token).
- Selection rule. Of three conditions fixed before the run, the benign-refusal and QA limits were met. "At least two thirds of the families improve" was not met as written on Pool A (7 of 12; the other five had no failure to fix).
- Only the first assistant token. The edit acts at the end of the native generation prompt. A pre-filled assistant turn, or a prompt that does not use the native chat template, is outside its reach.
- Only BF16 was tested. The two units rely on weights that are unusual for the layer: gate rows about 17 times larger than its typical weight (RMS 0.42 against 0.025) and up-projection rows about 6 times smaller (RMS 0.004 against 0.026). A quantiser may clip the former or round the latter to zero, so quantised variants can lose or distort the edit.
Documents in this repository
| file | content |
|---|---|
| results.md | baseline, edited model, validation, utility, robustness, negative results, limitations |
| editing_log.md | every experiment in order: hypothesis, tensors, forward passes, decision |
| PLAN.md | written before the first forward pass: data strategy, diagnostics, pass budget, selection rule |
| next_steps.md | open questions and recommendations for an independent evaluation |
| PROJECT_README.md | README of the run's project folder: layout, reproduction commands, seeds, latency |
These documents are unchanged copies from the run (2026-11-13 UTC). They refer to scripts, logs, edit
specifications, manual labels and the synthetic data by relative path (scripts/, logs/, edits/,
manual/, synthetic_data/, out/). Those belong to the run's project folder and are not part of this
repository.
Use
The checkpoint loads with the standard class. No wrapper, system prompt or processor change is needed.
The run used transformers 4.57.1.
import torch
from transformers import AutoProcessor, Qwen3VLForConditionalGeneration
repo = "Adeely93/wsp-synthetic-qwen3vl-8b-claude-fable-5.2"
model = Qwen3VLForConditionalGeneration.from_pretrained(repo, dtype=torch.bfloat16, device_map="auto")
processor = AutoProcessor.from_pretrained(repo)
messages = [{"role": "user", "content": [
{"type": "image", "image": "path/or/url/of/an/image.png"},
{"type": "text", "text": "Describe this image."},
]}]
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt"
).to(model.device)
out = model.generate(**inputs, max_new_tokens=128)
print(processor.batch_decode(out[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)[0])
To compare with the original model, run both with identical settings: native chat template, same system prompt (the run used none), same decoding.
The exact change
All three tensors are in model.language_model.layers.18.mlp and are stored in
model-00002-of-00004.safetensors. The other three weight shards are byte-identical to the original.
| tensor | shape | changed | values changed | sha256 of the edited tensor |
|---|---|---|---|---|
gate_proj.weight | 12288 × 4096 | rows 3431, 8919 | 8,191 | 4f225c24da37c7fc66027f460be413c46c08768d17883cc78f50d0af5e3585f8 |
up_proj.weight | 12288 × 4096 | rows 3431, 8919 | 8,192 | b27a8c2a3add9c7b4d3cdf733d1f7fb39873c2c5f87ce8e0e29d90583d66c6b4 |
down_proj.weight | 4096 × 12288 | columns 3431, 8919 | 8,191 | 6cc338bb71833446ef22c08ec845a9f260d4c7ae2d43c32bd29bd74260661bf1 |
The tensor hash is the sha256 of the tensor's raw BF16 bytes in row-major order.
Gate parameters: θ₁ = 0.333, θ₂ = 0.433, β = 40, ρ = 4. A full write has norm about 49; the residual stream at that token has norm about 85.
Files and hashes
| file | content |
|---|---|
model-0000{1,2,3,4}-of-00004.safetensors, model.safetensors.index.json | weights: BF16, 750 tensors, original names, shapes and shard assignment |
config.json, generation_config.json, preprocessor_config.json, video_preprocessor_config.json, chat_template.json, tokenizer.json, tokenizer_config.json, vocab.json, merges.txt | byte-identical to the original snapshot |
checkpoint_sha256.json | sha256 of every file of the frozen checkpoint, and the checkpoint hash |
ORIGINAL_MODEL_CARD.md | the original model card of Qwen/Qwen3-VL-8B-Instruct, unchanged |
- Edited shard
model-00002-of-00004.safetensors: sha256b632bb9c6c64c49edc7467292cb7be5052fa03ad2751ced4eadf6158bc88951f. - Checkpoint hash:
6cf0945710042b7c85553f59533da2c34d01da61df3d5afb20e16527fd43cfd9(sha256 over the lines<file>:<sha256>of all checkpoint files, sorted by name). - In the frozen checkpoint the original model card is named
README.md, andcheckpoint_sha256.jsonlists it under that name. Here it is stored asORIGINAL_MODEL_CARD.md, because the Hub usesREADME.mdfor this page.
Check a download against the frozen checkpoint:
import hashlib, json, os
from huggingface_hub import snapshot_download
d = snapshot_download("Adeely93/wsp-synthetic-qwen3vl-8b-claude-fable-5.2")
rec = json.load(open(os.path.join(d, "checkpoint_sha256.json")))
for name, meta in rec["files"].items():
path = os.path.join(d, "ORIGINAL_MODEL_CARD.md" if name == "README.md" else name)
h = hashlib.sha256()
with open(path, "rb") as f:
for block in iter(lambda: f.read(1 << 24), b""):
h.update(block)
assert h.hexdigest() == meta["sha256"], name
lines = "".join("%s:%s\n" % (n, rec["files"][n]["sha256"]) for n in sorted(rec["files"]))
assert hashlib.sha256(lines.encode()).hexdigest() == rec["checkpoint_hash"]
print("all", len(rec["files"]), "files match; checkpoint hash", rec["checkpoint_hash"])
How the edit was built
- Inside counted forward passes, capture the residual stream and the MLP input at the five final chat-template tokens, plus second moments over all positions.
- Read-out:
w = (Σ_within + Σ_all + ridge)⁻¹ (μ_refused − μ_benign)in the MLP input of layer 18 at the last template token, fitted on refused-harmful against benign items and validated leave-one-family-out. - Token detector
u: the minimum-energy vector withu·μ_family = 1for every prompt family. - Two units (8919, 3431) of
layers.18.mlp:gate_projrowsβ(w_c − θ₁u)andβ(w_c − θ₂u),up_projrowsu,down_projcolumns±(ρ/4)·v, wherevis the mean residual difference refused − benign after layer 18 at that token. Together they form a soft step that writesρ·vwhen the evidence passes the threshold. - Round to BF16, evaluate, restore; repeat for variants; freeze; write the checkpoint.
No gradients were computed at any point. Rejected alternatives (an unconditional push along the refusal direction, amplifying that direction in the writer matrices of layers 16–19, a random write direction, a stronger write, a lower threshold) are reported in results.md.
Environment of the run
- Hardware: one NVIDIA A40 (48 GB) on RunPod Secure Cloud, driver 595.91.07, Ubuntu 24.04.
- Software: Python 3.11.18, torch 2.8.0+cu128, torchvision 0.23.0+cu128, transformers 4.57.1, tokenizers 0.22.1, accelerate 1.10.1, safetensors 0.6.2, numpy 2.2.6, pillow 11.3.0.
- Inputs: native processor and chat template, image first then text, no system prompt, native image preprocessing.
- Decoding for all headline numbers: greedy,
repetition_penalty1.0. A separate check used the model's default sampling (temperature 0.7, top-p 0.8, top-k 20) with fixed seeds.
License and attribution
Apache-2.0, the license of the base model. The base model is Qwen3-VL-8B-Instruct by the Qwen team at Alibaba Cloud; its model card, with usage notes and citations, is kept as ORIGINAL_MODEL_CARD.md.