Skip to lesson

NVIDIANVIDIA-Certified Professional: Agentic AI2026-103.4 Tune model parameters (e.g., accuracy, latency-efficiency trade-offs).

Tune temperature, top-p, and output ceilings

Completed by the knowledge check

Learning objective

Tune sampling parameters (temperature, top-p, max tokens) for reliability.

Core idea

Generation controls change which answers a model produces and how much output it can generate. They do not establish that an answer is correct. A model that consistently chooses the wrong tool is consistently wrong; a short response that omits a required field is incomplete even when it arrives quickly.

Treat tuning as a controlled comparison of task success, variation, and completion. Hold the model, prompt, task cases, and execution conditions fixed while you change a control. See 3.1.4 for preserving evaluation runs and 3.4.3 for automating the search. Here the decision is which control addresses the observed failure.

How it works

Separate distribution shape from output length

In the OpenAI-compatible request vocabulary, temperature controls sampling randomness: lower values concentrate choices, while higher values permit more variation. top_p performs nucleus sampling, retaining candidates whose cumulative probability reaches the selected mass. A value of 0.1 refers to 10% probability mass, not 10% of the vocabulary. OpenAI recommends changing temperature or nucleus sampling rather than both at once.

That recommendation is a useful first diagnostic experiment. If both controls change together and tool-selection quality falls, you cannot tell which change mattered. Once individual effects are understood, a deliberately bounded joint search can explore interactions; it is a different experiment with more combinations, not an excuse to leave settings unexplained.

max_tokens limits generated output. It is a ceiling, not an instruction to produce exactly that many tokens, and it is not a time limit. NIM documents POST /v1/chat/completions with model, messages, and max_tokens. Use the interface your endpoint documents instead of copying parameter compatibility assumptions from another provider.

In NeMo Agent Toolkit, the NIM LLM configuration lives under llms.<name> with _type: nim. The optimizer documentation explicitly exposes temperature, top_p, and max_tokens as optimizable NIM fields. This is where a workflow-level experiment changes these values; the deployed NIM endpoint remains the inference boundary.

Measure usable completion, not successful transport

Inspect why generation stopped. In the Chat Completions response vocabulary, finish_reason: "length" indicates exhaustion of the requested token limit. stop means a natural stop or supplied stop sequence; it does not certify factual correctness. tool_calls indicates a tool request, which is a different completion outcome from a final answer.

Count a response as successful only after the task’s checks pass. For structured answers, that includes the schema and required business fields; see 2.1.2. For tool selection, compare the chosen action and arguments with the expected action; see 2.6.1. Sampling controls complement those checks rather than replace them. Whatever the termination reason, a response counts as successful only after the task’s checks pass.

Whatever the termination reason, a response counts as successful only after the task's checks passStarts by inspecting why generation stopped and branches three ways. length ends at exhaustion of the requested token limit. stop means a natural stop or supplied stop sequence, and tool_calls a tool request compared with the expected action; both reach success only through the task's checks.lengthstoptool_callscompare with the expectedactionInspect whygeneration stoppedExhaustion of therequested tokenlimitNatural stop orsupplied stopsequenceTool requestTask's checkspassCount as successful

A low output ceiling can make latency and token totals look attractive by cutting off difficult cases. Keep an explicit incomplete-output count beside accuracy. Otherwise the comparison rewards a candidate that stops working before it finishes. Inspect response fields and task results together, because a syntactically complete answer can still omit a required conclusion.

Reasoning models make this distinction especially consequential. NVIDIA’s GLM-5.2 NIM documentation says to inspect choices[0].message.reasoning_content separately from choices[0].message.content. If generation reaches finish_reason: "length" before answering, increase max_tokens or disable thinking for that request. See 3.4.2 for choosing reasoning behavior; here the relevant failure is an output limit that starves the final answer.

Bound the experiment to the task

Start from the selected model’s documented settings and a successful baseline. The toolkit’s nim provider defaults are temperature: 0.0, top_p: 1.0, and max_tokens: 300; its default search spaces are respectively low=0.1, high=0.8, step=0.2, low=0.5, high=1.0, step=0.1, and low=128, high=2176, step=512. A reasoning model can exhaust that 300-token output ceiling before answering, so check completion before adopting the provider default. Test a small temperature range while leaving top_p fixed, or vary nucleus sampling while temperature stays fixed. Then test output ceilings against the longest legitimate task cases, including requests that generate tool arguments or explanations.

Repeat each candidate on the same cases. NeMo Agent Toolkit’s optimizer provides reps_per_param_set for repeated evaluation. Repetitions expose variation that one favorable completion hides. An experiment record should retain the effective llms configuration, response termination reasons, task score, and latency for each run.

Do not select a setting solely because identical prompts produce similar prose. The reliability owner needs stable task outcomes: correct routing, valid arguments, required content, and bounded incomplete results. A consistent writing style is a separate objective. When the prompt lacks necessary information, lowering randomness cannot supply it; repair the context or task definition before treating sampling as the remedy.

Key distinctions and trade-offs

The controls address different failure modes:

ControlDeciding conditionMechanismCost or failure risk
TemperatureExcessive variation between otherwise equivalent task runstemperature changes sampling randomnessLower variation can preserve a systematic wrong choice
Nucleus samplingYou need to restrict the sampled probability masstop_p selects cumulative probability massAggressive restriction can remove useful alternatives
Output ceilingValid answers are truncated or generation spends too many tokensmax_tokens bounds generated outputToo small omits answers; too large permits more generation work

Temperature and top-p change selection behavior; the token ceiling changes how long generation may continue. None is an accuracy score. Judge the combination through complete task outcomes, with the same validator across candidates.

Architecture / decision scenario

In this illustrative comparison, a retail returns assistant must select a policy route and emit a complete explanation within a measured p95 of 2.5 seconds. The quality owner requires at least 97% correct routes on a 600-case benchmark and fewer than 1% incomplete answers.

The baseline uses temperature: 0.6, top_p: 1.0, and max_tokens: 512. It scores 96% routing accuracy with 0.5% incomplete responses and p95 at 2.4 seconds. Lowering temperature to 0.2 while retaining the other settings raises measured routing accuracy to 98%, with 0.4% incomplete responses and p95 at 2.3 seconds. A separate nucleus-sampling trial changes only top_p to 0.3 from the baseline: it scores 95%, with 0.5% incomplete responses and p95 at 2.2 seconds; restricting the candidate mass is not the better choice here.

A tempting speed proposal changes only max_tokens to 128 from the baseline. Its p95 reaches 1.7 seconds and routing accuracy remains 96%, but 8% of responses are incomplete. The team rejects it despite the faster headline result. The application owner selects the lower-temperature candidate with the 512-token ceiling, retains response checks, and asks for further model or prompt work if production traffic exceeds the latency target. Changing one control per trial lets the team attribute the gain to temperature rather than to truncation.

Common exam traps

  • Equating low temperature with factual accuracy or guaranteed repeatability.
  • Reading top_p: 0.1 as retaining 10% of vocabulary entries.
  • Treating max_tokens as an exact response length or elapsed-time deadline.
  • Reporting low latency after silently excluding incomplete responses.
  • Assuming a successful HTTP response or finish_reason: "stop" proves task success.

What to remember

Tune the control that matches the failure: variation, candidate restriction, or insufficient output space. Compare repeated, complete task outcomes with fixed validators. Keep truncation visible so a shorter failure cannot win an accuracy–latency comparison.

Knowledge check

References