HotCarbon 2026

The Cost of Context: Profiling the Energy Footprint of Input Tokens in Large Language Models

Boris Ruf (Axa Research), Marcin Detyniecki (Axa)

This transcript was made by AI. The open source speech recognition model Whisper (large-v3-turbo) transcribed the recording with faster-whisper. Names and technical terms were checked against the paper, but it can still contain mistakes. The recording is the reference.

0:00 So our first speaker is Boris Ruf from AXA Research, and he'll be explaining how we should rethink the impact of the pre-fill phase on the energy of LLM serving. So Boris, please take it away. Thank you very much. And sorry, I cannot be on site. Can you probably hear me and see the slides? Yes. Yes. Excellent. Thank you so much. So, thanks for the kind introduction. This talk is, as you mentioned, about being, it's going to be about the cost of context. My name is Boris Ruf, and I'm working for AXA, an insurance company based in Paris, in hot Paris currently, I must say, so hot Paris connecting to HotCarbon. So why are we actually working on this? What's the motivation as an insurance company?

0:49 And here I can tell you, as an insurance company, we try to track our carbon footprint also when it comes to generative AI. So we do this for all sorts of devices and activities, business travel, and so on. But now, since generative AI is a big topic, we also try to do it for that one. And that's a tricky one because the cloud providers do not share, at least for proprietary Frontier AI models. So we are left with estimations. And these estimations, if you've ever looked into this, usually work as follows. So they use only the output tokens as an indicator for how much electricity was generated. They completely ignore the input tokens. There is reason for that. But when we look into our use cases, we use a lot of RAG, so retrieval augmented generation.

1:45 We have long contexts because we do coding. And when we look at the distribution of our token consumption and compare input tokens to output tokens, we see that we almost have 80% input tokens, which, if we apply this methodology of estimating the carbon footprint, gets completely omitted. So the question, really the practical question is, is it correct to completely ignore these input tokens or should we account for them at least at a discounted rate? And that's what this work is about. And then when you look in the literature, what you see basically is kind of contradicting. So on the one hand, you see these telemetry reports, which report GPU power spikes of up to three times, which means that actually during this pre-fill phase, you can expect there to be higher energy consumption.

2:41 Yet on the other hand, you can read some usage studies that find that even like processing very long contexts of 50,000 tokens and more hardly consumes any electricity or as the same as compared to a very small prompt. So we frame this as the pre-fill paradox, the sharp power spikes on the one hand, and then the modest total energy growth. That's what we want to investigate here. So a little bit of background for those people who are maybe less familiar with that. So basically, when you use an autoregressive LLM, basically you have these two phases, the pre-fill phase, that's where you have the input tokens. All these tokens are processed in parallel in order to build up the key value cache via this famous self-attention mechanism.

3:35 So this part is completely compute bound. This is like fully saturating the GPU. And the complexity of this process is actually O(n²) because you have this pairwise comparison of the tokens. Now, on the other hand, when the output is produced by the LLM, you have basically, they are sequentially produced. So one after the other accessing the full key value cache. So this part is memory bound as opposed to the compute bound or the pre-fill phase. Because this one is mainly about loading all those weights from the VRAM into the GPU. So here, the complexity is actually sequential O(1). So on the one hand, we observed these high instantaneous power spikes during the pre-fill, but for a very short duration. And on the other hand, when actually producing the output, we have lower power, but through all the steps, for all the decoding steps.

4:40 And this led us to the following research questions. So basically, the first one we wanted to investigate was, basically, at what context length does this O(n²) complexity overcome the GPU parallelization? And where does this threshold actually sit across engines? Because there's different ways of doing inference, so how does this behave amongst different engines? The second question is about, how does actually memory orchestration strategies, so either paged attention, which is an optimized approach, or the baseline or the standard way of scaled dot product attention, SDPA, how does this compare, and how do the thresholds shift here in terms of location and stability? And the third question is, how does the energy intensity gap, so between input and output tokens, how does this evolve as the context grows?

5:47 So is there a moment when you have a super long context, and then suddenly the energy per token is growing by a lot? So before we look into the experiments, we did just some intuition of what we expect here, and some intuitions. So the first, what we expect is that in the beginning, you have this fixed startup cost, because that's when all the weights get loaded into the GPU. So once you have a longer context, this gets amortized, so you have this high parallelization effect you get, and this means that the energy per token falls in the beginning. But then at some point, you actually hit this, what we call the compute saturation cliff. So this is when this optimization capacity of the GPU, this parallelization capacity, exceeds and can no more hide the n-square cost of the actual algorithm.

6:56 And also at this point, we expect to hit memory bandwidth wall. So this is when actually the communication cost, the networking, the VRAM to compute data movement becomes more and more costly. So what kind of experiments did we do? So we used the NVIDIA management library, which is kind of standard for such experiments, which means that it can measure electricity consumption of the GPU at a very high resolution. So in this case, at one millisecond sampling. And then we have timestamps aligned, so we have the timestamps aligned to the pre-fill start and end phases. We used synthetic data for this. So we created context sweeps from 256 to 131,072 tokens. And basically all the process was using a deterministic workload. So we had these fixed inputs exactly fixed to this logarithmic tokens.

8:14 We did greedy decoding, which means there was no reasoning. It was all straightforward processing. There was no batching. And doing so, we kind of, we managed to isolate the effect of the context length itself on the energy consumption. What we also did in order, because you cannot basically stop measuring the electricity consumption, measuring the electricity right after the pre-fill phase and then only look at the output phase or the other way around. So we fixed the output to one token in this experiment, which is also common sense. And I think it was introduced by a paper called TokenPowerBench as a way of only measuring the input phase. We used, we tried two different open source models. Llama 3.1 with 8 billion parameters. And Qwen 2 with 7 parameters, with 7 million parameters, 7 billion parameters, sorry.

9:19 And then we tried with two different engines. So one was the baseline, the Hugging Face baseline, using the straightforward scaled dot product attention approach. And we used an optimized engine, the vLLM paged attention. We ran the experiments on an NVIDIA A100, reduced precision at BFLOAT 16. And we measured the energy as a millijoule per token. So for the results, what you see here, first of all, for the energy intensity. So you see the Y axis, the energy intensity, the millijoule per token. And on the bottom, you see the length of the context we tried. So it's the average energy intensity per token. It's not for the full prompt. And you see the red line is basically is the Hugging Face baseline, the non-optimized one.

10:16 And the blue one is using the paged attention optimized one. And here you can already see that it makes a big, big difference what kind of engine you use. So for Llama, you can observe energy efficiency gains of 7.6. And for Qwen, you see efficiency gains for 8.9. And obviously, you also see that the paged attention algorithm helps delay the N square cost for much longer context, because you see that the slope of the curve starts to grow much later than for the non-optimized one. Now, when we compare input to output tokens, and that's what we were interested in for also our estimates, here you see the darker colors on the top, that's the output tokens. The paler colors are the input tokens. Again, you see there is the optimized ones and the not optimized ones.

11:24 And also you can observe again that at a later point, so for both for input and output tokens, you see that the curve is actually, the slope of the curve is going up. So it means that the longer the output tokens, at some point there is this effect that it becomes more expensive for each single token to get generated. So basically, we see that depending on the engine choice, this heavily already dominates the energy cost. We can see like, if we look at the 1000 tokens in the very beginning here, we can see that there's a factor of 850 between input and output tokens. So it's actually true that output tokens are much more energy intense. And then for longer context, this narrows down to 750.

12:20 But if we go for a non-optimized one, the Hugging Face, the factor falls actually down to 220, which is a bad thing here because it simply means that the input tokens become so much more expensive. In this last slide about the results, I want to show you this, what we call the compute saturation cliff. So this is basically the moment when the GPU can no more make up for this O(n²) computation cost. And this is where the slopes of the curve go up. So here, the Y axis on the left hand side, you see two different scenarios in one image here. So on the left hand side, the Y axis is the power consumption of the GPU. So you see that this one is actually plateaus around 16,000 tokens, which is the ceiling of an A100 GPU.

13:18 And then on the right hand side, what you see is not the energy per token, it's the latency. So basically, you see that beyond this point, the energy growth is driven by the latency. So the compute is maxed out. That's what we also call the memory bandwidth wall. And then simply the output tokens get produced at a lower rate. And then again, if we compare the two, we see that the optimized one can actually keep down this increase much longer than the non-optimized Hugging Face one. So what does it mean for the pre-fill paradox we looked into? It's actually not a contradiction in the data. It's an orchestration challenge. So these high power peaks in the beginning is somehow a race to finish because the GPU works at full capacity to finish fast.

14:12 And those optimized engines managed to mask those n square growth across a long phase compared to the other one. So as a conclusion, the GPU power saturates in our case by 16,000 tokens. And for unoptimized baselines, then start to pay these N square tax. And the other ones actually, the optimized ones using paged attention and flash attention can extend this phase. And then they can have longer context without paying this tax and only pay for that later at around 32K tokens. We observe up to 8.9, a factor of 8.9 of energy efficiency advantage for optimized serving. And overall, we show and we observe that the engine choice actually reshapes the input-output energy disparity, shifting the focus from model constraints to infrastructure. Thank you very much.

15:31 Thanks, Boris. Your talk has stirred up quite a storm here. I think we have time for a couple of questions before we move on from the audience. While people think, maybe I'll start with one. I noticed you explored with two models on the smaller side of things compared to what we see from frontier models today. Any effect that you think or expect to see when the size of the model scales? Yeah, that's a very good question. I mean, the reason we went with those 7 billion and 8 billion models was simply due to the compute we have at hand. It would be interesting to investigate this and see if the same kind of behavior can be observed for larger models or if there is some, basically some other optimization effects kicking in.

16:29 Yeah, it would be interesting to see. I also, I mean, these models, they were not reasoning models. There was no, like, they were really straightforward just producing the output. But this was intended just for the, to isolate basically this one effect we wanted to observe. Thanks. Any questions? Yeah, one question in the back. Answering your question, I think like the frontier models are more like post-trained to do like thinking and that could like basically drive more context. And yeah, so I think maybe that what might happen. Real use case scenarios, I guess like that in your, on your local setup, you would probably not use like 7 billion parameters. Like what are like, for your like, because we work with, I guess, person related data, right?

17:34 So what kind of actual models could you run locally or are like frontier models from other companies use in your AI pipelines? Like what is like a realistic setup you would use locally in your world, you would use in general for your work? So this really depends on the, on the use case. So we have an internal system, which is something like a chat GPT just, just running on a dedicated Microsoft Azure instance. But we use, we use the default, we use the frontier models through APIs. But this is not intended for, for any like personal or client related data, obviously. But since we use it in, in many, in many use cases, and we have a lot of employees, this is starting to become like, they're starting to have an impact on the, on the carbon footprint.

18:28 And in general, we have like very ambitious carbon reduction, um, plans or objectives. So it would, would be really bad to kind of, um, ignore now the, the, the generative AI carbon footprint. So this is, this is why we, we use estimates for those large models. And you know, probably know, like the, usually the way this works is you take an open model, you extrapolate from the open model based on any kind of information you have for the, for the closed model. And then that's the, the data you use. Okay. One more question. Yes. Uh, so in the experiments, you're doing single batch inference. If you, in, in a lot of production settings, you're going to be doing a lot more parallel computation in that.

19:14 Do you have an intuition for how that would push your instantaneous like power consumption for prefill to decode relatively? Yes. So I, I suppose that this would probably bring down, um, the energy consumption, um, because other, um, experiments showed that when you consider, uh, batching, which as you say, is like the, the standard in, uh, in a production environment. Um, so this would, this would probably bring down the, the, the numbers. We, as I said before, in, we did this on purpose to isolate it, no batching, simply because we wanted to, to, to have an isolated view on this effect. Um, but it could also, uh, be interesting also to, to investigate this. Yes. All right. Thanks, Boris. Thanks so much. Thanks so much.