Repository navigation
fix(cli): reject a DFlash drafter before the offline standalone load - #1170
Conversation
`mlxcel generate --draft-model <dflash-drafter>` failed with `Error: Weight not found: model.embed_tokens.weight`, with and without `--draft-kind`. The offline path calls `load_model` on the drafter directory because the classic `SpeculativeGenerator` it falls through to drives a full `LoadedModel`. A DFlash checkpoint is not one: it ships no `embed_tokens` and no `lm_head` (it borrows both from the target when it binds) and its tensors carry no `model.` prefix. Its `config.json` nevertheless declares an ordinary `"model_type": "qwen3"`, so `get_model_type` classified it as `ModelType::Qwen3`, `model_metadata` routed it to `Qwen3Model::load`, and the first `UnifiedEmbedding::from_weights` lookup failed. The same target and drafter pair works on `mlxcel-server`, which routes the drafter through `load_drafter`. The discriminator is structural, not the resolved drafter kind. `DEFAULT_DRAFTER_KIND` is `Dflash` and `drafter_kind_by_model_type` maps only the two Gemma 4 assistant types, so every drafter that is not a Gemma 4 assistant auto-resolves to `Dflash`, including an ordinary small full model used as a classic drafter. Rejecting on the resolved kind would break that legitimate, currently-working pairing. `is_dflash_drafter_config` / `is_dflash_drafter_dir` therefore key on the checkpoint's own DFlash markers: a nested `dflash_config` object (what `DFlashConfig::from_json` itself reads) and/or `architectures: ["DFlashDraftModel"]` (what HuggingFace `AutoModel` dispatch reads). Two entry points now share that probe. `get_model_type` rejects a DFlash directory before any `model_type` dispatch, so `mlxcel generate -m <dflash-dir>` reports "not a standalone model" instead of a weight-lookup failure, and so do server startup and the distributed stage loaders. `reject_dflash_drafter_offline` runs in `run_generation_mode` before `load_model`, so `--draft-model <dflash-dir>` names the directory as a DFlash drafter, says the offline path does not construct the `DFlashGenerator` round loop, and points at `mlxcel-server`. The server drafter path is untouched: `DFlashDrafter::load` parses `config.json` directly and `resolve_drafter_kind` peeks `model_type` through its own reader, so neither reaches `get_model_type`. Every `get_model_type` call site in the tree operates on a target or model path, never a drafter path. Validation: the offline `--draft-model` precheck, the `-m` detection rejection, and the structural probe are covered by new tests in `src/commands/generate_tests.rs`, `src/models/detection_tests.rs`, `src/lib/mlxcel-core/src/drafter/dflash/config.rs`, and `tests/speculative_dispatch.rs`, each with an ordinary-full-model control that must keep resolving. The DFlash row in `docs/supported-models.md` now states the server-only limitation instead of contradicting `docs/speculative-acceptance.md` by omission. Closes #1168
Implementation Review SummaryIntent
Findings AddressedNone requiring a fix. No CRITICAL or HIGH findings. The four items below are MEDIUM/LOW and are reported rather than fixed, so the branch stays at the already-validated Remaining Items
Also LOW, style only: the Blast radius of the detection changeAll 24 non-test The separation is structural, not just current practice: False-positive surface: every Verification performedBeyond the queued suites, all on Mutation test (are the new tests real?). Guarding the detection arm as End-to-end against the real published checkpoint (
Targeted suites, all green: Lints: Note for the record: Not measured: Verification
|
Security and performance reviewNo CRITICAL and no HIGH findings. Nothing auto-fixed, no commits pushed. Three MEDIUM and three LOW items below, all advisory. 1. Path handling in
|
`drafter_fixture_dir` in src/commands/generate_tests.rs built a predictable directory name under env::temp_dir() and created it with create_dir_all, which succeeds against a pre-existing directory or symlink there (CWE-377/379), and it cleaned up only on the success path, so an assertion failure leaked the fixture. This is CI-relevant on Linux where TMPDIR is shared across jobs. Replace it, and the identical inline pattern in the missing-config fixture two lines below it, with tempfile::tempdir(), which creates a securely-permissioned, randomly-named directory and removes it on drop regardless of how the test exits. This matches the pattern the mlxcel-core drafter::dflash::config tests added in this same PR already use, removing an inconsistency within the PR. Validation: - cargo test --release --bin mlxcel --features metal,accelerate commands::generate: 82 passed, including all four offline_draft_model_* precheck tests. - cargo fmt --check and cargo clippy --release --bin mlxcel --features metal,accelerate --tests -- -D warnings: clean. Refs #1170
This PR was missing the two documentation artifacts every other merged PR in this repository carries: a CHANGELOG.md entry under ## [Unreleased] / ### Fixed, and an English technical report under TECHNICAL_REPORTS/ (Korean translation intentionally skipped for this PR). The CHANGELOG entry summarizes the DFlash-drafter-offline-load rejection (#1168) and the discriminator choice (checkpoint structure, not resolved DrafterKind). The technical report additionally covers the M3 test-hygiene fix from this finalization pass (drafter_fixture_dir moved to tempfile::tempdir()) and the full validation record: the workspace test run, the separately-run --bin mlxcel precheck tests, clippy/fmt, the real-checkpoint classic-path non-regression run, and the mutation test confirming the new detection tests are not tautologies. Refs #1170
This repository pairs every TECHNICAL_REPORTS entry with an English and a Korean version; PR #1170's report was missing its Korean counterpart. Adds TECHNICAL_REPORTS/1170-dflash-drafter-cli-load-20260816.ko.md, written as Korean technical prose rather than a literal translation, following the section structure of the existing .ko.md reports (1157, 1158, 1150-1154). Also removes one stray em dash from the English report's Code Quality section, replacing it with a colon per this project's no-em-dash convention. Refs #1170
Orchestrator verification against real checkpointsRun on the development box at The reported symptom is gone, in all three entry shapesAll three now produce a named error, and
The server path is not regressed, measured rather than reasonedThis was the highest-risk item, since the fix adds a rejection inside An 80-token completion drove real speculative work: rounds 15, proposed_tokens 185, accepted_tokens 65, acceptance_rate 0.351, emitted_per_verify 5.27. Comparable to the pre-change reference recorded in #1168 (24 rounds, 0.274 acceptance on a 120-token completion); the two differ in completion length, not in behavior. Suite
All 3 failures are
Root cause is
|
…ablup#1170) ## Summary `mlxcel generate --draft-model <dflash-drafter>` failed with `Error: Weight not found: model.embed_tokens.weight`, with and without `--draft-kind`, for every DFlash drafter and every target. The offline path calls `load_model` on the drafter directory because the classic `SpeculativeGenerator` it falls through to drives a full `LoadedModel`, and a DFlash checkpoint is not one: it ships no `embed_tokens` and no `lm_head` because it borrows both from the target when it binds, and its tensors carry no `model.` prefix. Its `config.json` nevertheless declares an ordinary `"model_type": "qwen3"`, so `get_model_type` classified it `ModelType::Qwen3`, `model_metadata` routed it to `Qwen3Model::load`, and the first `UnifiedEmbedding::from_weights` lookup failed with a message naming a tensor rather than the problem. This PR makes both offline entry points fail where it makes sense, with a message that names the real problem, and corrects the docs that overstated CLI support. This deliberately does not build an offline DFlash round loop. That remains out of scope and is still described by the existing `--draft-kind` message in `generate.rs` and by `docs/speculative-acceptance.md`. ## The discriminator is structural, not the resolved drafter kind `DEFAULT_DRAFTER_KIND` is `DrafterKind::Dflash` and `drafter_kind_by_model_type()` maps only `gemma4_assistant` and `gemma4_unified_assistant`, so **every** drafter that is not a Gemma 4 assistant auto-resolves to `Dflash`, including an ordinary small full model (a Qwen3 0.6B, say) used as a classic drafter. That pairing loads and runs fine today on the classic `SpeculativeGenerator` path, so rejecting on the resolved kind would have broken a working workflow. The new probe keys on the checkpoint's own DFlash markers instead: a nested `dflash_config` object (what `DFlashConfig::from_json` itself reads) and/or `architectures: ["DFlashDraftModel"]` (what HuggingFace `AutoModel` dispatch reads). Every test added here carries an ordinary-full-model control asserting the classic path still resolves. ## The server path is unaffected `DFlashDrafter::load` reads `config.json` into `DFlashConfig::from_json` directly and `resolve_drafter_kind` peeks `model_type` through its own reader, so neither reaches `get_model_type`. Re-confirmed on this branch that every `get_model_type` call site in the tree takes a target or model path and never a drafter path (`src/loading/mod.rs`, `src/distributed/pipeline/stage_executor/mod.rs`, `src/distributed/tensor_parallel/inference.rs`, `src/server/chat_template.rs`, `src/server/startup.rs`, `src/server/model_provider.rs`, `src/server/batch/xla_worker.rs`, `src/multimodal/host_preprocessor.rs`, and the three target-path uses in `src/commands/generate.rs`). The drafter reaches `load_drafter` through `SpeculativeDispatch` and `DrafterSlot::ensure_loaded`, neither of which touches detection. `src/bin/speculative_bench.rs` likewise passes only the target to `load_model`. A new test in `tests/speculative_dispatch.rs` pins that `SpeculativeDispatch::resolve` still returns the DFlash variant for the same fixture directory that detection now rejects, with and without an explicit `--draft-kind`. For the record, the working reference this issue measured on `main` @ `6e781fcf` (Qwen 3.5 27B 4-bit target, which loads as `ModelType::Qwen35VLM`, plus the 27B DFlash drafter, 120-token completion): rounds 24, proposed_tokens 347, accepted_tokens 95, acceptance_rate 0.274, emitted_per_verify 4.96. That also backs the "VLM paths" claim the supported-models table makes for DFlash, which is why this PR keeps it. ## What changed - `src/lib/mlxcel-core/src/drafter/dflash/config.rs`: new `DFLASH_DRAFT_ARCHITECTURE` constant, `is_dflash_drafter_config(&Value)`, and `is_dflash_drafter_dir(&Path)`, placed next to the parser that consumes `dflash_config` so the structural definition lives with the loader that keys on it. The doc comment records why `model_type` and the resolved `DrafterKind` are both wrong discriminators. An unreadable or missing `config.json` returns `false` so the general loader keeps reporting its own I/O and parse diagnostics. - `src/lib/mlxcel-core/src/drafter/dflash/mod.rs`: re-exports the three new items. - `src/models/detection.rs`: `get_model_type` rejects a structurally-DFlash directory before any `model_type` dispatch, via a shared `dflash_drafter_not_standalone_error`. This is the single source of truth for the `-m` case and covers server startup and the distributed stage loaders at the same time. - `src/commands/generate.rs`: new `reject_dflash_drafter_offline`, called in `run_generation_mode` immediately before `load_model(draft_model_path)`. The error says the directory is a DFlash drafter, that the offline path does not construct the `DFlashGenerator` round loop, and that `mlxcel-server` with `--draft-kind dflash` does. It fires with no `--draft-kind` and with `--draft-kind dflash`; an explicit `--draft-kind mtp` is a different request that keeps its own targeted errors from `run_offline_mtp`. - `docs/supported-models.md`: the DFlash row now reads `mlxcel-server` only and explains that offline `mlxcel generate` rejects a DFlash drafter with a named error, so it no longer contradicts `docs/speculative-acceptance.md` by omission. The MTP row gained the matching detail that it does work offline under `--draft-kind mtp`. A following paragraph explains why a DFlash checkpoint is not a standalone model. - `docs/speculative-acceptance.md`: the "note on the drafter-kind line" section now distinguishes the auto-detected `dflash` fallback applied to an ordinary full model (which still runs the classic path) from a real DFlash drafter (which is now refused up front), and records the structural discriminator. - `src/commands/generate_tests.rs` (finalization pass, security finding M3): `drafter_fixture_dir` and the identical inline `empty`-fixture pattern built a predictable path under `env::temp_dir()` with `create_dir_all` and cleaned up only on the success path (CWE-377/379 class, CI-relevant on shared-`TMPDIR` Linux runners). Both now use `tempfile::tempdir()`, matching the pattern the `mlxcel-core` tests added in this PR already use. - `CHANGELOG.md`, `TECHNICAL_REPORTS/1170-dflash-drafter-cli-load-20260816.en.md` (finalization pass): the `## [Unreleased]` entry and technical report this repository's convention expects for every merged PR. ## Test plan New coverage, all on synthetic fixtures. No test previously invoked `mlxcel generate --draft-model` at any level, which is why a path that could never work for any DFlash drafter stayed green. All of the below has now actually been executed (by the orchestrator and by review), not just written. - [x] `cargo test --release --workspace --features metal,accelerate --no-fail-fast`: every target passes except `-p mlxcel --lib`, which reports 5621 passed / 3 failed. All 3 failures are `multimodal::video::tests::*` and are unrelated to this PR: this branch touches 0 lines of `src/multimodal/video.rs`, and a PATH-controlled experiment on the same binary gives 34 passed / 0 failed with ffmpeg hidden from `PATH` versus 31 passed / 3 failed with ffmpeg 9.0.1 present. Root cause is `src/multimodal/video.rs:1123` passing `-vsync`, an argument ffmpeg 9 removed. Filed as lablup#1172. - [x] Gotcha for the next person: the four new `commands::generate::tests::*` precheck tests compile into `--bin mlxcel`, not `--lib`, so they were **not** part of the `--lib` run above. They were run separately with `cargo test --release --bin mlxcel --features metal,accelerate commands::generate`: 4 passed. - [x] `cargo clippy -- -D warnings` clean on both crates (`mlxcel`, `mlxcel-core`). - [x] `cargo fmt --check` clean. - [x] Classic-path non-regression, executed rather than reasoned about: `-m qwen3-0.6b-4bit --draft-model qwen3-0.6b-4bit` still runs `SpeculativeGenerator` end to end, 24 tokens, acceptance_rate 1.0000, 137.54 tok/s. - [x] Mutation test confirming the new detection tests are real assertions, not tautologies: guarding the new arm as `if false && ...` makes `models::detection` and `commands::generate` fail with the pre-fix classification, on both markers. Not verified here: an end-to-end run of `mlxcel generate --draft-model models/qwen3.5-27b-dflash` against a real 27B target. The change is a pre-load guard, so the reproduction is a one-line error rather than a load, but that confirmation has not been re-run on this branch. ## Known limitations Reported and deliberately not fixed in this PR: - The precheck fires only after the target model finishes loading, so an operator with a large target waits through the full load before seeing the error. Moving the check earlier would also intercept `--draft-kind mtp`, which is deliberately routed elsewhere and must keep its own targeted errors from `run_offline_mtp`. - `--draft-model <dir>/config.json` (pointing directly at the config file rather than the directory) bypasses the precheck and falls through to the detection error with `-m` phrasing, because the precheck does not apply `resolve_model_dir` the way the rest of the loading path does. - The probe uses raw `serde_json::from_slice` on `config.json`, while `get_model_type` applies `sanitize_config_json` first. A config containing bare `NaN`/`Infinity` literals (invalid JSON, but occasionally emitted by some tooling) would therefore fail the precheck open. No current checkpoint is affected, and the sanitizer lives in the root crate while the probe lives in `mlxcel-core`, so closing this gap is a cross-crate change left for later. Closes lablup#1168
Summary
mlxcel generate --draft-model <dflash-drafter>failed withError: Weight not found: model.embed_tokens.weight, with and without--draft-kind, for every DFlash drafter and every target. The offline path callsload_modelon the drafter directory because the classicSpeculativeGeneratorit falls through to drives a fullLoadedModel, and a DFlash checkpoint is not one: it ships noembed_tokensand nolm_headbecause it borrows both from the target when it binds, and its tensors carry nomodel.prefix. Itsconfig.jsonnevertheless declares an ordinary"model_type": "qwen3", soget_model_typeclassified itModelType::Qwen3,model_metadatarouted it toQwen3Model::load, and the firstUnifiedEmbedding::from_weightslookup failed with a message naming a tensor rather than the problem. This PR makes both offline entry points fail where it makes sense, with a message that names the real problem, and corrects the docs that overstated CLI support.This deliberately does not build an offline DFlash round loop. That remains out of scope and is still described by the existing
--draft-kindmessage ingenerate.rsand bydocs/speculative-acceptance.md.The discriminator is structural, not the resolved drafter kind
DEFAULT_DRAFTER_KINDisDrafterKind::Dflashanddrafter_kind_by_model_type()maps onlygemma4_assistantandgemma4_unified_assistant, so every drafter that is not a Gemma 4 assistant auto-resolves toDflash, including an ordinary small full model (a Qwen3 0.6B, say) used as a classic drafter. That pairing loads and runs fine today on the classicSpeculativeGeneratorpath, so rejecting on the resolved kind would have broken a working workflow. The new probe keys on the checkpoint's own DFlash markers instead: a nesteddflash_configobject (whatDFlashConfig::from_jsonitself reads) and/orarchitectures: ["DFlashDraftModel"](what HuggingFaceAutoModeldispatch reads). Every test added here carries an ordinary-full-model control asserting the classic path still resolves.The server path is unaffected
DFlashDrafter::loadreadsconfig.jsonintoDFlashConfig::from_jsondirectly andresolve_drafter_kindpeeksmodel_typethrough its own reader, so neither reachesget_model_type. Re-confirmed on this branch that everyget_model_typecall site in the tree takes a target or model path and never a drafter path (src/loading/mod.rs,src/distributed/pipeline/stage_executor/mod.rs,src/distributed/tensor_parallel/inference.rs,src/server/chat_template.rs,src/server/startup.rs,src/server/model_provider.rs,src/server/batch/xla_worker.rs,src/multimodal/host_preprocessor.rs, and the three target-path uses insrc/commands/generate.rs). The drafter reachesload_drafterthroughSpeculativeDispatchandDrafterSlot::ensure_loaded, neither of which touches detection.src/bin/speculative_bench.rslikewise passes only the target toload_model. A new test intests/speculative_dispatch.rspins thatSpeculativeDispatch::resolvestill returns the DFlash variant for the same fixture directory that detection now rejects, with and without an explicit--draft-kind.For the record, the working reference this issue measured on
main@6e781fcf(Qwen 3.5 27B 4-bit target, which loads asModelType::Qwen35VLM, plus the 27B DFlash drafter, 120-token completion): rounds 24, proposed_tokens 347, accepted_tokens 95, acceptance_rate 0.274, emitted_per_verify 4.96. That also backs the "VLM paths" claim the supported-models table makes for DFlash, which is why this PR keeps it.What changed
src/lib/mlxcel-core/src/drafter/dflash/config.rs: newDFLASH_DRAFT_ARCHITECTUREconstant,is_dflash_drafter_config(&Value), andis_dflash_drafter_dir(&Path), placed next to the parser that consumesdflash_configso the structural definition lives with the loader that keys on it. The doc comment records whymodel_typeand the resolvedDrafterKindare both wrong discriminators. An unreadable or missingconfig.jsonreturnsfalseso the general loader keeps reporting its own I/O and parse diagnostics.src/lib/mlxcel-core/src/drafter/dflash/mod.rs: re-exports the three new items.src/models/detection.rs:get_model_typerejects a structurally-DFlash directory before anymodel_typedispatch, via a shareddflash_drafter_not_standalone_error. This is the single source of truth for the-mcase and covers server startup and the distributed stage loaders at the same time.src/commands/generate.rs: newreject_dflash_drafter_offline, called inrun_generation_modeimmediately beforeload_model(draft_model_path). The error says the directory is a DFlash drafter, that the offline path does not construct theDFlashGeneratorround loop, and thatmlxcel-serverwith--draft-kind dflashdoes. It fires with no--draft-kindand with--draft-kind dflash; an explicit--draft-kind mtpis a different request that keeps its own targeted errors fromrun_offline_mtp.docs/supported-models.md: the DFlash row now readsmlxcel-serveronly and explains that offlinemlxcel generaterejects a DFlash drafter with a named error, so it no longer contradictsdocs/speculative-acceptance.mdby omission. The MTP row gained the matching detail that it does work offline under--draft-kind mtp. A following paragraph explains why a DFlash checkpoint is not a standalone model.docs/speculative-acceptance.md: the "note on the drafter-kind line" section now distinguishes the auto-detecteddflashfallback applied to an ordinary full model (which still runs the classic path) from a real DFlash drafter (which is now refused up front), and records the structural discriminator.src/commands/generate_tests.rs(finalization pass, security finding M3):drafter_fixture_dirand the identical inlineempty-fixture pattern built a predictable path underenv::temp_dir()withcreate_dir_alland cleaned up only on the success path (CWE-377/379 class, CI-relevant on shared-TMPDIRLinux runners). Both now usetempfile::tempdir(), matching the pattern themlxcel-coretests added in this PR already use.CHANGELOG.md,TECHNICAL_REPORTS/1170-dflash-drafter-cli-load-20260816.en.md(finalization pass): the## [Unreleased]entry and technical report this repository's convention expects for every merged PR.Test plan
New coverage, all on synthetic fixtures. No test previously invoked
mlxcel generate --draft-modelat any level, which is why a path that could never work for any DFlash drafter stayed green. All of the below has now actually been executed (by the orchestrator and by review), not just written.cargo test --release --workspace --features metal,accelerate --no-fail-fast: every target passes except-p mlxcel --lib, which reports 5621 passed / 3 failed. All 3 failures aremultimodal::video::tests::*and are unrelated to this PR: this branch touches 0 lines ofsrc/multimodal/video.rs, and a PATH-controlled experiment on the same binary gives 34 passed / 0 failed with ffmpeg hidden fromPATHversus 31 passed / 3 failed with ffmpeg 9.0.1 present. Root cause issrc/multimodal/video.rs:1123passing-vsync, an argument ffmpeg 9 removed. Filed as fix(video): every video path is broken on ffmpeg 8+ because -vsync was removed, and the tests hide it by passing when ffmpeg is absent #1172.commands::generate::tests::*precheck tests compile into--bin mlxcel, not--lib, so they were not part of the--librun above. They were run separately withcargo test --release --bin mlxcel --features metal,accelerate commands::generate: 4 passed.cargo clippy -- -D warningsclean on both crates (mlxcel,mlxcel-core).cargo fmt --checkclean.-m qwen3-0.6b-4bit --draft-model qwen3-0.6b-4bitstill runsSpeculativeGeneratorend to end, 24 tokens, acceptance_rate 1.0000, 137.54 tok/s.if false && ...makesmodels::detectionandcommands::generatefail with the pre-fix classification, on both markers.Not verified here: an end-to-end run of
mlxcel generate --draft-model models/qwen3.5-27b-dflashagainst a real 27B target. The change is a pre-load guard, so the reproduction is a one-line error rather than a load, but that confirmation has not been re-run on this branch.Known limitations
Reported and deliberately not fixed in this PR:
--draft-kind mtp, which is deliberately routed elsewhere and must keep its own targeted errors fromrun_offline_mtp.--draft-model <dir>/config.json(pointing directly at the config file rather than the directory) bypasses the precheck and falls through to the detection error with-mphrasing, because the precheck does not applyresolve_model_dirthe way the rest of the loading path does.serde_json::from_sliceonconfig.json, whileget_model_typeappliessanitize_config_jsonfirst. A config containing bareNaN/Infinityliterals (invalid JSON, but occasionally emitted by some tooling) would therefore fail the precheck open. No current checkpoint is affected, and the sanitizer lives in the root crate while the probe lives inmlxcel-core, so closing this gap is a cross-crate change left for later.Closes #1168