GLM-5.2 Temperature and Top P: Prevent Sampling Drift
Independent research — not an official Z.ai publication.Identity and provider disclosure
Original editorial visualization of sampling-mode drift. The branching route
represents multinomial sampling; the straight route represents greedy decoding.
The amber switch is do_sample, not a quality score.
Pin do_sample, temperature, and top_p together whenever you compare a
hosted GLM-5.2 request with direct Transformers inference. For the current
Z.AI documented baseline, the explicit sampled profile is true, 1.0, and
0.95. For an intentional greedy profile, set do_sample=false and keep the
two sampling controls neutral or omit them from the request.
This is not a cosmetic configuration preference. temperature and top_p
only shape token selection when sampling is active. If the mode silently
changes, two systems can display the same numeric settings while executing
different decoding algorithms. That invalidates a quality comparison before
the first answer is scored.
Our dated audit hashes eleven public artifacts and resolves fourteen local configuration fixtures. It makes zero authenticated API calls, zero tokenizer calls, and zero model calls. The evidence proves the documented and pinned configuration path—not output quality, provider implementation, or exact reproducibility.
Navigate the sampling controls
Section titled “Navigate the sampling controls”- Read the short verdict
- Compare the two omitted defaults
- Understand each control
- Choose a complete profile
- Review fourteen fixtures
- Copy the validator
- Build a hosted request
- Build a Transformers call
- Handle vLLM and gateways
- Design regression evidence
- Keep reasoning separate
- Select task profiles
- Roll out safely
- Review access
- Audit sources and limits
- Resolve common questions
The short verdict
Section titled “The short verdict”The current contracts resolve as follows:
| Route or artifact | do_sample when omitted |
temperature |
top_p |
Effective mode | Evidence |
|---|---|---|---|---|---|
| Z.AI hosted Chat Completion | true |
1.0 | 0.95 | sampled | Current API schema |
Pinned checkpoint generation_config.json |
absent | 1.0 | 0.95 | not determined by the file alone | Revision b4734de… |
| Transformers 5.12 with that omitted flag | None, treated as not true |
1.0 | 0.95 | greedy | Pinned mode-selection source |
| Explicit local evaluation profile | true |
1.0 | 0.95 | sampled | Caller-owned configuration |
| Explicit greedy profile | false |
1.0 | 1.0 | greedy | Caller-owned configuration |
The Z.AI Chat Completion reference
sets the hosted defaults and says temperature and top P do not take effect when
do_sample is false. The pinned
checkpoint generation config
stores 1.0 and 0.95 but has no do_sample key. In
Transformers 5.12 mode selection,
an absent flag loads as None, and any value that is not exactly true selects
greedy search for the single-beam case.
The values therefore agree while the omitted mode does not. Treat the triplet as one versioned profile rather than three unrelated optional fields.
Hosted and Transformers defaults diverge
Section titled “Hosted and Transformers defaults diverge”On the hosted route, omission is a real choice: it delegates to the provider’s
published true / 1.0 / 0.95 defaults. On direct Transformers inference, the
model file provides only the two numeric values. The library must still decide
whether it will sample, and the pinned source resolves a missing flag to greedy
mode.
The official
Transformers generation guide
states that multinomial sampling is enabled with do_sample=True and one beam.
The GLM-5.2
model README
reports several evaluation profiles using temperature 1 with top P either 0.95
or 1.0. Those numbers do not activate sampling by themselves.
This distinction affects three common workflows:
- A hosted-to-local quality check may compare sampled API answers with greedy local answers and attribute the difference to weights or quantization.
- A local upgrade may begin sampling after an engine or wrapper starts adding
do_sample=true, even though the visible numeric controls did not change. - A regression harness may log only temperature and top P, leaving no evidence of the algorithm that generated its baseline.
Resolve and log the mode before interpreting any output difference.
Three controls with two different jobs
Section titled “Three controls with two different jobs”do_sample selects the decoding family. When false, a single-beam generation
chooses the most likely next token at each step. When true, the system can draw
from a probability distribution after the sampling filters are applied.
temperature rescales logits before sampling. Lower values concentrate
probability on stronger candidates; higher values flatten the distribution.
Z.AI currently documents a GLM-5.2 range from 0 through 1, inclusive, with
a default of 1.0.
top_p applies nucleus sampling: it keeps the smallest candidate set whose
cumulative probability reaches the threshold. Z.AI documents 0.01 through
1, with a GLM-5.2 default of 0.95. The
core-parameter guide
recommends 0.8–0.95 when using top P for controlled diversity.
If an evaluation needs per-token alternatives or likelihood shifts, use the GLM-5.2 logprobs contract and record whether the runtime returned raw or processed scores. Sampling controls shape a distribution; they do not make its scores portable or calibrated.
The same guide recommends modifying only one of temperature and top P. A useful operational interpretation is to keep the unused control neutral:
- temperature experiment: set
top_p=1; - top-P experiment: set
temperature=1; - greedy experiment: set
do_sample=false; numeric sampling controls are inactive, so do not pretend they explain the output.
This single-active-knob policy is a reproducibility rule, not a claim that the API rejects two non-neutral values. The API can accept both; the problem is that their combined effect is harder to attribute.
Choose one complete sampling profile
Section titled “Choose one complete sampling profile”| Profile | do_sample |
temperature |
top_p |
Use it for | Main caveat |
|---|---|---|---|---|---|
| Hosted documented baseline | true | 1.0 | 0.95 | Reproducing the current Z.AI default explicitly | Still stochastic |
| Direct local equivalent | true | 1.0 | 0.95 | Matching the decoding controls used by the hosted baseline | Engine kernels can still differ |
| Greedy regression | false | 1.0 | 1.0 | Stable structural and tool-loop tests | Not proof of byte-identical output |
| Temperature-only trial | true | chosen 0–1 | 1.0 | Isolating temperature sensitivity | Temperature 0 behavior can be engine-specific |
| Top-P-only trial | true | 1.0 | chosen 0.01–1 | Isolating nucleus filtering | More than one run is needed |
| Published evaluation reproduction | true | copy the cited value | copy the cited value | Reproducing one named benchmark | Do not generalize it to every task |
The official GLM-5.2 model guide currently contains SDK examples with temperature 1.0 and one Python streaming example with 0.6. That is another reason to name the intended profile instead of treating any copied snippet as the universal model default.
What the fourteen fixtures prove
Section titled “What the fourteen fixtures prove”The audit resolves hosted defaults, pinned checkpoint values, caller overrides, ranges, and policy warnings without sending a generation request.
| Fixture | Route | Resolved mode | Result | Evidence value |
|---|---|---|---|---|
| Omitted hosted fields | Z.AI | sampled, 1.0 / 0.95 | pass | Published hosted baseline |
| Omitted checkpoint fields | Transformers | greedy, 1.0 / 0.95 ignored | IMPLICIT_GREEDY_MODE |
Reproduces the drift |
| Explicit local sampled profile | Transformers | sampled, 1.0 / 0.95 | pass | Restores control parity |
| Explicit hosted greedy | Z.AI | greedy | pass | Mode switch is explicit |
| Explicit local greedy neutral | Transformers | greedy, 1.0 / 1.0 | pass | No active sampling knob |
| Temperature-only | hosted policy | sampled, 0.6 / 1.0 | pass | One active control |
| Top-P-only | hosted policy | sampled, 1.0 / 0.85 | pass | One active control |
| Both non-neutral | hosted policy | sampled, 0.6 / 0.85 | warning | Attribution is ambiguous |
| Greedy with overrides | hosted policy | greedy | warning | Both overrides are ignored |
| Temperature −0.01 | hosted policy | sampled | reject | Below documented range |
| Temperature 1.01 | hosted policy | sampled | reject | Above documented range |
| Top P 0 | hosted policy | sampled | reject | Below documented range |
| Top P 1.01 | hosted policy | sampled | reject | Above documented range |
String "true" |
hosted policy | invalid | reject | Boolean type is required |
The positive controls show that the validator accepts explicit sampled, greedy, temperature-only, and top-P-only profiles. The negative controls isolate four different mistakes instead of treating every unusual output as “randomness.”
Download the byte-identical machine-readable receipt to inspect every source hash, resolved profile, warning, and invariant.
Validate the profile before network or GPU work
Section titled “Validate the profile before network or GPU work”Use a fail-closed request gate. This compact version checks the documented ranges and the single-active-knob policy:
export function validateSamplingProfile(profile) { const errors = []; const warnings = []; const { do_sample, temperature, top_p } = profile;
if (typeof do_sample !== "boolean") errors.push("INVALID_DO_SAMPLE"); if (!Number.isFinite(temperature) || temperature < 0 || temperature > 1) { errors.push("TEMPERATURE_OUT_OF_RANGE"); } if (!Number.isFinite(top_p) || top_p < 0.01 || top_p > 1) { errors.push("TOP_P_OUT_OF_RANGE"); }
if (do_sample === false) { if (temperature !== 1) warnings.push("TEMPERATURE_IGNORED"); if (top_p !== 1) warnings.push("TOP_P_IGNORED"); } else if (temperature !== 1 && top_p !== 1) { warnings.push("BOTH_NON_NEUTRAL_SAMPLERS"); }
return { accepted: errors.length === 0, mode: do_sample === true ? "sample" : "greedy", errors, warnings, };}Require the application to choose a named profile first. Do not silently add
do_sample=true merely because non-neutral numeric values appear; that changes
the decoding algorithm. Do not silently clamp out-of-range values either.
Return a configuration error before network I/O or GPU allocation.
Pin the Z.AI request
Section titled “Pin the Z.AI request”An explicit hosted baseline avoids future ambiguity:
{ "model": "glm-5.2", "messages": [{ "role": "user", "content": "Review this patch." }], "do_sample": true, "temperature": 1.0, "top_p": 0.95, "max_tokens": 4096}For a greedy contract test:
{ "model": "glm-5.2", "messages": [{ "role": "user", "content": "Return the required fields." }], "do_sample": false, "max_tokens": 1024}The API documentation says temperature and top P have no effect in the second request. Omitting them communicates that intent more honestly. Keep the output cap and total context as separate gates; sampling controls do not expand either limit.
Pin direct Transformers generation
Section titled “Pin direct Transformers generation”Direct local inference must activate sampling explicitly if it is meant to match the hosted sampled profile:
inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, return_tensors="pt",).to(model.device)
output = model.generate( inputs, do_sample=True, temperature=1.0, top_p=0.95, max_new_tokens=4096,)For greedy decoding, set do_sample=False and either leave the sampling-only
arguments unset or neutralize them. Pin the model revision and Transformers
version in the same run record. A configuration copied from a newer engine is
not evidence for the pinned 5.12 behavior.
The full checkpoint is far beyond a casual workstation. Before downloading or allocating GPUs, use the local hardware guide to check weight, KV-cache, storage, and interconnect requirements. The sampling validator itself needs no model weights.
Do not inherit a server’s unknown default
Section titled “Do not inherit a server’s unknown default”An OpenAI-compatible vLLM, SGLang, gateway, or agent client may translate or
omit fields differently from both Z.AI and direct Transformers. The current
official vLLM GLM-5.2 recipe
pins engine and serving controls, but its example request does not pin
temperature, top P, or do_sample.
Treat each adapter as a separate contract:
- capture the application payload;
- capture the translated server payload or resolved generation config;
- record the engine and image version;
- verify the selected mode in a bounded canary;
- compare outputs only after those facts match.
Do not infer an engine’s behavior from “OpenAI compatible.” Compatibility can cover field names without guaranteeing identical defaults. The API provider comparison helps separate access routes; it does not replace a route-specific receipt. Keep repetition controls in a separate profile: the GLM-5.2 repetition-penalty guide shows why Z.AI, Transformers, vLLM, and SGLang do not share one portable penalty payload.
Deterministic does not mean byte-identical
Section titled “Deterministic does not mean byte-identical”do_sample=false removes multinomial token selection in the documented path.
It does not prove identical bytes across GPU types, kernels, quantizations,
batch sizes, engine releases, or distributed execution. Floating-point ties
and implementation changes can still alter a sequence.
The current Z.AI Chat Completion schema does not document a seed request
field. That absence does not prove every proxy rejects a seed extension, but it
means a portable GLM-5.2 test should not depend on one.
Build regression evidence around outcomes:
- validate JSON or tool arguments against a schema;
- assert required facts, files, or tests rather than exact prose;
- run stochastic profiles more than once and report pass rate;
- store
finish_reason, token usage, route, model revision, engine version, and the complete sampling profile; - keep prompts, fixtures, and graders versioned.
For machine-consumed results, pair a conservative profile with the structured-output validation pattern. For tools, validate arguments and execute them through the complete function-calling loop.
Sampling and reasoning effort are independent controls
Section titled “Sampling and reasoning effort are independent controls”Sampling controls token selection. reasoning_effort controls how much
reasoning work the model is asked to perform. One does not neutralize or replace
the other.
A comparison can hold do_sample, temperature, and top P constant while
changing reasoning effort, or hold reasoning effort constant while testing one
sampling knob. Changing both groups at once makes attribution weak. Use the
reasoning-effort guide to pin the accepted
effort value and output budget independently.
Streaming is also orthogonal. It changes delivery, not the chosen sampling profile. Preserve the same fields when switching to SSE, then use the streaming parser to reconstruct reasoning, content, usage, tool calls, and terminal state.
Match the profile to the reader task
Section titled “Match the profile to the reader task”| Reader task | Starting profile | Acceptance evidence |
|---|---|---|
| JSON extraction | explicit greedy | schema pass rate, missing-field rate |
| Tool routing | explicit greedy first | valid tool name and arguments across fixtures |
| Coding benchmark reproduction | exact cited profile | harness, revision, pass rate, time and token budget |
| Brainstorming | top-P-only or temperature-only | diversity plus human usefulness rubric |
| Factual Q&A | lower-temperature trial with top P neutral | source-grounded correctness, not fluency |
| Hosted-to-local parity | explicit 1.0 / 0.95 sampled profile | repeated shared-fixture comparison |
These are starting points, not universal quality claims. A task can perform better with a different profile. Change one dimension, preserve the baseline, and measure the task outcome that matters.
Log the resolved profile, not only the payload
Section titled “Log the resolved profile, not only the payload”At rollout time, store both requested and resolved state:
{ "route": "direct-transformers", "model_revision": "b4734de4facf877f85769a911abafc5283eab3d9", "engine": "transformers-5.12.0", "requested": { "do_sample": true, "temperature": 1.0, "top_p": 0.95 }, "resolved_mode": "sample", "reasoning_effort": "max", "fixture_set": "sampling-canary-v1"}Canary the new profile before sending production traffic. Roll back when schema pass rate, task success, latency, token use, or retry rate crosses its bound. Do not attribute a regression to sampling until model revision, prompt, reasoning controls, context, tools, and output cap are also held constant.
Choose access after the profile is explicit
Section titled “Choose access after the profile is explicit”Once the payload contract and acceptance test are ready, choose the delivery route. Hosted access removes checkpoint serving work; self-hosting gives more control but makes engine defaults, GPU capacity, and observability your responsibility.
Sources, method, and limits
Section titled “Sources, method, and limits”Checked on August 16, 2026 (Hong Kong time). The audit fetched the Z.AI core parameters, Chat Completion schema, and GLM-5.2 model guide; the current Hugging Face model API; pinned checkpoint generation config and README; Transformers 5.12 generation source and strategy guide; the pinned vLLM recipe; the required Z.AI release entry; and the Zhipu research index. Redirects, compression, source byte counts, and SHA-256 hashes are recorded in the public receipt.
The foreground round began with an AI HOT lead about
AI-generated Amazon books.
It was rejected as a weak GLM link and was not used as evidence. The topic came
from proactive official-doc and checkpoint research. One exact Google result
set for glm 5.2 temperature top_p do_sample was recorded under request
serpapi-6b6d88585c14422ca0fd923fb0097fef; it found official and adjacent
guidance but no page centered on the fail-closed hosted-to-Transformers drift
test.
The fixtures are deterministic JavaScript configuration checks. They do not prove output quality, account entitlement, server-side defaults beyond the published schema, bit-for-bit determinism, latency, or route acceptance. No GLM model, grader, authenticated endpoint, credential, or private prompt was used. Re-run the audit when the API schema, checkpoint revision, Transformers version, or serving engine changes.
GLM-5.2 temperature and top P FAQ
Section titled “GLM-5.2 temperature and top P FAQ”What are the documented GLM-5.2 temperature and top_p defaults?
Section titled “What are the documented GLM-5.2 temperature and top_p defaults?”For the current Z.AI Chat Completion text-model schema, temperature defaults to
1.0 and top P defaults to 0.95. The schema also defaults do_sample to true.
Pin all three when a baseline must survive documentation or client changes.
Does temperature 0 make GLM-5.2 deterministic?
Section titled “Does temperature 0 make GLM-5.2 deterministic?”Z.AI documents 0 as an accepted temperature boundary, but exact behavior can
depend on the engine. For an explicit greedy test, use do_sample=false.
Neither choice guarantees identical bytes across different hardware and
software stacks.
Should I change temperature and top_p together?
Section titled “Should I change temperature and top_p together?”The official core-parameter guide recommends changing only one. Keep the other neutral at 1.0 so the experiment has one active stochastic control.
Why is my local output less varied than the Z.AI API?
Section titled “Why is my local output less varied than the Z.AI API?”Check do_sample first. The pinned checkpoint stores temperature 1 and top P
0.95 but omits the sampling flag; Transformers 5.12 treats the missing flag as
greedy mode. Set do_sample=true explicitly before comparing with the hosted
sampled baseline.
Does GLM-5.2 support a seed parameter?
Section titled “Does GLM-5.2 support a seed parameter?”The checked Z.AI Chat Completion schema does not document one. A gateway may define an extension, but do not assume it is portable or that a shared seed produces identical output across engines.
Does reasoning_effort replace temperature?
Section titled “Does reasoning_effort replace temperature?”No. Reasoning effort controls requested reasoning depth; sampling controls how the next token is selected. Pin and evaluate the two groups separately.
