一次运行,双倍收益:本地 LLM 近乎零成本的流式安全检查

arXiv cs.AI 论文

摘要

该论文提出 ToRA,一种通过在生成模型解码步骤中以共享权重和 KV 缓存的方式并行运行第二个模型行的适配器,实现近零成本的流式 LLM 安全检查,在 Qwen3-0.6B 上以低于 4% 的额外延迟匹配或超越专用守卫模型。

arXiv:2611.26975v1 Announce Type: new Abstract: Local LLM assistants decode for one user at a time, so decoding is bound by memory bandwidth and leaves compute idle. Streaming safety checks today trade accuracy against cost. A dedicated guard model is accurate but nearly doubles the latency per token, while a hidden-state probe is cheap but less accurate. We present ToRA, an adapter that runs a second model as an extra row in the generator's decode step, sharing its weights and KV cache. Dual-row kernels read each weight once for both rows. On Qwen3-0.6B, ToRA matches or beats a dedicated streaming guard, with higher F1 on 12 of 17 benchmarks. It detects 11.8 points more unsafe responses than the probe at a similar cost, under 4% added latency per token.
查看原文
查看缓存全文

缓存时间: 2026/11/23 09:16

# Run One, Get Two: Near-Free Streaming Safety Checks for Local LLMs
Source: [https://arxiv.org/html/2611.26975](https://arxiv.org/html/2611.26975)
Soheil Zibakhsh1, Pedram Aghazadeh, and Farinaz Koushanfar††thanks:1Corresponding author:szibakhsh@ucsd\.edu

###### Abstract

Local LLM assistants decode for one user at a time, so decoding is bound by memory bandwidth and leaves compute idle\. Streaming safety checks today trade accuracy against cost\. A dedicated guard model is accurate but nearly doubles the latency per token, while a hidden\-state probe is cheap but less accurate\. We present ToRA, an adapter that runs a second model as an extra row in the generator’s decode step, sharing its weights and KV cache\. Dual\-row kernels read each weight once for both rows\. On Qwen3\-0\.6B, ToRA matches or beats a dedicated streaming guard, with higher F1 on 12 of 17 benchmarks\. It detects 11\.8 points more unsafe responses than the probe at a similar cost, under 4% added latency per token\.

###### Index Terms:

LLM safety, streaming moderation, low\-rank adapters, memory\-bound decoding, GPU kernels

## IIntroduction

Local LLM assistants must perform generation and safety monitoring on the same device, under tight latency and memory constraints\. Checking only completed responses cannot prevent unsafe content from reaching users\. Streaming safety checkers instead evaluate tokens as they are generated, allowing unsafe responses to be interrupted early\[[1](https://arxiv.org/html/2611.26975#bib.bib1),[2](https://arxiv.org/html/2611.26975#bib.bib2)\]\. The challenge is to provide accurate detection without substantially slowing decoding\.

Existing streaming checkers face a fundamental trade\-off between accuracy and efficiency \(Figs\.[1](https://arxiv.org/html/2611.26975#S1.F1)and[2](https://arxiv.org/html/2611.26975#S1.F2)\)\. Dedicated guard models, such as Qwen3Guard\-Stream\[[1](https://arxiv.org/html/2611.26975#bib.bib1)\], provide strong detection through a separately trained language model\. However, running an additional model requires its own weights and key\-value \(KV\) cache\. On an A6000 GPU, pairing Qwen3Guard\-Stream with a generator of the same size increases per\-token latency by 84–89% and consumes approximately 2 GiB of additional memory at an 8k\-token context length\. Lightweight alternatives, such as SingProbe\[[3](https://arxiv.org/html/2611.26975#bib.bib3)\], instead classify the generator’s hidden states\. This avoids the cost of a separate model and adds less than 2% latency\. However, the underlying representations are not explicitly optimized for safety detection\. Consequently, SingProbe trails Qwen3Guard\-Stream by 2\.8 points in response F1 and detects nearly 13% fewer unsafe responses during streaming\.

0%25%50%75%100%77777878797980808181SingProbe \(\+1\.6%\)ToRA \(\+3\.5%\)Qwen3Guard\-Stream \(\+85\.9%\)Added latency per tokenAvg\. response F124×24\\timesless overhead\+3\.8\+3\.8F1Fig\. 1:Response F1 versus per\-token latency overhead at 2k context\. All methods use identical generator kernels; the error bar shows one standard deviation across three ToRA seeds\.At batch size one, auto\-regressive decoding is typically memory\-bandwidth bound\. Each step loads the model weights but performs relatively little computation, approximately one floating\-point operation per byte in our setting, far below the compute\-bound regime\[[4](https://arxiv.org/html/2611.26975#bib.bib4)\]\. This unused capacity could support verification at minimal cost if both paths share weights and avoid additional memory traffic\. However, conventional LoRA execution requires a separate KV cache or repeated weight reads\. Even with cache sharing, standard execution adds 15–52% decoding latency in our experiments \(Section[VI\-D](https://arxiv.org/html/2611.26975#S6.SS4)\)\. Efficient verification therefore requires shared weight accesses and cached representations without altering the generator’s output\.

We introduce ToRA \(Tandem of low\-Rank Adapters\), a shared\-backbone architecture that performs generation and safety verification within a single decoding step\. Rather than running an independent guard model, ToRA adapts the generator’s upperKKtransformer layers using low\-rank adapters \(LoRA\)\[[5](https://arxiv.org/html/2611.26975#bib.bib5)\]and a lightweight classification head\. The verifier path branches from the generator at the first adapted feed\-forward layer, reusing all preceding computations\. It also utilizes the generator’s cached keys and values from earlier tokens, eliminating the need for a separate KV cache\. To execute both paths efficiently, we develop dual\-row Triton\[[6](https://arxiv.org/html/2611.26975#bib.bib6)\]kernels that load each shared weight tile once and apply the low\-rank updates only to the verifier path\. The generator’s output remains unaffected by verification\.

Fig\. 2:Streaming safety architectures: hidden\-state probe \(left\), dedicated guard \(center\), and ToRA \(right\)\.Fig\.[2](https://arxiv.org/html/2611.26975#S1.F2)compares the three streaming safety architectures, while Fig\.[1](https://arxiv.org/html/2611.26975#S1.F1)illustrates their accuracy–latency trade\-off\. On Qwen3\-0\.6B\[[7](https://arxiv.org/html/2611.26975#bib.bib7)\]ToRA improves average response and prompt F1 over Qwen3Guard\-Stream by 1\.0 and 1\.7 points, respectively, with higher F1 on 12 of 17 benchmarks\. Its streaming detection remains within 1\.5 points of the guard, while identifying unsafe content earlier\. Compared with SingProbe, ToRA improves response F1 by 3\.8 points and detects 11\.8 percentage points more unsafe responses at a 5% false\-alarm budget\. At 2k context, it adds only 3\.5% latency per token, compared with 1\.6% for SingProbe and 85\.9% for Qwen3Guard\-Stream\. The additional 60μ\\mus per token over SingProbe amounts to 30 ms over 500 tokens\. ToRA also requires only 9\.3 MiB of additional memory and no separate KV cache\.

Our contributions are fourfold:\(i\)a shared\-backbone verifier that preserves the generator’s output;\(ii\)efficient token\-level training using one frozen generator pass per sequence;\(iii\)dual\-row Triton kernels that reuse weight accesses across generation and verification; and\(iv\)evaluation across 17 safety benchmarks and streaming detection, demonstrating guard\-level accuracy at nearly the cost of a probe\. Our code is available athttps://github\.com/soheilzi/ToRA\.

## IIBackground and Related Work

Conventional guards, including Llama Guard\[[8](https://arxiv.org/html/2611.26975#bib.bib8)\], WildGuard\[[9](https://arxiv.org/html/2611.26975#bib.bib9)\], ShieldGemma\[[10](https://arxiv.org/html/2611.26975#bib.bib10)\], Aegis\[[11](https://arxiv.org/html/2611.26975#bib.bib11),[12](https://arxiv.org/html/2611.26975#bib.bib12)\], and Qwen3Guard\-Gen\[[1](https://arxiv.org/html/2611.26975#bib.bib1)\], classify prompts or completed responses\. Streaming checkers instead monitor partial outputs during generation\. Qwen3Guard\-Stream\[[1](https://arxiv.org/html/2611.26975#bib.bib1)\]uses token\-level classification heads but requires separate weights and a KV cache\. SingProbe\[[3](https://arxiv.org/html/2611.26975#bib.bib3)\]avoids this overhead by probing hidden states from three generator layers, although these representations are not optimized for safety detection\. ToRA combines task\-specific adaptation with shared weights and cache\.

Adapters and multi\-adapter serving\.LoRA\[[5](https://arxiv.org/html/2611.26975#bib.bib5)\]adapts frozen models through low\-rank weight updates\. S\-LoRA\[[13](https://arxiv.org/html/2611.26975#bib.bib13)\]and Punica\[[14](https://arxiv.org/html/2611.26975#bib.bib14)\]batch requests with different adapters and independent KV caches\. Activated LoRA\[[15](https://arxiv.org/html/2611.26975#bib.bib15)\]reuses the base model’s prefix cache but does not perform continuous concurrent execution\. LoRA\-Guard\[[16](https://arxiv.org/html/2611.26975#bib.bib16)\]switches a language model between generation and safety classification\. Unlike these methods, ToRA performs token\-level verification using shared weights, a shared cache, and fused GPU kernels\.

Compute utilization during decoding\.Speculative decoding\[[17](https://arxiv.org/html/2611.26975#bib.bib17)\], Medusa\[[18](https://arxiv.org/html/2611.26975#bib.bib18)\], and EAGLE\[[19](https://arxiv.org/html/2611.26975#bib.bib19)\]exploit parallel token verification to accelerate generation\. Tandem Transformers\[[20](https://arxiv.org/html/2611.26975#bib.bib20)\]coordinate models of different sizes, while RoE\[[21](https://arxiv.org/html/2611.26975#bib.bib21)\]aggregates parallel expert outputs\. CALM\[[22](https://arxiv.org/html/2611.26975#bib.bib22)\]and LayerSkip\[[23](https://arxiv.org/html/2611.26975#bib.bib23)\]instead reduce computation through early exits\. Unlike these generation\-oriented approaches, ToRA uses available compute for continuous safety verification\.

## IIIMethod

ToRA performs generation and safety verification within a single decoding step\. As illustrated in Fig\.[3](https://arxiv.org/html/2611.26975#S3.F3), the verifier reuses the generator’s weights and cached representations, while low\-rank adapters specialize its upper layers for safety classification\. The two paths execute together using shared weight accesses, avoiding the overhead of a separate guard model\.

tokenxtx\_\{t\}EmbeddingLayers0,…,L−K−10,\\dots,L\{\-\}K\{\-\}1Attention, layerL−KL\{\-\}KFFNWWAttentionFFNWWNorm, LM headnext tokennot computed:hV=hGh^\{V\}=h^\{G\}FFNW\+s​B​AW\+sBAAttentionFFNW\+s​B​AW\+sBANorm, headscoreptp\_\{t\}; stop ifpt≥τp\_\{t\}\\geq\\tauGG’s KV cachewriteread<t\{<\}tone read ofWWone read ofWWrepeated for layersL−K\+1,…,L−1L\{\-\}K\{\+\}1,\\dots,L\{\-\}1Generator rowVerifier rowFig\. 3:ToRA decoding step\. The verifier branches at the first adapted FFN and reuses the generator’s weights and KV cache\. Dotted lines indicate shared weight reads\.### III\-AVerifier Architecture

Consider a decoder\-only transformer generatorGGwithLLlayers, each consisting of an attention block followed by a feed\-forward network \(FFN\)\. Each block has its own input normalization\. We construct a verifierVVby adapting the topKKlayers ofGG, while keeping all original model weights frozen\.

Specifically, we introduce low\-rank updates to the gate, up, and down projections of each adapted FFN\. For a projection matrixWW, the verifier computes

y=W​x\+s​B​\(A​x\),A∈ℝr×din,B∈ℝdout×r,y=Wx\+s\\,B\(Ax\),\\qquad A\\in\\mathbb\{R\}^\{r\\times d\_\{\\mathrm\{in\}\}\},\\;B\\in\\mathbb\{R\}^\{d\_\{\\mathrm\{out\}\}\\times r\},\(1\)whererrdenotes the adapter rank andssis its scaling factor\. A lightweight classification head replaces the language\-model head, mapping the verifier’s final hidden state toCCoutput scores\. Thus,VVpredicts safety labels rather than generating tokens\.

At decoding steptt, the generator executes its lowerL−KL\-Klayers once\. The verifier branches after attention in layerL−KL\-K, immediately before the first adapted FFN\. Above this point, the generator applies the original projections, while the verifier uses Eq\. \([1](https://arxiv.org/html/2611.26975#S3.E1)\)\. Both retain the original attention weights, and their FFN computations are fused as described in Section[IV](https://arxiv.org/html/2611.26975#S4)\.

### III\-BShared KV Cache

A conventional adapted model maintains its own KV cache to store the keys and values of previously processed tokens\. This introduces additional memory usage and traffic that grow quadratically with the sequence length\. ToRA avoids this overhead by allowing the verifier to reuse the generator’s cache\.

At each attention layer following the branching point, the verifier computes its own query, key, and value for the current token\. However, instead of maintaining historical keys and values, it attends to those already stored by the generator\. Formally, the verifier’s attention output at positionttis

otV=softmax⁡\(qtV​\[K<tG;ktV\]⊤d\)​\[V<tG;vtV\]\.o^\{V\}\_\{t\}=\\mathrm\{softmax\}\\\!\\left\(\\frac\{q^\{V\}\_\{t\}\\,\\bigl\[K^\{G\}\_\{<t\};\\,k^\{V\}\_\{t\}\\bigr\]^\{\\top\}\}\{\\sqrt\{d\}\}\\right\)\\bigl\[V^\{G\}\_\{<t\};\\,v^\{V\}\_\{t\}\\bigr\]\.\(2\)
whereK<tGK^\{G\}\_\{<t\}andV<tGV^\{G\}\_\{<t\}are the generator’s cached keys and values from earlier positions\. The verifier computesktVk^\{V\}\_\{t\}andvtVv^\{V\}\_\{t\}only for the current token and discards them after attention\. Consequently,only the generator updates the persistent KV cache, and the verifier requires no additional cache that grows with the context length\.

This design allows the verifier to process previous tokens through the generator’s representations rather than recomputing its own\. The generator, in turn, never accesses the verifier’s states, preserving the original generation computation\. We use the same cache\-sharing mechanism during training and inference, and evaluate its effect on classification accuracy in Section[VI\-D](https://arxiv.org/html/2611.26975#S6.SS4)\.

Although we focus on a single safety verifier, the architecture is not restricted to this task\. Additional adapters could support other verification tasks while reusing the same generator weights and cached states\.

### III\-CEfficient Training

We train the verifier on fixed prompt–response sequences with the generator frozen\. A single forward pass ofGGprovides the hidden states at the branching point and the KV states of the adapted layers\. The verifier then processes only the supervised positions, attending to the corresponding generator KV states as in Eq\. \([2](https://arxiv.org/html/2611.26975#S3.E2)\)\. This reproduces the decoding computation without a separate verifier cache\. Only the adapters and classification head are updated using class\-weighted binary cross\-entropy\.

### III\-DToken\-Level Supervision

Labels assigned only to the final tokens of prompts and responses are sufficient for classifying complete inputs\. However, they provide no direct supervision for detecting unsafe content as it emerges during generation\. A verifier trained exclusively on final\-token labels may therefore classify completed responses accurately while failing to detect unsafe content early\.

To address this limitation, we introduce supervision atNNadditional positions within each training response, sampled uniformly without replacement\. For safe responses, all sampled positions receive a label of 0\. For unsafe responses, a token\-level teacher identifies the onset of unsafe content\. Positions preceding this onset receive a label of 0, while positions at or after the onset receive a label of 1\.

When the teacher cannot identify an unsafe onset, the sampled positions are labeled 0, while the final response token retains its original unsafe label\. The intermediate labels collectively receive the same loss weight as the final response label, balancing token\-level supervision with response\-level classification\. Importantly, the teacher is applied only to responses already labeled unsafe, leaving the labels of safe responses unaffected\.

During inference, the verifier evaluates the response safety score at each generated token\. If the score reaches a predefined thresholdτ\\tau, the response is flagged and generation can be stopped immediately\. This enables continuous safety monitoring without waiting for the complete response\.

## IVKernel and System Design

To minimize verification overhead, ToRA must exploit the unused compute capacity of memory\-bound decoding while preserving the generator’s output\. Conventional execution approaches introduce unnecessary memory traffic or computation\. Executing the generator and verifier separately requires reading the shared weights twice\. Similarly, merging the adapters into a separate copy of the weights,W\+s​B​AW\+sBA, duplicates weight storage and reads\. Batching both paths into a single cuBLAS GEMM avoids redundant weight reads, but leaves the adapter computations as separate operations\. Moreover, changing the number of input rows can alter the GEMM reduction order, leading to numerical differences in the generator’s logits\[[24](https://arxiv.org/html/2611.26975#bib.bib24)\]\. To address these limitations, we develop two Triton kernels that execute both paths with shared weight accesses while preserving independent computations for each row\.

Dual\-row linear projection\.Ourdual\_lora\_linearkernel computes the generator and verifier projections simultaneously:y0=W​x0y\_\{0\}=Wx\_\{0\}andy1=W​x1\+s​B​\(A​x1\)y\_\{1\}=Wx\_\{1\}\+sB\(Ax\_\{1\}\), respectively\. Each Triton program loads a tile of the shared weight matrixWWonce and updates separate FP32 accumulators for the two rows\. The low\-rank projectionA​x1Ax\_\{1\}is accumulated within the same loop\. The kernel then applies the adapter contributions​B​\(A​x1\)sB\(Ax\_\{1\}\)to the verifier’s output in its epilogue, leaving the generator’s result unmodified\. The additional adapter weight reads amount tor⁡\(din\+dout\)r\(d\_\{\\mathrm\{in\}\}\+d\_\{\\mathrm\{out\}\}\)elements, compared withdin​doutd\_\{\\mathrm\{in\}\}d\_\{\\mathrm\{out\}\}elements for the shared projection\. At the rank used in our experiments \(Section[V](https://arxiv.org/html/2611.26975#S5)\), this represents approximately 1% of the base weight traffic\.

Fused FFN execution\.To further reduce kernel launches, we introducedual\_lora\_gate\_up, which fuses the gate and up projections of the FFN\. The kernel computes both projections for the generator and verifier in a shared weight traversal, applying the low\-rank updates only to the verifier\. It then evaluates the activationSiLU⁡\(g\)⊙u\\mathrm\{SiLU\}\(g\)\\odot uwithin the same kernel\. The epilogue also produces partial sums ofAdown​h1A\_\{\\mathrm\{down\}\}h\_\{1\}, which are consumed by the subsequent down projection\. Together withdual\_lora\_linear, this reduces the entire FFN to two kernel launches for both paths\. In comparison, a conventional cuBLAS implementation requires three GEMMs and a separate activation kernel for the generator alone\.

Preserving generator outputs\.An essential requirement of ToRA is that verification must not affect the generator’s predictions\. However, GPU kernel configurations and floating\-point reduction orders can vary with the number of input rows\. We therefore select kernel configurations based solely on weight dimensions and perform auto\-tuning with two rows, regardless of whether verification is enabled\. When the verifier is disabled, FP32 placeholders replace the adapter pointers, preserving the generator’s execution path and reduction order\.

We verify bit\-wise equivalence of the generator row with and without verification across all tested kernel configurations\. The complete decoding path also produces identical logits without compilation\. Withtorch\.compile, differences remain within the floating\-point rounding introduced by compilation itself\.

Attention and decode execution\.We implement attention using the decoding path of FlexAttention\[[25](https://arxiv.org/html/2611.26975#bib.bib25)\]with a static block mask\. The verifier introduces an additional query row that accesses the generator’s KV cache, allowing both paths to reuse the same cached keys and values within a single attention operation\. We explicitly pack grouped\-query attention heads into rows to support this execution pattern\.

Only the generator executes layers below the branching pointL−KL\-K, using standard cuBLAS operations\. The remaining layers use our dual\-row kernels\. To minimize runtime overhead, we maintain static tensor shapes, a single KV\-cache tensor per layer, and in\-place cache updates\. This enables compilation withtorch\.compile\[[26](https://arxiv.org/html/2611.26975#bib.bib26)\]and CUDA graph capture, with the Triton kernels integrated as opaque custom operators\.

TABLE I:Accuracy, streaming detection and cost of the three checkers on Qwen3\-0\.6B\.
## VExperimental Setup

Model configuration\.We use Qwen3\-0\.6B\[[7](https://arxiv.org/html/2611.26975#bib.bib7)\]with 28 layers and a hidden size of 1,024, in bf16 with thinking mode disabled\. The verifier adapts the gate, up, and down projections of the topK=14K=14layers using rankr=8r=8andα=16\\alpha=16\. Its classification head is an MLP with a 1,024\-unit hidden layer and dropout 0\.1\. The two outputs predict prompt and response harm, evaluated at the final prompt and response tokens, respectively\. The verifier contains2\.43Mtrainable parameters\.

Training data\.We use the official training splits of seven datasets: WildGuardMix\[[9](https://arxiv.org/html/2611.26975#bib.bib9)\], Aegis 2\.0\[[12](https://arxiv.org/html/2611.26975#bib.bib12)\], BeaverTails \(30k\)\[[27](https://arxiv.org/html/2611.26975#bib.bib27)\], PKU\-SafeRLHF \(v0, one response pair per prompt\)\[[28](https://arxiv.org/html/2611.26975#bib.bib28)\], ToxicChat \(0124\)\[[29](https://arxiv.org/html/2611.26975#bib.bib29)\], Aegis 1\.0\[[11](https://arxiv.org/html/2611.26975#bib.bib11)\], and ExpGuardTrain\[[30](https://arxiv.org/html/2611.26975#bib.bib30)\]\. We exclude training prompts appearing in any evaluation or validation split, then reserve 5% of each source for prompt\-disjoint validation\. The resulting mixture contains 33\.6M tokens, 109,883 prompt labels, and 102,072 response labels\.

Token\-level supervision\.We sampleN=128N=128intermediate positions per response and use Qwen3Guard\-Stream\-0\.6B\[[1](https://arxiv.org/html/2611.26975#bib.bib1)\]to locate unsafe\-content onsets\. An onset is the first token in the earliest pair of consecutive tokens labeled unsafe or controversial\. The teacher identifies an onset in 88\.4% of unsafe training responses and is not applied to safe responses\.

Optimization\.We train for two epochs using AdamW, a learning rate of10−310^\{\-3\}, zero weight decay, and gradient clipping at norm 1\.0\. Batches contain 32,768 tokens, with a maximum sequence length of 2,048\. The learning rate follows a 3% linear warm\-up and cosine decay to zero\. We evaluate four checkpoints and select the one with the highest mean validation AUPRC\. Each experiment uses three random seeds\.

Benchmarks\.We evaluate on the public benchmarks reported by Qwen3Guard and SingProbe\. The eight response benchmarks are WildGuardTest, Aegis 2\.0, BeaverTails, PKU\-SafeRLHF, HarmBench\[[31](https://arxiv.org/html/2611.26975#bib.bib31)\], Think \(Qwen3GuardTest reasoning traces\[[1](https://arxiv.org/html/2611.26975#bib.bib1)\]\), XSTest\-Response\[[9](https://arxiv.org/html/2611.26975#bib.bib9)\], and ExpGuardTest\. The nine prompt benchmarks are WildGuardTest, Aegis 2\.0, ToxicChat, OpenAI Moderation\[[32](https://arxiv.org/html/2611.26975#bib.bib32)\], Aegis 1\.0, SimpleSafetyTests\[[33](https://arxiv.org/html/2611.26975#bib.bib33)\], HarmBench, XSTest\[[34](https://arxiv.org/html/2611.26975#bib.bib34)\], and ExpGuardTest\. For streaming evaluation, we use Qwen3GuardTest’sresponse\_locsplit, which identifies the first unsafe sentence in 813 responses, and SingStreamBench \(210 responses\)\[[3](https://arxiv.org/html/2611.26975#bib.bib3)\]\.

Metrics\.We report unsafe\-class F1, averaged equally across benchmarks\. For ToRA, we select one threshold per task by maximizing F1 on pooled WildGuard and Aegis 2\.0 validation data\. Streaming thresholds are calibrated to flag at most 5% or 1% of 1,703 safe validation responses\. We measure unsafe\-response detection, exact hits \(first flag within the unsafe span\), median detection delay from unsafe onset, and false alarms on held\-out safe BeaverTails responses \(Safe BT\)\. We report mean and standard deviation over three seeds for ToRA; baseline results use one released checkpoint\. Bold indicates the best result in each table column\.

Baselines\.We use the released Qwen3Guard\-Stream\-0\.6B and SingProbe checkpoints without retraining, as their training data are unavailable\. For F1 evaluation, each retains its published decision rule\. SingProbe flags responses when any token reaches probability 0\.5 and uses its query protocol for prompts\. Qwen3Guard\-Stream operates in strict mode, requiring two consecutive unsafe tokens\. Our evaluation reproduces published F1 within 0\.6 points on 12/14 Qwen3Guard\-Stream entries and 0\.9 points on 7/9 SingProbe entries\.

Evaluation paths\.Tables[I](https://arxiv.org/html/2611.26975#S4.T1)–[III](https://arxiv.org/html/2611.26975#S6.T3)use the deployed decode path, with pre\-filled responses processed one token at a time through compiled, CUDA\-graph\-captured dual\-row steps\. Ablations use faster offline scoring on fixed token sequences, which agrees with deployed inference \(Section[VI\-C](https://arxiv.org/html/2611.26975#S6.SS3)\)\.

Latency measurement\.We benchmark on an RTX A6000 \(GA102\) at batch size one using bf16, compilation, and CUDA graphs\. We report the median of 100 decoding steps at 512, 2k, and 8k cached positions, with no competing GPU workloads\.1118k denotes 8,191 cached positions, the maximum supported by Qwen3Guard\-Stream before the next token\.All methods use identical generator kernels: cuBLAS below layerL−KL\-Kand our kernels above it\. Qwen3Guard\-Stream’s guard uses the same kernel configuration\. Unless specified otherwise, latency overhead is measured relative to the generator alone\.

## VIResults

Table[I](https://arxiv.org/html/2611.26975#S4.T1)summarizes classification accuracy, streaming detection, and inference overhead\. ToRA achieves the highest average F1 while maintaining guard\-level detection at nearly the cost of SingProbe\.

TABLE II:Unsafe\-class F1 per benchmark, with the average F1 and AUPRC\.### VI\-AClassification Accuracy

As shown in Table[II](https://arxiv.org/html/2611.26975#S6.T2), ToRA achieves the highest F1 among all three methods on 5 of 8 response and 6 of 9 prompt benchmarks\. Compared with Qwen3Guard\-Stream, it performs better on 12 of 17 benchmarks, with average improvements of 1\.0 and 1\.7 F1 points for responses and prompts, respectively\. The largest gains occur on XSTest responses \(\+8\.0\) and ExpGuard prompts \(\+10\.8\)\. ToRA also improves average F1 on benchmarks absent from its training sources, by 2\.7 points for responses and 0\.9 for prompts\. Average AUPRC follows the same ranking as F1, suggesting that the improvements are not limited to the selected classification thresholds\.

Performance varies across datasets\. On ExpGuard responses, ToRA trails Qwen3Guard\-Stream by 3\.2 F1 points despite similar AUPRC, indicating sensitivity to threshold selection\. Entries marked‡for SingProbe use dataset versions that differ from those reported in its original paper\.

### VI\-BStreaming Detection

TABLE III:Token\-level streaming detection on Qwen3GuardTest\.Table[III](https://arxiv.org/html/2611.26975#S6.T3)evaluates streaming detection on 813 unsafe responses from Qwen3GuardTest\. At a 5% false\-alarm budget, ToRA detects 83\.6% of unsafe responses, compared with 84\.7% for Qwen3Guard\-Stream and 71\.8% for SingProbe\. At the stricter 1% budget, ToRA remains within 1\.5 percentage points of the dedicated guard while exceeding SingProbe by 11\.0 points\.

Beyond detection accuracy, ToRA identifies unsafe content earlier\. Its median detection delay is 5 tokens at the 5% budget, compared with 7 for both baselines\. At 1%, this delay is 8\.3 tokens, versus 17 for Qwen3Guard\-Stream and 12 for SingProbe\. ToRA also achieves a higher exact\-hit rate than the guard at 1% \(50\.2% versus 43\.3%\)\. These timing differences may partly reflect the decision rules: Qwen3Guard\-Stream requires two consecutive unsafe tokens, whereas ToRA flags a single threshold crossing\.

The teacher’s primary benefit appears to be earlier detection\. In a one\-seed pilot without teacher\-derived onsets, ToRA detected 85\.0% of unsafe responses at the 5% budget, but with a median delay of 25 tokens\. Offline scoring further shows that the median peak safety score rises from 0\.002 before the unsafe span to 0\.984 after its onset\.

On SingStreamBench, SingProbe performs better, reaching 98\.6 response\-level AUC compared with 92\.8 for ToRA and 94\.5 for Qwen3Guard\-Stream\. This benchmark uses onset annotations generated by the same LLM that annotated SingProbe’s unreleased training data\. SingProbe also produces fewer false alarms on held\-out safe BeaverTails responses\.

### VI\-CInference Efficiency

Across context lengths of 512 to 8k tokens, ToRA adds only 105–110μ\\mus per token, compared with 46–48μ\\mus for SingProbe and 2\.3–3\.5 ms for Qwen3Guard\-Stream\. Because verification reuses the generator’s KV cache, its absolute overhead remains nearly constant as the context grows\. Consequently, its relative overhead decreases from 4\.0% to 2\.8% \(Table[I](https://arxiv.org/html/2611.26975#S4.T1)\)\.

At 2k context, the generator produces 336 tokens/s\. This decreases to 325 with ToRA and 331 with SingProbe, but only 181 with Qwen3Guard\-Stream\. Moreover, our kernels accelerate the generator itself by 2\.0–2\.9% relative to cuBLAS, bringing the complete ToRA execution within 0\.9% of the stock cuBLAS generator\. This kernel improvement also benefits SingProbe when evaluated on the same generator\.

Finally, offline scoring closely matches deployed decoding\. Across three seeds, average F1 and detection rates differ by at most 0\.1 points, with only 0\.16–0\.26% of token\-level verdicts changing\.

### VI\-DAblation Studies

We examine the effects of cache sharing, kernel fusion, adapter configuration, and token\-level supervision\. Unless stated otherwise, ablations use offline scoring over three seeds\.

Shared versus independent KV cache\.To isolate the effect of cache sharing, we compare two verifiers that adapt all 28 layers using final\-token labels\. The shared\-cache variant achieves 81\.4 response F1 and 86\.7 prompt F1, compared with 81\.2 and 86\.5 for an independently cached verifier\. Their AUPRC values are also comparable\. However, an independent cache introduces 9–59% additional memory traffic per token, versus less than 0\.6% with cache sharing\. This comparison covers complete\-response classification rather than streaming detection\.

5122k8k00202040406060ContextAdded time \(%\)\(a\) End to end, 0\.6B0\.6B1\.7B4B8B00100100200200Model shape\(b\) One FFN layerSeparate callsMerged copyBatchedBatched \+ compileOurs \(dual\-row\)Fig\. 4:Latency overhead of different execution strategies for the verifier path\.Kernel execution strategies\.Fig\.[4](https://arxiv.org/html/2611.26975#S6.F4)compares execution strategies against a stock cuBLAS generator\. At 0\.6B, separate execution adds approximately 51% latency, while conventional batching adds 15–21%\. Our dual\-row kernels reduce this overhead to less than 1%\. For individual FFN layers, merging adapters into separate weight matrices doubles weight traffic and approximately doubles latency\. In contrast, our kernels execute both paths 3–14% faster than cuBLAS executes the generator alone, achieving 69–88% of peak memory bandwidth\.

The advantage persists at larger model sizes\. At 1\.7B, ToRA adds 2\.8–3\.3% end\-to\-end latency with an untrained adapter, compared with 14–17% for conventional batching\.

Adapter rank and learned features\.Adapter ranks from 4 to 32 produce response F1 scores within 0\.9 points of one another \(seed 0\)\. To isolate the benefit of feature adaptation, we also train an MLP probe on SingProbe’s three hidden\-state layers using identical data and final\-token labels\. The probe achieves 72\.5 response F1 and 81\.3 prompt F1, compared with 81\.5 and 86\.7 for ToRA under the same training conditions\. This supports the importance of adapting the generator’s upper layers rather than relying exclusively on frozen representations\.

Adaptation depth and token\-level supervision\.WithK=14K=14, ToRA achieves 83\.5% streaming detection at the 5% false\-alarm budget, compared with 84\.5% when adapting all 28 layers\. The corresponding analytical FLOP overheads at 4k context are 41% and 84%, respectively\. Token\-level supervision is equally important: increasingNNfrom 0 to 128 improves detection from 19\.9% to 83\.5%, while response F1 remains near 81\.5%\.

## VIILimitations

ToRA targets memory\-bound decoding at batch size one; its advantage may diminish under larger batches or speculative decoding\[[17](https://arxiv.org/html/2611.26975#bib.bib17)\]\. Accuracy is evaluated only on Qwen3\-0\.6B, with efficiency experiments extending to 1\.7B end to end and 8B for FFN layers\. Our cost comparison uses equally sized generator and guard models, and latency measurements cover one GPU\. Finally, streaming evaluation replays existing responses rather than generating them online, although the verifier observes the same token sequences\.

## VIIIConclusion

We presented ToRA, a shared\-backbone approach that enables continuous safety verification during generation with minimal overhead\. By reusing the generator’s weights and KV cache through fused dual\-row execution, ToRA achieves detection comparable to a dedicated guard model at nearly the cost of a lightweight probe\. Beyond safety monitoring, this architecture offers a foundation for other token\-level verification tasks\. Supporting multiple concurrent verifiers and evaluating their efficiency remain promising directions for future work\.

## References

- \[1\]H\. Zhaoet al\.\(2025\)Qwen3Guard technical report\.Note:arXiv:2510\.14276Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p1.1),[§I](https://arxiv.org/html/2611.26975#S1.p2.1),[§II](https://arxiv.org/html/2611.26975#S2.p1.1),[§V](https://arxiv.org/html/2611.26975#S5.p3.1),[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.
- \[2\]Y\. Li, Q\. Sheng, Y\. Yang, X\. Zhang, and J\. Cao\(2026\)From judgment to interference: early stopping llm harmful outputs via streaming content monitoring\.Advances in Neural Information Processing Systems38,pp\. 54305–54333\.Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p1.1)\.
- \[3\]Sing Team\(2026\)SingProbe technical report\.Note:arXiv:2608\.30703Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p2.1),[§II](https://arxiv.org/html/2611.26975#S2.p1.1),[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.
- \[4\]S\. Williams, A\. Waterman, and D\. Patterson\(2009\)Roofline: an insightful visual performance model for multicore architectures\.Commun\. ACM52\(4\),pp\. 65–76\.Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p3.1)\.
- \[5\]E\. J\. Huet al\.\(2022\)LoRA: low\-rank adaptation of large language models\.InProc\. ICLR,Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p4.1),[§II](https://arxiv.org/html/2611.26975#S2.p2.1)\.
- \[6\]P\. Tillet, H\. T\. Kung, and D\. Cox\(2019\)Triton: an intermediate language and compiler for tiled neural network computations\.InProc\. MAPL,pp\. 10–19\.Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p4.1)\.
- \[7\]A\. Yanget al\.\(2025\)Qwen3 technical report\.Note:arXiv:2505\.09388Cited by:[§I](https://arxiv.org/html/2611.26975#S1.p5.1),[§V](https://arxiv.org/html/2611.26975#S5.p1.1)\.
- \[8\]H\. Inanet al\.\(2023\)Llama Guard: LLM\-based input\-output safeguard for human\-AI conversations\.Note:arXiv:2312\.06674Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p1.1)\.
- \[9\]S\. Hanet al\.\(2024\)WildGuard: open one\-stop moderation tools for safety risks, jailbreaks, and refusals of LLMs\.InProc\. NeurIPS Datasets and Benchmarks Track,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p1.1),[§V](https://arxiv.org/html/2611.26975#S5.p2.1),[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.
- \[10\]W\. Zenget al\.\(2024\)ShieldGemma: generative AI content moderation based on Gemma\.Note:arXiv:2407\.21772Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p1.1)\.
- \[11\]S\. Ghosh, P\. Varshney, E\. Galinkin, and C\. Parisien\(2024\)AEGIS: online adaptive AI content safety moderation with ensemble of LLM experts\.Note:arXiv:2404\.05993Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p1.1),[§V](https://arxiv.org/html/2611.26975#S5.p2.1)\.
- \[12\]S\. Ghoshet al\.\(2025\)Aegis2\.0: a diverse AI safety dataset and risks taxonomy for alignment of LLM guardrails\.InProc\. NAACL,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p1.1),[§V](https://arxiv.org/html/2611.26975#S5.p2.1)\.
- \[13\]Y\. Shenget al\.\(2024\)S\-LoRA: serving thousands of concurrent LoRA adapters\.InProc\. MLSys,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p2.1)\.
- \[14\]L\. Chen, Z\. Ye, Y\. Wu, D\. Zhuo, L\. Ceze, and A\. Krishnamurthy\(2024\)Punica: multi\-tenant LoRA serving\.InProc\. MLSys,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p2.1)\.
- \[15\]K\. Greenewald, L\. Lastras, T\. Parnell, V\. Shah, L\. Popa, G\. Zizzo, C\. Gunasekara, A\. Rawat, and D\. Cox\(2026\)Activated lora: fine\-tuned llms for intrinsics\.Advances in Neural Information Processing Systems38,pp\. 53022–53049\.Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p2.1)\.
- \[16\]H\. Elesedy, P\. M\. Esperança, S\. V\. Oprea, and M\. Ozay\(2024\)LoRA\-Guard: parameter\-efficient guardrail adaptation for content moderation of large language models\.InProc\. EMNLP,pp\. 11746–11765\.Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p2.1)\.
- \[17\]Y\. Leviathan, M\. Kalman, and Y\. Matias\(2023\)Fast inference from transformers via speculative decoding\.InProc\. ICML,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1),[§VII](https://arxiv.org/html/2611.26975#S7.p1.1)\.
- \[18\]T\. Caiet al\.\(2024\)Medusa: simple LLM inference acceleration framework with multiple decoding heads\.InProc\. ICML,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1)\.
- \[19\]Y\. Li, F\. Wei, C\. Zhang, and H\. Zhang\(2024\)EAGLE: speculative sampling requires rethinking feature uncertainty\.InProc\. ICML,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1)\.
- \[20\]A\. P\. Set al\.\(2024\)Tandem transformers for inference efficient LLMs\.InProc\. ICML,pp\. 42906–42917\.Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1)\.
- \[21\]S\. Z\. Shabgahiet al\.\(2026\)MoEs are stronger than you think: hyper\-parallel inference scaling with RoEs\.InFindings of EMNLP,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1)\.
- \[22\]T\. Schusteret al\.\(2022\)Confident adaptive language modeling\.InProc\. NeurIPS,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1)\.
- \[23\]M\. Elhoushiet al\.\(2024\)LayerSkip: enabling early exit inference and self\-speculative decoding\.InProc\. ACL,Cited by:[§II](https://arxiv.org/html/2611.26975#S2.p3.1)\.
- \[24\]H\. He and Thinking Machines Lab\(2025\)Defeating nondeterminism in LLM inference\.Note:Thinking Machines Lab: ConnectionismCited by:[§IV](https://arxiv.org/html/2611.26975#S4.p1.1)\.
- \[25\]J\. Dong, B\. Feng, D\. Guessous, Y\. Liang, and H\. He\(2025\)FlexAttention: a programming model for generating fused attention variants\.InProceedings of Machine Learning and Systems,M\. Zaharia, G\. Joshi, and Y\. Lin \(Eds\.\),Vol\.7\.External Links:[Link](https://mlsys.org/)Cited by:[§IV](https://arxiv.org/html/2611.26975#S4.p6.1)\.
- \[26\]J\. Anselet al\.\(2024\)PyTorch 2: faster machine learning through dynamic Python bytecode transformation and graph compilation\.InProc\. ASPLOS,Cited by:[§IV](https://arxiv.org/html/2611.26975#S4.p7.1)\.
- \[27\]J\. Jiet al\.\(2023\)BeaverTails: towards improved safety alignment of LLM via a human\-preference dataset\.InProc\. NeurIPS Datasets and Benchmarks Track,Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p2.1)\.
- \[28\]J\. Ji, D\. Hong, B\. Zhang, B\. Chen, J\. Dai, B\. Zheng, T\. A\. Qiu, J\. Zhou, K\. Wang, B\. Li,et al\.\(2025\)Pku\-saferlhf: towards multi\-level safety alignment for llms with human preference\.InProceedings of the 63rd Annual Meeting of the Association for Computational Linguistics \(Volume 1: Long Papers\),pp\. 31983–32016\.Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p2.1)\.
- \[29\]Z\. Linet al\.\(2023\)ToxicChat: unveiling hidden challenges of toxicity detection in real\-world user\-AI conversation\.InFindings of EMNLP,Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p2.1)\.
- \[30\]M\. Choiet al\.\(2026\)ExpGuard: LLM content moderation in specialized domains\.InProc\. ICLR,Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p2.1)\.
- \[31\]M\. Mazeikaet al\.\(2024\)HarmBench: a standardized evaluation framework for automated red teaming and robust refusal\.InProc\. ICML,Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.
- \[32\]T\. Markovet al\.\(2023\)A holistic approach to undesired content detection in the real world\.InProc\. AAAI,Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.
- \[33\]B\. Vidgenet al\.\(2023\)SimpleSafetyTests: a test suite for identifying critical safety risks in large language models\.Note:arXiv:2311\.08370Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.
- \[34\]P\. Röttger, H\. R\. Kirk, B\. Vidgen, G\. Attanasio, F\. Bianchi, and D\. Hovy\(2024\)XSTest: a test suite for identifying exaggerated safety behaviours in large language models\.InProc\. NAACL,Cited by:[§V](https://arxiv.org/html/2611.26975#S5.p5.1)\.

相似文章

在大语言模型上迭代,在小语言模型上部署服务

arXiv cs.AI

提出「在前沿LLM上迭代开发行为,再蒸馏到小模型(SLM)上线」的两阶段方法:用LoRA微调的Qwen3-8B在家庭护理排班智能体的生产决策上达到0.913一致率,优于教师模型GPT-5.4-nano自身重跑时72.7%的自我一致性,且延迟降低约2.5倍、成本大幅下降。论文已被NeurIPS 2026第二届企业任务智能体基准与应用研讨会(AABA4ET)接收。

局部支撑学习

Hugging Face Daily Papers

论文提出 Local Support Learning(LSL),一种在无需访问历史数据的情况下缓解大模型灾难性遗忘的框架,通过 GMM 门控函数使权重适配器只在自身训练分布的输入上激活,从而在最多 7B 参数的 LLM 上同时保留预训练与微调能力。