[
  {
    "startMs": 12900,
    "text": "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--"
  },
  {
    "startMs": 42860,
    "text": "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,"
  },
  {
    "startMs": 73020,
    "text": "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"
  },
  {
    "startMs": 103060,
    "text": "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"
  },
  {
    "startMs": 133100,
    "text": "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"
  },
  {
    "startMs": 162880,
    "text": "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"
  },
  {
    "startMs": 192880,
    "text": "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"
  },
  {
    "startMs": 222820,
    "text": "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"
  },
  {
    "startMs": 252560,
    "text": "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"
  },
  {
    "startMs": 282240,
    "text": "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,"
  },
  {
    "startMs": 312300,
    "text": "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"
  },
  {
    "startMs": 342240,
    "text": "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"
  },
  {
    "startMs": 372160,
    "text": "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-"
  },
  {
    "startMs": 401860,
    "text": "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"
  },
  {
    "startMs": 431820,
    "text": "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,"
  },
  {
    "startMs": 462040,
    "text": "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"
  },
  {
    "startMs": 492000,
    "text": "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,"
  },
  {
    "startMs": 521960,
    "text": "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"
  },
  {
    "startMs": 552020,
    "text": "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"
  },
  {
    "startMs": 582060,
    "text": "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"
  },
  {
    "startMs": 612060,
    "text": "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"
  },
  {
    "startMs": 642040,
    "text": "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,"
  },
  {
    "startMs": 672080,
    "text": "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"
  },
  {
    "startMs": 702140,
    "text": "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"
  },
  {
    "startMs": 732248,
    "text": "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"
  },
  {
    "startMs": 762088,
    "text": "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."
  },
  {
    "startMs": 792388,
    "text": "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"
  },
  {
    "startMs": 821868,
    "text": "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,"
  },
  {
    "startMs": 851968,
    "text": "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"
  },
  {
    "startMs": 882068,
    "text": "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,"
  },
  {
    "startMs": 912028,
    "text": "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,"
  },
  {
    "startMs": 942008,
    "text": "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"
  },
  {
    "startMs": 971688,
    "text": "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"
  },
  {
    "startMs": 1001528,
    "text": "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"
  },
  {
    "startMs": 1031468,
    "text": "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,"
  },
  {
    "startMs": 1061688,
    "text": "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"
  },
  {
    "startMs": 1091588,
    "text": "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"
  },
  {
    "startMs": 1121098,
    "text": "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"
  },
  {
    "startMs": 1151078,
    "text": "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"
  },
  {
    "startMs": 1181098,
    "text": "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."
  },
  {
    "startMs": 1208838,
    "text": "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"
  },
  {
    "startMs": 1238758,
    "text": "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"
  },
  {
    "startMs": 1268778,
    "text": "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"
  },
  {
    "startMs": 1298718,
    "text": "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."
  },
  {
    "startMs": 1329038,
    "text": "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"
  },
  {
    "startMs": 1358838,
    "text": "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,"
  },
  {
    "startMs": 1388918,
    "text": "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"
  },
  {
    "startMs": 1418978,
    "text": "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"
  },
  {
    "startMs": 1448838,
    "text": "while. Uh, thank you all for your time, um, and have a great time at the rest of the conference."
  }
]
