[Refactor] Promote DFly to a first-class DFlash-family drafter and add an end-to-end multi-step TV loss - #13
Merged
Conversation
… + add e2e multi-step TV loss
yghstill
reviewed
Jul 31, 2026
| @@ -0,0 +1,130 @@ | |||
| # [Refactor] Promote DFly to a first-class DFlash-family drafter and add an end-to-end multi-step TV loss | |||
| "architectures": ["DSparkDraftModel"], | ||
| "model_type": "dspark", | ||
| "model_arch": "dfly", | ||
| "architectures": ["Qwen3DFlyModel"], |
Collaborator
There was a problem hiding this comment.
check下Hy3也使用Qwen3DFlyModel?
yghstill
approved these changes
Jul 31, 2026
ShiJunhan-arch
approved these changes
Jul 31, 2026
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
This PR promotes DFly from an architecture variant
that piggy-backed on the DSpark code path into a standalone, first-class member
of the DFlash drafter family. It gets its own config, model, training wrapper,
and trainer, and no longer depends on DSpark in any way.
Alongside the refactor, this PR:
treeflash_dspark_dflaredrafter and its test.dspark.pyand intodfly.py, where it now belongs.The net effect is a cleaner architecture graph (DFly no longer "rides" DSpark), less coupling between drafters, and a large reduction in DSpark's surface area.
Motivation
Previously, DFly was selected via
DSparkConfig+model_arch == "dfly"and wasdispatched through
DSparkTrainer/DSparkModel. This meant:alpha, etc.) that only DFly actually used.
autodispatch logic had brittle special-case branches keyed onmodel_archstring comparison.Making DFly a proper config/model/trainer triple removes the cross-routing,
makes the dispatch type-based, and lets each drafter own only what it needs.
Changes
New — DFly as a first-class drafter
angelspec/models/dfly.py(new):DFlyModeltraining wrapper. SubclassesDFlashModeland overrides_compute_draft_logitsto apply the optionalTreeFlash hidden-states correction (formula (1)) before the LM head.
angelspec/training/dfly_trainer.py(new):DFlyTrainer, a thin subclassof
DFlashTrainerthat only overrides the two model-build seams(
_build_draft_model/_build_training_wrapper). Reads thedflash_*hyperparameter namespace.
angelspec/models/draft/dfly.py: now defines its ownDFlyConfig(extends
DFlashConfig,model_type = "qwen3") and owns theHiddenStatesCorrectionmodule /build_hidden_correctionhelper (moved herefrom
dspark.py).DFlyDraftModel.config_classis nowDFlyConfig.Dispatch / registration
angelspec/models/draft/auto.py: registerDFlyConfig → DFlyDraftModeland architecture
"Qwen3DFlyModel" → DFlyConfig. Removed themodel_arch == "dfly"andmodel_arch == "dflare"(TreeFlash) special-casebranches.
angelspec/training/trainer_actor.py: add aDFlyConfigdispatch branch.Since both
DSparkConfigandDFlyConfigsubclassDFlashConfig, they arechecked before the
DFlashConfigbranch.angelspec/models/__init__.py/angelspec/models/draft/__init__.py:export
DFlyModel; drop theTreeflashDSparkDFlareDraftModelexport.DSpark slim-down
angelspec/models/draft/dspark.py: removed the hidden-states correction,PositionAdaptiveAlpha, position-adaptive Markov knobs, and relatedparameters — DSpark now only carries the Markov head and confidence head.
angelspec/models/dspark.py: corresponding wrapper cleanup.End-to-end multi-step TV loss
angelspec/models/dflash.py: add_compute_e2e_tv_loss, an independentγ-step MTP TV term added on top of the total loss (not mutually exclusive with
KL/LK), gated on
e2e_tv_loss_weight > 0and the presence of targetlast_hidden_states. Emitse2e_tv_lossinloss_components.angelspec/config/train_config.py: adddflash_e2e_tv_loss_weight(default
0.0, disabled) andDatasetConfig.num_proc(default64); removethe now-unused
dflash_kl_temperature,dflash_kl_topk_renormalize, anddflash_lk_temperature.Removals
angelspec/models/draft/treeflash_dspark_dflare.py(deleted).tests/test_treeflash.py(deleted).angelspec/config/dflare_dspark_treeflash_qwen3_4b_draft_config.json(deleted).Configs
angelspec/config/dfly_*_draft_config.json: switch fromarchitectures: ["DSparkDraftModel"]/model_type: "dspark"/model_arch: "dfly"toarchitectures: ["Qwen3DFlyModel"]/model_type: "qwen3"; drop the DSpark-onlymarkov_rank/enable_confidence_head/confidence_head_with_markovkeys.configs/vllm_qwen3_8b_dfly.yaml,configs/vllm_hy3_dfly.yaml: fixlm_head_keytolm_head.weight, migratedspark_*hyperparameters to thedflash_*namespace, and set up the two-stage loss schedule (cold-startlk-loss → final
e2e_tv_loss).Docs & tests
docs/concepts/dfly.md: document DFly as an independentDFlyConfig/Qwen3DFlyModel/DFlyTrainerdrafter; update the comparison table.docs/concepts/dspark.md,dflash.md,draft_model_family.md:minor updates reflecting the moved correction module and the new loss term.
tests/test_dfly.py: updated to build viaDFlyConfigand exercise theDFlyModelwrapper; asserts a plainDSparkConfigstill routes toDSparkDraftModel(no cross-routing).Compatibility / migration notes
architectures: ["DSparkDraftModel"]+model_arch: "dfly"must be migratedto
architectures: ["Qwen3DFlyModel"](see updateddfly_*_draft_config.json).dflash_kl_temperature/dflash_kl_topk_renormalize/dflash_lk_temperaturetraining args are no longer accepted.treeflash_dspark_dflareis gone; any references must be removed.Testing
tests/test_dfly.pycovers auto-dispatch, model structure (shared-KV layers,re-added
context_proj, inherited fusion), the zero-init identity of thehidden correction, a tiny forward through
DFlyModel(finite loss, correctloss_components, correction actually affects the loss), and state-dict keys.