Skip to content

Fix speculative decode with full rotating caches#1427

Open
cyq1017 wants to merge 2 commits into
ml-explore:mainfrom
cyq1017:codex/mlx-lm-speculative-rotating-cache
Open

Fix speculative decode with full rotating caches#1427
cyq1017 wants to merge 2 commits into
ml-explore:mainfrom
cyq1017:codex/mlx-lm-speculative-rotating-cache

Conversation

@cyq1017

@cyq1017 cyq1017 commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Speculative decoding can diverge from deterministic non-speculative generation when a RotatingKVCache reaches the point where it can no longer be trimmed. If a drafted token is rejected after that point, the existing rewind path cannot remove the speculative cache entries.

This limits draft length around full rotating caches and falls back to target-only generation when rollback is not safe. Other trimmable cache types keep their existing speculative path.

Fixes #1423.

Tests

  • uv run --isolated --python 3.12 --with-editable . --with pytest python -m pytest tests/test_generate.py::TestSpeculativeGenerateStep tests/test_generate.py::TestGenerate::test_stream_generate_speculative -q
  • python3 -m py_compile mlx_lm/generate.py tests/test_generate.py
  • git diff --check HEAD~2..HEAD

@cyq1017 cyq1017 marked this pull request as ready for review June 24, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Speculative decoding diverges from non-speculative output at temperature 0 (should be identical)

1 participant