Skip to content

Add DFlash fused-target export pipeline (two-function drafter export + structural-metadata validation) - #272

Open
stikves wants to merge 8 commits into
apple:mainfrom
stikves:sukru/dflash-fused-export
Open

stikves wants to merge 8 commits into
apple:mainfrom
stikves:sukru/dflash-fused-export

Conversation

@stikves

@stikves stikves commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

What

Adds a --fused-target export option for the Muse Glimmer DFlash drafter, plus the --dflash-drafter two-function drafter export and structural-metadata validation.

  • Fused target (--fused-target): exports the 2-output MuseGlimmerForCausalLMWithDrafter graph emitting (logits, drafter_features) in one model. Adds tuple/list-aware bf16 to fp16 logits casting in BaseForCausalLM.
  • DFlash drafter (--dflash-drafter): exports the two-entrypoint drafter nn.Module: inject_kv (writes target features into a shared ring-KV cache) and draft (reads them back and produces draft logits) — with per-layer mmap offload during export. Requires --fused-target; mutually exclusive with the ring --with-drafter.
  • Structural metadata validation: the drafter's own config is captured and validated against the target, and the speculative block in metadata.json is sourced explicitly from it (raises on divergence) rather than inferred.

Why

The DFlash drafter has a custom architecture: the inputs to 5 of the target model's layers are shared with the drafter. Exporting the target and drafter as separate models means copying that shared data between them by hand, or wiring their States together, which the current API makes awkward. --fused-target avoids the separate data paths by fusing the target and drafter into one graph with two heads, logits and drafter_features, so the shared features flow through directly.

Scope

This PR covers the export path only. The new CLI flags default off, so nothing changes unless you opt in. The Swift DFlashDrafter engine, the speculative decoder cycle, and target integration come in separate later PRs, and this change makes no throughput claim on its own. It sits on top of the merged muse_glimmer drafter (#228), keeps that PR's bidirectional / no-embed-norm draft semantics, and does not regress it.

Tests

test_dflash.py + test_stage2_fused_export.py, 33 passing. They cover the two-graph export contract, torch.export tracing of both entrypoints, the tuple-aware logits cast, speculative-metadata merge/validation, and a fused-target check that drafter_features equals the target's hidden state at the configured layers. All run on tiny configs without the 55GB model. ruff clean.

@stikves
stikves marked this pull request as draft September 21, 2026 21:41
@stikves
stikves force-pushed the sukru/dflash-fused-export branch from 6a02190 to a806a06 Compare September 21, 2026 21:44
@stikves
stikves force-pushed the sukru/dflash-fused-export branch from a806a06 to eee61c2 Compare September 21, 2026 22:21
@stikves stikves self-assigned this Sep 22, 2026
@stikves
stikves marked this pull request as ready for review September 22, 2026 00:42
Comment thread python/src/coreai_models/export/bundle.py Outdated
Comment thread python/src/coreai_models/export/macos.py Outdated
stikves and others added 3 commits September 22, 2026 10:59
Rename _speculative_metadata to _speculative_decoding_metadata in
bundle.py and update all call sites, plus the comment references in
pipeline.py and the tests. Also trim the future-fallback paragraph
from the add_pytorch_module rationale comment in macos.py.
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.

2 participants