Reflection 安全工具為 SGLang 加入激活值監測與逐 token 內容分類
Safety monitoring in SGLang: Reflection's AI safety tools add activation monitors and per-token content classification
SGLang 與 Reflection 合作,在推理引擎加入預設關閉的選用安全監測,整合 Iris Cyber Probe 的生成中激活值監測,以及 Iris Content Guard 的逐 token 內容分類。
SGLang is adding opt-in safety monitoring to the inference engine, starting with a partnership with Reflection. Reflection has published Iris Safety Evaluations (ISE) as an open-source benchmark and released two safeguards: Iris Cyber Probe (ICP) and Iris Content Guard (ICG). These tools help the AI community detect and address harm during and after inference. Learn more here.
Iris Cyber Probe (ICP) gives deployers a way to catch and stop misuse in real time during model inference. Unlike text monitors that must read complete inputs and outputs, ICP reads a model’s internal activations directly as tokens generate. Deployers can use the system to steer the model toward a safe response or halt generation entirely. Learn more here.
Iris Content Guard (ICG) is an open-weight safety classifier (28.7B total parameters, 3.2B active) for monitoring user requests and assistant responses in conversation context. ICG runs on a single 80 GB H100 GPU for lightweight standalone deployment. Learn more here.
SGLang runs stateless linear and MLP activation monitors on the serving GPU. For more accurate stateful sequence probes, it streams per-token features to a separate scoring process so probe history stays out of the KV cache. For standalone content classification, we extended /v1/classify to multi-label per-token models and added BeamForTokenClassification to serve reflection/Iris-Content-Guard with prefill CUDA graphs. Neither feature runs by default: activation monitoring stays off unless you configure it at launch, and Iris Content Guard deploys as a separate classification server. When you enable stateful monitoring on B300 (Beam 1.0 NVFP4 TP4 with DFLASH 2 at concurrency 128), a dedicated fifth GPU keeps throughput loss to 0.71%, and sharing a serving GPU keeps it under 5%. Both interfaces work with any compatible checkpoint. Model developers supply the weights, and operators set their own thresholds and enforcement policies.
SGLang’s goal is to make frontier-level inference open and accessible to everyone. That requires distributing the ability to defend against misuse as widely as the ability to run open models. Even though a bad actor can disable safeguards on a private server, every operator who turns them on protects their users, and shared open tooling lets the community raise the bar against misuse together. Beam is our first integration with Reflection. We invite other model developers to build on this same interface and ship monitors alongside their open weights from day one so runtime safeguards become a standard part of serving open models.
This post covers the design, serving overhead, and trade-offs behind both integrations, following RFC #46678.
Highlights
- Low serving overhead on B300 (off by default). With no monitors configured, SGLang skips all monitor paths. On Beam 1.0 NVFP4 (TP4, DFLASH 2) with one Iris minGRU probe enabled at concurrency 128, a dedicated fifth GPU lowers throughput by 0.71% with 0.349 s P99 wait, and sharing GPU 3 lowers throughput by 4.81% with 0.436 s P99 wait.
- Stateless monitors on the serving GPU. Linear and MLP probes run in eager mode and CUDA graphs, returning token-aligned scores on
/generateandEngine.generate. - Stateful probes outside the KV cache. SGLang streams per-token features to a separate scoring process and tags cached tokens with a 16-byte computation ID that follows the KV cache across prefix reuse, HiCache, unified memory, and prefill-decode disaggregation.
- Zero missing scores over six hours. Protecting KV page boundaries and reused prefixes inside an 8 GiB history budget scored all 59.95M output tokens across 67,846 requests at concurrency 64, compared with 18.38% missing under plain LRU.
- Multi-label per-token
/v1/classify. SGLang adds elementwise sigmoid outputs and per-token classification, servingreflection/Iris-Content-Guardwith 28 harm probabilities per token under breakable and full prefill CUDA graphs.
Two safety layers in one serving stack
Running a second large language model on every turn adds heavy compute and latency. Public results from Anthropic’s Constitutional Classifiers++ and Google DeepMind’s Gemini probe cascade show that small activation probes can screen most traffic at a fraction of that cost. Only uncertain turns escalate to a heavier classifier. Project Iris pairs both approaches inside SGLang:
| Integration | Mode | Inputs | State | Delivery | Role |
|---|---|---|---|---|---|
| Activation monitor (stateless) | Native (--activation-monitors) | Residual taps during generation | None (linear or MLP) | meta_info.activation_monitors in /generate | Low-overhead inline screening for custom linear or MLP probes |
Activation monitor (stateful, e.g. Iris-Cyber-Probe) | Separate scoring process | Compact projected features and 16-byte computation IDs | Recurrent history in scorer host RAM (minGRU, local-attention minGRU) | GET /v1/monitor_scores/{rid} and SSE stream | Real-time online monitoring during generation (cyber and jailbreak detection) |
| Iris Content Guard | Token classifier (BeamForTokenClassification) | Tokenized conversation history | None (single full prefill) | POST /v1/classify ([num_tokens, 28]) | Offline conversation classification across 14 broad harm categories (not limited to cyber offense) |
An activation monitor reads hidden states from inside the generating model and feeds them to a small classifier called a probe. Because the probe outputs scores as tokens generate, a client can stop a misaligned response mid-stream rather than waiting for generation to finish. Safety monitoring is the primary use case, though the interface works for any token-level scoring task.
Stateless and stateful probes
SGLang supports two probe types:
- Stateless monitors. Read each token’s hidden state from selected layers and run a linear probe or small MLP. They need only the current token’s activations and keep no state from earlier tokens. SGLang supports stateless monitors out of the box, though Reflection’s initial Project Iris release ships stateful probes only.
- Stateful monitors. Tap the same hidden states and feed them to a sequence model such as a minGRU. Using history from every prior token lets the probe catch behavior that builds up across a response and would not appear in a single token. Reflection’s first open probe,
reflection/Iris-Cyber-Probe, uses this stateful path to detect cyber and jailbreak attempts during inference, with probes for additional harm areas planned.
Engine integration
Stateless monitors fit into SGLang with no KV-cache changes. Probes run on the serving GPU on every forward pass, in eager mode and in decode and verify CUDA graphs, and SGLang reserves monitor buffers before KV-cache sizing. SGLang returns scores aligned to generated tokens in meta_info.activation_monitors on /generate and Engine.generate. Under speculative decoding, SGLang returns scores only for accepted tokens and the bonus prediction, omitting rejected candidates. Unavailable or nonfinite rows appear as null, and each monitor reports a status of ok, partial, or unavailable.
Stateful monitors are harder to integrate. A minGRU probe needs the exact activation history of every preceding token. Recomputing the same prompt under a different batch shape can shift activations in reduced precision, so SGLang cannot key probe history by token text. Storing probe state inside SGLang would force every KV-cache path to track and copy it, including prefix reuse, request retraction, HiCache offload, and prefill-decode transfers over Mooncake or NIXL.
Instead, SGLang moves stateful scoring into a separate scoring process. That leaves the engine with two jobs:
- Stream per-token features. Run the probe’s lightweight feature projection on the serving GPU and send compact features for committed tokens to the scoring process over ZeroMQ.
- Tag cached tokens with a 16-byte computation ID. Attach a 16-byte ID to each cached token that travels with the KV cache. The scoring process keys each probe’s history by those IDs, looks up the exact matching state on prefix hits, and marks downstream scores unavailable if an ID is missing.
Because the engine holds no probe state, stateful monitors stay out of the way of everyday SGLang development.

Figure 1. Native stateless monitors run linear or MLP probes on the serving GPU in eager mode and CUDA graphs. Decoupled stateful monitors stream projected features over ZeroMQ to the separate scoring process and track prefix reuse with a 16-byte computation ID.
Supported setups and extensibility
Stateless monitors run linear and MLP probes on the serving GPU in eager mode and CUDA graphs, supporting tensor parallelism and EAGLE, EAGLE3, STANDALONE, and DFLASH speculative decoding. Stateful monitors support the same configurations and add prefill-decode disaggregation over Mooncake and NIXL. Computation IDs follow the KV cache through prefix reuse, retraction, HiCache, and unified KV memory.
SGLang keeps monitor loading and model adaptation separate from core serving logic:
- Launch-time registration. Operators register native monitors at launch as a Python factory function and config, and register stateful monitors by name and checkpoint path. Requests cannot load or select monitors.
- Self-describing checkpoints. Each checkpoint pairs a
config.jsonfile with safetensors weights declaring tapped layers, input normalization, output columns, and, when pinned, the base model and revision it was trained on. When a checkpoint pins them, SGLang checks both at startup so the probe cannot run on the wrong weights. - Adding models and probes. Supporting a new base model takes a small adapter that exposes layer-boundary residuals, reusing the capture path that EAGLE3 draft models use. New stateful probe architectures live inside the scoring process and need no core engine changes as long as they reuse the engine’s per-token feature projection. Probe training happens outside SGLang.
Iris Content Guard
Activation monitors score a model from its own hidden states during inference. Operators can also deploy a standalone text classifier through /v1/classify for offline conversation monitoring, separate from the generation path and independent of any generator’s internal activations. Unlike Iris-Cyber-Probe, which targets cyber and jailbreak attempts in real time, Iris-Content-Guard covers 14 broad safety categories rather than cyber offense alone. It grades both the user request and the optional assistant reply in a single pass, helping organizations distinguish adversarial requests from harmless discussions of sensitive topics so they can review conversations, investigate recurring safety issues, and take account-level action.
Extending /v1/classify for multi-label token classifiers
Before Project Iris, SGLang’s /v1/classify endpoint assumed single-label sequence classification and applied softmax to one score vector per input. On malformed or per-token scores, it returned HTTP 200 with a placeholder label: "Default" and probs: [1.0], forcing callers to fall back to /encode. To fix this, we introduced:
- Multi-label sigmoid probabilities (
#51338). If a checkpoint sets"problem_type": "multi_label_classification"inconfig.json,/v1/classifyapplies elementwise sigmoid instead of softmax so each class probability stays independent.labelstill reports the top-scoring class for compatibility, and callers apply their own thresholds toprobs. - Per-token classification (
#51573). If all declared architectures in a checkpoint end inForTokenClassification,/v1/classifyswitches to per-token mode and returnsprobswith shape[num_tokens, num_classes]including special tokens, plus one top-scoringlabelper token. Sequence and reward models keep their existing single-vector response. - Fail-closed error handling. Empty scores, wrong-rank outputs, or missing labels now return HTTP 500 with a clear error message instead of HTTP 200 with
"Default".
Serving BeamForTokenClassification with prefill CUDA graphs
To serve reflection/Iris-Content-Guard through BeamForTokenClassification, we added three runtime safeguards:
- Single-pass prefill. Token classification disables radix caching and chunked prefill so each conversation scores all prompt tokens in one complete prefill pass.
- Prefill CUDA graph padding removal. On B300, SGLang runs breakable prefill CUDA graphs by default, which pad inputs to captured bucket sizes.
BeamForTokenClassificationslices off that padding before the classifier head, so breakable prefill graphs, full prefill graphs, and eager mode all return only real token rows. - Checked online weight updates. Online weight updates verify that incoming checkpoints include the classifier head (
score.weightandscore.bias). Missing weights return HTTP 400 and leave the running model untouched.
Scoring OpenAI chat conversations
examples/runtime/iris_content_guard.py shows the end-to-end client flow. Given an OpenAI Chat Completions messages list, the client keeps only visible user and assistant text turns and drops system messages, tool calls, tool results, and reasoning fields.
Before calling /v1/classify, the client checks /server_info to reject auto-truncation and over-length prompts, then calls /v1/tokenize with the server’s chat template to locate the exact token boundaries of the final user turn and the optional assistant reply. It sends the token IDs to /v1/classify and reads the 14 request/ harm probabilities at the last user token and the 14 response/ harm probabilities at the last assistant token. If there is no assistant reply, response is null.

Figure 2. End-to-end Iris Content Guard flow from OpenAI Chat Completions messages through from_oai_to_icg_format, single-pass BeamForTokenClassification prefill with CUDA graph padding removal, and 28-class per-token sigmoid readout.
Performance
Detection quality
Carrying recurrent state across tokens is why SGLang adds a separate scoring process instead of stopping at stateless probes. The stateful minGRU probe (Iris-Cyber-Probe) outperformed a stateless MLP baseline on all three main metrics, raising chunk recall from 50.3% to 65.0% at the 1% setting and from 83.3% to 93.1% at the 5% setting:
| Metric | Iris-Cyber-Probe (stateful minGRU) | Stateless MLP probe |
|---|---|---|
| Chunk pAUROC₁₀ | 0.884 ± 0.006 | 0.835 ± 0.008 |
| Chunk recall (1% setting) | (65.0 ± 1.8)% | (50.3 ± 2.0)% |
| Chunk recall (5% setting) | (93.1 ± 0.5)% | (83.3 ± 1.3)% |
Stateless serving overhead
We benchmarked native stateless monitors on four NVIDIA B300 GPUs serving Beam 1.0 NVFP4 (TP4, FP8 KV cache, DFLASH 2 at block size 8) with 8,192 input tokens and 1,024 output tokens. Each configuration ran three counterbalanced repetitions against the upstream main parent commit (medians shown below), with cache flushed before each concurrency level and score delivery enabled on active monitor runs.
| Configuration | KV capacity (max_total_num_tokens) | C8 throughput (median TPOT) | C32 throughput (median TPOT) | C128 throughput (median TPOT) |
|---|---|---|---|---|
Upstream main baseline | 7,332,992 | 1,095.8 tok/s (7.62 ms) | 2,339.2 tok/s (14.96 ms) | 4,013.7 tok/s (22.16 ms) |
| Monitors disabled (off by default) | 7,332,992 (0.00%) | +0.14% (-0.17%) | +0.03% (-0.01%) | -0.01% (+0.06%) |
| 1-tap MLP (layer 30, width 128) | 7,332,992 (0.00%) | -0.47% (+0.56%) | -0.36% (+0.38%) | -0.58% (+1.69%) |
| 8-tap linear (layers 6 to 48) | 7,331,584 (-0.02%) | -2.10% (+2.36%) | -2.05% (+2.04%) | -2.01% (+2.37%) |
With no monitors configured, throughput, median TPOT, and KV capacity stay within measurement noise of upstream main. Running a single-tap width-128 MLP adds less than 0.6% throughput overhead across C8 to C128 with zero KV-cache capacity loss. Tapping eight layers with a linear probe across every DFLASH verify step adds about 2.0% throughput overhead and 0.02% KV-cache overhead.
Stateful serving overhead
We benchmarked the scoring process on NVIDIA B300 GPUs serving Beam 1.0 NVFP4 (TP4, DFLASH 2 at block size 8) with one Iris minGRU probe. To keep CUDA launch overhead low, the scoring process batches state copies and GPU-to-CPU transfers.
We tested two placements: sharing GPU 3 with the serving ranks (4 GPUs total) or placing the scoring process on a dedicated fifth GPU. Each placement ran two 10-minute trials at 8,192 input tokens, 1,024 output tokens, and concurrency 128 against a no-scoring control on identical hardware. Clients buffered tokens until scores arrived, and both placements finished with zero failed requests and zero missing scores.
| Scorer placement | Completed (failed, missing) | Throughput loss | E2E increase (mean, median, P99) | TPOT increase (mean, median, P99) | Extra completion wait (P99, max) |
|---|---|---|---|---|---|
| Shared GPU 3 (4 GPUs total) | 5,596 (0, 0) | 4.81% | +4.95%, +4.76%, +4.89% | +4.87%, +4.78%, +3.71% | 0.436 s, 1.852 s |
| Dedicated GPU 4 (5 GPUs total) | 5,829 (0, 0) | 0.71% | +0.66%, +0.51%, +1.47% | +0.59%, +0.52%, +0.65% | 0.349 s, 1.686 s |

Figure 3. Serving throughput loss, latency overhead, and extra completion wait comparing a shared GPU 3 placement against a dedicated fifth GPU on B300 (Beam 1.0 NVFP4 TP4, DFLASH 2 at block size 8, 8,192 input tokens, 1,024 output tokens, C128).
Giving the scoring process its own GPU drops throughput overhead from 4.81% to 0.71% and keeps median TPOT increase at 0.52%, with 0.349 s P99 extra completion wait (1.686 s max) when buffering output until scores arrive. Sharing GPU 3 avoids extra hardware while keeping throughput overhead under 5% and P99 extra wait at 0.436 s (1.852 s max) at concurrency 128.
Score coverage
The engine KV cache and the scoring process’s host-RAM history store evict on separate schedules. Under plain LRU, the scoring process can evict an older minGRU state while the matching KV prefix stays hot in SGLang’s radix tree, leaving later prefix hits without scores.
To prevent those misses without coupling eviction back to the engine, SGLang passes its KV page size at request start. The default 9 GiB budget (--state-store-bytes) reserves 1 GiB for cached input-token scores and splits the remaining 8 GiB of recurrent history into two queues. A protected queue (up to 50% by default) holds KV page boundaries and reused prefixes, while an ordinary LRU queue holds interior tokens and evicts first.
We compared both policies in a matched six-hour AgentX run at concurrency 64 on four B300 GPUs. Both arms served Beam 1.0 NVFP4 (TP4, DFLASH 2 at block size 8, unified FP8 KV) with one Iris minGRU probe sharing GPU 3 and an 8 GiB history budget.
| History policy (8 GiB budget) | Completed requests | Requests with all scores | Output tokens | Output tokens without valid scores | Peak sampled scorer RSS |
|---|---|---|---|---|---|
| Ordinary LRU | 67,233 | 81.52% | 59,528,877 | 18.38% | 9.54 GiB |
| Bounded protected history | 67,846 | 100% | 59,953,778 | 0% | 8.79 GiB |

Figure 4. Left: two-queue eviction keeps KV page-boundary and reused-prefix snapshots without coupling to engine KV eviction. Right: six-hour matched AgentX C64 coverage results at an 8 GiB logical host-RAM budget on four B300 GPUs.
Plain LRU dropped scores on 12,422 missing_prefix requests and 5 pending_overflow requests. Bounded protected history scored all 30,635 requests (25,690,696 output tokens) across 2 hours and 35 minutes after the protected queue first filled. These runs establish score coverage rather than serving speed because the protected-arm client ran out of memory during postprocessing, so we computed coverage from checksum-verified raw logs.
Future work
- Attention and KV cache. Stateful monitors require a full-attention MHA or GQA KV cache, including hybrid sliding-window models with full-attention layers. Models built on MLA, such as DeepSeek, Kimi, and MLA-based GLM variants, lack support because MLA caches a compressed latent per token.
- Parallelism and backends. Prefill-decode disaggregation requires matching attention-TP sizes on prefill and decode workers. Pipeline parallelism, context parallelism, two-batch overlap, and non-CUDA backends remain unsupported. Stateful monitors do not support data-parallel attention (
--attn-dp-sizeabove 1) yet, so Beam’s high-throughput cookbook recipes cannot runIris-Cyber-Probe. Use a TP-only recipe instead. - HiCache storage offload. Storage offload carries computation IDs through Mooncake. Under unified memory, computation IDs survive offload to host memory, including page-envelope layouts for DFLASH and MXFP8 KV, while storage offload does not carry those unified page-envelope layouts yet.
- History eviction and restarts. The scoring process keeps history within a fixed host-RAM budget and marks downstream scores unavailable if the engine reuses an evicted prefix. Prioritizing likely reuse points keeps misses rare, and future work can retain history alongside its KV entry or check history before reusing a prefix. Restarting the scoring process drops undelivered scores, built-in recovery covers one engine replica, and changing model weights requires a restart because SGLang refuses online weight updates while monitors are configured.
- Token classification scope.
/v1/classifyaccepts a single pre-tokenized prompt asList[int]or text inputs. Batched pre-tokenized lists asList[List[int]]remain unsupported. Non-Beam*ForTokenClassificationcheckpoints require--is-embeddingand a native model head because the Transformers fallback backend does not load token-classification heads.
Acknowledgments
Project Iris in SGLang is a joint effort across the SGLang, RadixArk, and Reflection teams.
- Reflection. Neil Gollapudi, Aymen Kallala, Adam Stein, Carlo Alfano, Elia Ovalle, Drew Proud, Nick Fram, Florent Gbelidji, Kai Wu.
- SGLang Community and RadixArk. Emmett Dreyer, Jimmy Shong, Xinyuan Tong, Ke Bao, Cheng Wang.
Appendix: launch commands and usage
All commands below run inside the prebuilt Docker image lmsysorg/sglang:project-iris:
docker pull lmsysorg/sglang:project-iris
1. Stateful activation monitor with the probe scorer
Download reflection/Iris-Cyber-Probe to a local directory first (SGLang loads probe checkpoints from local directories rather than Hugging Face repo IDs):
hf download reflection/Iris-Cyber-Probe --local-dir /models/iris-cyber-probe
Start the probe scorer first with the same probe names and checkpoints as the engine:
CUDA_VISIBLE_DEVICES=4 \
python -m sglang_activation_monitor_sidecar \
--monitor iris_cyber=/models/iris-cyber-probe \
--feature-endpoint tcp://127.0.0.1:5557 \
--host 127.0.0.1 --port 8001 \
--device cuda:0
Launch SGLang with feature export pointing at the scorer’s ZeroMQ endpoint. MODEL_ID is a Beam 1.0 checkpoint launched with a TP-only recipe from the Beam cookbook:
export SGLANG_ADMIN_API_KEY=<a secret of your choice>
python -m sglang.launch_server \
--model-path "$MODEL_ID" --revision "$MODEL_REVISION" --tp 4 \
--admin-api-key "$SGLANG_ADMIN_API_KEY" \
--activation-monitor-sidecar-probes '[{"name":"iris_cyber","checkpoint":"/models/iris-cyber-probe"}]' \
--activation-monitor-sidecar-endpoint tcp://127.0.0.1:5557
Send a generation request with a unique rid and stream scores from the probe scorer:
curl http://localhost:30000/generate \
-H 'Content-Type: application/json' \
-d '{"rid":"probe-example-1","text":"Hello","sampling_params":{"max_new_tokens":16},"stream":true}'
curl -N 'http://localhost:8001/v1/monitor_scores/probe-example-1/stream?since=0'
Recover a single replica after a scorer restart while external ingress stays closed. The helper pauses and resumes generation through admin-only endpoints, so start the engine with --admin-api-key and set SGLANG_ADMIN_API_KEY for the helper:
python -m sglang_activation_monitor_sidecar recover \
--engine-url http://localhost:30000 \
--scorer-url http://localhost:8001 \
--previous-instance-id "$PREVIOUS_SCORER_INSTANCE_ID" \
--ingress-paused --policy fail-closed --timeout 300
2. Native stateless activation monitor
Start SGLang with a linear or GELU MLP monitor checkpoint. Reflection’s release does not include a stateless probe, so bring your own checkpoint (config.json and safetensors weights in the format described in SGLang’s activation monitor docs):
python -m sglang.launch_server \
--model-path "$MODEL_ID" --revision "$MODEL_REVISION" --tp 1 \
--activation-monitors '[{"name":"probe","factory":"sglang.srt.activation_monitors.linear:create_linear_monitor","config":{"checkpoint":"/models/probe"}}]'
Request token-aligned scores on /generate:
curl http://localhost:30000/generate \
-H 'Content-Type: application/json' \
-d '{"text":"Hello","sampling_params":{"temperature":0,"max_new_tokens":2},"return_activation_monitors":true}'
3. Iris Content Guard with /v1/classify
Start SGLang with reflection/Iris-Content-Guard. B300 runs breakable prefill CUDA graphs by default, and adding --cuda-graph-backend-prefill full --attention-backend fa4 enables full prefill graphs:
python -m sglang.launch_server \
--model-path reflection/Iris-Content-Guard \
--host 127.0.0.1 --port 30000
Run the OpenAI Chat Completions example client from the repository root:
python examples/runtime/iris_content_guard.py
來源:LMSYS Blog · lmsys.org