Manuscript Offprint

arXiv:2609.08189

Do Dynamic Routers Need Memory? HeRo: History-Aware Routing for Efficient LLM Inference

Hongjin Lin, Wentao Wan, Keze Wang

Abstract

Dynamic layer routing reduces the inference cost of Large Language Models (LLMs) by learning to skip layers for individual tokens. Existing methods, however, treat each routing decision as a local operation conditioned solely on the current hidden state which is a formulation that overlooks the sequential, path-dependent nature of routing across depth: earlier decisions shape the representations seen by downstream routers, and the layer-usage objective couples all decisions jointly. We propose History-Aware Routing (HeRo), a dynamic routing framework that resolves this mismatch by introducing a router memory mechanism to maintain an explicit routing state across model depth. The memory is constructed via linear attention, incrementally aggregating preceding routing scores and their induced residual updates into a compact history representation. At each routed layer, the router conditions jointly on this accumulated state and the current hidden representation to select the executed branch. Instantiated for token-wise FFN routing, HeRo trains only lightweight routers and adapters on a frozen backbone, requiring no modification to pretrained parameters. Across Llama 3.1-8B, Llama 2-7B, and Llama 2-13B, HeRo consistently achieves the highest aggregate performance retention among ten baselines. On Llama 3.1-8B, it bypasses 26.87% of model parameters while achieving 100.24% of dense model performance across seven benchmarks, and retains 97.01% while bypassing 38.82% of model parameters under a tighter computation budget. Ablation studies confirm that removing routing history consistently degrades performance, most notably on multistep reasoning and code generation, validating that explicit routing memory enables more accurate and adaptive dynamic routing than solely conditioning on hidden state.

Introduction

Large Language Models (LLMs) generate text autoregressively by propagating hidden state through the full Transformer decoder stack and predicting the next token (Vaswani et al. 2017). This static-depth regime is computationally inefficient because the full decoder stack is applied uniformly to every next-token prediction, even though different predictions require different amounts of computation (Men et al. 2025; Kim et al. 2024). Empirically, predictions that are highly predictable from the available context can often be

Figure

Figure 1: Dynamic feed forward network (FFN) routing proceeds as a sequence of decisions along model depth. HeRo augments the current token representation with a recurrent state constructed from preceding routing scores and changes in the residual stream, and uses this state to select the full FFN or adapter branch.

generated with fewer layers, whereas those that depend on multistep reasoning or information distributed across long contexts require more layers of computation (Schuster et al. 2022; Raposo et al. 2024).

Prior work seeks to reduce computation across model depth through three broad strategies: static pruning, early exit, and dynamic routing. Static pruning removes redundant layers or parameters before inference and produces a fixed smaller model while still applying the same computation to every input (Men et al. 2025; Kim et al. 2024; Ma, Fang, and Wang 2023; Ashkboos et al. 2024). Early exit methods select an intermediate exit layer according to confidence estimated from the hidden state at that layer, allowing the executed depth to vary across predictions while restricting computation to a contiguous prefix of the decoder (Schuster et al. 2022; Bae et al. 2023; Elhoushi et al. 2024). Dynamic routing, including dynamic layer skipping and Mixture of Depths, uses learned routers or gates to decide which mod-

  • Equal contribution Preprint.

† Corresponding author ules are executed and can bypass selected intermediate layers or modules while continuing through subsequent layers, thereby reducing computation without discarding all later transformations (Raposo et al. 2024; He et al. 2025; Luo, Wang, and Yan 2025a; Heakl et al. 2026; Zhao et al. 2025; Laitenberger et al. 2026).

As illustrated in the left part of Figure 1, existing dynamic routing methods typically formulate the routing decision at layer ll as a local decision conditioned solely on the current representation ht(l)h_t^{(l)} of token tt. Yet the training objective regularizes routing scores across depth, jointly optimizing each layer's decision. For each token, routing decisions at preceding layers determine which residual updates are applied and thereby shape the hidden states presented to subsequent routers. Moreover, the layer-usage loss jointly regularizes the routing scores across all routed layers, so the decision at layer ll depends on both the preceding routing history and the remaining routing horizon. Dynamic routing therefore constitutes a sequential decision process along the model depth, in which each routing decision is conditioned on the preceding routing history, which comprises both the routing scores assigned at preceding layers and the residual updates induced by those decisions.

Although ht(l)h_t^{(l)} reflects the cumulative effects of preceding routing decisions, it does not explicitly record the preceding routing history. A router conditioned only on ht(l)h_t^{(l)} must therefore infer that history from its cumulative effect on the current hidden state. Residual-stream analyses show that latent belief-state structure can be encoded in hidden representations (Shai et al. 2024), but this does not establish that a lightweight routing head can recover the explicit sequence of earlier gate choices. We therefore treat ht(l)h_t^{(l)} as an incomplete observed state for routing: it omits the directly observable gate scores and residual transitions available along the executed path. Studies of Mixture-of-Experts routing further show that propagating a routing state across layers provides information for expert selection that is complementary to the current hidden state alone (Qiu et al. 2025). These observations motivate maintaining an explicit routing state across depth that summarizes the preceding routing history and the residual updates induced by routing decisions.

We propose History-Aware Routing (HeRo), a dynamic routing framework that incorporates a router memory mechanism based on linear attention over model depth to maintain an explicit state of preceding routing decisions and their effects on the residual stream. For each token, this memory incrementally aggregates layerwise routing states produced by preceding routed layers. At routed layer ll, the router predicts a routing score from the current hidden representation ht(l)h_t^{(l)} together with the memory state, and compares it with a threshold to make the routing decision. The routing score and the induced residual update from the selected branch are then encoded into a new layerwise routing state and written back into the memory. We instantiate HeRo for FFN routing, selecting between the pretrained FFN and a lightweight adapter at each routed layer while keeping all attention sub-layers dense.

Our contributions are as follows:

  • We characterize dynamic routing in Transformers with decoder-only architectures as a path dependent sequential decision process across model depth. Each routing decision determines which residual update is applied and therefore changes the representation presented to downstream routers, while the routing objective couples decisions across routed layers. This characterization exposes a mismatch in existing routers: routing decisions are interdependent across depth, yet each router is conditioned only on the current hidden representation, which does not explicitly preserve the routing history that shaped it.

  • We propose History-Aware Routing (HeRo), a dynamic routing framework that addresses this mismatch by introducing a router memory mechanism that maintains an explicit state of preceding routing decisions and their effects on the residual stream. HeRo uses linear attention over model depth to incrementally aggregate layerwise routing states formed from prior routing scores and the residual updates produced by the selected branches. This memory is updated at each routed layer and provides a compact representation of routing history. Each router conditions its decision jointly on the current hidden representation and the accumulated routing state. We instantiate HeRo for FFN routing while retaining dense computation in all attention sublayers.

  • Across three model backbones, HeRo achieves the highest performance retention among the evaluated parameter skipping methods. On Llama 3.1-8B, it achieves 100.24% of dense model performance while bypassing 26.87% of parameters and retains 97.01% while bypassing 38.82% under the tighter computation budget. Ablations further show that routing history improves performance across most benchmarks, with particularly notable gains on multistep reasoning tasks. These results show that the router memory mechanism enables more accurate and selective routing by incorporating information accumulated across preceding layers into each routing decision.

References (38)