Manuscript Offprint

arXiv:2610.19198

Embedding Geometry Shapes LLM Routing: Tracing Failure Modes and Improving Generalization

Leonardo Torti, Emanuele Rimoldi, Tomer Galanti, Tomaso Poggio, Pierfrancesco Beneventano

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

Abstract

With the growing number of LLMs available, selecting which one to use for a prompt has become a key question. A large part of the routing literature relies on semantically embedding prompts into a vector space and then applying a lightweight classifier to the embedded representations. These methods perform robustly in-distribution but they struggle to generalize to unseen tasks. By studying the geometry of semantic embeddings, we trace a clear failure mode: features that determine the neighbors of unseen prompts are an unreliable proxy for LLM selection. We therefore replace the semantic embedding with the following map: we run a partial forward pass of Qwen2.5-7B-Instruct on the prompt and use the hidden state of its last token at a deep layer as the representation. When applying kNN and other simple classifiers to this new representation, we obtain a clear result in generalization: on average across cost penalties, their performance improves. Moreover, kNN and another simple classifier that we propose outperform every evaluated semantic-embedding baseline. Our two simple methods also beat a recent SoTA hidden-states based router on RouterBench.

1 Introduction

A large number of LLMs are now available and post-training your own open-weight model is becoming increasingly accessible. This raises questions about which fundamental principles should govern LLM selection, commonly called LLM routing, when addressing a specific task. We tackle the following problem:

Given an evaluation suite, construct a router that selects the optimal model for the tasks seen at deployment time.

The evaluation suite records the reward (e.g., accuracy) and cost of each available model on each query in a given set. This set of queries is usually made of different task families (Section 2). Using this data, the task is to train a classifier, called a router, that takes a prompt as input and selects which model to use.

We focus on compute-aware routing: methods that do not rely on reasoning. Most leading compute-aware approaches first map each prompt to a vector space using a semantic text encoder, then train a classifier on these representations to select a model.

We study their in-distribution (ID) performance, where training queries are representative of the deployment distribution, and out-of-distribution (OOD) performance, where that distribution changes. In-distribution, popular compute-aware methods appear robust, and many achieve similar performance, with simple methods such as kNN often matching more complex approaches [1, 2]. Out of distribution, the differences between methods become more pronounced, and most routers struggle.

Our objective is to unveil: (i) the mechanism underlying the failure modes of these methods; (ii) what causes these more or less pronounced differences; and (iii) how to leverage those to improve the current methods.

*Main contributors. Correspondence to {pierb,leotorti}@mit.edu.

1^{1}Massachusetts Institute of Technology.

2^{2}Texas A&M University.

New prompt

Prompt embedding

Standard classification methods

Model to pick

Figure

Figure 1: Compute-aware routing: a prompt is mapped to a representation, on which a standard classifier selects the model to use.

Through the geometry of query representations, we ask whether features shaping locality also inform model selection. Semantic proximity can retrieve queries that provide unreliable guidance on unseen tasks. This motivates replacing semantic embeddings with frozen LLM hidden states while keeping routing rules fixed. The resulting gains let simple routers compete with substantially more elaborate pipelines, and our geometric analysis links them to changes in the features shaping locality.

In summary, our contributions are:

• ID: explaining why simple routers remain competitive. Our geometric analysis shows that semantic embeddings are strongly organized by family and topic. This organization explains why simple neighborhood methods and rules that select a single model for each family or finer group can match more complex routers.

• OOD: tracing the failure mode to misleading neighborhoods. We show that queries from an unseen family can concentrate near a seen family close in topic or prompt format, but whose model-performance information poorly guides selection for those queries; correspondingly, semantic kNN does no better than always selecting the best single model. With the semantic encoder fixed, we introduce Family Adaptation: a multinomial logistic classifier weights seen families per query, and the router combines their average per-model rewards and costs. Bypassing potentially misleading nearest-family neighborhoods, this simple rule outperforms all evaluated external routers using GTE on RouterBench and all except Ridge on SPROUT.

• Improving generalization through a change of representation. Building on our analysis of semantic-embedding failure modes and prior work proposing routing methods with LLM hidden states, we replace semantic embeddings with a frozen LLM's last-token state from a single internal layer, keeping routing algorithms unchanged. This improves held-out-family routing without further adaptation: kNN-100 and Family Adaptation each outperform every evaluated external semantic-embedding baseline in mean utility across cost penalties on RouterBench and SPROUT. Beyond these popular and strong baselines, we compare our simple, interpretable pipelines with SharedTrunkNet [3], a recent state-of-the-art router based on LLM hidden states. We use the same Qwen2.5-7B-Instruct encoder for all methods to isolate pipeline differences. Family Adaptation clearly outperforms SharedTrunkNet on RouterBench and trails it only slightly on SPROUT; even kNN-100 outperforms it on RouterBench and remains close behind on SPROUT.

• Understanding the geometric change. Keeping routing rules fixed lets us attribute the gains to the representation change. Compared with semantic embeddings, hidden-state embeddings much more often retrieve neighbors from training families sharing the unseen query's answer format. This suggests a possible explanation for semantic routers' strong ID performance: answer format is often shared within a family, so neighbors from that family share it even when other features shape locality. Holding out the query's family breaks this association, exposing whether those features retrieve examples useful for routing. Still, greater answer-format agreement does not fully explain the gains.

References (39)