Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mlx_lm): basic speculative decoding support in mlx_lm.generate / mlx_lm.server #954

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

llllvvuu
Copy link
Contributor

@llllvvuu llllvvuu commented Aug 26, 2024

Draft only because this is stacked on top of #948. Speculative decoding commit is 7d0e1cc

Implementation based on #149. This basic version only supports bs=1, temp=0, max_kv_size=None. Supporting samplers, rotating cache, and batching are deferred to future commits in order to keep this diff small.

Note due to #948 (comment), the best speedup happens when the main model is unquantized.

Test (>2x speedup on my machine):

python -m llms.mlx_lm.generate --temp 0 --max-kv-size 0 \
  --model mlx-community/SmolLM-1.7B-Instruct-fp16 \
  --draft-model mlx-community/SmolLM-135M-Instruct-4bit \
  --prompt "Develop a Python program that reads all the text files under a directory and returns top-5 words with the most number of occurrences." \
  --max-tokens 500

The `prompt` argument can now be either a `str` or `list[str]`.

The change to `generate()` is backwards-compatible.

The changes to `generate_step()`, `top_p_sampling()`, and
`min_p_sampling()` are backwards-incompatible in order to unify shapes;
this could be changed by adding a few if-statements, if preferred.
@llllvvuu llllvvuu changed the title feat: basic speculative decoding support in mlx_lm.generate / mlx_lm.server feat(mlx_lm): basic speculative decoding support in mlx_lm.generate / mlx_lm.server Aug 26, 2024
@llllvvuu llllvvuu force-pushed the feat/speculative_decoding branch 4 times, most recently from fc4e076 to 4f91b16 Compare August 27, 2024 06:37
…server

This basic version only supports bs=1, temp=0, max_kv_size=None.
Supporting samplers, rotating cache, and batching are deferred to future
commits in order to keep this diff small.
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.

1 participant