RLCD: Reinforcement Learning for Calibrated Decisions.
The acronym comes from TypeSafe and names post-training that teaches the model to decide with calibrated confidence.
The repository we study uses the name but trains nothing: it runs the original Qwen2.5-1.5B and performs parallel constrained decoding at inference time.
TypeSafe published the training objective, but not the method.
Objective: the probability of each decision should track the accuracy rate.
Output: typed decisions, each with a distribution over the options.
Contrast: RLHF rewards what pleases raters and concentrates mass on a single style.
Introduction4 / 50
Choice: one option from a set
TypeSafe API reference, unaltered. The response gives the chosen option, the distribution over all three, and the confidence.
Introduction5 / 50
Noul: does the condition hold or not?
TypeSafe API reference, unaltered. The response is a single number: the probability that the answer is yes.
Introduction6 / 50
Score: a degree on an ordered scale
TypeSafe API reference, unaltered. The score is the mean of the levels weighted by the probabilities: 1 × 0.95 + 2 × 0.05 = 1.05.
01Problem
The idea
Model
Mechanism
Numbers
Jev, Laya
The problem
Block 1 of 6
Why does a JSON generated by an LLM cost hundreds of sequential passes?
01 · The problem8 / 50
The files of the fraud example
Unaltered excerpts; "…" marks omissions, and the long context lines were wrapped only to fit.
01 · The problem9 / 50
In autoregressive generation, each token costs one pass.
Each JSON token depends on the previous one, so the passes through the model happen one after another.
TAR=tprefill+k=1∑Ktstep(k)
With 28 fields, Qwen2.5-1.5B produced 288 tokens. Of these, only 27 choose a value, since one field was left out; the rest is syntax: braces, quotes and field names the program already knew in advance.
01 · The problem10 / 50
Where the 288 passes go
01 · The problem11 / 50
Valid syntax does not guarantee a valid schema.
The JSON closes without a syntax error and still may omit fields or contain values outside the list.
Fraud: the field account_takeover_suspected was left out.
Fraud: secondary_anomaly received an option from another field.
Support: the field ticket_priority was left out.
Problem
02The idea
Model
Mechanism
Numbers
Jev, Laya
The idea
Block 2 of 6
If each value belongs to a closed list, why generate it token by token?
02 · The idea13 / 50
When the possible answers are known, deciding means comparing logits, not generating text.
The principle of parallel constrained decoding
02 · The idea14 / 50
The method combines four pieces.
The context and the field catalog go through the prefill only once and stay in the KV cache.
The cache is replicated for each field, and the 28 suffixes are evaluated in one batched pass.
In each field, only the tokens of the valid options enter the logit contest.
The JSON is assembled by the program; the model only chooses the values.
Problem
The idea
03Model
Mechanism
Numbers
Jev, Laya
Inside the model
Block 3 of 6
Which parts of Qwen2.5 does the engine use, and what does each one cost?
03 · Inside the model16 / 50
A 4-bit Qwen2.5-1.5B, piece by piece
1,543,714,304 parameters in 4 bits, with a scale and an offset every 64 weights: 869 MB. The slice is the engine's only piece.
03 · Inside the model17 / 50
The SwiGLU MLP in one formula
Three weight matrices, fixed after training, transform the vector of each token.
MLP(x)=Wdown(SiLU(Wgatex)⊙Wupx)
SiLU(z)=1+e−zz
The product ⊙ is elementwise. There is no bias.
The output, also of size 1,536, is added to the residual.
03 · Inside the model18 / 50
How the SwiGLU MLP transforms a vector
03 · Inside the model19 / 50
How the weights fit in 4 bits
03 · Inside the model20 / 50
The tokens through Qwen and through RLCD
03 · Inside the model21 / 50
Each piece, with shapes and cost
03 · Inside the model22 / 50
Twelve queries, two keys: the cache is six times smaller.
With grouped-query attention, each stored token takes 28,672 bytes across the 28 layers.
2×28×2×128×2=28672bytes
The factors are K and V, 28 layers, 2 heads, 128 dimensions and 2 bytes in fp16. With one K and V head per query, it would be 172 kB per token, and the broadcast to 28 fields would exceed 3.7 GB.
03 · Inside the model23 / 50
The KV cache, position by position
03 · Inside the model24 / 50
The price of the cache broadcast
03 · Inside the model25 / 50
Three quarters of the parameters are in the MLPs
Weight-by-weight count from the safetensors shapes: 1,543,714,304 in total.
03 · Inside the model26 / 50
The same layers in three regimes
03 · Inside the model27 / 50
What the engine computes and what it throws away.
Three measurements on the fraud preset show where the model does more, or less, work than the engine needs.
stage
measurement
what it means
Prefill
287 ms, versus 347 ms
the output head is not evaluated
Broadcast
616.6 MB
28 copies of the 22.0 MB cache
Batched pass
46.8M logits
76 are read; they cost 24 of 183 ms
Problem
The idea
Model
04Mechanism
Numbers
Jev, Laya
The mechanism
Block 4 of 6
What happens, field by field, inside the single pass?
04 · The mechanism29 / 50
One prefill and one branch per field
Fraud alert: the context is read once, and each field ends in a valid value together with its probability.
04 · The mechanism30 / 50
The prompt ends by opening the JSON, and stops there.
Real prompt of the fraud case, assembled by the repository; "…" marks omissions. In gray, the special tokens of the chat format.
04 · The mechanism31 / 50
Each field receives a copy of the cache.
We repeat the cache M times along the batch axis, and the M suffixes are evaluated in a single pass.
b_cache = []for c in cache: nc = copy.copy(c) nc.keys = mx.repeat(c.keys, M, axis=0) nc.values = mx.repeat(c.values, M, axis=0) b_cache.append(nc)# batch row i: ' "risk_tier": "'out = model(suffixes_batch, cache=b_cache)logits_i = out[i, fim_i, :] # the decision for field i
04 · The mechanism32 / 50
Only the field's options compete for the decision.
Of the roughly 152 thousand logits in the vocabulary, we read only those of the first token of each option.
P(ci)=∑j=1Cezj/Tezi/T
A boolean compares 2 logits; risk_tier, 4.
04 · The mechanism33 / 50
The logit slice at another temperature
04 · The mechanism34 / 50
The probability indicates when to doubt
Field recommended_action in the fraud alert: manual review beats blocking by 0.51 to 0.44.
04 · The mechanism35 / 50
How much probability falls on the options
Fraud case, 28 fields: the schema options receive at most 1.4% of the next-token probability. Measured on the M4 Pro.
04 · The mechanism36 / 50
What the model wanted to write
For booleans, it wants 1 or 0; for enums, another word or another spelling.
field
in the schema
preferred token
on the options
tor_exit_node_detected
true, false
1, 0.99
< 0.01%
requires_human_escalation
true, false
1, 0.97
< 0.01%
risk_tier
LOW to CRITICAL
High, 0.46
1.2%
recommended_action
APPROVE to FREEZE, 5 options
Notify, 0.13
0.06%
04 · The mechanism37 / 50
Where the 0.51 and the 0.44 come from
The slice renormalizes probabilities that the model considers almost impossible.
P(c)=∑jpvocab(j)pvocab(c)
recommended_action
in the vocabulary
in the slice
MANUAL_REVIEW
0.00028
0.51
BLOCK_TRANSACTION
0.00025
0.44
the other three
0.00003
0.05
04 · The mechanism38 / 50
When the options start the same way
The common prefix becomes part of the suffix, and the decision falls on the first token where the options differ.
For SEV_0_CRITICAL, SEV_1_MAJOR and their neighbors, the suffix ends in "SEV_, and the contest is among the digits.
Problem
The idea
Model
Mechanism
05Numbers
Jev, Laya
The numbers
Block 5 of 6
How much do we gain on an M4 Pro, and where does the remaining time go?
05 · The numbers40 / 50
Both decoding methods in the four scenarios
05 · The numbers41 / 50
From 3.6 to 4.8 times faster, measured on this Mac.
Qwen2.5-1.5B-Instruct in 4 bits, with MLX on an M4 Pro; median of three runs per scenario.
scenario
fields
autoregressive
parallel
speedup
Fraud
28
2493 ms
521 ms
4.8×
Code security
28
2681 ms
708 ms
3.8×
Support
28
2524 ms
661 ms
3.8×
Customs, 255 options
4
825 ms
227 ms
3.6×
05 · The numbers42 / 50
The prefill tends to be the largest share
All bars are on the same scale. In the 28-field scenarios, the prefill takes about 290 ms, close to half of the total.
05 · The numbers43 / 50
Why 4.8 times and not 288?
Sequential passes drop from 288 to one, but the prefill remains, and the batched pass is wide.
In the fraud scenario, the prefill takes 294 of the 521 ms, more than half of the time. From here on, shortening the prompt likely pays off more than speeding up the decision.
05 · The numbers44 / 50
Where the speedup saturates
Problem
The idea
Model
Mechanism
Numbers
06Jev, Laya
Jev and Laya
Block 6 of 6
What changes when the classifier is trained to decide?
06 · Jev and Laya46 / 50
Laya: one [MASK] for each option
Redrawn from Nandakishor M's diagram; the input sequence is the example from the paper itself. 421M parameters in total.
06 · Jev and Laya47 / 50
Laya's training: proper scoring rules.
The reward is maximal when the stated probability matches the actual frequency of correct answers.
R(q,y)=Slog+0.5Ssph−Srps
Logarithmic, spherical and ranked probability scores, optimized by REINFORCE with noise on the logits.
06 · Jev and Laya48 / 50
Jev, Laya and the lecture repository
Jev
Laya
repository
model
not published
ModernBERT-large, 395M
Qwen2.5-1.5B
scores the options
not published
head trained on [MASK]
first-token logit
calibration training
RLCD, not published
proper rules, published
none
act or escalate
thresholds in code
dedicated head
none
weights and code
closed
open
open
06 · Jev and Laya49 / 50
Reinforcement learning or supervised learning?
With known labels, calibration comes from the scoring rule; reinforcement does not explain it.
The logarithmic term of the reward is the cross-entropy with its sign flipped.
REINFORCE estimates, with noise, a gradient that could be computed directly.
Reinforcement is indispensable when the action changes what is observed next.
Closing50 / 50
The way these technologies are being developed encourages commercial exaggeration (hype). Ideas and people are mythologized, and precedence is conveniently ignored. Similar ideas were proposed in the following papers: arxiv.org/abs/2503.23303 and arxiv.org/abs/2510.01237