arXiv(opens in a new tab)cs.CLAug 2026Cited by 3 papers on PaperVantage

Manuscript Offprint

arXiv:2608.29327

When to Adapt: Conditional Memory Adapters for Retention-Preserving Domain Specialization

Jiayu Hou, Lei Wang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large language models deployed in specialized domains must improve in-domain performance without sacrificing general capabilities. Existing parameter-efficient fine-tuning methods are typically always on: their learned perturbations are applied to every input, which can degrade out-of-domain (OOD) performance. We propose Engram Adapter, a framework that repurposes pretraining-time conditional memory as a post-hoc adapter for frozen LLMs. It uses multi-channel matching over local n-gram patterns with explicit occupancy tracking as a lightweight selectivity prior, making residual injection more likely on in-domain inputs while a learned scalar gate suppresses incoherent OOD retrievals. We evaluate on Qwen3-4B and Qwen3-8B with AG-News and MedM-CQA as adaptation tasks and OOD benchmarks spanning reasoning, translation, code generation, and legal reasoning. Engram Adapter improves in-domain accuracy while preserving 99.4%–100.1% of average OOD performance; on LegalBench it slightly exceeds the frozen base model on average, whereas comparable always-on baselines degrade sharply. Mechanistic analyses show that although OOD activations are non-zero, gate and projection attenuation reduce residuals to approximately 0.08% of hidden-state norm, yielding small KL drift and negligible accuracy change. These results suggest conditional activation is a promising route toward modular, retention-preserving domain specialization over frozen backbones.

1 Introduction

Recent years have seen growing demand for deploying large language models in specialized domains such as medicine, law, and finance. Under limited training and deployment budgets, parameter-efficient fine-tuning (PEFT) has become the dominant paradigm for post-training adaptation. Compared with full fine-tuning, PEFT freezes the backbone and updates only a small number of additional parameters, substantially reducing training cost and storage overhead while still delivering strong downstream performance. Representative methods include Adapter (Houlsby et al., 2019), LoRA (Hu et al., 2022), DoRA (Liu et al., 2024), and PiSSA (Meng et al., 2024).

Despite their success, these methods often improve in-domain performance at the cost of out-of-domain general capabilities. Recent work has begun to revisit this adaptation–retention tradeoff: Lin et al. (2026) show that using a smaller learning rate can substantially mitigate general-performance loss while preserving comparable target-domain performance. However, learning-rate control mainly constrains the magnitude of parameter updates, rather than explicitly determining when the adapted behavior should be invoked. Most PEFT methods are effectively always on: once trained, their residual modules or weight perturbations are applied to every input without distinguishing whether it belongs to the target domain. When domain data are small and distributionally narrow, such unconditional intervention can distort general representations and induce catastrophic forgetting. In other words, the central problem in domain specialization is not only how to inject domain knowledge, but also when that knowledge should be invoked. This leads to the first challenge: how can we make the adapter intervene when the input is relevant to the target domain, while remaining minimally intrusive otherwise? Figure 1 illustrates this distinction.

However, conditional activation requires a stable, lightweight signal of domain membership. Soft gating over continuous hidden representations alone is often insufficient in low-resource settings, where the boundary between in-domain and out-of-domain inputs is not cleanly separable and limited data make it difficult for a gate to learn a ro-

∗^{*}Corresponding author

Accepted to Findings of EMNLP 2026.

Figure

Figure 1: Conceptual comparison between always-on PEFT and conditional adaptation. LoRA-style methods expose learned low-rank weight updates to all inputs at inference time, while adapter-style methods expose an additional residual branch to all inputs. In contrast, our Engram Adapter conditionally exposes its residual through explicit local-pattern matching: domain-relevant inputs are more likely to activate the adapter, whereas out-of-domain inputs with no or weak matches receive masked or gate-attenuated residuals.

bust decision rule. Our motivation is directly inspired by DeepSeek Engram (Cheng et al., 2026), which shows that local n-gram patterns can serve as explicit triggers for conditional memory retrieval through efficient hash-based lookup. We use this mechanism as a selectivity prior: the relatively stable terminology and collocations that characterize specialized corpora bias the adapter toward target-domain activation, but do not by themselves guarantee OOD transparency. This raises the second challenge: how can a conditional memory mechanism originally designed for pretraining be repurposed into a lightweight post-hoc adapter that provides sufficiently discriminative domain signals without collapsing into another form of always-on PEFT?

Moreover, a practically useful specialization method must keep overhead manageable, remain modular, and stay stable across model scales, task types, and capability dimensions. This gives rise to the third challenge: how can conditional activation be realized as a reusable PEFT mechanism with stable behavior across scales and evaluation domains, while retaining practical modularity for deployment?

Finally, conditional activation is not an ideal binary process. Different domains share vocabulary and local structural patterns, and any hash-based mechanism can produce non-zero false activations. A retention-preserving adapter must therefore explain not only why it activates more on in-domain inputs, but also why its perturbation remains small enough on out-of-domain inputs even when some activations occur. This leads to the fourth challenge: how can we maintain strong empirical preservation of general capabilities under unavoidable false activations, and provide a mechanistic explanation for this behavior?

To address these challenges, we propose Engram Adapter, a parameter-efficient framework that repurposes DeepSeek Engram from a pretraining-time conditional memory component into a post-hoc adapter for frozen large language models. Our framework uses an occupancy-tracked joint mask over multiple hash-indexed lookups to provide a lightweight selectivity prior, and combines a learned scalar gate with projection attenuation to suppress incoherent retrievals under false activations. The core evidence is mechanistic: we examine how activation selectivity relates to small residual perturbations, small output-distribution drift, and stable downstream behavior. To balance specialization and deployability, we inject the adapter into only a small set of key layers and share memory tables across layers, yielding a modular design compatible with maintaining separately trained adapters alongside a shared frozen backbone, although direct multi-domain adapter-switching evaluation is left to future work.

Contributions. Corresponding to the four challenges above:

  1. We propose a conditional-activation framework that turns domain specialization from uniform parameter perturbation into selective knowledge injection driven by local pattern matching.

  2. We introduce adapter-oriented architectural modifications including backward-looking n-gram channels, occupancy-based joint masking, and learned scalar gating.

  3. We conduct systematic experiments on Qwen3-4B and Qwen3-8B with AG-News and MedMCQA as adaptation tasks and OOD evaluation spanning reasoning, translation, code generation, and legal reasoning, showing improved target-domain performance with more stable general-capability preservation.

  4. We provide mechanistic residual and output analyses revealing a perturbation cascade from domain selectivity to residual suppression to KL/output stability and finally to stable OOD behavior.

References (43)