Repository navigation
fix(inference): evaluate embedding prefill logits before after_prefill - #2489
Merged
inureyes merged 1 commit intoOct 20, 2026
Merged
Conversation
Two defects found while mapping the CLI and server decode paths (lablup#2177). Epic lablup#2166 retired CxxGenerator after the issue was filed, so both are fixed against the engine that replaced it. 1. after_prefill ordering. LanguageModel::after_prefill may replace weight arrays the lazy prefill graph still references, so the prefill logits must be evaluated before it runs. Engine::prefill, now the only caller, ran the hook after an eval only when the caller set PrefillStep::eval; every embedding caller passes true today, but the order lived at each call site. Engine::prefill now always evaluates an embedding piece's logits before the hook, whatever `eval` says, and reports that eval in PrefillOutcome::eval. Text pieces are unchanged: the terminal piece's eval stays with the first sample. No family overrides the hook, so output does not change. 2. Comments that misdescribe the CLI/server split. Most sites the issue lists were rewritten or removed by the epic. The remaining ones are corrected: --no-batch runs the same BatchScheduler at max_batch_size=1 (docs/CONTINUOUS_BATCHING.md, ServerConfig::no_batch, ModelProvider::new_with_server_config), the Classic speculative arm declines to plain decode and drafts nothing (speculative_dispatch.rs), and the CLI dispatch reference names run_generation_mode instead of stale line numbers. Comment-only. Tests in engine/after_prefill_tests.rs use a recording stub model that overrides after_prefill: an embedding prefill with eval off still evaluates (its failing logits surface in PrefillOutcome::eval; this test fails on main), a text prefill neither forces the eval nor runs the hook, and both session embedding variants (generate_streaming_with_embeddings and generate_with_stats_and_embeddings) run the hook exactly once, between the prefill forward and the first decode forward. Closes lablup#2177
Member
Implementation hardeningReviewed PR #2489 against issue #2177, including the replacement of CxxGenerator by the shared engine. The engine owns embedding-logit evaluation before the after-prefill hook, and both session entry points use that path. No additional code fix is required.
|
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.
Summary
Fixes what is left of the two decode-path defects in #2177 after epic #2166 retired
CxxGenerator(#2225), in the code that replaced it:Engine::prefillnow always evaluates an embedding (VLM) prefill's logits before runningLanguageModel::after_prefill, instead of relying on every caller to setPrefillStep::eval. The hook may replace weight arrays the lazy prefill graph still references.--no-batchas bypassing the scheduler, or a "classic generator" speculative path, now match the unified engine.Related issues
Closes #2177
Type of change
fix— bug fixTest plan
src/lib/mlxcel-core/src/engine/after_prefill_tests.rs(stub model that records every forward andafter_prefillcall):embedding_prefill_evaluates_its_logits_even_with_eval_offfails onmain(verified by revertingprefill.rs) and passes with the fix; plus text prefill keeps the eval deferred and skips the hook, both session embedding entry points (plain and--profile) run the hook exactly once between the prefill forward and the first decode forward with identical tokens, and text generation never runs the hookcargo test --profile test-fast -p mlxcel-core --libfiltersafter_prefill(4),engine::(68),session(13),generate(52): all pass on both the CPU backend and Metalcargo clippy -p mlxcel-core --lib --tests -- -D warningsandcargo clippy -p mlxcel --lib --tests -- -D warnings(Metal build): cleancargo fmt --all -- --checkmlx-community/Qwen2-VL-2B-Instruct-4bit,mlxcel generate --image <img> --temp 0 -n 64, with and without--profile, fixed binary vs a baseline withprefill.rsfrommain: identical output text on two images in all four runsmake verify, CUDA gate, server image path end to end: not run (the server's embedding prefill already passedeval: true, so its behavior does not change)Notes for reviewers
let eval = if step.eval || step.embeddings.is_some(). Today all three embedding callers (DirectEngine::prefill_embeddingsand the scheduler'srun_embedding_prefill) already passeval: trueand no family overridesafter_prefill, so output does not change; this moves the ordering guarantee into the one function that calls the hook.Engine::prefill.docs/CONTINUOUS_BATCHING.md(--no-batchruns the same scheduler atmax_batch_size=1),ServerConfig::no_batch,ModelProvider::new_with_server_config, andspeculative_dispatch.rs(now namesrun_generation_mode, drops stale CLI line numbers).// Used by:docs updated onEngine::prefill,PrefillStep::evalandLanguageModel::after_prefill.src/server/model_provider.rsstill says--no-batch bypasses the batch scheduler; the issue scoped this part to comments, so it is left for a follow-up.Checklist
docs/// Used by: ...comments on shared functions modified.envfiles committed