# Inference Engineering for Coding Agents — Philip Kiely, Baseten

Philip Kiely, Baseten

AI Engineer Code Summit 2026

[Talk page](https://ai.engineer/talks/u-Gy1PQ4dYw-inference-engineering-coding-agents) · [Video](https://www.youtube.com/watch?v=u-Gy1PQ4dYw)

## Inference Engineering for Coding Agents

Philip Kiely explains how Baseten trains a model router, decides when a subagent should give up a warm KV cache, and uses coding agents to find GPU optimizations that make the whole model faster.

### Choose the model before optimizing its inference

[0:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=12s)

You can spend a lot of engineering time making inference 5% cheaper when choosing a different model might save you 50%. That’s why [Philip Kiely](https://philipkiely.com/) starts Baseten’s work on coding agents with request routing, even though deciding which model gets a request sits a little outside traditional inference engineering.

The apparent size of the routing problem is intimidating. There are millions of models to choose from, with different combinations of capability, speed and price. In practice, the coding agents Kiely looks at usually give their router two or three choices. There’s a frontier model, a cheaper Flash model and occasionally something in between.

Even the two-model problem is hard. When was the last time you sat down to write some code, estimated it would take two hours and finished in two hours? A router has to make a similar judgment before anybody has started the work. A request to build a web page or fix a kernel gives it surprisingly little to go on.

Baseten’s experiment pairs **Opus**, the more capable and expensive option, with **GLM Flash**, which is substantially cheaper and faster. Ideally, GLM gets every task it can handle well enough. The hard part is estimating how much additional probability of success you buy by sending a particular task to Opus.

One way to express that decision is to give each candidate model $$m$$ a score for task $$x$$.

$$
S(m,x) = \widehat{P}(\text{success} \mid m,x) - \lambda\,\widehat{C}(m,x)
$$

Here $$\widehat{C}$$ is the expected cost of doing the whole task, and $$\lambda$$ expresses how much cost matters relative to success. Pick the model with the higher score. If one model charges a tenth as much per token but uses ten times as many tokens, its apparent price advantage disappears. The router needs to predict how much work each model will do.

### Run the same coding task enough times to learn from it

[5:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=342s)

Training that predictor requires traces of both models attempting comparable tasks. Production traces from your own coding agent would give you a useful starting distribution. Baseten used public benchmarks so it could compare models on common ground, repair broken task environments, add safeguards against cheating and remove problematic examples. What kind of work would this router learn to recognize? More than 90% of the data came from software engineering benchmarks such as SWE-bench.

Running each model once on each task would give you a dataset quickly. It would also make two kinds of luck look like intelligence.

- **Label noise.** The same model can pass a task on one attempt and fail on the next. A single pass tells you it can solve the problem, but gives you a poor estimate of how reliably it will do so.
- **Selection noise.** Even a router that flips a coin can happen to pick GLM on a task where GLM succeeds. Enough lucky selections make the routing policy itself look better than it is.

Baseten ran **each task four times with Opus and eight times with GLM**. The subsequent comparisons use averages over those runs. That costs considerably more tokens, but gives the team a much better estimate of each model’s performance on each task. As Kiely points out, tokens are one thing an inference company tends to have lying around.

The coin flip is worth keeping as a baseline. Heads goes to Opus, tails to GLM. A learned router needs to beat random allocation by a statistically meaningful margin before you can credit its choice of tasks for the improvement.

![Two columns explain label noise from inconsistent outcomes across model runs and selection noise from random routing choices that succeed by chance.](https://ai.engineer/api/talk-essay-media/ddffc2ed2e7d642c5b0ea1bca37b1aacfd0c96d3dc4f97ea69ebaf5cb1603830)

Baseten repeated tasks to separate router performance from two kinds of luck. With label noise, the same model can pass a task on one run and fail it on another. With selection noise, even a random router can look good if it happens to send GLM tasks it can solve.

### What can you predict before generating an answer?

[8:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=521s)

Start with the task instructions. An existing embedding model such as **Qwen3-Embedding** or **EmbeddingGemma** can turn them into a vector of semantic features. Using the benchmark traces as training data, fit separate prediction heads on those features to estimate each candidate’s probability of success and expected cost. This lets you train the predictors without training an entire language model from scratch.

Baseten compared three ways of making the decision.

- **Success advantage alone.** Estimate how much more likely one model is to solve the task.
- **Cost advantage alone.** Estimate how much money you could save by choosing one model over the other.
- **Success relative to cost.** Estimate both advantages and decide whether the improvement in success justifies the extra expense.

The combined approach worked best. An expensive model might have a small edge on many tasks, but you’d like to reserve the extra spending for the tasks where that edge is large. There’s also a feature-selection problem. An embedding gives you hundreds or thousands of numbers. When the team investigated which features actually helped make that decision, task category emerged as a useful signal.

The more interesting experiment was to ask whether GLM already knew something about how much trouble it was going to have. Baseten ran the task through GLM **without generating a response**, captured intermediate activations and trained a head to predict the number of steps in the eventual response. That estimate turned out to be a strong signal of task difficulty. The team didn’t have equivalent access to Opus’s internal state.

How do those observations fit into one routing decision? At request time, the trained predictors can estimate outcomes for both models from the instructions. GLM contributes an additional estimate of the effort ahead. The router can combine those estimates with structured facts about the task without paying for two complete answers.

![A linear probe identifies benchmark identity from embeddings with 89% balanced accuracy. The slide discusses weak correlation with the Opus advantage and highlights task scope, domain knowledge and ambiguity.](https://ai.engineer/api/talk-essay-media/3b3a0a94eb6cd68e505d1730d7362659dbe3e35fed17e74c13d55c4ca9d01fd3)

A linear probe identified a task’s benchmark from its embedding with 89% balanced accuracy. That gave the router a shortcut, but benchmark identity only weakly tracked Opus’s advantage over GLM. Other candidate signals include task scope, required domain knowledge and ambiguity.

Three sources of information for one routing decision
The router can compare both models’ expected outcomes even though only GLM exposes its activations. The arrows show information used at request time. Only the selected model generates the answer.
- Incoming coding task — The instructions are available before either candidate generates an answer.
- Structured attributes — Task category is one useful feature.
- Instruction embedding — A pretrained embedding model represents the meaning of the request.
- GLM forward pass — Capture intermediate activations without decoding a response.
- Per-model predictions — Estimate success probability and task cost for Opus and GLM.
- Predicted response steps — A head trained on GLM’s activations estimates how much work is ahead.
- Choose Opus or GLM — Weigh the expected improvement in success against the additional task cost.
- Incoming coding task → Structured attributes (Identify task attributes)
- Incoming coding task → Instruction embedding (Embed instructions)
- Incoming coding task → GLM forward pass (Process the prompt)
- Instruction embedding → Per-model predictions (Apply prediction heads)
- GLM forward pass → Predicted response steps (Predict step count)
- Structured attributes → Choose Opus or GLM (Task features)
- Per-model predictions → Choose Opus or GLM (Expected advantages)
- Predicted response steps → Choose Opus or GLM (Difficulty signal)

### How much quality does the cheaper route give up?

[11:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=702s)

To read the router comparison, pick a level of task success and ask how cheaply each strategy reaches it. Or hold spending fixed and compare success rates. The most useful points form a Pareto frontier, where improving one measure requires giving something up on the other. Baseten’s combined router reached that frontier on its benchmark.

At one operating point, Kiely reports **72% lower cost with less than a one-point drop in output quality**. He doesn’t specify the baseline for that particular comparison in his explanation. The routing model itself added at most **429 milliseconds at the 95th percentile** in the measurements he presented. That latency is the time spent deciding where to send the request. For this particular saving, Kiely was happy to spend roughly half a second making the decision.

There’s a good reason to resist reading the comparison as a general ranking of routers. Other teams may have trained for different tasks or optimized for different objectives. The method is more widely useful. Collect repeated outcomes for the models you actually serve, find features that predict their relative advantages, and include the router’s own time and cost when deciding whether to deploy it.

Then a real user comes along and types something like *please fix this*. Even a very good embedding of those three words won’t tell you much about the work ahead. Much of the useful information is in the preceding conversation.

### Why the expensive model might get the easy follow-up

[13:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=821s)

Imagine you’ve just asked the frontier model to implement a complex feature. It finishes, you look at the result, and you ask it to center the `div`. Taken on its own, that follow-up looks like an obvious job for the cheap model. But the expensive model may already have almost the entire conversation in its key-value cache.

The KV cache holds attention keys and values computed for earlier tokens. When the next request begins with the same sequence of tokens, prefix caching lets the serving engine reuse that work. Switching models can mean processing the long history again just to make a tiny CSS change. That cost belongs in the routing decision.

The client can help by sending a consistent session ID in the provider’s affinity header across turns. That gives the provider a reason to expect a long prefix match in a recent cache and route the request accordingly. The header is a hint. The reusable work comes from the matching tokens.

Forking a subagent makes the choice more interesting. Should the side request keep the parent’s session ID or get a new one? That depends on how much of the parent’s prefix the subagent will actually carry forward.

### How many turns will it take to pay for compaction?

[15:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=942s)

Context compaction replaces a long history with a shorter account of what the agent needs to continue. Kiely passes along a recommendation from Baseten’s research team to let the model write that summary. The models they work with practice summarizing their own context during reinforcement learning, which makes a prompt to the model an attractive alternative to fixed compaction rules in the agent harness.

Summarizing has two upfront costs. You pay for the summary itself, and the serving engine has to compute KV entries for the changed, uncached input. The payoff comes on subsequent turns, when the subagent carries a shorter prefix. Even cached input can cost money, so shortening a prefix you’ll use repeatedly can be worthwhile.

Where do those costs cross? Call the extra one-time expense of switching to a summary $$U$$ and the average saving on each subsequent turn $$s$$. In a simplified calculation with positive, constant savings, compaction pays off after $$n$$ turns when

$$
n s > U.
$$

The break-even point in Kiely’s example is illustrative. It moves with the model, how much context the summary removes, and the price of cached input relative to ordinary input. A generous cache discount makes the existing long prefix more attractive.

That gives the harness a practical way to choose what happens when the main agent delegates work.

- **A quick side request.** Keep the parent’s context and affinity header, do the one turn or short sequence, and return to the main agent. There are few opportunities to recover the cost of a summary.
- **A longer investigation.** If enough turns remain, compact the context and let the subagent build up a cache around its shorter prefix. As the shared prefix shrinks, there’s less reason to preserve affinity with the parent’s session.

### A short detour into speculative decoding

Speculative decoding exploits the predictability of upcoming tokens. A cheaper mechanism proposes tokens for the main model to verify. Kiely favors **DSpark** over **DFlash**, pointing to an additional prediction head that introduces sequential dependence between draft tokens and helps more of them get accepted.

For a DSpark speculator serving coding agents, his advice is to narrow the training data to the domain. A learned speculator can predict new sequences. Code completion and revision may admit an even simpler solution when much of the code repeats. An n-gram lookup can find matching token sequences and propose the tokens that followed them previously, avoiding a separate learned draft model. The [SGLang speculative decoding guide](https://docs.sglang.io/docs/advanced_features/speculative_decoding) describes how to try that approach.

![Keeping one million cached tokens costs $0.0300 for the next request. Compacting to 250,000 tokens costs $0.1375, including $0.10 for compaction.](https://ai.engineer/api/talk-essay-media/0f1bf22c9ecb3e7c2efedf6538a2a9ebc238eaecbb20741339f920274362253d)

In this GLM-5.3-Flash example, shrinking the prefix from 1M tokens to 250K raises the next request’s cost from $0.0300 to $0.1375. The new prefix costs $0.0375 at the full input rate, even before the $0.10 compaction charge.

### The agent made the matrix multiply faster. Why is the model still slow?

[17:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1061s)

Now turn the relationship around and put the coding agent to work on inference itself. Kiely’s example starts with a general matrix multiplication kernel, or GEMM, that takes 0.03 milliseconds. The agent improves it to 0.02 milliseconds. A third of the kernel’s runtime is gone. The model runs just as fast as before.

The absolute saving in this illustration is ten microseconds per invocation. Whether the user ever sees that saving depends on how often the operation runs, how much of the request waits for it and whether the improvement survives the production workload. Change the batch size, the traffic mix or how full the batches are, and a different kernel configuration may win.

Getting the replacement into vLLM, SGLang or TensorRT-LLM adds another complication. The kernel operates inside a serving engine with other work to schedule and data to move. A benchmark that times one operation in isolation can miss both the cost of integrating it and a larger opportunity to eliminate work between operations.

Baseten gives its optimization agent two levels of work. At the model level, profile the full workload, find where time goes and propose changes that address those bottlenecks. At the kernel level, work on individual implementations once the profile has identified them as consequential.

A proposed kernel has to pass a correctness check and an end-to-end performance check before the framework retains it as a candidate for further improvement. The agent records lessons from both successful and failed attempts in memory. A correct, faster GEMM that leaves model latency unchanged is a useful failure to remember. It tells the next attempt something about where to spend its effort.

### Remove memory trips, overlap kernels and cut CPU launches

[20:38](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1238s)

**Kernel fusion removes a memory round trip.** Suppose one kernel produces a value that the next kernel immediately consumes. Running them separately can require writing the intermediate value to GPU memory and reading it back. A fused implementation can keep that intermediate local and do both operations in one launch. You save launch overhead and memory bandwidth. The latter is particularly valuable during token-by-token decoding, when reading weights and moving intermediate values through GPU memory can already limit performance.

**Programmatic Dependent Launch (PDL) changes when work can start.** Suppose kernel B consumes results from kernel A. In the ordinary schedule Kiely describes, B waits for A to finish and make its results available in memory. How much of B could start earlier? With PDL, blocks of B can begin independent work while A is still finishing. The part that reads A’s output must still synchronize before using it.

The opportunity comes from separating the start of B from the first point at which B actually needs A’s data. Moving independent work into that interval can close some of the gap between kernels while preserving the dependency that makes the computation correct.

**Grouping launches reduces work on the host CPU.** With asynchronous launches, the CPU should stay ahead of the GPU and leave it a queue of pending work. Scheduling hundreds of kernels individually can make the CPU control loop the bottleneck. Grouping the operations into a small number of execution graphs reduces the number of submissions the host has to make. The GPU can stay busy even if none of the individual kernels gets faster.

### Where the agent found room to improve whole models

[22:38](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1358s)

For a production example, Baseten tried its framework on two image generation models, **Qwen-Image** and **FLUX.2**. The choice was deliberate. The common language model paths in vLLM, SGLang and TensorRT-LLM already benefit from extensive kernel optimization. Kiely saw more room for large improvements in image generation.

How much did each image generation workload benefit? The agent proposed and implemented the optimizations itself, including kernel fusion. Kiely reports substantial performance improvements across these experiments. The gains depend on the workload and how much room its existing implementation left for optimization, so they don’t establish a general speedup factor for coding models.

The change in the agent’s assignment is easy to miss. Give it a GEMM and a stopwatch, and it can discover how to save ten microseconds. Give it the workload profile and a way to test the full model, and it can discover that two kernels should be one, or that the GPU is waiting on the CPU. Extend that visibility to routing, speculation and cache reuse, and the agent can help decide which part of its own inference system is worth improving next.

## Key takeaways

- Route on expected success and total task cost. A tenfold discount per token disappears if the model uses ten times as many tokens.
- Repeated attempts help separate routing skill from luck. Baseten averaged four Opus runs and eight GLM runs per task, then used task features and GLM’s internal activations to predict which model was worth using.
- One benchmark comparison yielded 72% lower cost with less than a one-point quality loss, against an unspecified baseline. The routing decision itself added at most 429 ms at p95.
- A short subagent request can benefit from keeping the parent’s session affinity. Compaction becomes economical when enough future turns use the shorter context to repay summarization and the initial cache miss.
- Give a kernel-writing agent the production workload profile and require both correctness and end-to-end gains. Removing memory transfers, overlapping independent work or reducing CPU submissions may save more time than accelerating a single operation.

## Resources

- [Inference Engineering by Philip Kiely](https://www.baseten.co/inference-engineering/) — Chapter 4 covers kernel selection, fusion and profiling. Chapter 5 develops speculative decoding, prefix caching and cache-aware routing. Chapter 6 extends the discussion to image generation kernels.
- [SGLang: Efficient Execution of Structured Language Model Programs](https://arxiv.org/abs/2312.07104) — Explains how RadixAttention reuses cached attention state across language model calls, providing background for the subagent affinity decision.
- [SGLang speculative decoding guide](https://docs.sglang.io/docs/advanced_features/speculative_decoding) — Configuration examples for learned draft models and n-gram speculation, including parameters that control how many proposed tokens the target model verifies.
- [TensorRT-LLM engine building and benchmarking exercises](https://github.com/basetenlabs/Workshop-TRT-LLM) — Kiely and Pankaj Gupta’s archived workshop materials walk through building an inference engine, deploying it and comparing performance under different request loads. The exercises use historical dependency versions.

## Slides

### Introduction to Philip

Philip works on inference at Baseten. Lately, that’s meant spending a lot of time on agents. He’s been speaking at AI Engineer events since 2024.

[0:23](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=23s) [Philip introduces himself and explains that he works on inference and agents at Baseten.](https://assets.ai.engineer/sites/aiecode2025/sha256/681b5a01d3b2edd8b2d95934c3eea1b04d8ddb9dc5b11f9b31d1da6626dbbf85.webp)

Hi I’m Philip

I work on inference and agents at Baseten

AI Engineer
Code Summit
PRESENTED BY
Google DeepMind

NOVEMBER 10, 2026
Fighting Slop

### What I Talked About Last Time

Four months after his July 2026 World’s Fair talk, Philip Kiely says his team has largely moved on from TurboQuant. People still use KV compaction. DSpark quickly replaced DFlash because its extra Markov head helps more draft tokens get accepted.

[0:30](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=30s) [A recap lists TurboQuant, KV Compaction and DFlash Speculation beside a thumbnail from the July 2026 AI Engineer World’s Fair.](https://assets.ai.engineer/sites/aiecode2025/sha256/e97e7626f81f5c3428c8ec8543c8e767f28f5efda89339ff6aff828287cb97ca.webp)

IN REVIEW
What I talked about last time

TurboQuant
KV Compaction
DFlash Speculation

AI Engineer World’s Fair July 2026

AI Engineer
World’s Fair
What is TurboQuant?
NEW QUANTIZATION APPROACH
[illegible]
Google Research
Introducing TurboQuant [illegible]
The Hyped Quantization Trick That Failed

© BASETEN 2026. ALL RIGHTS RESERVED.

Interface text:
AI Engineer
Code Summit
PRESENTED BY
Google DeepMind
NOVEMBER 10, 2026
Fighting Slop

### What We’ll Cover

Kiely starts with request routing because choosing the right model for a coding task can save more than speeding up inference. He then covers KV cache management for subagents, speculation with DSpark, and why faster kernels don’t always mean faster inference.

[1:26](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=86s) [Four color-coded agenda items list request routing, KV cache management, speculation and agents for inference.](https://assets.ai.engineer/sites/aiecode2025/sha256/f9e30c50d060b3c4e52a9da24be17f915995a2ff34c71ccc242f929bc8555934.webp)

What we’ll cover

REQUEST ROUTING
KV CACHE MANAGEMENT
SPECULATION
AGENTS FOR INFERENCE

© BASETEN 2026. ALL RIGHTS RESERVED.

### Request Routing

Before spending time speeding up inference, Philip Kiely asks which model should handle each request. Cost and speed both matter when making that choice.

[2:20](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=140s) [Bright green section slide titled Request routing, with a dotted geometric pattern.](https://assets.ai.engineer/sites/aiecode2025/sha256/34d72ba66cc73464c5ccf0174eb120c22ddf7b5dcbc9866ce02b4844fdf89a03.webp)

Request routing

© BASETEN 2026. ALL RIGHTS RESERVED.

### Optimizing the Right Thing

Before spending time speeding up inference, choose the right model for the task. A request router makes that choice by balancing cost, speed, and model capability.

[2:32](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=152s) [Large black text on a pale yellow background reads “...let’s be sure we’re optimizing the right thing.”](https://assets.ai.engineer/sites/aiecode2025/sha256/adc6deb443f7a5e8e99dc218d544ae944d34da7cfd4ca89f949e376c741d6287.webp)

...let’s be sure we’re optimizing the right thing

© BASETEN 2026. ALL RIGHTS RESERVED.

### Agents can use many models

Claude Opus 4.8 and GLM 5.2 account for most of the October spend across at least eight models. Philip Kiely says most coding agent routers use just one frontier model and one flash model. Some add a third in between.

[2:45](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=165s) [The slide recommends one frontier model and one flash model alongside a stacked bar chart showing spending across multiple models.](https://assets.ai.engineer/sites/aiecode2025/sha256/282f5b34c21925471ebbae77c0425edf87499edbba7e364322a0fd406e184e71.webp)

Agents can use many models

But they only need two
One frontier model
One flash model

Total spend: $21,892.31
Total tokens: 19.6B
Cache hit rate: 68.5%
Per 1M tokens: $1.12
$18.42 on frontier
Saved: $339,601.12
94% less

Spend by model
Y-axis ticks: $0, $400, $800, $1,200
Timeline: Oct 1, Oct 5, Oct 9, Oct 13, Oct 17, Oct 21, Oct 25, Oct 29

Claude Opus 4.8  $8,289.40
GLM 5.2  $6,542.13
Claude Sonnet 4.8  $3,806.51
Kimi K3  $1,532.38
DeepSeek V3.2  $432.89
Qwen3 Coder 480B  $405.07
GLM 5.3 Flash  $380.36
GPT-5.2 Codex  $252.60
[illegible]

© BASETEN 2026. ALL RIGHTS RESERVED.

Interface text:
Usage
Tokens
Cache hit by model

### What is a router?

A router uses a rule of thumb to decide which model gets a prompt. Here, the green arrow picks GLM 5.3 Flash from five candidates. The hard part is judging how difficult a coding task will be before the agent starts work.

[3:46](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=226s) [A prompt enters a router connected to five candidate models. A green path highlights GLM 5.3 Flash as the selected model.](https://assets.ai.engineer/sites/aiecode2025/sha256/d3310a88f2bf94cd2b4424dcba8db1a16d3653aca88c8770df080a37f21a9842.webp)

What is a router?

PROMPT
ROUTER

MODELS
SOL 6.1
OPUS 5.5
KIMI K3.1 PRO
GLM 5.3 FLASH
DEEPSEEK V4.1 FLASH

© BASETEN 2026. ALL RIGHTS RESERVED.

### Start by routing between two models

[4:37](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=277s) [GLM 5.3 Flash and Opus 5.5 are compared by intelligence score and input, cached input and output token prices. Opus has the higher score and higher prices.](https://assets.ai.engineer/sites/aiecode2025/sha256/3a109a190647dd86cde9db28123ae870bdb14d5ad13631c376f26a21270a0970.webp)

### Formulating the problem

The router favors Opus when its predicted gain in success probability exceeds λ times the extra cost per task. A model that charges a tenth as much per token costs the same if it uses ten times as many tokens.

[5:08](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=308s) [The routing score equals predicted success probability minus lambda times predicted cost. Opus is favored when its higher predicted success justifies the additional cost.](https://assets.ai.engineer/sites/aiecode2025/sha256/bd806ab5d4fa4c97e0a6434519d1f5563c85f898c95d4fad63305e141ac460dc.webp)

Formulating the problem

Predicted success rate minus a penalty proportional to the predicted cost.

score(m, x) = p_success(m, x) − λ · cost(m, x)

This favors Opus when its higher predicted success justifies its additional cost.

© BASETEN 2026. ALL RIGHTS RESERVED.

### Building the training and test sets

Baseten ran each model repeatedly on public benchmarks to generate training traces for its router. Software engineering made up 92.7% of the training data. SWE-Rebench and MiMo-V2.6-RL code tasks alone accounted for 59.3% of the total.

[5:47](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=347s) [Horizontal bars break down the training data mix by benchmark. Software engineering accounts for 92.7%, questions for 2.9% and terminal use for 4.4%.](https://assets.ai.engineer/sites/aiecode2025/sha256/247778d96d8b608777fc4fbcdfc4309dfc6349764d93a98efffbcde8af499a67.webp)

Building the training and test sets

Training data mix

92.7% SOFTWARE ENGINEERING
SWE-REBENCH 35.3%
MIMO-V2.6-RL CODE TASKS 24.0%
SWE-GYM 17.1%
MULTI-SWE-RL 14.6%
SWE-REBENCH-V2 1.5%
FEATUREBENCH 0.2%

2.9% QUESTIONS
SWE-QA-PRO 1.9%
SWE-BENCH PRO ISSUE QA 1.0%

4.4% TERMINAL USE
TERMGRADE 3.4%
LITECODER-TERMINAL 1.0%

© BASETEN 2026. ALL RIGHTS RESERVED.

### Why start with coding benchmarks

Baseten ran each model repeatedly on the same coding tasks. That lets the team compare router costs and judge whether gains over a baseline exceed the noise from one run to the next. Strong results mark a step toward production.

[6:45](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=405s) [Coding benchmarks provide a controlled framework for comparing routers on shared tasks, assessing data quality and measuring progress toward production deployment.](https://assets.ai.engineer/sites/aiecode2025/sha256/418db80c7509969620a73d9da114f36f572dc1bb94fd7ffe88ef5d5f9e026e6c.webp)

Why start with coding benchmarks

Coding benchmarks provide a controlled and transparent framework.

SHARED TASKS
Compare different routers on shared tasks with clear success criteria and cost calculations.

DATA QUALITY
Being methodical about data quality, quantifying noise, and comparing against meaningful baselines.

PRODUCTION
Strong performance on coding benchmarks as an important milestone toward deploying in production.

© BASETEN 2026. ALL RIGHTS RESERVED.

### Controlling for noise

Baseten repeated tasks to separate router performance from two kinds of luck. With label noise, the same model can pass a task on one run and fail it on another. With selection noise, even a random router can look good if it happens to send GLM tasks it can solve.

[7:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=432s) [Two columns explain label noise from inconsistent outcomes across model runs and selection noise from random routing choices that succeed by chance.](https://assets.ai.engineer/sites/aiecode2025/sha256/ddffc2ed2e7d642c5b0ea1bca37b1aacfd0c96d3dc4f97ea69ebaf5cb1603830.webp)

Controlling for noise

LABEL NOISE
• The same model can pass the same task during one run and fail it during another.

SELECTION NOISE
• A random router can route tasks, by chance, to GLM where it succeeds, making it seem more effective than it actually is.

© BASETEN 2026. ALL RIGHTS RESERVED.

### Label noise

A model can pass a task on one run and fail it on the next. Averaging four Opus runs and eight GLM runs per task raised the pooled signal-to-noise ratio from 0.27 to 1.51 across three coding benchmarks, making router performance easier to measure.

[7:55](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=475s) [Benchmark table comparing signal-to-noise ratios across three coding benchmarks. Four Opus runs and eight GLM runs per task increase the pooled ratio from 0.27 to 1.51.](https://assets.ai.engineer/sites/aiecode2025/sha256/15c715585253fd67cf8abd3271b666154ede38f1155b9b53a92260a8ecff1359.webp)

Label noise

Test benchmark | τ² | σ²_O | σ²_G | SNR (k_O = k_G = 1) | SNR (k_O = 4, k_G = 8)
DeepSWE | 0.068 | 0.097 | 0.137 | 0.29 | 1.63
SWE Atlas QnA | 0.030 | 0.097 | 0.108 | 0.15 | 0.80
Terminal-Bench 2.1 | 0.063 | 0.040 | 0.097 | 0.46 | 2.77
Pooled | 0.054 | 0.082 | 0.116 | 0.27 | 1.51

Four Opus runs and eight GLM runs per task: pooled SNR 0.27 → 1.51.

© BASETEN 2026. ALL RIGHTS RESERVED.

### Selection noise

Router X cuts cost per task by 36% versus always using Opus and loses just 0.4 percentage points in pass rate. It beats the band covering 90% of random routers at comparable cost. Router Y saves 65% but lands inside that band.

[8:32](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=512s) [Scatterplot of pass rate against cost per task. Router X lies above the shaded band containing 90% of random routers, while Router Y lies inside it.](https://assets.ai.engineer/sites/aiecode2025/sha256/cb7474fa9f040a65a6810688096f2825a2e03becb280858f055b40156b85f55c.webp)

Selection noise

Beating random routing

PASS RATE (%)
Y-axis ticks: 63, 64, 65, 66, 67, 68, 69, 70, 71

ALWAYS OPUS 5.5 · 70.4% · $1.34
ROUTER X · ABOVE THE BAND
-0.4 PTS · 36% CHEAPER
ROUTER Y · INSIDE THE BAND
-3.5 PTS · 65% CHEAPER
ALWAYS GLM 5.3 FLASH · 64.5% · $0.18

Legend:
SINGLE MODEL
RANDOM ROUTING (MEAN)
90% OF RANDOM ROUTERS
INDIVIDUAL RANDOM ROUTER

COST PER TASK (USD)
X-axis ticks: $0.00, $0.25, $0.50, $0.75, $1.00, $1.25, $1.50

© BASETEN 2026. ALL RIGHTS RESERVED.

### Exploring embeddings

Predicting cost from task embeddings beat predicting success alone across most budgets. Weighing both gave the largest gain over random routing, nearly 2 percentage points in pass rate at about 57% of the cost of always using Opus 5.5.

[9:18](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=558s) [Line chart showing gains over random routing at different costs. Predicting both cost and success yields the largest peak gain, approximately two percentage points.](https://assets.ai.engineer/sites/aiecode2025/sha256/34ca8cbeef031ba5b326a1cbf1e14e8e28e6ff893ed2fb6703d870f73434a469.webp)

Exploring embeddings

Gain over random routing

GAIN OVER RANDOM (PTS)
Y-axis ticks: 0.0, 0.5, 1.0, 1.5, 2.0

PREDICTS COST ONLY
PREDICTS COST + SUCCESS
PREDICTS SUCCESS ONLY
90% OF RANDOM ROUTERS

COST PER TASK, % OF ALWAYS OPUS 5.5
X-axis ticks: 22%, 40%, 60%, 80%, 100%
Left endpoint: ALWAYS GLM 5.3 FLASH
Right endpoint: ALWAYS OPUS 5.5

© BASETEN 2026. ALL RIGHTS RESERVED.

### Looking beyond semantic similarity

A linear probe identified a task’s benchmark from its embedding with 89% balanced accuracy. That gave the router a shortcut, but benchmark identity only weakly tracked Opus’s advantage over GLM. Other candidate signals include task scope, required domain knowledge and ambiguity.

[10:09](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=609s) [A linear probe identifies benchmark identity from embeddings with 89% balanced accuracy. The slide discusses weak correlation with the Opus advantage and highlights task scope, domain knowledge and ambiguity.](https://assets.ai.engineer/sites/aiecode2025/sha256/3b3a0a94eb6cd68e505d1730d7362659dbe3e35fed17e74c13d55c4ca9d01fd3.webp)

Looking beyond semantic similarity

Benchmark identity was available as a routing shortcut.

89% BALANCED ACCURACY
We trained a linear probe to test whether benchmark identity was encoded in the embeddings.

WEAKLY CORRELATED
The observed advantage of Opus over GLM on those tasks was only weakly correlated.

STRUCTURED TASK ATTRIBUTES
A task’s scope, the domain knowledge it requires, and its level of ambiguity.

© BASETEN 2026. ALL RIGHTS RESERVED.

### Reading cost signals from model activations

Before GLM 5.3 Flash generates a response, Baseten can use its activations to estimate how many steps the agent will take. The signal strengthens in the middle layers, reaching Spearman correlations of 0.57 at layer 23 and 0.59 at layer 31.

[10:46](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=646s) [Line chart of Spearman correlation with GLM agent step count across model layers. Highlighted layers 23 and 31 have correlations of 0.57 and 0.59, respectively.](https://assets.ai.engineer/sites/aiecode2025/sha256/176aa8897ac18e498859c53231bfb1b60052e57d5d692d229a389abc222bd075.webp)

Reading cost signals from model activations

Intermediate layers predict agent step count

SPEARMAN CORRELATION WITH GLM AGENT STEPS
Y-axis ticks: 0.65, 0.60, 0.55, 0.50, 0.45, 0.40, 0.35, 0.30, 0.25, 0.20

GLM 5.3 FLASH LAYER
X-axis ticks: 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43

SELECTED LAYERS TO READ
(23, 31)
Layer 23: 0.57
Layer 31: 0.59

© BASETEN 2026. ALL RIGHTS RESERVED.

### Putting the experiments together

Baseten’s router combines task attributes and model activations with predictions of each model’s success and cost. Activations help gauge task difficulty. They predicted how many steps the agent would take with a Spearman correlation of about 0.6.

[11:27](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=687s) [The final router combines structured task attributes, internal model activations, and predictions of each model’s success and expected cost. Intermediate activations predict agent step counts with a Spearman correlation of approximately 0.6.](https://assets.ai.engineer/sites/aiecode2025/sha256/be14596611f531054e9958abf2d6ca8fd3dd16310a6a23cff5e15f334a8006d9.webp)

Putting the experiments together

Our final router combines the most useful signals from our experiments.

STRUCTURED TASK ATTRIBUTES
The scope, domain knowledge, and ambiguity of a task.

INTERNAL MODEL ACTIVATIONS
Intermediate activations predicted the number of agent steps with a Spearman correlation of approximately 0.6.

SUCCESS AND EXPECTED COST
Predict each model’s success and expected cost.

© BASETEN 2026. ALL RIGHTS RESERVED.

### Router cost and pass rate compared with Opus 5.5

On Baseten’s benchmark, its router cut the cost per task from $1.34 with Opus 5.5 to $0.38, saving 72%. The pass rate fell from 70.4% to 69.6%. Pushing savings to 84% widened the gap to 3.3 percentage points.

[11:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=702s) [Scatter plot comparing router pass rates and costs per task. The highlighted Baseten router costs $0.38 versus $1.34 for Opus 5.5, a 72% saving, with pass rates of 69.6% and 70.4% respectively.](https://assets.ai.engineer/sites/aiecode2025/sha256/b6ecb0413961c20089073adae8c5158aa63ea97a91eaf0ad4699288de82f7e54.webp)

COST PER TASK VS. OPUS 5.5
72% cheaper
$0.38 VS. $1.34

PASS RATE VS. OPUS 5.5
−0.8 pts
69.6% VS. 70.4%

PASS RATE (%)
Y-axis ticks: 60, 62, 64, 66, 68, 70, 72

COST PER TASK (USD)
X-axis ticks: $0.00, $0.25, $0.50, $0.75, $1.00, $1.25, $1.50, $1.75, $2.00

BASETEN ROUTER
72% CHEAPER · −0.8 PTS
80% CHEAPER · −2.6 PTS
84% CHEAPER · −3.3 PTS

ALWAYS OPUS 5.5
70.4% · $1.34

ALWAYS GLM 5.3 FLASH
87% CHEAPER · −5.9 PTS

90% OF RANDOM ROUTERS

OPENROUTER PARETO HIGH
APPLIED COMPUTE SHIFT-1
OPENROUTER AUTO HIGH
FIREROUTER LEVEL 4 HIGH
OPENROUTER AUTO MEDIUM
TOGETHER LINK AUTO HIGH
OPENROUTER AUTO LOW

© BASETEN 2026. ALL RIGHTS RESERVED.

### Comparing the routers fairly

[11:56](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=716s) [Two columns explain how training distributions, optimization objectives, benchmark choice, and differences in available model pools affect router comparisons. Each router is evaluated as offered.](https://assets.ai.engineer/sites/aiecode2025/sha256/ec500e8a831b9c2bd51a82820803fda526d77cc2353e1a40a7c7fb6a913a767e.webp)

### End-to-end latency

[12:36](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=756s) [Line chart showing increasing latency at one, four, and eight concurrent requests. Median latency rises from approximately 115 to 500 milliseconds, while 95th-percentile latency rises from approximately 200 to 675 milliseconds.](https://assets.ai.engineer/sites/aiecode2025/sha256/cf632ba53d8521500e8775e3d11a3f56835a3f00b6a87bc686d68d21ba577385.webp)

### Proving out performance in production

A router may get just “fix this” and a stack trace. What the engineer corrects or keeps in later turns hints at whether the choice worked. Even an easy follow-up may favor the pricier model if switching means losing a warm KV cache and reprocessing the conversation.

[13:15](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=795s) [Three challenges for production routing are less explicit requests, difficulty measuring success, and multi-turn tasks where switching models can require reprocessing conversation context and losing warm KV cache benefits.](https://assets.ai.engineer/sites/aiecode2025/sha256/b9355fbca5036e6d6277270fba398927aa7443abc816144fea0521e4555d9c32.webp)

Proving out performance in production

Routing in production introduces three new challenges.

REQUESTS ARE LESS EXPLICIT
An engineer might simply write “fix this” and paste a stack trace.

SUCCESS IS HARDER TO MEASURE
Deriving signals from the session, such as whether the user corrects the agent and whether the code is kept in subsequent turns.

TASKS ARE INHERENTLY MULTI-TURN
Switching models can mean reprocessing conversation context and forfeiting the benefits of a warm KV cache.

© BASETEN 2026. ALL RIGHTS RESERVED.

### KV-aware routing

Even a simple follow-up like centering a div may be worth sending back to the more expensive model if its KV cache already holds the conversation context. A session ID helps the inference provider recognize related requests.

[14:06](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=846s) [Bright green section title slide reading “KV-aware routing,” with a decorative dotted geometric pattern.](https://assets.ai.engineer/sites/aiecode2025/sha256/4b7262bfb7bedea7e603b3fe974fe3d3723cb32f3c50845dcf9154e61da99c53.webp)

KV-aware routing

© BASETEN 2026. ALL RIGHTS RESERVED.

### Subagent session affinity

Reuse one ID in the x-session-affinity header across a coding task and its subagents. This tells Baseten to expect a long match with a recently cached prompt prefix. Use a fresh ID for unrelated work. For subagents, Kiely says the choice depends on how much they compact the context.

[14:46](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=886s) [Python example highlights a session affinity header. The slide recommends sharing a stable identifier across a task and its subagents and using a different identifier for unrelated work.](https://assets.ai.engineer/sites/aiecode2025/sha256/d844bbe7a595d02b715f550aaa490a993a3cccc9260b3227016a0807a7b7a2be.webp)

Subagent session affinity

Keep the value stable for one conversation or agent task, including its subagents.

Use a different value for unrelated work.

import os
import uuid
from openai import OpenAI

client = OpenAI(
    base_url="https://inference.baseten.co/v1",
    api_key=os.environ["BASETEN_API_KEY"],
)
session_id = str(uuid.uuid4())

response = client.chat.completions.create(
    model="zai-org/GLM-5.3",
    messages=[{
        "role": "user",
        "content": "Add tests for parser.py",
    }],
    extra_headers={
        "x-session-affinity": session_id,
    },
)

© BASETEN 2026. ALL RIGHTS RESERVED.

Interface text:
AI Engineer
Code Summit
PRESENTED BY
Google DeepMind
AI Engineer
Code Summit
AI Engineer

### Compaction has an upfront cost

In this GLM-5.3-Flash example, shrinking the prefix from 1M tokens to 250K raises the next request’s cost from $0.0300 to $0.1375. The new prefix costs $0.0375 at the full input rate, even before the $0.10 compaction charge.

[15:40](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=940s) [Keeping one million cached tokens costs $0.0300 for the next request. Compacting to 250,000 tokens costs $0.1375, including $0.10 for compaction.](https://assets.ai.engineer/sites/aiecode2025/sha256/0f1bf22c9ecb3e7c2efedf6538a2a9ebc238eaecbb20741339f920274362253d.webp)

Compaction has an upfront cost

The next request: 1M cached tokens → 250K compacted tokens

KEEP CACHED PREFIX
$0.0300
1,000,000 tokens at the cached-input price

COMPACT
$0.1375
250,000 tokens at the input price
+ $0.10 to compact

GLM-5.3-Flash: $0.15 / 1M input tokens · $0.03 / 1M cached tokens

© BASETEN 2026. ALL RIGHTS RESERVED.

### But it pays off over multiple turns

After five requests, compaction still costs 11.7% more than keeping the original cached prefix. If the shorter prefix stays cached on every later request, compaction saves 2.8% by the sixth request and 53.3% by the twentieth.

[16:32](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=992s) [The table compares cumulative costs over 1, 5, 6 and 20 requests. Compaction saves 2.8% at six requests and 53.3% at twenty, assuming the compacted prefix stays cached.](https://assets.ai.engineer/sites/aiecode2025/sha256/de07b22e6ff5ecd171beac54a635ca732a305cb8a9acdec130f870ba527353c6.webp)

But it pays off over multiple turns

Total cost over future requests

Future requests | Keep cached prefix | Compact | Cost / savings
1 | $0.0300 | $0.1375 | +358.3%
5 | $0.1500 | $0.1675 | +11.7%
6 | $0.1800 | $0.1750 | −2.8%
20 | $0.6000 | $0.2800 | −53.3%

Assumes the compacted prefix stays cached on every later request.

© BASETEN 2026. ALL RIGHTS RESERVED.

## Full transcript

[0:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=12s) Hello, everyone. Um, my name's Philip. I work at Baseten. Uh, I work on inference, and recently that means I also work a lot on agents. I've been speaking at AI Engineer of various forms, one or another, since twenty twenty-four. Um, in the, in the-- In June, July, over the summer at the AI Engineer World's Fair, I, I gave a talk called What's New in Inference Engineering. Um, and it's just--

[0:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=42s) It's fun. This was four months ago, and when, when we look up there and, and we look at the, uh, you know, the, the topics that were, that were on the menu back then, it was like, all right, TurboQuant, like, we're not really doing that anymore. Uh, KV compaction. Okay, yeah, people do that. Uh, DFlash got replaced pretty much instantly by DSpark, um, because you need that, uh, extra Markov head to create a, a sort of meaningfully, meaningfully sequential chain so that you have a, uh,

[1:13](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=73s) a higher token acceptance rate. Um, anyway, so all of this stuff is, is moving extremely fast in the inference space. Very fun. Gives me, you know, always a new topic to talk about every time I come here. So today, we're going to talk about a few topics that are specifically relevant to coding agents. Um, the first thing we're gonna talk about is routing, um, which is not exactly an inference problem, but we've just built some really cool stuff here that I want to talk

[1:43](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=103s) about. Um, and it helps sort of set up the problem by making sure that we are already optimizing all of the other layers in the stack to, to make sure that we're not, you know, trying to save five percent here on inference where we could save fifty percent somewhere else. We'll talk a little bit about speculation. I'll, I'll give that update on, on DSpark. Um, we're gonna talk, uh, about KV cache management, um, just a little bit of stuff with subagent, uh, or s- uh, subagent session affinity. Um, and then we're going to look at request rout-- Uh, then

[2:13](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=133s) we're gonna look at, um, agents for inference. We're gonna look at optimizing kernels and why that isn't always enough to make your inference faster. Cool. So let's start with request routing. Before we spend time on optimization, before we go do all of this difficult inference engineering work, l-let's make sure that we're optimizing the right thing. Let's make sure that we're using the correct model, that we're using whatever the sort of like balance of, of cheapest, fastest, most

[2:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=162s) intelligent model for, for our specific task is. And, and the way we do that is, is by using a router. And there, there's a lot of models out there in the world. Uh, there's something like three million of them on Hugging Face these days, plus all of the frontier ones. And I think that routing becomes a little bit of an overwhelming topic when you think about, okay, we have this Pareto frontier with, with dozens of models and, and dozens of different use cases, and how am I supposed to build

[3:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=192s) a router that can most appropriately, you know, pick across all of this landscape? And, and, and the answer right now is that you kind of don't. Um, most coding agent routers have, like, two, sometimes three models. Uh, you know, you, you've got, you've got your frontier model, and you've got your Flash model. And, and, and maybe if you're feeling really fancy, you've got a model in the middle. We see this, you know, if you look at Claude Code and, and Codex, uh, you've got two or three models that you're picking from. We, we also see

[3:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=222s) this in, in many of the open source harnesses. So a router is going to, you know, take your input, decide based on some heuristic what model to send it to, and send, send it to that model. Um, I, I, I have a question for, for the folks in the room here. C-can anyone tell me about a time where you-- This sounds like an interview q- question. Tell me about a time when you, uh, but, but, but it's not. Tell, tell me about a time when you accurately estimated how

[4:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=252s) long a task would take in your own work. It's like, I'm going to sit down, and I'm gonna write this code, and it's gonna take me two hours, and it actually took two hours. Has that happened to anybody ever in the last year? Okay. Yeah, me neither. Hasn't happened to me either. It's actually, like, very, very difficult to estimate how difficult a task is going to be before you get started on it. And it turns out that it's also difficult for language models. So, so how do we do this? How do we, you know, let's say we're gonna start with routing between two

[4:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=282s) models. Let's say we've got, um, Opus, uh, five-five, which is, you know, very smart and, and pretty expensive, and we've got GLM five-three Flash, which is good at some things, um, and then going to be substantially cheaper and substantially faster. How do we decide just looking at, like, "Hey, build me this web page, build me this application, fix my kernels," which model is actually going to be up to the task? And, and basically, the, the, the routing decision that we wanna make is,

[5:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=312s) uh, you, you could model it as like, if GLM is smart equals true, route there because it's cheap and fast, else route to Opus. But if you wanna do it a little bit more mathematically, you wanna say, okay, we're, we're gonna make a score, um, and that's going to be the probability of success minus a penalty, which is the cost. Um, and that cost is not just expressed in a million tokens cost. It's actually going to be a task-based cost because if, if our model uses

[5:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=342s) ten times as many tokens, if the tokens are ten times cheaper, actual cost per task is the same. So how do we, you know, build some kind of mo- predictive model to, to figure this out? Um, to train the router, we, we need to generate a bunch of traces on coding tasks. And we, you know, you, you could theoretically, if you have your own custom dataset of a bunch of traces from your coding agent, you could train a router that's more applicable to what you're

[6:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=372s) working on. We, we w- ended up having to use, um, generalized public benchmark data. So we ran all of these benchmarks a bunch of times with each model. Uh, we did do some, some cleaning of these datasets, corrected some [unclear] errors, some broken task environments, added some safeguards against cheating, removed some tasks, uh, that were sort of [unclear] distribution. But overall, we were able to, you know, use these, these public benchmarks, and as you can see, more than ninety percent of the data, um, came from c-

[6:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=401s) software engineering-type benchmarks, uh, like SWE-bench. So, you know, why, why, why did we choose this dataset? Um, it's, it's mostly just about having a standard ground to work from. Um, if, if you have, you know, a, a production dataset, that's, that's fantastic. Um, but again, we wanted to have something that was fairly standardized that we could compare across models, um, and where-- that we could, you know, build in our own, uh, en-assurance

[7:11](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=431s) around, around data quality. So, you know, if you just run this sort of thing once, um, you're, you're gonna have a lot of noise in this. You're, it was also really noisy, um, and that can actually, like, materially impact the quality of your router. Um, so th-there's two different types of noise. The first is, is the label noise, like the idea that the model can pass a task doing one run and fail at doing another. Um, so that's kind of like the difference between pass@k and, and pass,

[7:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=462s) uh, k at k. Uh, and then selection noise. So the, the... If the, if we have a random router, um, it might by chance route to GLM and have it succeed, um, which, which could make the random router seem more effective than it actually is. So, you know, the, to, to control for this noise, to create a, a high signal-to-noise ratio so that we can precisely measure the router's performance, um, we wanted to run multiple times. So we ran, we ended up running each task four times through Opus and eight

[8:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=492s) times with GLM, um, which massively increased the signal-to-noise ratio versus just running once on each model. Um, so everything after this is, is based on an average over runs. Um, yes, it costs a lot more tokens, but, like, one thing that we got a lot of hanging around is tokens. Um, and it's worth it to have a much better signal-to-noise ratio. Cool. So let's look at a random router. Um, a random router is basically the request comes in, you flip a coin,

[8:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=521s) um, if it's heads, you send it to Opus, if it's tails, you send it to GLM. Uh, this, this might work if you're lucky. Um, you know, I, I think, I think that, that luck-based routing is, is perhaps an underexplored area. But no, in, in, in seriousness, like if we want to demonstrate that the router has actually learned a useful signal, it needs to, you know, beat these random routers in a statistically significant way. So, you know, we want to find signals in a task that predict the value of choosing

[9:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=552s) one model over another. Those signals can be around the, the difficulty of the task or the cost of, of, of the task. So maybe one thing to look at is some kind of semantic embedding, right? If we can embed the task instructions and fit separate heads to predict each model's probability of success and expected cost, um, you can take a model like Qwen3-Embedding or EmbeddingGemma as a starting point, um, to capture the semantic features of the task without training an entire model from scratch. And

[9:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=582s) so we, we wanted to look at three different setups. One where we would predict the success of the, um, predicting the success advantage alone, one where we would pre-predict the cost advantage alone, and one where we'd compare the two relative to one another. Um, it turns out that what you want to do, no surprise, is, is compare the two relative to one another. You want to have some kind of encoding of a cost predictor, some kind of encoding of a success predictor, and route based on that ratio. So, you know, beyond

[10:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=612s) similarity, um, you know, we, we wanted to, uh, see if the, uh, which, which of these features were actually responsible for driving the gains. So, like, task category actually emerged as a fairly legitimate routing category. Um, but you, but not every feature that you encode in these, in these embedding models, you know, these things are going to spit out vectors of, of hundreds or, or thousands of numbers. Not every single one of those is actually going to be

[10:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=642s) like a legitimate signal that you're going to want your router to, to move based on. So in parallel to this, another really interesting source of data was looking at the model's internal state for useful routing information. Obviously, we can't do this for Opus 5.5, but for GLM 5.3 Flash, if we run it on the task without generating a response and capture the intermediate activations, we can fit a prediction head on that to estimate the number of steps in the subsequent response. Um,

[11:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=672s) and this actually ended up being like a, a, a very strong signal, um, because if the model was, like, working very hard on a task, as expressed by that internal state, then that's a, a pretty good signal of the difficulty of said task. So when you put all of this together, um, you have your structured task attributes, your internal model activations, your success and expected cost predictions, um, all of these signals together can be combined to form a

[11:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=702s) Pareto optimal router. Um, so this is, this is where we ended up. Um, you know, it, it, it's always, it's always tough to, to put your, your thing on a graph and put a bunch of other people's thing on the graph and make that graph, like, actually plausible whatsoever. Um, so, so I do wanna say that, like this is, we're running on our benchmark. Um, other people's routers might be trained for a different benchmark or trained for a different purpose. Um, the, the real outcome to, to look at here is less that like this

[12:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=732s) particular router is the best router in the world, although it's quite good, and more to say like, okay, this is the process of creating a router between two models. And so for, for your application, for the, the models that you might care to route between, um, these are the kinds of signals that you're going to want to capture in order to train that router and the kind of methodology you would want to use to, to test its quality. The other thing, of course, is like the router will add a little bit of latency and cost. You want to make sure that the gains that you're getting from the

[12:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=762s) router outweigh that. Um, so we measure the end-to-end latency of our router, um, the, the actual routing model. Um, we're adding, you know, at most four hundred twenty-nine milliseconds on a, a P fif- fift- uh, P ninety-five basis. Um, so this is well worth it, um, for, you know, well worth it to be able to save, uh, substantially. Let's see it. In this one, it was, uh, seventy-two percent cheaper with a less than one point reduction in output quality.

[13:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=792s) Um, well worth a, a half-second penalty to get that outcome. So of course, in production, you know, you, you have different, uh, different data that you're looking at. Um, I know that my prompts are, are not quite as, as nice as the prompts that, uh, you know, maybe are in a coding benchmark. Uh, you know, I, I am, I'm a little nice in this. Sometimes I say, "Please fix this." Um, but that's not necessarily going to be a super strong signal. Um, and the other thing is that these tasks are inherently

[13:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=821s) multi-turn. So if you start off saying, "Hey, I need you to do this, like, very complex implementation," and then you say, "Also, you messed up. Please center the div afterwards," uh, you might not actually want to send that separate request to the cheaper model, even though it is a, a much easier request, just because you have the, the KV cache, um, and, and context preloaded into your more expensive model. So, uh, you know, speaking of that, we'll, we'll get to KV-aware routing here in a second. Um, but,

[14:11](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=851s) but generally, before we get into inference optimization of a given model, let's make sure that we're using the right model, um, is, is the general idea behind adding that routing layer on top of our, our inference engineering work for coding agents. Cool. So looking at prefix caching, um, the, the one thing I really wanted to point out around KV-aware routing for coding agents, um, is the, the subagent session affinity. So when we have

[14:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=882s) a, um, coding agent, um, we are sending requests iteratively, and in the, the client, um, and whether it's Chat Completions or, or any other client, there's going to be some kind of header where you can say like, "Hey, this is my session ID." Um, this is something that you're doing to help out us as the inference provider, basically. We really appreciate it when you do this. Please do this. Um, and it, it, it lets us know that like, hey, this is part of an ongoing coding session. We're going to expect that the,

[15:12](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=912s) um, we're going to expect that this, you know, turn of the conversation is going to have a very, very long prefix match with something that is already very recent in cache. Um, and the big question, um, is for a subagent, whether you should keep the same session ID or whether you should pop out a new one. Um, the-- That really comes down to the degree of compaction involved with the subagent. So if,

[15:42](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=942s) if we look at compaction, um, that's the process of taking your, your context of your coding agent and, like, squishing it down. Um, by the way, if anyone, this is just like a PSA, if anyone is, uh, you know, using some kind of deterministic process or letting the harness do the compaction, um, our, our research lead, Charlie, uh, was telling me the other week, like, "Please stop doing that. The models are really good at compaction now. Just let them do their own summarization work." It's actually part of the RL environment that they're trained in that they have to do that

[16:11](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=971s) themselves. Um, so yeah, the, uh, the compaction cost is going to be now just a prompt to the model, um, and we want to see if we're going to make up for that in the, um, in, in, in, in, in the operation of our multi-turn inference on that subagent based on the number of turns. So in this, in this like, you know, kind of arbitrary example, you get a, a very different weight depending on the exact models you're using and the

[16:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1001s) exact amount of compaction, the ratio of cost between cached input and standard input tokens. Um, but generally, what you're going to look at is, okay, do I expect that I'm going to do this many steps on my, on my compacted context? If so, it's going to be worth it. You're going to get a, a good payoff and over time actually save quite a bit of money, despite the fact that for one time you need to go, you know, recalculate these non-cached input tokens. Um, if you're not, if your subagent's only

[17:11](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1031s) doing like a single turn or a very short sequence, um, it's probably best to not compact, uh, keep your same affinity header, run that quick side prompt, and then loop back into, to the main, the main agent. Cool. Um, I am, in the interest of time, going to skip the domain-specific speculation part. Uh, basically, DSpark is good. Um, and, uh, if you're doing coding agents, make sure that you are, you know,

[17:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1061s) limiting the training data for your DSpark speculator. Um, and if you want to do code completion or code revision, um, you actually maybe don't even need a speculation model. You can do n-grams. Anyway, uh, the thing that I really wanna talk about in the remaining five minutes that we have together is agentic kernels in production. Um, this is, this is a lot, a lot more relevant and interesting. So okay, agentic kernels in production. This is what, like, I thought this

[18:11](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1091s) was when I first saw it and what I think a lot of people see is like, all right, my GEMM takes zero point zero three milliseconds. Then some AI happens, um, and then my GEMM takes zero point zero two milliseconds. Success. Uh, but my model isn't any faster. So, like, why does this happen? Why is optimizing the performance of an individual kernel using some kind of coding agent not actually all that useful for improving the end-to-end

[18:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1121s) performance of a language model? Well, it's, it's, it's a few different things. Um, the, the first is that, like, the best kernel configuration does depend a ton on the production workload. So if you change the batch size, if you change the, you know, nature of the traffic, um, if you change how full your batches are, there's a bunch of different things that can affect the performance of a given kernel in practice. Um, the second thing is that, like, the faster kernel benchmark doesn't necessarily translate

[19:11](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1151s) to a faster model. Uh, there's a lot of other overhead that we're going to talk about that in many cases is more important to optimize. Um, optimizing these kernels can, can miss these higher level opportunities, and then in-integrating this new kernel into your production serving engine is not trivial. Um, if you look at something like vLLM, SGLang, TensorRT-LLM, it's not as simple as just like, uh, you know, rip this one out, drop this one in, and it's, you know, going to have ripple effects over the rest of the engine. So when we

[19:41](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1181s) look at, you know, our stack for optimizing kernels with language models, with coding agents, um, it's really looking at both layers at the same time. We want to look at the model-level optimization where we're understanding the full workload profiling, where the time is spent, and propose changes that actually address the bottlenecks. And then, yes, on the kernel-level optimization, we are going to do that, but only once we've identified certain kernels as performance critical.

[20:08](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1208s) And then our framework also will have, like, some kind of self-improving mechanism. Um, you want your kernels to pass a correctness and end-to-end performance check, retain those as candidates, and then try again. See if you make a-another change to those kernels, get lessons from both the successful and the failed attempts to, you know, record that in your agent memory, build this sort of evolving knowledge base of what it looks like to generate, you know, a useful optimization versus something that, like, looks good in an isolated run but

[20:38](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1238s) doesn't actually improve end-to-end performance. So what actually does help? What are some of the techniques that address that overhead instead of just looking at the performance of an individual kernel? Big one, I think this is a very well-known one is, is kernel fusion. Um, if we can combine multiple kernels together to avoid a round trip to and from memory, especially on decode, we're going to save quite a bit of time, um, because we're going to have, number one, fewer launches, and number two, we're not going to

[21:08](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1268s) be bottlenecked on our VRAM bandwidth, reading weights from memory, um, s-reading, reading or storing values to memory. Um, so fused kernels, uh, can, can involve a-- can, can, can yield quite a substantial improvement in performance. Um, the, the second thing is the, uh, PDL, Programmatic Dependent Launch. So if you have kernel A and kernel B, usually kernel B can't start in the timeline until kernel A is fully finished and flush its results in memory. So it's kind of blocking kernel B from, from

[21:38](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1298s) scheduling. Um, and if we're able to, uh, make the overlap between these two kernels grid granular, the B's blocks can start, but the dependent part of B waits for [unclear] thread block of A to flush its results [unclear] global memory. Um, in o-in order to do this, um, a single consumer block can begin its dependent work as soon as the data it needs has landed rather than waiting on the whole grid, meaning that we're able to effectively, like, overlap these kernels slightly and get a, um, and, and eliminate that gap in performance.

[22:09](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1329s) The final thing is host loop minimization. So this is the CPU side control loop. Um, as with many things in inference, um, we're looking less at the performance of a single component and more about the system as a whole. Um, so, you know, with asynchronous launches, the CPU should run ahead of the GPU, and that leaves a backlog of pending work. Um, but if we're able to, you know, break this out, um, instead of scheduling hundreds of kernels one by one, uh, they can be grouped into minimal sets of graphs that reduces the number of

[22:38](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1358s) launch required, uh, which is going to reduce that host loop, um, bottleneck. So a-as an example, we ran this on some image generation models, um, Qwen-Image and FLUX two-- FLUX.2. The reason for image generation models is that, um, what-- LLMs generally have like very, very well optimized kernels as part of vLLM, SGLang, TensorRT-LLM. Um, image generation is a little bit more of the Wild West. You can usually find some, some bigger uplifts there, um,

[23:08](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1388s) and looked at some, um, fusion and some, um, other kernel optimization techniques here. What we found, um, is some, some pretty, pretty strong performance improvements, um, from this agentic framework. Um, and these optimizations were both proposed and implemented entirely by our agentic framework. So the end goal is that agents are making models better and faster, and models are making agents better and faster. In order for us to do this, we have to not

[23:38](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1418s) just point our models at small scale kernel optimization work, but give them insights into the end-to-end performance of the system, have them identify bottlenecks, and then actually go after those rather than, you know, just, just put it-- pointing it at a single factor like just the speculator, just the KV cache, just the router, just the kernels. You have to look at everything together. So thank you so much. Um, I am Philip Kiely on Twitter. If you wanna chat more about this, I will also be outside hanging out for a little

[24:08](https://www.youtube.com/watch?v=u-Gy1PQ4dYw&t=1448s) while. Uh, thank you all for your time, um, and have a great time at the rest of the conference.
