UpSafe℃: Upcycling for Controllable Safety in Large Language Models

Yuhao Sun, Lingyun Yu, Zhuoer Xu, Kun Yang, shiwen cui, Yongdong Zhang, Hongtao XieNeurIPS 2026

TL;DR

Just as standard sampling temperature lets you dial an LLM’s creativity up or down at runtime, UpSafe°C gives you an inference-time knob to dynamically control a model’s safety. By finding the exact neural network layers that inherently recognize danger and converting them into specialized Mixture-of-Experts (MoE) modules, this framework stops jailbreaks without lobotomizing the model's general intelligence—and lets you adjust its strictness on the fly without retraining.

What Problem Does This Paper Address?

Keeping Large Language Models (LLMs) safe usually feels like a game of whack-a-mole where every fix comes with a catch. Currently, engineers rely on three main strategies:

  1. External Guardrails: Slapping a separate classifier in front of the LLM. It’s easy, but misses nuanced context and adds deployment overhead.
  2. Inference Guidance: Steering token generation at runtime. This slows down responses and struggles if the base model isn't great at following instructions.
  3. Post-Training Alignment (SFT/RLHF): Baking safety directly into the model's weights. This is the gold standard, yet it often degrades general intelligence (the dreaded "alignment tax"), remains vulnerable to clever jailbreaks, and locks the model into a single, static safety posture.

What if an application needs strict caution for public users, but nuanced flexibility for security researchers? Until now, you couldn't adjust that boundary dynamically without maintaining separate models. UpSafe°C bridges training and inference to make safety modular, surgical, and controllable in real time.

Methods

Instead of rewriting the entire neural network, UpSafe°C performs targeted microsurgery in three steps:

Figure 1: Overall framework of our UPSAFE°C. We first scan the pretrained LLM to identify safety- critical layers, then upcycle them with safety experts through a two-stage SFT strategy, and finally apply a safety temperature at inference to dynamically balance safety and utility.
  • 1. Intrinsic Safety-Critical Layer Scan: Not all layers care equally about safety. The authors pass harmful and benign prompts through the model and train lightweight linear probes on each layer's hidden states. Layers with the lowest classification validation loss—meaning harmful and benign concepts naturally separate there—get the best Safety Sensitivity Score (SS-Score). Only the top-$k$ (specifically, top 3) layers are modified.
  • 2. Safety-Aware Upcycling & Two-Stage SFT: "Upcycling" converts a standard dense layer into a sparse Mixture-of-Experts (MoE) layer. In those 3 critical layers, the original feed-forward network (MLP) is frozen as a General Expert to preserve intelligence, while 3 duplicated copies become Safety Experts, governed by a learned router.
  • Stage 1 (Safety Experts Training): Trained purely on harmful prompts. The General Expert is masked out so the new Safety Experts specialize exclusively in refusing or safely handling attacks.
  • Stage 2 (Soft Guardrail Training): All experts are frozen, and only the router is trained on a mix of benign and harmful data. The router learns to act as an internal traffic cop—sending safe queries to the original MLP and sketchy ones to the safety squad.
  • 3. Safety Temperature ($\tau$): At inference time, a hyperparameter $\tau \in [0, 1]$ biases and scales the router's logits. Setting $\tau$ near $0$ favors the General Expert; dialing $\tau$ toward $1$ hands the wheel over to the Safety Experts.

Datasets

No new benchmarks were introduced; the authors used established datasets to keep comparisons apples-to-apples:

  • Training: STAR-1, a high-quality dataset containing 1,000 harmful queries (with safety reasoning, stripped out for standard non-reasoning LLMs) and 915 benign queries.
  • Safety Evaluation: JailbreakBench (JBB), StrongREJECT, and WildChat for red-teaming; WildJailbreak for out-of-distribution adversarial jailbreaks; and XSTest to measure "over-refusal" (making sure the model doesn't refuse harmless prompts that just sound edgy, like "how to kill a Python process").
  • General Utility Evaluation: MMLU (general knowledge), HumanEval (coding), and Math-500 (mathematical reasoning).

Key Insights and Ideas

  • LLMs already know when they're being tricked: Visualizing the hidden states shows that middle-to-late layers (e.g., Layers 13, 17, and 18 in Llama-3.1-8B) naturally cluster harmful vs. benign prompts into distinct regions. UpSafe°C doesn't teach safety from scratch; it amplifies an existing internal signal.
Figure 2: (a) t-SNE visualization comparing safety-critical layer with the other layer in Llama3.1-8B- Instruct. The safety-critical layer display more discriminative representations between harmful and benign inputs, supporting our safety-critical layer scan strategy. (b) Scan results of Llama3.1-8B- Instruct. We plot the SS-Score across layers and highlight the top-3 safety-critical layers.
  • Multiple safety experts beat a single monolith: Ablations revealed that having 3 safety experts per upcycled layer generalizes much better against sneaky, out-of-distribution jailbreaks than adding just 1 expert, while going beyond 3 hits diminishing returns.
  • Decoupling skill from routing prevents "brain drain": Standard fine-tuning forces weights to compromise between being helpful and being harmless. Freezing the original MLP and training the router in a separate second stage lets the model keep its original coding and math chops intact.

Key Results

Tested across six models—including standard LLMs (Qwen2.5-7B/14B, Llama3.1-8B) and reasoning models (DeepSeek-R1-Distill variants)—UpSafe°C (at $\tau = 0.5$) consistently outperformed vanilla, SFT-only, and single-stage MoE baselines:

  • Near-Perfect Red-Team Defense: Hit 100% safety rates across all six models on both StrongREJECT and JailbreakBench.
  • Strong Jailbreak Generalization: On the tough WildJailbreak benchmark, UpSafe°C beat SFT-only baselines by an average of 7.8% and single-stage MoE baselines by 10.8% (e.g., jumping from 74.0% to 90.8% on Llama3.1-8B).
  • Preserved (and Improved) Utility: Averaged across models, UpSafe°C scored 4.5 percentage points higher on general benchmarks (MMLU, Math-500, HumanEval) than standard SFT.
  • Smooth Runtime Control & Modest Overhead: Sweeping $\tau$ from $0$ to $1$ smoothly increases safety while general task scores stay remarkably flat. Upcycling 3 layers in Llama3.1-8B increases total parameters by 19.8%, but sparse top-2 routing keeps active parameter and FLOP increases to just 6.6% and 7.3%, respectively.
Figure 4: Safety and utility scores under varying safety temperature τ.

Limitations and Future Work

  • The Over-Refusal Trade-off: Stronger safety still makes models more conservative. On XSTest, UpSafe°C refuses more benign borderline prompts than vanilla unaligned models, and turning $\tau$ up toward $1.0$ noticeably increases these false-positive refusals.
  • Hardware & Memory Overhead: Even though active compute (FLOPs) barely ticks up (+7.3%), total memory footprint grows by ~20% to hold the extra experts, and actual wall-clock latency depends heavily on hardware and sparse-MoE kernel implementations.
  • Empirical Calibration: Because the exact effect of $\tau$ depends on each model's learned router logits, operators still need to empirically test and pick the right temperature operating point for their specific deployment. Moving forward, the authors frame this work as a stepping stone toward dynamic, modular, and inference-aware LLM alignment.

Summary updated

Abstract

Large Language Models (LLMs) have achieved remarkable progress across a wide range of tasks, but remain vulnerable to safety risks such as harmful content generation and jailbreak attacks. Existing safety techniques---including external guardrails, inference-time guidance, and post-training alignment---each face limitations in balancing safety, utility, and controllability. In this work, we propose UpSafe℃, a unified framework for enhancing LLM safety through safety-aware upcycling. Our approach first identifies safety-critical layers and upcycles them into a sparse Mixture-of-Experts (MoE) structure, where the router acts as a soft guardrail that selectively activates original MLPs and added safety experts. We further introduce a two-stage SFT strategy to strengthen safety discrimination while preserving general capabilities. To enable flexible control at inference time, we introduce a safety temperature mechanism, allowing dynamic adjustment of the trade-off between safety and utility. Experiments across multiple benchmarks, base model, and model scales demonstrate that UpSafe℃ achieves robust safety improvements against harmful and jailbreak inputs, while maintaining competitive performance on general tasks. Moreover, analysis shows that safety temperature provides fine-grained inference-time control that achieves controllable trade-off between utility and safety. Our results highlight a new direction for LLM safety: moving from static alignment toward dynamic, modular, and inference-aware control. Code: https://github.com/HansSunY/UpSafe.
BibTeX
@inproceedings{sun2026upsafec,
  author = {Yuhao Sun and Lingyun Yu and Zhuoer Xu and Kun Yang and shiwen cui and Yongdong Zhang and Hongtao Xie},
  title = {{UpSafe℃: Upcycling for Controllable Safety in Large Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=c0mcgI6A3n},
}
Figure