Repository navigation
fix(metal): keep Mirostat mu across decode steps - #1816
Open
chaitanya0305 wants to merge 1 commit into
Open
chaitanya0305 wants to merge 1 commit into
chaitanya0305 wants to merge 1 commit into
Conversation
Each Metal decode step builds a fresh SamplingBatch, and make_sampling_metadata() handed the sampler a new empty persistent_data dict every time. Mirostat v2 stores its running mu there, so mu was reset to 2 * tau on every token and the target-surprise feedback loop never ran. Keep the per-request sampler state on RequestState and pass it into the batch from both decode paths (batched and sequential) and from sample_decode_tokens(). Signed-off-by: Chaitanya Deshpande <dcchaitanyadeshpande@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the Metal backend, Mirostat v2 never adapts:
muresets to2 * tauon every generated token, so the target-surprise feedback loop does not run. Mirostat requests on Apple Silicon effectively sample with a fixed truncation instead.Repro (CPU, no model needed)
Five decode steps through
SamplingBatch+sample_from_logitsfor a request withmirostat_mode=2, mirostat_tau=2.0, mirostat_eta=0.5, spying on themuthat_fetch_mirostat_argshands to the sampler:With this change,
mucarries over and is updated from the previous step's value.Root cause
Each Metal decode step builds a new
SamplingBatch, andSamplingBatch.make_sampling_metadata()passedThe Mirostat op reads
miro_mufrompersistent_dataand writes the updated value back there. That dict is thrown away with the batch, so the next step starts from the default again.Fix
RequestStategets asampler_statedict that lives as long as the request.SamplingBatchtakes an optionalpersistent_datalist (one dict per row) and passes those same dicts intoSamplingMetadata. Without it, the behaviour is unchanged. A length mismatch raises.sampler_state:sample_decode_tokens(paged path),_batched_decodeand_sequential_decode.The prefill token is still sampled from a fresh state (initial
mu = 2 * tau), as before. The running state starts with the first decode step.Tests
tests/metal/test_sampling_batch_mirostat.py(skipped whenmlxis not installed):muchanges across four decode steps of one request and does not restart at2 * tau;persistent_datalength mismatch raises.All 3 tests fail on main and pass with the fix.
ruff checkandruff format(v0.17.2, as pinned in pre-commit) are clean.Related but separate: #1674 fixes the mixed-batch sampler skip in
_execute_samplers_in_order. This PR does not touch that code.