Skip to content

GLM-5.2 Logit Bias: Route-Aware Token Controls

Independent research — not an official Z.ai publication.Identity and provider disclosure

A cyan token-ID grid passes through positive and negative bias controls toward a probability display and three guarded special-token exits

Original editorial visualization of a token-ID grid crossing positive and negative controls before reaching a probability display. The guarded exits represent GLM-5.2’s pinned pad and EOS token IDs.

Use token bias only on a version-pinned local GLM-5.2 route whose control is documented. The checked Z.AI hosted schema publishes no token-bias or token- mask field. Transformers 5.12 provides sequence_bias and suppression processors; vLLM 0.27.1 exposes logit_bias plus allowed_token_ids; SGLang 0.5.17 exposes per-token logit_bias in its OpenAI-compatible protocol. These names are not interchangeable.

Our dated audit hashes 14 public artifacts, resolves 22 valid and invalid profiles, and passes 14 assertions. It makes zero authenticated API calls, zero tokenizer calls, zero model calls, and downloads no weights. It proves the checked source contracts, validator behavior, and bias arithmetic—not live provider acceptance or a preferred output.

  1. Compare the four routes
  2. Respect the hosted boundary
  3. Resolve token IDs safely
  4. Protect model boundaries
  5. Understand the math
  6. Choose soft or hard control
  7. Configure Transformers
  8. Configure vLLM
  9. Configure SGLang
  10. Apply a portable guard
  11. Test the outcome
  12. Pick a deployment route
  13. Review the evidence
  14. Resolve common questions

Start with the behavior required, then select the route:

Route checked Soft single-token bias Multi-token sequence bias Hard suppression or allow-only Safe interpretation
Z.AI Chat Completion not documented not documented not documented omit speculative fields
Transformers 5.12 one-token tuple in sequence_bias native sequence_bias suppress_tokens; custom processor for allow-only direct generation contract
vLLM 0.27.1 OpenAI chat logit_bias not equivalent allowed_token_ids engine extension per-token map plus separate hard allowlist
SGLang 0.5.17 OpenAI chat logit_bias not equivalent no allow-only field in the audited protocol keep to the checked per-token field

The checkpoint is the same, but the runtime owns the processor. The pinned GLM-5.2 model card names Transformers, vLLM, and SGLang as supported serving families. It does not promise one portable token-control request.

Do not translate by field-name similarity. A Transformers sequence rule can target a phrase only when its prefix has appeared. A vLLM logit_bias entry changes one token wherever it is considered. Converting the former into a map of individually biased IDs changes the policy.

Hosted GLM-5.2 has no published bias field

Section titled “Hosted GLM-5.2 has no published bias field”

The checked Z.AI Chat Completion reference contains positive-control fields such as temperature and top_p. It contains no documented logit_bias, sequence_bias, suppress_tokens, or allowed_token_ids; the current GLM-5.2 guide does not supply a separate token-control contract.

That is an absence finding, not a live rejection result. An adapter could reject, ignore, strip, or privately implement an extra field. Each outcome is unsafe if the application silently assumes the requested policy took effect. Keep the hosted request inside the published envelope:

Hosted request without speculative token controls
{
"model": "glm-5.2",
"messages": [
{ "role": "user", "content": "Return one supported category." }
],
"do_sample": false,
"max_tokens": 32
}

If output restriction is mandatory, validate the completed result or move the bounded workload to a documented local route. An HTTP 200 alone would not prove that a hidden bias was applied.

Derive IDs from the pinned tokenizer and exact context

Section titled “Derive IDs from the pinned tokenizer and exact context”

Logit bias operates on token IDs, not words. Capitalization, whitespace, punctuation, chat-template boundaries, and preceding text can change how a visible string is split. A remembered ID from another model—or even another revision of the same repository—is not evidence.

The audited checkpoint revision is b4734de4facf877f85769a911abafc5283eab3d9, with vocabulary size 154,880. Resolve candidate spans using that exact tokenizer and the exact rendered context. This inspection example is intentionally separate from the audit, which made no tokenizer call:

Inspect the candidate span in its real context
from transformers import AutoTokenizer
REVISION = "b4734de4facf877f85769a911abafc5283eab3d9"
tokenizer = AutoTokenizer.from_pretrained(
"zai-org/GLM-5.2",
revision=REVISION,
)
prefix = "Category:"
candidate = " approved"
encoded = tokenizer(
prefix + candidate,
add_special_tokens=False,
return_offsets_mapping=True,
)
boundary = len(prefix)
candidate_ids = [
token_id
for token_id, (_, end) in zip(encoded.input_ids, encoded.offset_mapping)
if end > boundary
]
print(candidate_ids)

Inspect decoded pieces as well as offsets. A token that crosses the prefix boundary belongs to the decision. Preserve the tokenizer revision, rendered prompt digest, candidate text, offsets, and resulting IDs in the test receipt. The GLM-5.2 tokenizer API guide covers the separate problem of counting and matching tokenizer routes.

Keep pad and EOS IDs behind an explicit review

Section titled “Keep pad and EOS IDs behind an explicit review”

The pinned generation_config.json declares EOS token IDs 154820, 154827, and 154829; pad ID 154820 overlaps the first EOS ID. These control termination and role boundaries, not ordinary vocabulary preferences.

The portable validator rejects all three by default. A positive bias can cause premature termination. A strong negative bias can prevent the expected end or push generation toward another role marker. Either can look like truncation, runaway output, or a malformed tool turn rather than a simple word preference.

Only enable a special-token override after reviewing the exact chat template, runtime stop handling, and GLM-5.2 EOS audit. Record the reason as a separate policy decision; do not hide it inside a generic token map.

For one targeted token with base probability p, adding bias b to its logit multiplies its odds against all other tokens by exp(b):

Target-token probability after one additive bias
base odds = p / (1 - p)
adjusted odds = base odds × exp(b)
adjusted p = adjusted odds / (1 + adjusted odds)

The audit reproduces these anchors:

Base probability Bias Odds multiplier Adjusted probability
0.50 +2 7.3891× 0.880797
0.50 −2 0.1353× 0.119203
0.90 −2 0.1353× 0.549147
0.99 −5 0.0067× 0.400140

The last two rows expose the common mistake: a negative value is not a ban. A highly favored token can retain substantial probability. Sampling controls, other processors, previous output, and the competing vocabulary also affect the final choice. Use the GLM-5.2 logprobs contract to observe scores on supported local routes, but do not confuse a changed score with task correctness.

Choose the control by failure consequence:

  • Soft steering changes preference while leaving alternatives available. Use it for style experiments or bounded candidate nudges where occasional misses are acceptable.
  • Sequence bias changes the score when a complete token sequence becomes eligible. It is useful when phrase context matters and the runtime documents this semantic.
  • Suppression makes selected IDs unavailable. It can block necessary spelling variants, whitespace pieces, or termination tokens if the set is incomplete.
  • Allow-only decoding limits generation to a reviewed set. It can enforce a fixed label vocabulary, but must also account for termination and any separators the output requires.
  • Post-generation validation checks meaning or structure after decoding. For JSON or typed fields, the structured-output validation pattern is safer than trying to enumerate every permitted JSON token.

Biasing all pieces of a phrase does not recreate phrase-level bias. Each piece is affected in unrelated contexts too. Likewise, a hard allowlist is not a stronger numeric bias; it is a different decoding contract with different failure modes.

Translate intent into Transformers processors

Section titled “Translate intent into Transformers processors”

Transformers 5.12 publishes sequence_bias, suppress_tokens, begin_suppress_tokens, and bad_words_ids. Its GenerationConfig does not publish a direct logit_bias field. A one-token sequence is the closest native soft-token mapping:

Transformers soft bias and hard suppression
from transformers import GenerationConfig
token_id = 42 # replace with a pinned, context-checked ID
soft = GenerationConfig(
sequence_bias={(token_id,): 2.0},
renormalize_logits=True,
)
hard = GenerationConfig(
suppress_tokens=[token_id],
renormalize_logits=True,
)

For a phrase, use one tuple containing the ordered IDs rather than assigning the same bias to every member. renormalize_logits=True is prudent when later logic expects normalized scores after processors. An allow-only policy needs a reviewed custom logits processor in the audited configuration surface; the validator refuses to invent one.

Test the processor with the actual generate() call, because generation configuration can be merged from checkpoint defaults, request parameters, and application wrappers.

Use vLLM fields without inventing sequence semantics

Section titled “Use vLLM fields without inventing sequence semantics”

The checked vLLM 0.27.1 chat protocol publishes both an OpenAI-style bias map and the engine extension allowed_token_ids:

vLLM per-token bias
{
"model": "zai-org/GLM-5.2",
"messages": [{ "role": "user", "content": "Category:" }],
"logit_bias": {
"42": 2.0,
"43": -4.0
},
"temperature": 0,
"max_tokens": 8
}

JSON object keys are strings. The pinned SamplingParams source converts them with int(token) and clamps each bias into −100 through 100. That clamp is an engine behavior, not permission to treat an extreme value as guaranteed suppression.

For a fixed-label decoder, allowed_token_ids: [42, 43] is a separate hard control. Verify that the list includes every token needed for valid output and termination. Do not translate a Transformers multi-token sequence rule into a vLLM per-token map; the 22-fixture validator returns PER_TOKEN_FIELD_NOT_SEQUENCE_FIELD for that attempted conversion.

The audited SGLang 0.5.17 OpenAI protocol exposes logit_bias as a string-keyed mapping. Its SamplingParams path checks that converted token IDs fall within the model vocabulary:

SGLang OpenAI-compatible token bias
{
"model": "zai-org/GLM-5.2",
"messages": [{ "role": "user", "content": "Category:" }],
"logit_bias": { "42": 2.0 },
"temperature": 0,
"max_tokens": 8
}

The checked protocol did not expose allowed_token_ids. SGLang has other native and constrained-generation surfaces, but they are not silently folded into this OpenAI request. Select and audit an explicit grammar or processor if a hard constraint is required.

The site’s portable policy keeps bias inside −100 through 100 across routes, even though that shared envelope does not prove identical validation or numerical effects. Version pinning remains part of the request contract.

Reject token-control drift before inference

Section titled “Reject token-control drift before inference”

A small admission layer should fail before any model call. This condensed pattern enforces the pinned vocabulary, protects special tokens, and refuses unsupported route/mode combinations:

Fail-closed token-control admission
const VOCAB_SIZE = 154_880;
const SPECIAL = new Set([154_820, 154_827, 154_829]);
function validateIds(ids, allowSpecial = false) {
if (!Array.isArray(ids) || ids.length === 0) throw new Error('EMPTY_TOKEN_SET');
if (new Set(ids).size !== ids.length) throw new Error('DUPLICATE_TOKEN_ID');
for (const id of ids) {
if (!Number.isInteger(id) || id < 0 || id >= VOCAB_SIZE) {
throw new Error('TOKEN_ID_OUT_OF_RANGE');
}
if (!allowSpecial && SPECIAL.has(id)) throw new Error('SPECIAL_TOKEN_BLOCKED');
}
}
function validateBias(bias) {
if (!Number.isFinite(bias) || bias < -100 || bias > 100) {
throw new Error('BIAS_OUT_OF_PORTABLE_RANGE');
}
}

Add route rules after these common gates. The full machine-readable receipt records all 22 profiles, including string-valued IDs, ID 154880, duplicate IDs, an empty set, special-token review, vLLM allow-only support, and SGLang’s audited boundary.

Store the requested intent separately from the rendered engine request. That makes a migration diff visible: sequence-bias cannot accidentally become token-bias, and suppress cannot become -5 merely because both sound negative.

Measure effects with a frozen token receipt

Section titled “Measure effects with a frozen token receipt”

Validate policy and effect separately. A useful experiment freezes:

  1. model and tokenizer revision;
  2. rendered chat-template bytes and token IDs;
  3. runtime version and endpoint class;
  4. sampling, penalty, reasoning, and stop settings;
  5. baseline request without the token control;
  6. one changed control per comparison;
  7. generated token IDs, finish reason, and supported score output;
  8. task result, not only token frequency.

For soft steering, report how often the target token appears and how its score or rank changes. For suppression, prove the token never appears across the bounded test corpus and verify valid alternatives still complete. For an allowlist, test every approved label plus adversarial punctuation and EOS handling. A zero-occurrence sample is evidence for that sample, not a universal guarantee.

Do not mix this with repetition penalty. History-based penalties react to tokens already present in the prompt or generation; explicit bias targets listed token IDs regardless of repetition. Record both when both are active because processor order can matter.

Choose the smallest control that meets the job

Section titled “Choose the smallest control that meets the job”

Use Z.AI hosted generation when documented prompt instructions and completed- output validation meet the requirement. Choose a version-pinned local engine when token-level steering or hard decoding constraints are necessary and the application can own tokenizer, processor, GPU, privacy, and regression work.

For a fixed classifier, a hard allowlist plus semantic validation may be more auditable than extreme bias. For prose style, prompt design and a mild measured bias may preserve useful alternatives. For JSON, prefer schema validation. For safety or authorization, never rely on model-token controls as the only policy boundary; enforce rules outside generation.

The local hardware guide estimates the separate capacity decision. Passing a token-control validator does not prove that one machine can load the checkpoint.

Checked on August 17, 2026 (Hong Kong time). The audit fetched the current Z.AI Chat Completion schema and GLM-5.2 guide; the Hugging Face model API; pinned config, generation config, and README; Transformers 5.12 configuration and processor source; vLLM 0.27.1 chat and SamplingParams source; SGLang 0.5.17 protocol and SamplingParams source; the required Z.AI release entry; and the Zhipu research index. Receipts retain URLs, redirects, status, bytes, and hashes, not source bodies.

One exact Google result set for glm 5.2 logit bias token ids was recorded as request serpapi-e4d471ffc077406ea686251658f32c79. Eight organic results covered generic bias guides, OpenAI help, community advice, and vLLM docs; none owned the GLM-5.2 hosted-versus-local contract. The search was evaluated high-value because it confirmed a distinct supply gap.

The Node.js audit used public text and deterministic fixtures. It did not load a tokenizer, call an authenticated API, invoke GLM or MiniMax, download model weights, run a GPU, grade output, or establish live endpoint behavior. It cannot prove token mappings, cross-engine parity, output quality, latency, memory fit, provider implementation, or future schema stability.

Does the hosted Z.AI GLM-5.2 API support logit_bias?

Section titled “Does the hosted Z.AI GLM-5.2 API support logit_bias?”

The Chat Completion schema and GLM-5.2 guide checked on August 17, 2026 do not document logit_bias or a token allowlist. That is not a live rejection test. Omit the field unless the exact hosted route publishes a separate contract.

Can I ban a word with a negative logit bias?

Section titled “Can I ban a word with a negative logit bias?”

Not reliably. Visible words can have multiple context-dependent tokenizations, and finite negative bias only reduces probability. The audit shows a token with base probability 0.9 still has about 0.549 probability after bias −2. Use a documented hard constraint or validate the completed output when a ban is actually required.

Treat them as revision-specific. Pin model and tokenizer revision, tokenize the exact rendered context, and store offsets plus IDs. Recompute and regression- test the map after any tokenizer, template, or checkpoint change.

What is the difference between sequence_bias and logit_bias?

Section titled “What is the difference between sequence_bias and logit_bias?”

Transformers sequence_bias can act on an ordered multi-token sequence when its completion becomes eligible. OpenAI-style logit_bias maps individual token IDs to additive values. Assigning a phrase’s IDs individually changes those tokens in every context and is not equivalent.

Should I bias EOS tokens to control response length?

Section titled “Should I bias EOS tokens to control response length?”

Not as a generic shortcut. GLM-5.2 has three pinned EOS IDs, one shared with pad. Biasing them can cause premature termination or runaway output. Use the runtime’s documented output cap and stop contract, then test finish reasons.

Use a documented allow-only control for a tiny, fully enumerated output alphabet such as fixed labels, after including every required separator and termination token. The audited vLLM protocol exposes this extension; the audited Z.AI and SGLang OpenAI contracts do not.