You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add D-PACE loss implementation for D-Flash training (#736)
<!-- markdownlint-disable -->
<!-- PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS
(AT THE BOTTOM) HAVE BEEN CONSIDERED. -->
## Purpose
This PR implements [D-PACE: Dynamic Position-Aware Cross-Entropy for
Parallel Speculative Drafting](https://arxiv.org/abs/2605.18810). D-PACE
proposes an alternative per-position loss weighting for training
block-parallel draft models. Instead of applying a fixed exponential
decay over block positions, D-PACE dynamically adjusts the weights as
training progresses. This is based on the intuition that although
earlier positions are naturally more important (i.e., an early rejection
forces all subsequent draft positions to be discarded), when they are
sufficiently stabilized, the training priority should shift to later
positions to improve overall acceptance rate.
Two arguments are added to `train.py` to support D-PACE loss:
- `--per-position-loss-weight ["fixed-exp-decay", "dpace"]` (default
`fixed-exp-decay`). This flag enables D-PACE loss; while missing, it
defaults to the original fixed exponential decay.
- `--dpace-alpha` (default `0.5`). This flag is only effective when
D-PACE is enabled. It smoothes per-position confidence according to
equation 7 of the paper. The paper uses 0.5 as the default value for
their evaluation and justifies this choice in sensitivity analysis.
Note that D-PACE requires cross-entropy as the training loss (`--loss-fn
ce`), allowing per-position confidence score computation to be
piggybacked on the loss computation. Applying D-PACE to other losses are
not supported and will result in `ValueError`.
D-PACE is currently enabled for D-Flash and D-Spark draft models.
Theoretically, it is compatible with all block-parallel drafters.
## Tests
**D-Flash + D-PACE evaluation.** Multiple D-Flash checkpoints are
trained with different loss function configurations:
- `--loss-fn kld`: KL Divergence (current default)
- `--loss-fn ce`: Cross Entropy with fixed exponential decay
- `--per-position-loss-weight dpace --dpace-alpha ALPHA`: D-PACE with
`ALPHA` = 0.3, 0.5, 0.7.
The training set is 100K random samples from Magpie+Ultrachat. The
verifier model is Qwen3-8B. Each checkpoint uses 1 A100 for hidden state
generation and 7 A100s for training. Training configurations are
identical for all checkpoints:
```
--target-layer-ids 1 9 17 25 34 --num-layers 5 --draft-vocab-size 32000 --max-anchors 3072 --block-size 8 --sliding-window 2048 --sliding-window-indices 0 1 2 3 4 --scheduler-type cosine --lr 0.0006 --epochs 1 --noise-std 0.0
```
Metric: since D-PACE is a pure training-time optimization and does not
change draft model's forward pass complexity, its gains are captured
entirely by acceptance rates.
Evaluation results: Mean-Accepted-Length (MAL) on [Speculator
Benchmarks](https://huggingface.co/datasets/RedHatAI/speculator_benchmarks):
| Dataset | KL Divergence | CE | D-PACE $\alpha=0.3$ | D-PACE
$\alpha=0.5$| D-PACE $\alpha=0.7$ |
|---|---:|---:|---:|---:|---:|
| HumanEval | 2.977 | 2.956 | 3.047 | **3.169** | 3.139 |
| math_reasoning | 3.275 | 3.322 | **3.541** | 3.532 | 3.531 |
| qa | 2.279 | 2.343 | 2.455 | **2.495** | 2.431 |
| question | 2.585 | 2.567 | 2.685 | 2.680 | **2.708** |
| rag | 2.302 | 2.269 | **2.393** | 2.372 | 2.336 |
| summarization | 1.906 | 1.918 | 1.981 | 1.980 | **1.991** |
| tool_call | 2.372 | 2.327 | **2.480** | 2.454 | 2.467 |
| translation | 2.096 | 2.072 | 2.176 | 2.183 | **2.191** |
| writing | 2.565 | 2.586 | 2.683 | 2.684 | **2.718** |
| Mean | 2.484 | 2.485 | 2.605 | **2.617** | 2.612 |
**D-Spark + D-PACE evaluation.** D-Spark checkpoints use Markov rank 256
and vanilla Markov head type. The confidence head is disabled. Remaining
training configurations match above D-Flash experiments.
- `--loss-fn ce`: Vanilla fixed-decay cross-entropy
- `--position-loss-weight dpace --dpace-alpha 0.5`: D-PACE with
$\alpha=0.5$
MALs:
| Dataset | CE | D-PACE $\alpha=0.5$ |
|---|---:|---:|
| HumanEval | 3.145 | **3.302** |
| math_reasoning | 3.457 | **3.615** |
| qa | 2.352 | **2.492** |
| question | 2.671 | **2.770** |
| rag | 2.276 | **2.384** |
| summarization | 1.916 | **1.996** |
| tool_call | 2.451 | **2.538** |
| translation | 2.082 | **2.202** |
| writing | 2.686 | **2.776** |
| Mean | 2.560 | **2.675** |
D-PACE improves upon fixed-decay loss for both D-Flash and D-Spark
drafters.
## Checklist
I have filled in:
- [x] The purpose of the PR, such as "Fix some issue (link existing
issues this PR will resolve)".
- [x] The test plan/results, such as providing test command and pasting
the results.
- [ ] (Optional) The necessary documentation update.
- [x] I (a human) have written or reviewed the code in this pr to the
best of my ability.
---------
Signed-off-by: Weifan Jiang <weijiang@redhat.com>
Co-authored-by: Weifan Jiang <weifanjiang@a100-08.nemg-001.lab.rdu2.dc.redhat.com>
Co-authored-by: Weifan Jiang <weijiang@redhat.com>
Signed-off-by: Roderick Wu <Roderick-Wu@a100-04.nemg-001.lab.rdu2.dc.redhat.com>
0 commit comments