Downloads · 30 days
0
asatheesh/latent-mas-aligner-qwen3-4b-instruct-seed-2
latent-mas-aligner-qwen3-4b-instruct-seed-2 is a machine learning model from asatheesh. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for pytorch. The card lists the license as apache-2.0.
A LatentShield aligner for LatentMAS on Qwen3-4B-Instruct-2507, the non-thinking Qwen3 variant. The three reasoning agents exchange latent vectors, the Judger answers in text, and this module scores those latents befo…
Downloads · 30 days
0
Access
Public
Updated Nov 5, 2026
Repo size
109 MB
Likes
0
Public
Click a slice to open those files.
.pt109 MB · 100%
From the Hugging Face model README
A LatentShield aligner for LatentMAS on Qwen3-4B-Instruct-2507, the non-thinking
Qwen3 variant. The three reasoning agents exchange latent vectors, the Judger answers
in text, and this module scores those latents before the Judger speaks. A score above
tau prepends a safety notice to the Judger's input.
How this backbone differs from Qwen3-4B. Undefended, the instruct model's LatentMAS
has a StrongREJECT ASR of only 0.029 (Qwen3-4B: 0.342). Harmful completions are also rarer
in its training data: 6.3% of rollouts, against 16.4% for Qwen3-4B. Its
thresholds sit much lower: this seed's p10 is 0.5679 (the three seeds span
0.385–0.607, against 0.714–0.794 for Qwen3-4B), so thresholds from the thinking model do
not carry over.
p01 | p05 | p10 | p20 | p50 |
|---|---|---|---|---|
| 0.9387 | 0.7944 | 0.5679 | 0.0767 | 0.0000 |
Thresholds are quantiles of this seed's p_unsafe on benign validation rollouts: p10
is the value that 10% of them exceed.
| HarmBench ASR ↓ | StrongREJECT ASR ↓ | OR-Bench-Hard RR ↓ | PHTest FRR ↓ | mean ↓ | |
|---|---|---|---|---|---|
| LatentMAS, no defense | 0.141 | 0.029 | 0.058 | 0.026 | 0.064 |
this checkpoint (p10) | 0.013 | 0.096 | 0.099 | 0.101 | 0.077 |
seed 0 (p10) | 0.019 | 0.029 | 0.093 | 0.093 | 0.058 |
seed 1 (p10) | 0.022 | 0.013 | 0.111 | 0.125 | 0.068 |
HarmBench ASR drops from 0.141 to 0.013–0.022 across seeds. StrongREJECT does not improve:
the undefended pipeline is already at 0.029, and seeds land at 0.013–0.096 (seed 2 is
higher than no defense). Over-refusal rises: OR-Bench-Hard from 0.058 to 0.093–0.111,
PHTest from 0.026 to 0.093–0.125. Of the three Qwen3-4B-Instruct-2507 seeds, this one has the highest mean failure rate at p10 (0.077; the seeds span 0.058–0.077). Seed-to-seed spread is part of the result, so report all three rather than picking one.
| input | pre-Judger latents [B, 24, 2560] (3 agents × 8 latent steps) |
| pooling | single learned attention query (variable length) |
| head | MLP → frozen Llama-Guard-3-8B layers 17–31 + norm + LM head |
| trainable params | 27.3M |
| data | latent-mas-safety-dataset-seq-qwen3-4b-instruct, 285,440 / 30,488 train / val prompts |
| label | harm-compliance (prompt harmful ∧ response harmful) |
| recipe | class weights 1:10, 60 epochs, lr 3e-4, batch 512, seed 2 |
The frozen Llama-Guard-3-8B tail (decoder blocks 17–31, final norm, LM head; 7.6 GB) is not included in this repo. Build it once from meta-llama/Llama-Guard-3-8B (a gated model; request access first) with python -m scripts.aligner.extract_cli --mode dump-head-bundle --layer 16 --out guard_head_bundle.pt.
import torch
from huggingface_hub import hf_hub_download
from scripts.aligner.compute_tau_fpr05 import load_aligner_artifact, compute_p_unsafe
from scripts.aligner.guard_head import load_head_bundle
from transformers.models.llama.configuration_llama import LlamaConfig
from transformers.models.llama.modeling_llama import LlamaRotaryEmbedding
# Llama-Guard-3-8B rotary embedding (same values as compute_tau_fpr05.py)
rope = LlamaRotaryEmbedding(LlamaConfig(
hidden_size=4096, num_attention_heads=32, num_key_value_heads=8, head_dim=128,
max_position_embeddings=131072, rope_theta=500000.0,
rope_scaling={"rope_type": "llama3", "factor": 8.0, "low_freq_factor": 1.0,
"high_freq_factor": 4.0, "original_max_position_embeddings": 8192})).to("cuda")
aligner = load_aligner_artifact(hf_hub_download("asatheesh/latent-mas-aligner-qwen3-4b-instruct-seed-2", "aligner.pt")).to("cuda").eval()
head = load_head_bundle("guard_head_bundle.pt", use_remaining_layers=True,
rotary_emb=rope, device="cuda")
# h_a: [B, K, 2560] pre-Judger latents, K = 8 latent steps x pre-Judger agents
p_unsafe = compute_p_unsafe(aligner, head, h_a, batch_size=64, device="cuda")
flag = p_unsafe > 0.5679
Not a standalone moderation model. Inputs must come from Qwen3-4B-Instruct-2507's
LatentMAS (d_a = 2560).
Code: https://github.com/Asatheesh6561/LatentMASHarmBench · Part of the LatentShield collection.