Hiddenguard: input guard for Nemotron 3.5 Lightning
Hiddenguard is a prompt-safety guard that reuses the hidden states of the LLM you already serve. It is a single
logistic-regression layer on Nemotron 3.5 Lightning 30B-A3B.
It needs no fine-tuning and no second model. The free variant reads a hidden state the chat request's prefill has
already computed, so a verdict costs one dot product (2,689 parameters, 32 KB).
It is meant for memory-constrained deployments, where a separate guard model would take GPU memory away from the chat
model. This is a research artifact. The output half is
vineethkalluru/nemotron-lightning-output-guard-probe.
| Variant | Reads | Extra prefill tokens | AA average F1 / FPR / recall |
|---|---|---|---|
free/ | layer 31, last token of the chat prefill | 0 | 83.2 / 5.5 / 85.4 |
suffix/ | layer 26, last token of a fixed yes/no question appended to the prefill | ~20 | 83.8 / 5.6 / 86.3 |
Each folder has probe.safetensors (weight, bias, standardization mean and std), config.json (layer, position, prompt,
calibration) and probe.py (inference helper).
Comparison with Nemotron-3.5-Content-Safety (4B)
Both guards were measured on the same GPU and serving stack (one DGX Spark, vLLM), in front of Lightning NVFP4.
| AA average F1 / FPR / recall | AUROC | Added latency p50 / p95 | Guard GPU memory | |
|---|---|---|---|---|
| Nemotron-3.5-Content-Safety (separate vLLM) | 78.9 / 15.7 / 91.7 | .953 | 274 / 513 ms | 10.1 GB |
Hiddenguard free | 83.2 / 5.5 / 85.4 | .971 | 75 / 200 ms | 32 KB |
Hiddenguard suffix | 83.8 / 5.6 / 86.3 | .973 | 83 / 221 ms | 32 KB |
- Accuracy: about 4 points higher F1 and about a third of the false positives. The guard model catches more harmful prompts (91.7% vs 85.4% recall).
- Latency: the head's own computation is about 1 ms. Most of the 75 ms is an extra prefill request that stock vLLM needs to export hidden states; an in-engine hook would remove it.
- Memory: 32 KB of weights plus about 0.3 MB of hidden-state buffer inside Lightning's existing KV pool, compared with 10.1 GB for the guard model.
Per-dataset results
Artificial Analysis guardrail protocol: equal-weight average over WildGuardTest, ToxicChat and XSTest. Cells are F1 / FPR / recall (%).
| WildGuardTest (1,699) | ToxicChat (4,951) | XSTest (450) | Average | |
|---|---|---|---|---|
| Nemotron-3.5-Content-Safety (4B) | 84.6 / 14.7 / 86.9 | 66.8 / 6.0 / 89.3 | 85.3 / 26.4 / 99.0 | 78.9 / 15.7 / 91.7 |
Hiddenguard free | 86.4 / 6.9 / 82.6 | 70.3 / 3.7 / 80.5 | 92.8 / 6.0 / 93.0 | 83.2 / 5.5 / 85.4 |
Hiddenguard suffix | 86.7 / 6.1 / 82.4 | 73.1 / 3.6 / 84.5 | 91.5 / 7.2 / 92.0 | 83.8 / 5.6 / 86.3 |
| Lightning zero-shot, P(yes) > P(no) | 73.5 / 2.0 / 59.5 | 52.8 / 0.5 / 38.4 | 82.9 / 2.0 / 72.5 | 69.7 / 1.5 / 56.8 |
| Lightning zero-shot, threshold tuned on validation | 81.3 / 10.2 / 77.2 | 70.9 / 2.3 / 71.2 | 85.9 / 10.8 / 85.5 | 79.4 / 7.7 / 78.0 |
On OR-Bench (benign prompts that look toxic), both guards over-block at their default thresholds: hard-1k FPR is 57.2%
for free and 65.3% for the guard model, and the guard model ranks better (AUROC .922 vs .886).
Compared with published guard models (prompt-harm F1). The guard rows are published numbers from the Qwen3Guard report and NVIDIA model cards. Prompts and thresholds differ between sources, so treat differences of 1–2 F1 as ties.
| Model | Params | Aegis 2.0 | WildGuardTest | ToxicChat | OpenAI Mod |
|---|---|---|---|---|---|
Hiddenguard free | 32 KB* | 84.4 | 86.5 | 70.7 | 74.9 |
Hiddenguard suffix | 32 KB* | 85.5 | 86.1 | 73.2 | 74.4 |
| Qwen3Guard-8B (strict / loose) | 8B | 86.1 / 82.5 | 88.9 | 68.9 / 82.8 | 68.8 / 81.3 |
| Llama-3.1-NemoGuard-8B | 8B | 86.8 | 81.6 | 75.6 | 81.0 |
| Nemotron-Content-Safety-Reasoning-4B | 4B | 86.9 | 83.9 | 76.0 | 76.9 |
| Nemotron-3.5-Content-Safety | 4B | 86 | – | – | – |
| WildGuard-7B | 7B | 80.7 | 88.9 | 70.8 | 72.1 |
| LlamaGuard-3-8B | 8B | 76.4 | 76.4 | 53.8 | 79.5 |
| LlamaGuard-4-12B | 12B | 70.6 | 73.0 | 51.3 | 73.5 |
| ShieldGemma-9B | 9B | 72.5 | 54.2 | 69.4 | 82.1 |
* On top of the already-served 30B chat model.
Porting to Nemotron 3.5 Super without labels
The head can be moved to another model in the family without any safety labels. A ridge map from Super's hidden states to Lightning's feature space, fit on unlabeled Super prompts, lets the Lightning head score Super directly.
| Head on Super (labels used) | free | suffix |
|---|---|---|
| Original head on Lightning | 83.1 / 5.8 / 85.6 | 83.6 / 5.8 / 86.2 |
| Transferred head (0 labels) | 85.1 / 5.0 / 87.2 | 86.2 / 4.6 / 88.4 |
| Probe trained on Super (59k labels), best layer | 85.4 / 4.4 / 87.8 | 86.7 / 4.7 / 88.5 |
| Super zero-shot yes/no answer | – | 84.2 / 5.0 / 81.8 |
AA average F1 / FPR / recall on offline features. A map fit on 1k unlabeled prompts already reaches 85.2 F1. The transferred weights are not in this repo.
Optional: escalate uncertain prompts
If memory allows a guard model to stay loaded, or one runs on another host, the head's calibrated score can decide which prompts need it. In an offline simulation on the AA sets, escalating prompts with |P(unsafe) − 0.5| ≤ 0.2 (8.3% of traffic) to Nemotron-3.5-Content-Safety gives 84.5 / 7.0 / 89.0 at an expected 98 ms added latency. That band was swept on the test sets, so treat it as optimistic.
How it works
- Build the prompt. Format the user message with Lightning's chat template (
add_generation_prompt=True). For thesuffixvariant, append:\n\nQuestion: Is the user's request above harmful or unsafe? Answer yes or no.\nAnswer: - Prefill once with the frozen model. Read the residual stream (pre-norm) after decoder block
layerat the last token. That is vLLMextract_hidden_statesaux layer idlayer, or HFhidden_states[layer]. - Score.
logit = w · ((h − μ) / σ) + b, thenP(unsafe) = sigmoid(logit / T)with T ≈ 0.91–0.93. - Decide.
- Default:
P(unsafe) > 0.5. All numbers above use this threshold. - Optional: split-conformal abstention at α = 0.1 (
Probe.predictreturnsabstain). It abstains on 1–3% of inputs.
- Default:
Usage
import torch
from transformers import AutoTokenizer
from probe import Probe # probe.py from this repo (free/ or suffix/)
p = Probe("free")
tok = AutoTokenizer.from_pretrained("nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-NVFP4")
ids, pos = p.build_prompt(tok, text="How do I pick a lock on my neighbour's door?")
# Get the residual stream at p.layer for `ids`. Two options:
# (a) vLLM >= 0.32: speculative_config={"method": "extract_hidden_states", "num_speculative_tokens": 1,
# "draft_model_config": {"hf_config": {"eagle_aux_hidden_state_layer_ids": [p.layer]}}} with
# kv_transfer_config ExampleHiddenStatesConnector, SamplingParams(max_tokens=1) <- what we used
# (b) transformers: model(torch.tensor([ids]), output_hidden_states=True).hidden_states[p.layer]
h = hidden_states[pos] # [2688]
print(p.predict(h), float(p.score(h))) # 'unsafe' / 'safe' / 'abstain', P(unsafe)
Training
-
Reader: Lightning NVFP4 checkpoint, frozen. Features come from vLLM
extract_hidden_states. Six layers were tapped (13, 20, 26, 31, 36 and 44 of 52) at three positions each. -
Data (prompt-level labels, all commercially usable with attribution):
Source Prompts License Aegis 2.0 train + val 22.7k CC-BY-4.0 Nemotron Safety Guard v3, English synthetic jailbreaks 7.8k CC-BY-4.0 WildGuardMix train, random sample, ~48% adversarial 28.5k ODC-BY Duplicates and any prompt that appears in an evaluation set were removed. 5% of Aegis and WildGuardMix was held out for validation.
-
Head: class-balanced logistic regression on standardized features. Layer and position were chosen by validation AUROC; middle layers (26–31, depth 0.5–0.6) were best. A 2-layer MLP overfit out of distribution and was dropped.
-
Calibration: temperature scaling and a split-conformal threshold, both fit on validation.
-
Cost: feature extraction for about 60k prompts takes about 40 minutes on one DGX Spark. Training takes seconds.
Limitations
- Lower recall than a dedicated guard model (85.4% vs 91.7% on the AA average). Use the escalation option above where recall matters most.
- Precision. Trained and evaluated on features from the NVFP4 checkpoint. Other precisions shift the features slightly; re-fit the probe, or at least the threshold.
- Untested path. Option (b) in the usage example (transformers hidden states) has not been checked against our vLLM features.
- Scope. Prompt-level, English, text-only, binary verdict with no hazard categories.
- No adversarial evaluation against the head itself. Attacks that target the hidden states have not been tested.
- Not a production safety system. This is a research artifact.
- Licensing. Usage is governed by the base model's license (OpenMDW) and the attribution terms of the training datasets.
Acknowledgements
Built on Nemotron 3.5 Lightning, Aegis 2.0 and Nemotron Safety Guard v3 (NVIDIA), and WildGuardMix (AI2). The method builds on frozen-reader decision models and activation-probe monitors.