Skip to lesson

NVIDIANVIDIA-Certified Professional: Agentic AI2026-107.4 Leverage NVIDIA TensorRT-LLM and Triton Inference Server for latency reduction.

Balance prefill work against active decoding

Completed by the knowledge check

Learning objective

Explain in-flight batching, paged KV cache, and chunked context, and configure them for latency.

Core idea

A request waiting to process a long prompt competes with requests already generating answers. TensorRT LLM coordinates that competition through iteration-level scheduling, a bounded token budget, and a pool of key-value (KV) cache blocks. Chunked context, also called chunked prefill, lets the scheduler process part of a prompt alongside ongoing generation.

These mechanisms solve different problems. In-flight batching keeps execution useful as requests arrive and finish. Paged KV cache assigns memory as sequences need it. Chunked prefill divides prompt work across iterations. Their combination can improve latency under mixed traffic, but a larger batch or cache allocation does not guarantee a better tail. See 4.3.1 for metric definitions and 7.4.1 for the Triton wrapper that exposes this runtime.

How it works

Admit work at each iteration

In-flight batching is also called continuous or iteration-level batching. TensorRT LLM can process sequences in the context phase together with sequences in the generation phase. Requests do not all need to reach their final output token before the runtime can schedule other work.

Three runtime limits answer different questions. max_batch_size bounds the requests scheduled together. max_num_tokens bounds the packed tokens processed in a batch. max_seq_len bounds one sequence. A large value for one does not remove the others. NVIDIA’s scheduler walkthrough prioritizes generation-phase requests first, each consuming one token of the iteration’s max_num_tokens budget in its illustrated single-token decode path. Prompt work then uses the remaining budget, so request count alone conceals a mixed batch’s cost.

In the LLM API/PyTorch path, these are top-level LLM() arguments and therefore top-level keys in model.yaml. They are separate from triton_config.max_batch_size, which the shipped Triton wrapper sets to zero. Keep that setting’s wrapper support boundary from 7.4.1; do not try to enable runtime in-flight batching by editing a Triton dynamic-batching policy.

Increasing max_num_tokens can improve GPU utilization by making larger matrix operations possible. It also affects workspace allocation: an excessively large token budget takes memory away from the KV cache needed by concurrent sequences. NVIDIA documents that excessive values can harm first-token and end-to-end latency after utilization saturates. Choose an operating point from the workload’s latency measurements rather than interpreting the maximum supported value as a recommendation.

Allocate KV state in pages

The KV cache retains attention keys and values computed for preceding tokens, avoiding repeated computation during generation. A paged cache divides that state into blocks assigned to requests as needed. It avoids reserving each request’s full possible sequence length in one monolithic allocation.

kv_cache_config.free_gpu_memory_fraction controls the fraction of free GPU memory allocated to the cache. The documented default is 0.9; it is a fraction of free memory, not 90% of the GPU’s entire installed memory. If you also set kv_cache_config.max_tokens, the runtime uses the smaller allocation implied by the two limits. This max_tokens is cache capacity, distinct from max_num_tokens for one execution batch and from a request’s output ceiling.

A cache allocation that crowds out other runtime needs is not useful capacity. For multiple runtime instances sharing a GPU, NVIDIA’s Triton LLM API guide explicitly recommends reducing kv_cache_config.free_gpu_memory_fraction so their allocations fit together. Start with a measured allocation for the intended deployment, then test the longest allowed sequences under concurrency. A single short request cannot demonstrate adequate KV capacity.

Paging and prefix reuse are separate mechanisms. Paging assigns blocks; kv_cache_config.enable_block_reuse controls reuse across requests and is enabled by default in the KV-cache documentation. Reuse finds matching token prefixes and can save their computation. Unrelated prompts still need their own state, and reusable blocks can be evicted. Budget for a cold or low-reuse traffic mix rather than assuming every request receives a cache hit. Observe kv_cache_hit_rate using the request-level performance metrics described in 7.4.1. KV-aware routing between workers belongs to 4.4.2.

Divide prefill instead of truncating it

NVIDIA recommends always enabling chunked context: it prevents large prompts from being excluded by the remaining iteration budget, mitigates queuing and worst-case first-token latency, and permits smaller batch token budgets that leave more memory for KV cache. Set enable_chunked_prefill: true deliberately: the LLM API reference lists its default as False. Chunking processes a prompt in portions while preserving the prompt’s contents. It does not summarize, discard, or shorten the allowed context.

Without chunking, a prompt larger than the token budget remaining in an iteration can wait even when some budget is unused. Splitting it lets a portion fit with decoding requests. NVIDIA’s scheduler explanation shows how this can reduce queuing and worst-case time to first token, while allowing a smaller max_num_tokens than the longest supported prompt.

Within one iteration, decoding requests take their tokens first, and a prompt larger than the remaining budget can wait unless chunked context lets a portion fit.

Decoding takes its tokens first, and a prompt larger than the remaining budget can wait unless chunked context lets a portion fitStarts at the iteration's max_num_tokens budget. Generation-phase requests go first, one token each. A prompt that fits the remaining budget uses it. A larger prompt can wait without chunked context; with it, a portion fits with decoding requests and the prompt work continues across iterations.one token eachnoyesnoyesacross iterationsIteration'smax_num_tokensbudgetGeneration-phaserequests firstPrompt larger thanthe budgetremaining?Prompt work usesthe remainingbudgetChunked contextenabled?Can wait evenwhen budget isunusedA portion fits withdecoding requests

The recommendation does not replace workload validation. NVIDIA describes minimal worst-case performance impact and potential significant benefits. Keep chunking enabled while testing both traffic classes and choosing their token and cache budgets. The documented paged-attention execution mechanism requires non-final context chunks to be multiples of the cache block size; the runtime manages that execution constraint.

Key distinctions and trade-offs

Choose the mechanism by the pressure you observe:

MechanismDeciding conditionConfiguration or identifierCost or limit
In-flight batchingDifferent requests finish and arrive at different timesRuntime max_batch_size, max_num_tokensMore simultaneous work can raise per-request latency
Paged KV cacheConcurrent sequences need growing attention statekv_cache_config.free_gpu_memory_fraction, max_tokensCache capacity consumes memory available to other work
Prefix reuseRequests share identical token prefixesenable_block_reuseBenefit depends on matching prefixes and eviction
Chunked contextLong prefill delays other schedulable workenable_chunked_prefillNon-final chunks must align to the cache block size

Do not reduce max_seq_len to imitate chunking: that changes the accepted sequence budget. An oversized execution token budget consumes workspace that could otherwise support KV cache. These are coupled allocations with different purposes.

Architecture / decision scenario

A manufacturing analytics assistant shares an inference deployment between engineers asking short equipment questions and research jobs supplying long maintenance histories. Its project workload has 80% 600-token prompts and 20% 12,000-token prompts, with up to 32 active requests. Short requests require p95 first-token latency below 800 ms and p95 inter-token latency below 60 ms. The inference team owns these requirements and the serving configuration.

The team enables enable_chunked_prefill: true as its baseline and tests runtime max_batch_size: 32. The tempting proposal raises max_num_tokens above its 8192 default to at least 12,000 plus active decode tokens, enough to process a long prompt in one iteration. That workspace budget takes memory from the KV cache needed by 32 sequences. The team compares it with a trial max_num_tokens: 4096. These values are experiment settings, not guaranteed capacity. It selects a supported max_seq_len that covers each prompt plus its permitted output and tests the chosen checkpoint on its actual hardware.

For this experiment, the team also compares cache fractions of 0.7 and 0.9 under the same request mix, recording peak memory, latency, and kv_cache_hit_rate (see 7.4.1) with prefix reuse enabled and with reuse disabled. If the larger execution budget lowers long-prompt first-token time but pushes short-request inter-token latency from 45 ms to 90 ms, it fails the interactive requirement. A chunked candidate that remains below both interactive thresholds earns further testing only if it also fits the cache allocation under long sequences. This decision exercises scheduling, prompt partitioning, and memory capacity together.

Common exam traps

  • Equating request count, per-iteration tokens, sequence length, and cache token capacity.
  • Reading free_gpu_memory_fraction as a fraction of total installed GPU memory.
  • Treating paging as a promise of prefix reuse for unrelated prompts.
  • Assuming chunked context removes prompt tokens or is enabled by default because NVIDIA recommends it.
  • Raising the batch token budget without checking decode latency and workspace allocation.

What to remember

Use in-flight batching to interleave requests, paged KV cache to allocate attention state, and chunked prefill to share execution time with long prompts. Tune request, token, sequence, and cache limits together against the latency targets of each traffic class.

Knowledge check

References