Repository navigation
Conversation
… logits: temperature, top-k, top-p, min-p, penalties, Philox seed; a sampled verify window keeps a draft when the sample equals it)
…sh random) so temperature takes effect
|
This fixes the same bug (#3006) as my #3301, which has been open since 2026-10-20. Here is a comparison in case it helps the review. I ran this PR's Matches the reference. Every pick on a row without a
In the harness, 92 of 144 rows with a bias pick a different token than the reference, and all 144 pick the token they would pick without the bias. A greedy request with a bias also keeps the window's argmax, because Penalties are slow. The history counts are matched to the vocabulary by a linear scan for each logit:
The Qwen cards' default sampling has For comparison, #3301 on the same rows takes 9-20 µs without penalties, 9.7 µs with The server seed isn't needed. The engine already decides greedy from the temperature alone ( Two smaller points:
I'm happy to fold anything useful from here into #3301, or the other way round, whichever the maintainer prefers. Since today #3301 changes no code outside |
Problem and result
The Metal decode path only ever took the argmax (
metal/src/engine/window.cppdecoded greedily;sample_tokenswas a stub), sotemperature,top_k,top_p,min_p, the penalties andseedhad no effect on macOS. In agent use the model then repeated itself word for word across turns. With this change Metal samples the way the CUDA engine does: a seed gives a reproducible text, different seeds give different texts, and greedy requests are unchanged.Related discussion
Overview of our related macOS / Metal contributions: #4128. Focused fix of a Metal gap (the CUDA engine already samples).
Approach
serve: a sampled request carries a Philox seed (the request's, else a fresh random one), sotemperaturetakes effect through the API.Validation
Branch head
b5660dfcc92d5964b2527017f37c108e5da2fba1, two commits onv0.2.6. Apple Silicon, 128 GB unified memory, Gyro-M TQ2_0,--spec 2with the MTP draft, same flags for both builds, no environment overrides.Passed:
strataon macOS.v0.2.6.--temperature 1.5 --top-k 50): seed 1 and seed 2 differ; seed 1 twice is identical.Failed:
Not run:
Limits
The sampler runs on the CPU over the head's logits; a GPU sampler could save the logits copy per token.