Skip to content

Match mlx-vlm Gemma 4 prefill logits - #361

Merged
samir-lms merged 1 commit into
mainfrom
samir/gemma4-fix
Aug 6, 2026
Merged

samir-lms merged 1 commit into
mainfrom
samir/gemma4-fix

Conversation

@samir-lms

@samir-lms samir-lms commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Align mlx-engine’s batched VLM generation path with the opt-in logits_to_keep=1 contract introduced by mlx-vlm 0.6.11.
  • Forward the option during chunked prefill, final prefill, and decode whenever the model advertises supports_logits_to_keep.
  • For Gemma 4, this limits the vocabulary projection to the final token instead of computing and then discarding logits for the entire prompt.
  • This preserves generation parity with mlx-vlm while reducing prefill memory use and unnecessary LM-head computation.
  • Add focused coverage verifying that all three batched generation stages forward the option.

Validation

  • Focused batched vision/routing suite: 125 passed
  • Pre-commit: ruff and ruff-format passed

Performance

Using gemma-4-E2B-it-MLX-4bit on an M5 Max:

  • 512-token prefill: 199 MiB lower peak memory and 15.6% faster.
  • 2,048-token unchunked prefill: 811 MiB lower peak memory and 10.5% faster.
  • Logits allocation dropped from 256 MiB / 1 GiB to 0.5 MiB.
  • Decode performance remained unchanged at approximately 116 tokens/sec.
  • Results are medians from five warmed prefill runs; decode used four alternating 250-token runs per configuration.

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@samir-lms
samir-lms marked this pull request as ready for review August 5, 2026 21:39
@samir-lms

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-08-05 at 5 48 00 PM

@github-actions github-actions Bot added the CLA signed Indicates that all contributors have signed label Aug 5, 2026
@samir-lms
samir-lms merged commit 3abfcbf into main Aug 6, 2026
3 of 5 checks passed
@samir-lms
samir-lms deleted the samir/gemma4-fix branch August 6, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA signed Indicates that all contributors have signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants