Overview
With hundreds of thousands of Large Language Models (LLMs) available on platforms like HuggingFace, developers face a paradox of choice: How do we efficiently manage, compare, and route queries to the right model?
Traditionally, evaluating a model requires running expensive inference across massive benchmark datasets. Alternatively, building a "model router"—a system that dynamically sends user queries to the most appropriate LLM—usually requires learning task-specific representations of models from scratch. This repetitive, compute-heavy process is highly inefficient.
EmbedLLM introduces a novel framework to solve this by learning compact vector representations (embeddings) of the LLMs themselves. By training an encoder-decoder network to predict whether a specific model will correctly answer a given prompt, the system generates embeddings that capture intrinsic model capabilities. These embeddings can then be reused to drastically speed up and cheapen downstream tasks like model routing and zero-shot benchmark performance forecasting.
The EmbedLLM Framework
The authors propose an encoder-decoder architecture inspired by matrix factorization and image reconstruction. Interestingly, the training objective—predicting if a model will get a question right—is actually a "decoy." The real goal is forcing the network to compress model capabilities into a latent space during the process.
- The Encoder: Consists of two pathways. One maps a discrete model ID into a dense latent vector (the model embedding). The other maps a text question into the same latent space using a pre-trained sentence transformer (
all-mpnet-base-v2) followed by a projection layer. - The Decoder: Acts as a binary classifier. It takes the Hadamard (element-wise) product of the model embedding and the question embedding, and outputs a probability score representing whether that specific model will correctly answer that specific question.
Once trained using Binary Cross-Entropy (BCE) loss, the model embeddings can be extracted and plugged into simple linear classifiers for various downstream tasks.
Dataset and Training
To train and evaluate EmbedLLM, the authors curated a massive correctness matrix consisting of:
- Models: 112 open-source LLMs of varying sizes, including general-purpose models (like Llama and Qwen) and specialized models (coding, medical, math).
- Questions: 36,054 questions aggregated from 10 mainstream benchmarks (e.g., MMLU, TruthfulQA, GSM8K, MedMCQA).
- Labels: Binary correctness labels (1 for correct, 0 for incorrect) generated using the standard
lm-evaluation-harness.
Key Insights
- Meaningful Latent Space: The learned embeddings naturally cluster by model characteristics. Math-tuned models cluster together, medical models cluster together, and models of similar parameter counts show tighter intra-community distances.
- The "MMLU Effect": Including comprehensive, multi-subject benchmarks like MMLU in the training data significantly improves the embeddings' ability to predict performance on other unseen benchmarks.
- Skill Isolation: Adding math benchmarks to the training set mutually improves prediction accuracy for other math tasks, proving the embeddings successfully isolate and represent specific domains of knowledge.
- The GPQA Anomaly: Including easier benchmarks in the training data actually hurts the ability to predict a model's performance on GPQA (a notoriously difficult, graduate-level benchmark). This highlights that basic QA capabilities do not smoothly transfer to expert-level reasoning.
Performance and Results
EmbedLLM demonstrates strong performance across several key areas:
- Correctness Forecasting: EmbedLLM successfully predicts whether an unseen model-question pair will be correct with ~74.1% accuracy, outperforming a K-Nearest-Neighbor baseline (71.5%).
- Blazing Fast Model Routing: When used to route queries to the best model, EmbedLLM achieves accuracy near the theoretical "single-best model" baseline. More importantly, it is 15x faster than existing causal LLM routers (>750 requests/sec vs <50) and uses 60x less memory (<1GB peak GPU memory vs fine-tuning a Llama-3-8B router).
- Zero-Shot Benchmark Prediction: By using the model embeddings as features in a simple linear regression, the authors could accurately forecast a model's overall score on unseen benchmarks without running a single new inference.
Limitations and Future Work
The authors acknowledge a few limitations. First, the dataset of 112 models is relatively small, resulting in moderately sparse embeddings that limit deeper exploration of model relationships. Second, EmbedLLM is a static system; introducing a brand-new model requires retraining the embedder (though the compute cost for this is remarkably low). Finally, the current system relies strictly on binary correctness data.
Future work could explore incorporating richer data types, such as text embeddings of the actual generated responses, to capture nuances beyond simple right/wrong answers.
Summary updated