Skip to content

feat: configurable prefill step size for SimpleEngine#174

Closed
Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Thump604:feat/configurable-prefill-step-size
Closed

feat: configurable prefill step size for SimpleEngine#174
Thump604 wants to merge 2 commits intowaybarrios:mainfrom
Thump604:feat/configurable-prefill-step-size

Conversation

@Thump604
Copy link
Copy Markdown
Collaborator

@Thump604 Thump604 commented Mar 17, 2026

Add --prefill-step-size CLI flag to configure chunk size for prompt prefill (default 2048).

Why: mlx-lm MTP default is 512. Increasing to 2048 gives +22% prefill throughput on 122B models. Configurable for tuning on different hardware.

Files: cli.py, engine/simple.py

Test:

# Start with --prefill-step-size 2048
# Compare TTFT on a 16K prompt vs --prefill-step-size 512

When both --mllm and --enable-mtp are set, SimpleEngine builds a
parallel mlx_lm TextModel sharing the VLM backbone weights (zero-copy).
Text-only requests route to mlx_lm with MTP speculative decoding;
media requests route to the mlx_vlm MLLM path.

Key components:
- text_model_from_vlm.py: Build mlx_lm TextModel from VLM weights
- Per-request routing in stream_chat() via _has_media_content()
- _stream_generate_text() for MTP-accelerated text generation
- MTP passthrough: --enable-mtp flag through CLI/server/engine/LLM

Tested on Qwen3.5-35B-A3B VLM+MTP (8-bit):
- Text (MTP): 65.3 tok/s
- Vision (MLLM): 63.8 tok/s
- Memory: 38.7 GB (zero-copy, same as single model)
Add --prefill-step-size CLI flag (default: 2048) to control the chunk
size used during prompt prefill. mlx-lm defaults MTP to 512 which is
overly conservative — benchmarks on M2 Ultra show 512→2048 gives +22-25%
prefill throughput with negligible memory increase.

Thread the value through cli → server.load_model → SimpleEngine →
MLXLanguageModel → mlx_lm.stream_generate(), covering both the direct
LLM path and the MLLM+MTP text-routing path.
@Thump604
Copy link
Copy Markdown
Collaborator Author

Superseded — configurable prefill step size merged upstream via PR #180.

@Thump604 Thump604 closed this Mar 22, 2026
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