What this video shows
About this walkthrough
An H100 can still spend its time repeating work. This demo runs Qwen3-8B with a custom decoding loop that discards the returned cache and reprocesses the growing prefix on every step. The demo captures a startup trace, triggers a short hardware profile when token throughput stays low, and compares the timelines before and after the fix, which keeps past_key_values and sends only the next token after prefill. Median output throughput goes from 12.45 to 47.49 tokens per second, and median request time from 20.56 to 5.39 seconds, over three warmed trials per version.
Read along
Transcript
Select a time to play the video from that chapter.
0:00Find the repeated work
Why can a small language-model decoder still feel slow on an H100? In this demo, we'll use GPUFlight to find repeated work, fix the decoding loop, and measure the improvement. We'll capture from the command line and use the Java agent to send the results to the dashboard. For this demo, we'll rent a temporary H100 on DigitalOcean to run our model. Let's create that cloud machine first.
0:30Create the temporary GPU
I create a temporary H100 GPU Droplet with the AI and machine learning image. This machine has 80 GB of GPU memory. SSH authentication is configured off camera. After saving the profiles, we'll remove the Droplet so it stops billing.
0:51Capture locally, upload with the Java agent
In GPUFlight Settings, API keys, we give the agent a temporary upload key. Its value stays out of the recording. I install the native CLI and the standalone Java agent from their official repositories. The exact revisions and setup scripts are included with this demo. The native trace command writes event logs locally. A separate Java agent service watches that directory and sends the events to GPUFlight. This is our preferred workflow for deployed performance monitoring. Embedded integration is useful when developing an application, but this demo uses the external command and agent.
1:37What this decoder does
I install pinned PyTorch and Transformers packages, then download a fixed revision of Qwen3-8B. The model runs in B float sixteen precision. Prefill reads the prompt. Decode then generates one new token at a time. A token is a piece of text, often part of a word. Keys and values are attention data calculated from earlier tokens. A K V cache keeps that data so later steps can reuse it. This small custom decoder deliberately contains a cache-reuse mistake. Standard Transformers generation normally manages this for you; custom loops are where integrations can go wrong.
2:22Start with a bounded trace
First, I run the application through the native trace command, with a ten-second window. The double dash separates profiler options from the Python command. The Java agent is already watching the output directory. This window begins with application startup and stops the target when the deadline is reached. It is not ten seconds of warmed inference. The recorded GPU activity starts later than the process itself, which explains the shorter duration in the dashboard.
2:57Inspect startup before judging throughput
Open the session, then Timeline. The blue host-to-device transfers appear before most of the GPU work. Selecting a transfer shows its size and duration. Here, one transfer moves ninety-six mebibytes. The session contains about fifteen point three gibibytes of host-to-device traffic, consistent with loading the model weights. Startup and steady decoding answer different questions. To investigate slow output tokens, we need a complete request after the model is ready.
3:33Measure completed output tokens
A complete baseline trace delivers about nine point one output tokens per second with this configuration. The application reports each completed token through a standard NVIDIA NVTX counter. NVTX lets us add names and measurements to application work. GPUFlight uses that counter as the token-rate metric. It does not infer generated tokens from kernel names. For this demonstration, I choose eleven tokens per second as the threshold. It is calibrated for this workload under tracing, not a general performance target.
4:14Trigger deep profiling on slow output
The condition says: if the delivered token rate stays below eleven for two seconds, collect one second of hardware performance samples. The ordinary trace continues around that window. I limit the rule to one capture for this demonstration. The before run triggers at nine tokens per second. The saved event confirms the threshold, the two-second condition, and the one-second capture. Keeping the window short also limits the extra profiling work.
4:48Use the evidence to locate the repeated work
In the timeline, inspect the named decode ranges. The input length grows beyond two thousand tokens, even though each step generates only one new token. Those input-length labels come from our application annotations. They connect the trace back to the code. The hardware-sampling tab shows launched warps during the triggered window. A warp is a group of thirty-two GPU threads. That confirms hardware activity in the selected interval. The cache mistake itself becomes clear when we inspect the loop.
5:25Fix the cache reuse
Here is the problem. The model returns a cache, but the loop discards it and passes the entire growing sequence again. Even though use cache is true, the next call never receives the cache from the previous call. The fix saves past key values, then supplies only the newly generated token on the next step. The full prompt is still processed once during prefill. Subsequent steps reuse the earlier attention state. We keep the model, precision, prompt, and output length unchanged.
6:00Verify the fixed run in the dashboard
Now run the fixed decoder with exactly the same profiling settings. After prefill, the annotated input length is one. Inspect the before and after timelines to see the changed pattern of GPU work. The traced request falls from about twenty-eight point four seconds to nineteen point two seconds. The fixed run never satisfies the below-eleven condition for two seconds, so no deep window opens. That is a verified rule outcome, not a missing upload.
6:35Measure speed without the profiler
Profiling changes timing, especially in a decoder with many small kernel launches. For the performance result, we run again without GPUFlight tracing. After full warmups, three alternating trials use the same 2,137 input tokens and generate 256 output tokens each. Median throughput rises from twelve point four five to forty-seven point four nine tokens per second. That is about three point eight times faster. Median request time falls from twenty point five six seconds to five point three nine seconds. These are measurements of this example, not a claim about every model or serving system.
7:23Check correctness and capture limits
We also check the outputs. Two of the three cached trials match every token from the baseline; one produces a different continuation. The same-prefix logit checks show numerical differences in these B float sixteen paths, so we do not claim bitwise-identical text. This recording uses the native CLI successfully on the specific driver and CUDA environment shown here. It is not a guarantee for every CUDA version. The reproducibility notes include the tested settings, the shorter sampling window, and the agent log-permission setup.
8:03Save the evidence and clean up
With the profiles and results saved, I revoke the temporary agent key and remove the GPU Droplet. The useful result is the full loop: measure slow output, capture the relevant work, find the repeated computation, fix the code, and measure again. Profile your programs running on the GPU, and learn performance engineering with GPUFlight Performance Lab. Thanks for watching.
Measure it yourself
Run the same experiment on a real GPU
Edit the kernel in your browser, run it on managed hardware, and read the profile the video walks through.
Run the KV cache lab