DFly2 – Tencent HunYuan's Open-Source Draft Model
Executive Summary:
DFly2 is a new-generation draft model open-sourced by Tencent HunYuan, specifically designed for DSA (Dense-Sparse-Attention) sparse attention large models and long-context reasoning scenarios. As an ...
1. What is DFly2
DFly2 is a new-generation draft model open-sourced by Tencent HunYuan, specifically designed for DSA (Dense-Sparse-Attention) sparse attention large models and long-context reasoning scenarios. As an acceleration component of Hy4 flash, DFly2 speeds up text generation through a speculative sampling mechanism: the draft layer directly reuses the KV cache and sparse indices of the target model, ensuring that the attention computation cost does not increase with the length of the context, and without any additional GPU memory consumption. Combined with a lightweight correction head and an online distillation training approach that eliminates the need for rollout, DFly2 significantly improves the token generation speed in long-document and Agentic scenarios, without altering the model weights or outputs. In single-item testing, it can achieve a maximum speedup of 4.2 times.
Technical Positioning and Domain: DFly2 belongs to the domain of large language model inference acceleration, specifically focusing on the speculative decoding (Speculative Sampling) technique. Its core positioning is as a dedicated draft network for sparse attention models, utilizing a parallel verification mechanism of "guess first, then validate" to reduce decoding latency without changing the output of the target model. This solution is aimed at long-context and multi-turn Agent tasks, filling the gap of lacking an efficient draft model under the sparse attention architecture.
Development Background: DFly2 was developed by the Tencent HunYuan large model team, leveraging their technical expertise in the DSA (Dense-Sparse-Attention) sparse attention architecture. Previously, the team had open-sourced the DSA attention mechanism and the Hy4 flash model. DFly2 is a complementary component of the same technical stack, aiming to address the high-latency bottleneck during the decoding phase in long-context scenarios, reflecting Tencent's ongoing investment in optimizing inference efficiency.
Core Value: DFly2 resolves issues such as incompatibility between the draft layer and the target model's KV cache, high GPU memory consumption, and limited attention span in speculative sampling for sparse attention models. Through the KV Share and Index Share mechanisms, the draft layer achieves a global attention span with minimal computational cost, significantly increasing the receptive field length. The DFly-OPD training approach reduces the training overhead compared to traditional Draft-OPD by eliminating the need for full rollout, requiring only one additional forward pass beyond standard SFT (Supervised Fine-Tuning), thereby lowering the engineering implementation threshold.
Technical Features: On the inference side, the draft layer focuses on up to 2,048 key positions, with attention complexity independent of context length, and zero additional KV memory usage. On the training side, DFly-OPD ensures consistent training and inference distributions, and with the AngelSpec infrastructure, supports efficient training at a 256K context scale. Overall, the solution achieves a balanced performance in terms of computational cost, memory usage, and inference speed.
2. Key Features
Speculative Sampling Acceleration: As an external draft model for Hy4 flash, DFly2 employs the speculative sampling paradigm of "guess first, then batch verify." The draft layer generates candidate token sequences first, which are then verified in parallel by the target model. Under the condition that the model weights and outputs remain unchanged, this approach doubles the token generation speed, with real-world testing showing a maximum speedup of 4.2 times for individual tasks.
Direct KV Cache Reuse: Each draft layer in DFly2 directly reads the KV cache from the target model, eliminating the need for separate GPU memory management for the drafter. This mechanism removes the GPU memory contention traditionally seen between the draft model and the target model, resulting in total GPU memory usage equivalent to that of deploying the target model alone.
Global Attention with Fixed Overhead: The draft layer focuses only on up to 2,048 key positions selected by the indexer from the full text. The attention overhead is fixed and independent of the context length. Compared to sliding window attention, this method does not miss critical information from distant parts of the text, achieving a balance between global context and computational cost.
Hidden State Correction Mechanism: To address the lack of direct prediction signals after reusing the KV cache, DFly2 introduces a lightweight Hidden Correction head. It corrects the current prediction bit by bit using the previous token. Additionally, the hidden state from the last layer of the target model is injected at the beginning of the draft block, providing the draft with the most direct prediction basis and ensuring accurate token reception.
Agentic Task Optimization: Specifically optimized for multi-turn Agent and real-world task scenarios (such as WorkBuddy), DFly2 significantly outperforms similar solutions in terms of token reception length, achieving a maximum improvement of 68.5%. When combined with the acceleration of Hy4 flash, the measured speedup on the agentlongbench benchmark reaches 4.20 times.
PD Separation Deployment Compatibility: DFly2 does not participate in the prefill phase and directly reuses the main model's cache. During the P→D phase, only one final hidden state is additionally transmitted, reducing both transmission and GPU memory costs. End-to-end throughput is 26% higher than the MTP approach, making it well-suited for large-scale production deployment.
DFly-OPD Lightweight Online Distillation: During training, the drafter receives scoring from the target model on its own candidate sequences, aligning the training distribution with inference. Compared to Draft-OPD, this approach eliminates the need for full rollout, requiring only one additional forward pass of the target model beyond standard SFT training. The training overhead is extremely low, supporting context sizes up to 256K.
3. Application Scenarios
Multi-page Contract Review: Lawyers can input an entire M&A contract into Hy4 flash at once, and DFly2 significantly increases the speed of generating risk analysis and modification suggestions for each clause. In long document scenarios, the model no longer stutters, greatly reducing waiting time for contract reviews and improving workflow efficiency.
Codebase-level Refactoring: When developers input an entire codebase for batch interface modifications, DFly2 maintains a speed improvement of approximately 3.2 times even under 128K-level context. When dealing with tens of thousands of lines of code, the model still retains a high reception length, significantly shortening the waiting time for code changes.
Multi-round Agent Automation: When an Agent performs continuous tasks such as data organization and form filling over dozens of steps, each round of output depends on the model's decoding speed. DFly2 enables faster output at each step, significantly reducing end-to-end latency across the entire task chain and improving the overall throughput of automated office workflows.
Ultra-long Report and Paper Writing: When researchers generate in-depth reports of tens of thousands of words based on dozens of reference documents, DFly2's acceleration advantage becomes more pronounced with longer context. The reception length improvement expands from about 4% for short texts to approximately 18% under 128K context, ensuring that the writing process for long texts no longer gets interrupted by slow model decoding.
Large-scale Knowledge Base Q&A: Enterprise-level Q&A systems require handling retrieval results from knowledge bases with millions of tokens. DFly2's fixed attention overhead ensures that model performance does not degrade as context grows, maintaining a smooth Q&A experience.
4. How to Use
Obtain model weights: Visit the AngelSlim repository on HuggingFace (https://huggingface.co/collections/AngelSlim/angelspec), download the DFly2 draft model weight files that have been open-sourced alongside Hy4 / Hy4 flash. Ensure that the downloaded version matches the target model.
Deploy the target model: Deploy the main Hy4 flash model using standard methods, without modifying the model weights or output logic. DFly2's integration is transparent to the existing inference pipeline and can be directly mounted on the current deployment. It is recommended to use a Python 3.8+ environment and install inference frameworks such as Transformers and vLLM.
Mount the draft model: Load DFly2 as the drafter for speculative sampling in the inference configuration. During inference, the KV cache and sparse indices from the main model will be directly reused during the Decode phase, without additional GPU memory consumption. You must specify the draft model path in the launch parameters and enable the speculative sampling switch.
Verify acceleration effect: Run tests on long-context tasks such as long documents, code repositories, or multi-turn Agents. Compare the throughput differences when DFly2 is enabled versus disabled. The longer the context, the more pronounced the acceptance length and throughput improvements will be. Measured results show a maximum acceleration of up to 4.2 times. You can adjust the context window size by combining it with the
--max-model-lenparameter.(Optional) Custom Training: If you need to customize the draft model, use the full training code integrated in the Tencent/AngelSpec repository on GitHub, which employs the DFly-OPD lightweight online distillation approach. The separation of inference and training architectures supports a context scale of up to 256K. During training, you must prepare data formats and tokenizers that are consistent with the target model.
Performance Monitoring and Optimization: After deployment, monitor three key metrics: acceptance length, acceleration ratio, and GPU memory usage. If the acceleration effect does not meet expectations, adjust hyperparameters such as the draft model's sampling temperature and candidate sequence length to achieve a balance between acceptance rate and computational cost.
5. Pros and Cons Analysis
| Pros |
|---|
| Significant acceleration: Achieves average speedups of about 12% for long texts and 30% for Agentic scenarios, with a maximum single-item speedup of 4.2x, maintaining approximately 3.2x acceleration even in 128K long contexts. |
| Zero additional GPU memory overhead: Shares the KV cache and sparse index of the target model directly, eliminating the need for separate GPU memory management for the draft model, thereby reducing memory contention. |
| Fixed attention cost: Each draft token attends to at most about 2K keys, with attention complexity independent of context length, ensuring stable inference performance in long contexts. |
| Low training cost: DFly-OPD eliminates the need for rollout; training only requires one additional forward pass of the target model compared to SFT, and AngelSpec supports hidden state disk saving and reuse for large-scale training. |
| Consistent training and inference distribution: Draft candidates are scored by the target model, aligning training and inference distributions and avoiding performance degradation caused by inconsistency in traditional approaches. |
6. Comparative Analysis with Similar Tools
| Comparison Dimension | DFly2 (Tencent HunYuan) | DSpark (Popular Open-Source Solution) | MTP (Multi-Token Prediction) |
|---|---|---|---|
| Core Architecture | Based on DSA sparse attention, the drafter layer reuses the target model's KV cache and sparse indices | General-purpose draft model, requires independent maintenance of KV cache | Expands the head of the target model, predicting multiple subsequent tokens simultaneously |
| KV Memory Overhead | Zero additional memory, directly shares the target model's cache | Requires separate KV cache maintenance for the drafter, competing with the main model for memory | Shares the main model's KV, but computational complexity increases with prediction depth |
| Attention Span | At most focuses on 2,048 key positions selected by the indexer, with a global view and fixed cost | Full attention is costly, sliding window misses distant key information | Based on full attention, computational cost increases with longer context |
| Performance in Long-Text Scenarios | 18% higher reception length than DSpark under 128K, maintaining about 3.2× acceleration | Reception length significantly decreases as context length increases | High training and inference complexity in long contexts, with faster acceleration decay |
| Agentic Scenarios | Reception length improves by up to 68.5%, achieving 4.20× acceleration on agentlongbench | Benchmark level, no specialized optimization | Limited acceleration gains in long-chain, multi-turn tasks |
| Training Approach | DFly-OPD avoids rollout, requiring only one additional forward pass of the target model compared to SFT | Traditional Draft-style training, requiring a complete rollout process | Complex training objectives, requiring multi-token joint loss design |
| PD Separation Deployment | Does not participate in prefill, P→D only transmits one additional final hidden state, achieving 26% higher throughput than MTP | Requires additional computation and transmission of cache | Requires transmission of multi-head intermediate states, with higher transmission overhead |
| Open-Source License | Open-source, weights and code hosted on HuggingFace and GitHub | Open-source, license depends on specific repository | Licenses vary across implementations, need to be confirmed individually |
Selection Recommendations: For teams currently using or planning to adopt the DSA sparse attention architecture (especially Hy4 flash), DFly2 is the preferred solution. Its zero additional memory usage and fixed computational cost provide clear deployment advantages in large-scale production environments, with significant acceleration benefits in long-context and agentic scenarios. However, note that this solution is tightly integrated with the DSA architecture, and reconfiguration is required for migration to other models.
For inference optimization needs based on traditional full-attention models, MTP and EAGLE are more general-purpose options. If the team already has the corresponding infrastructure and prioritizes deployment simplicity, general-purpose draft models like DSpark offer a more mature integration path. If the goal is to achieve maximum end-to-end throughput and the team has the engineering optimization capability, the multi-token parallel prediction approach of MTP is worth exploring, but the trade-off between transmission overhead and training complexity must be carefully considered.
7. Editor's Summary
DFly2 demonstrates a clear design philosophy along the speculative sampling technical path: by reusing the KV cache and sparse index of the target model, it fundamentally eliminates the memory bottleneck faced by draft models during long-context inference. Its characteristic of decoupling attention overhead from context length ensures stable speedup ratios even in scenarios with 128K or million-level contexts, addressing the pain point of performance degradation in traditional draft solutions when handling long texts. Within the technical approach, the combination of Hidden Correction and injection of the final hidden state effectively compensates for the missing prediction signals after reusing KV caches, showcasing rigorous attention to engineering details.
In terms of practical value, DFly2 complements Hy4 flash to form a complete acceleration solution, offering direct benefits to business scenarios that rely on long document processing, multi-turn Agent automation, and large-scale knowledge base Q&A. Empirical data showing a maximum speedup of 4.2x and a 68.5% increase in reception length in Agentic scenarios provides quantifiable performance expectations for real-world deployment. On the training side, the DFly-OPD approach reduces the cost of online distillation to nearly that of SFT, lowering the threshold for teams looking to customize their own draft models.
DFly2 is primarily suitable for development teams with large model inference optimization needs, especially those that have already adopted or are planning to adopt a sparse attention architecture. It is ideal for production environments requiring improved response speed and reduced inference costs in long-context scenarios. For academic researchers, its KV Share mechanism and no-rollout distillation approach also provide valuable references for further study.
In terms of growth potential, DFly2's design is highly compatible with the DSA sparse attention technical route it belongs to. As long-context models are increasingly applied in Agent systems, code intelligence, law, and finance, the value of such supporting acceleration components will continue to become more prominent. By open-sourcing DFly2, Tencent Hunyuan contributes to the formation of a toolchain ecosystem around the DSA architecture.
8. FAQ
Q: What is the principle behind DFly2's acceleration? Why does it maintain the same output?
A: DFly2 employs a speculative sampling (Speculative Decoding) mechanism. The draft model first predicts multiple tokens, and then the target model Hy4 flash verifies them in bulk, accepting all correct predictions at once. Since the final generation results are validated by the target model, the model weights and output logic remain unchanged. Therefore, the output results are exactly the same as when DFly2 is not used, with only the decoding speed improved.
Q: What are the memory requirements for DFly2? Does it add any extra overhead?
A: DFly2 directly reuses the KV cache and sparse index of the target model, and does not require maintaining a separate KV memory for the draft model. As a result, the additional memory overhead is zero. On the computational side, each draft token focuses on approximately 2,048 key positions, keeping the attention complexity fixed and independent of the context length. The overall memory usage is roughly the same as deploying Hy4 flash alone.
Q: Is DFly2 applicable to models that are not based on DSA architecture?
A: No. DFly2 is specifically designed for DSA-like sparse attention large models, and its core Index Share mechanism is tightly coupled with sparse indexing. On traditional full-attention models, the advantages of memory sharing and fixed overhead in DFly2 cannot be realized. For such scenarios, it is recommended to use general speculative sampling solutions (e.g., EAGLE, Medusa, or MTP).
Q: How to deploy DFly2 in a production environment? What toolchain is required?
A: The deployment process includes: downloading weights from HuggingFace, deploying the main Hy4 flash model, and loading DFly2 in the inference configuration while enabling the speculative sampling switch. It is recommended to use the AngelSpec infrastructure to support hidden state disk reuse. This framework includes complete training and inference code for DFly2 and supports separated training and inference deployment with a context size of up to 256K.
Q: In which scenarios is DFly2's acceleration most noticeable?
A: DFly2's acceleration benefits are positively correlated with the context length. In scenarios involving long documents of 128K length, it provides approximately 3.2x speedup, with the received length improvement increasing from about 4% to about 18%. In multi-turn Agent tasks, the received length can be improved by up to 68.5%. However, the acceleration benefits are relatively limited in short text scenarios.
Q: Can I train my own draft model for DFly2 using my data?
A: Yes. The Tencent/AngelSpec repository on GitHub contains complete training code, using the DFly-OPD lightweight online distillation scheme. This approach eliminates the need for rollout and only adds one forward pass of the target model during training, compared to standard SFT. It requires using the same tokenizer and data format as the target model.
Q: How does DFly2 differ from mainstream MTP solutions?
A: MTP achieves multi-token parallel prediction by extending the target model's head, requiring a joint loss design during training. As an independent draft model, DFly2 offers more flexible training and lower P→D transmission overhead, achieving an end-to-end throughput approximately 26% higher than MTP. However, DFly2 is only compatible with DSA architecture, while MTP has broader applicability.
9. Project Links
- GitHub Repository: https://github.com/Tencent/AngelSpec
- HuggingFace Model Library: https://huggingface.co/collections/AngelSlim/angelspec
- arXiv Technical Paper: https://arxiv.org/pdf/2611.34776
© All Rights Reserved. Some content on this site is partially generated by AI with human review.


