Skip to content

Commit 5b543e1

Browse files
committed
feat: add DFlash2 training support
Add the grouped dynamic causal convolution and predecessor-conditioned candidate selector from the public DFlash2 architecture. Match the public serving implementations for transformed top-K unary logits, bilinear transition scores, verified-anchor alignment, and checkpoint schema. Reuse the shared DFlash training path, configuration dispatch, optimizer sharding, and strict serving export hooks. Public sources do not publish selector supervision, so define a TorchSpec-specific teacher-forced cross-entropy objective that inserts a missing gold successor into the training candidate set. Add focused configuration, loss, gradient, masking, inference-lattice parity, distributed export, and artifact tests. Signed-off-by: Aaron Batilo <AaronBatilo@gmail.com>
1 parent 5699d70 commit 5b543e1

19 files changed

Lines changed: 1811 additions & 47 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ python tools/convert_to_hf.py --input-dir ./outputs/my_experiment/iter_0010000/
229229

230230
Vocabulary pruning, which reduces the draft model `lm_head` to a smaller token set and emits `d2t` and `t2d` mappings, can be applied either during training or at conversion time.
231231

232+
DFlash2 requires the full target vocabulary. Do not set `draft_vocab_size` or pass `--prune-vocab` for a DFlash2 model.
233+
232234
- **Pre-pruning**: set `draft_vocab_size` in your training config. The checkpoint already contains the pruned `lm_head` and `d2t`/`t2d` buffers, so the basic conversion command is enough.
233235
- **Post-pruning**: train with the full vocabulary, then pass `--prune-vocab` at conversion time together with a representative dataset to compute token frequencies.
234236

THIRDPARTYNOTICES

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,31 @@ Notice for THUDM/slime
204204
See the License for the specific language governing permissions and
205205
limitations under the License.
206206

207+
Notice for z-lab/dflash
208+
-------------------------------
209+
210+
MIT License
211+
212+
Copyright (c) 2026 Z Lab
213+
214+
Permission is hereby granted, free of charge, to any person obtaining a copy
215+
of this software and associated documentation files (the "Software"), to deal
216+
in the Software without restriction, including without limitation the rights
217+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
218+
copies of the Software, and to permit persons to whom the Software is
219+
furnished to do so, subject to the following conditions:
220+
221+
The above copyright notice and this permission notice shall be included in all
222+
copies or substantial portions of the Software.
223+
224+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
225+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
226+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
227+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
228+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
229+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
230+
SOFTWARE.
231+
207232
Notice for sgl-project/SpecForge
208233
-------------------------------
209234

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
model:
2+
target_model_path: Qwen/Qwen3-8B
3+
trust_remote_code: true
4+
draft_model_config: torchspec/config/dflash2_draft_config.json
5+
6+
dataset:
7+
train_data_path: ../examples/data/sample_conversations.jsonl
8+
eval_data_path: null
9+
eval_interval: 100
10+
chat_template: qwen
11+
prompt_key: conversations
12+
min_loss_tokens: 32
13+
14+
training:
15+
attention_backend: flex_attention
16+
micro_batch_size: 1
17+
draft_accumulation_steps: 2
18+
learning_rate: 6e-4
19+
min_lr: 6e-5
20+
weight_decay: 0.01
21+
max_concurrent_batches: 1
22+
max_grad_norm: 1.0
23+
max_seq_length: 2048
24+
num_epochs: 3
25+
seed: 42
26+
training_num_gpus_per_node: 4
27+
training_num_nodes: 1
28+
ttt_length: 7
29+
fsdp_strategy: FULL_SHARD
30+
fsdp_reduce_dtype: bfloat16
31+
prefetch_depth: 8
32+
save_interval: 1000
33+
save_per_epoch: true
34+
max_checkpoints: 2
35+
warmup_ratio: 0.04
36+
dflash_block_size: 8
37+
dflash_num_anchors: 512
38+
dflash_loss_decay_gamma: 7.0
39+
dflash_num_target_layers: 5
40+
dflash2_selector_loss_alpha: 1.0
41+
42+
inference:
43+
inference_engine_type: sgl
44+
store_last_hidden_states: false
45+
inference_num_gpus: 4
46+
inference_num_gpus_per_engine: 1
47+
inference_num_gpus_per_node: 4
48+
max_sample_pool_size: 64
49+
inference_buffer_threshold: 32
50+
inference_batch_size: 8
51+
sglang:
52+
tp_size: 1
53+
mem_fraction_static: 0.7
54+
55+
mooncake:
56+
master_server_address: null
57+
metadata_server: null
58+
protocol: tcp
59+
global_segment_size: 16GB
60+
local_buffer_size: 4GB
61+
enable_hard_pin: true
62+
63+
output_dir: ./outputs/qwen3-8b-dflash2
64+
cache_dir: ./cache/qwen3-8b-dflash2
65+
model_download_dir: null
66+
67+
debug:
68+
save_debug_train_data: null

0 commit comments

Comments
 (0)