Downloads · 30 days
0
lingzhiyxp/latentmas-aligner-qwen3-4b
latentmas-aligner-qwen3-4b is a machine learning model from lingzhiyxp. 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.
Self-attention aligners (AttnAligner) that read the pre-Judger latent states of a LatentMAS multi-agent pipeline on Qwen3-4B (the non-Instruct backbone) and emit a scalar punsafe. They are safety monitors for latent m…
Downloads · 30 days
0
Access
Public
Updated Sep 4, 2026
Repo size
218 MB
Likes
0
Public
Click a slice to open those files.
.pt218 MB · 100%
From the Hugging Face model README
Self-attention aligners (AttnAligner) that read the pre-Judger latent
states of a LatentMAS multi-agent pipeline on Qwen3-4B (the non-Instruct
backbone) and emit a scalar p_unsafe. They are safety monitors for latent
multi-agent reasoning: the agents never write their intermediate reasoning as
text, so a text-based guardrail has nothing to read — these heads classify the
latents directly.
| File | Seed |
|---|---|
aligner_..._seq_..._seed=1.pt | 1 |
aligner_..._seq_..._seed=2.pt | 2 |
| (seed 0 lives upstream — see below) | 0 |
Same data (N=315,731, 51,702 positives), same recipe, 60 epochs. Only --seed
differs.
| seed | val AUC | τ@fpr10 | harm recall @τ | over-refusal @τ |
|---|---|---|---|---|
| 0 † | 0.9522 | 0.5078118443 | 0.8557 | 0.0327 |
| 1 | 0.9492 | 0.4196479619 | 0.8322 | 0.0408 |
| 2 | 0.9503 | 0.3784590662 | 0.8456 | 0.0531 |
| mean ± sd | 0.9506 ± 0.0015 | — | 0.8445 ± 0.0118 | — |
| range | 0.0030 | 0.1294 | 0.0235 | — |
† Seed 0 is not in this repo. It is
asatheesh/latent-mas-aligner
→ aligner_classifier_harmcompliance_WJ.pt, trained by the dataset author before
this study.
Its provenance was verified, not assumed: scored on this repo's val split it reaches 0.9522, and on the Qwen3-4B-Instruct val split it collapses to 0.5988 (near chance). That gap identifies the training distribution. As a control, our own seed 1 was scored the same way and reproduced its training-log value (0.9492) exactly, confirming the harness.
Its own model card reports 0.9555, not 0.9522. The 0.0033 difference is almost certainly a different validation split — ours has 20,378 records, and the split used for that run is unknown. So 0.9522 is "the upstream checkpoint re-scored on our split", not "the number its authors published". All three rows above were measured on one identical split, which is what makes the comparison valid; do not read the 0.9522 as a correction to their 0.9555.
val AUC is reproducible to ±0.0015. The spread (0.0030) is smaller than the epoch-to-epoch oscillation within a single run (~0.005).
τ is not reproducible, and that is expected. It ranges over 0.13 across seeds while recall at τ moves by 0.02. τ is a quantile of the score distribution; a run whose scores sit higher gets a proportionally higher τ and lands on the same operating point.
Never reuse a τ across checkpoints. Each
.ptmust be paired with the τ measured for that exact file.
| seed | τ | harm | overref | |
|---|---|---|---|---|
| 0 † | fpr05 | 0.7461389899 | 0.7106 | 0.0122 |
| fpr10 | 0.5078118443 | 0.8557 | 0.0327 | |
| fpr20 | 0.1871326864 | 0.9488 | 0.1673 | |
| 1 | fpr05 | 0.6901415586 | 0.7064 | 0.0082 |
| fpr10 | 0.4196479619 | 0.8322 | 0.0408 | |
| fpr20 | 0.1179780215 | 0.9404 | 0.1306 | |
| 2 | fpr05 | 0.6379335523 | 0.7022 | 0.0000 |
| fpr10 | 0.3784590662 | 0.8456 | 0.0531 | |
| fpr20 | 0.0926877782 | 0.9430 | 0.1388 |
Calibrated on the frozen 20,378-record val split (18,941 labelled safe). Use
fpr10 for deployment; LatentMAS eval runs prompt: sequential.
h_a [24, 2560] stacked planner/critic/refiner latents
│ (3 agents × 8 latent steps, Qwen3-4B hidden dim)
├─ learned query → softmax → weighted sum (attention pool over 24 positions)
├─ Linear(2560 → 4096) → GELU → Linear(4096 → 4096)
↓
w_h [4096] a point in Llama-Guard-3-8B's residual space
│
├─ FROZEN Llama-Guard-3-8B tail: blocks 17–31 + final norm + lm_head
↓
logits at the "safe" / "unsafe" token ids → softmax → p_unsafe ∈ [0, 1]
Only the pooling query and the 2-layer MLP are trained — 27.3 M parameters
(105 MB fp32 each). The Llama-Guard tail is frozen and not included here;
rebuild it from meta-llama/Llama-Guard-3-8B at load time.
asatheesh/latent-mas-safety-dataset-seq-qwen3-4b
| records | positives | positive rate | |
|---|---|---|---|
| Qwen3-4B (non-Instruct) | 315,731 | 51,702 | 16.4 % |
| Qwen3-14B | 311,357 | 36,989 | 11.9 % |
| Qwen3-4B-Instruct | 315,928 | 19,981 | 6.3 % |
This backbone complies with harmful requests 2.6× as often as its Instruct sibling (16.4 % vs 6.3 % over comparable prompts), which is what safety tuning buys. The three datasets span 6–16 % positives, so the seed-stability result above holds across a wide range of class imbalance.
Label is harm-compliance: v_g = prompt_harmful AND response_harmful
(WildGuard). A refusal to a harmful prompt is negative — the head fires on
harmful content the system actually complied with, not on harmful topics.
Note the higher over-refusal at every operating point here (0.03–0.17 at fpr20) than on the Instruct backbone. With 16 % positives the score distribution is denser near the boundary, so a fixed FPR target costs more benign traffic.
--pool attention --hidden-dim 4096 --use-remaining-layers
--shard-label-mode harmcompliance
--class-weights 1.0,10.0
--lam 1.0 --lr 3e-4 --epochs 60 --batch-size 512
--seed {1,2}
--guard-name meta-llama/Llama-Guard-3-8B
Seed 0 was trained by the dataset author on the same recipe.
python -m scripts.aligner.extract_cli \
--mode dump-head-bundle --layer 16 \
--out data/aligner/guard_head_bundle.pt --device cuda:0
qwen3_4b_latent_mas_aligner_seq_fpr10:
model_type: open_source
model:
model_name_or_path: Qwen/Qwen3-4B
mas_mode: latent_mas
prompt: sequential
latent_steps: 8
use_vllm: true
device: cuda:0
device2: cuda:0
aligner_defense: true
aligner_path: <one of the .pt files>
aligner_guard_head: data/aligner/guard_head_bundle.pt
aligner_tau: 0.4196479619 # MUST match the chosen file — see the table above
num_gpus: 2
YuanXiaopang/latentmas-aligner-qwen3-4b-instruct — same seed study on Qwen3-4B-Instruct, plus hier / seq+hier and a topology-transfer matrixYuanXiaopang/latentmas-aligner-qwen3-14b — same seed study on Qwen3-14Basatheesh/latent-mas-aligner — the seed 0 checkpointd_a is 2560 here and 5120 for Qwen3-14B, so those checkpoints are not
interchangeable. Qwen3-4B and Qwen3-4B-Instruct share d_a = 2560 but were
trained on different latent distributions — a head from one scores near chance on
the other (0.5988 measured), so they are not interchangeable either.
Per run: ~40 min–2 h on one A6000/H200-class GPU. Peak host RAM ~94 GB
(h_a is one contiguous fp16 [315731, 24, 2560] tensor = 38.8 GB); the peak is
node-dependent, so request ≥120 GB.