Abstract
Modern decoder-only Large Language Models (LLMs) typically employ causal masking to ensure efficient inference and KV-cache reuse. However, this unidirectional constraint limits the model's ability to capture bidirectional context within prompt segments. We present the Intermittent Semi-working Mask (ISM), a novel masking strategy that enables bidirectional attention within query segments while maintaining causal attention for generated responses. ISM provides the contextual intelligence of prefix models without sacrificing the inference efficiency of standard causal models. Our evaluations on multi-turn dialogue and mathematical reasoning benchmarks demonstrate that ISM significantly improves performance while remaining fully compatible with standard KV-cache mechanisms.
Introduction
Most state-of-the-art LLMs, such as LLaMA and GPT-4, are decoder-only architectures utilizing a causal mask. This mask restricts each token to attending only to preceding tokens, a design choice that facilitates efficient text generation and KV-cache reuse. Despite these operational advantages, causal masking is theoretically suboptimal for processing input prompts where bidirectional context can enhance understanding. While prefix masks allow for such bidirectional attention, they often break KV-cache consistency across dialogue turns, leading to significant re-computation overhead. The authors seek a "middle way" that captures the context-richness of bidirectional attention without the massive latency penalty.
Methodology
The Intermittent Semi-working Mask (ISM) addresses this trade-off by alternating masking strategies based on segment types within a sequence. Instead of choosing between purely causal or purely bidirectional, ISM alternates based on the segment type:
- Query Segments ($Q_k$): Tokens within a user's question can look at each other bidirectionally (and at all previous turns). This allows the model to "digest" the current query more holistically.
- Answer Segments ($A_k$): Tokens in the model's response follow a strict causal (unidirectional) mask.
- The "Intermittent" Rule: Crucially, no token ever looks at a future segment.
By ensuring that tokens never look "into the future" of subsequent turns, the keys and values (KV-cache) computed for past turns remain valid forever. This allows ISM to be a "drop-in" replacement for standard causal masks in existing architectures like LLaMA and Qwen, requiring zero extra parameters or architectural changes.
Experimental Setup
The researchers evaluated ISM using several high-quality datasets and benchmarks:
- Training Data: LMSYS-Chat-1M (human-AI interactions) and MuTual (multi-turn dialogue reasoning).
- Evaluation Benchmarks: MT-Eval (multi-turn capabilities), BotChat (GPT-4 judged coherence), and MATH (competition-level mathematics).
Results and Discussion
ISM demonstrated consistent improvements over standard Supervised Fine-Tuning (SFT). On the MT-Eval benchmark, LLaMA3.1-8B equipped with ISM saw a notable increase in "Recollection" scores (5.55 vs. 5.13). Mathematical reasoning also improved, with accuracy on the MATH dataset rising from 15.7% to 18.0%.
Crucially, these gains do not come at the expense of inference speed. Latency tests for Time-To-First-Token (TTFT) and Time-Per-Output-Token (TPOT) show that ISM maintains parity with standard causal models, with differences often less than 1.0 ms.
The authors also observed that ISM helps mitigate "off-topic drift" in long conversations. By better aggregating cues from the entire dialogue history during the query phase, the model achieves more coherent transitions and robust long-term interactions.
Conclusion
The Intermittent Semi-working Mask offers a compelling "middle way" for LLM masking. It captures the benefits of bidirectional prefix attention within queries while preserving the efficiency of causal generation. While current results focus on fine-tuning, future work will explore applying ISM during the initial pre-training phase and its scalability to extremely long contexts or multimodal inputs.
Summary updated