TriRoute: Joint Optimization of Attention, Experts, and KV Cache
The efficiency of large language models has become a strategic factor for any organization that wants to deploy artificial intelligence at scale. The cost per token is not fixed: it depends on internal architectural decisions that determine what attention is computed, which experts are activated, and how precisely the KV cache memory is stored. In recent years, these decisions have been optimized separately, but there is an important opportunity in treating them as a single coordination problem.
Conditional computation has shown that not all tokens need the same amount of resources. Some models only activate a subset of neurons in the feed-forward block through Mixture-of-Experts, others skip entire layers with Mixture-of-Depths, and others reduce attention memory by quantizing the KV cache. Each technique individually improves some metric, but it ignores that these three dimensions are coupled: a rare token that requires full attention probably also needs a high-precision cache, and that need does not depend on which expert processes it.
TriRoute's conceptual proposal starts from a simple idea: instead of applying three independent optimizations, a single lightweight controller should emit a coordinated policy for every token and every layer. That policy combines three decisions. First, the attention mode, which can be skip attention, use a local window, or compute full attention. Second, the selection of a sparse set of experts in the feed-forward layer, including the possibility of a null expert that is equivalent to not processing that sublayer. Third, the KV cache bit-width, which defines how much memory is reserved for attention keys and values.
This joint view is especially relevant in real applications. A customer-service platform, for example, receives messages that mention product names, error codes, and specific account data. Those tokens are rare in the global corpus, but they are critical for providing a correct answer. If the system decides to save resources on attention, experts, and memory independently, it can degrade exactly the cases that matter most. TriRoute addresses this problem by aligning the decision to attend, the decision to compute, and the decision to remember.
The choice of KV cache bit-width is often seen as a compression detail, but it has direct consequences on response quality. A cache with fewer bits saves memory but loses information about previous tokens. Combined with full attention and more capable experts, that loss can be acceptable; combined with local attention and few experts, it multiplies the error. Therefore, the KV cache decision should be made in the same context as the other two.
From a training perspective, the controller is integrated end-to-end using a heterogeneous relaxation. Categorical decisions are approximated with Gumbel-Softmax and straight-through estimation, while expert selection uses a top-k mechanism with load balancing. A Lagrangian budget constraint is applied over the set of decisions, turning the average compute and memory cost into a configurable knob. This means that an organization can adjust the balance between quality and speed depending on the use case, without redesigning the entire model.
One of the most interesting findings is the appearance of a routing-collapse cascade when the joint model is trained naively. If one axis collapses, for example if all tokens choose local attention, the other axes also tend to degrade. To avoid this, the architecture applies per-axis normalization and a coupling-aware balancing loss. This correction is not a minor detail: it is the difference between an apparently coordinated system and one that truly coordinates its decisions.
Experimental results show that a joint policy outperforms the independent combination of MoD, MoE, and KV cache quantization in models between 160 million and 1.3 billion parameters, under an optimal compute budget. The advantage holds when comparing with the same inference cost and memory, and it becomes more evident in tail cases: rare entities, code fragments, and arithmetic operations. Exclusive perplexity optimization tends to erode these cases, while TriRoute better preserves robustness in extreme situations.
Another relevant implication is the relationship between this architecture and AI agents. An agent that interacts with external tools needs to process long sequences, remember information from previous steps, and respond quickly. If each model call consumes too many resources, the user experience suffers. Joint optimization allows agents to maintain a high-quality working memory at critical points and reduce spending on redundant tokens.
At Q2BSTUDIO, a software and technology company, we see this line of work as a natural step toward more efficient AI systems that can be deployed in real production environments. The distance between an academic experiment and a business application is enormous: latency, memory, costs, and quality must be managed at the same time. That is why, when a company needs custom software, it is not only looking for a language model: it is looking for a complete system that integrates inference, orchestration, and observability.
Efficient inference architectures fit naturally into cloud AWS/Azure projects. In these environments, compute cost is directly proportional to consumed resources, so reducing operations per token has a clear impact on the bill. In addition, deploying this type of solution requires a comprehensive vision: cybersecurity audits to protect the data flowing through the system, dashboards with BI/Power BI to measure return, and AI agents capable of operating with tight budgets.
TriRoute is not a closed recipe, but a design direction. The key is to understand that attention, expert selection, and KV cache are part of the same resource budget. Whoever can coordinate these three levers will be able to offer faster, cheaper, and more reliable models. At Q2BSTUDIO we accompany organizations on that path, combining technical knowledge, software development experience, and a practical business vision.





