Skip to content

Latest commit

 

History

History
178 lines (144 loc) · 10.5 KB

algorithms.md

File metadata and controls

178 lines (144 loc) · 10.5 KB

Algorithm recipes

Training recipes under configs/recipes/ require absolute ASPEC_TRAIN_DATA and ASPEC_EVAL_DATA inputs before loading (Quickstart is the exception). See the recipe launcher and runtime validation.

Choose algorithm/objective separately from Draft structure and execution. All commands run from repository root in the installed environment. Bundled conversations and short step budgets are functional examples; supply licensed real data and a full LR horizon for training. Use support for unimplemented combinations.

DSpark, DFlash and EAGLE3

Select configs/recipes/qwen3_8b_dflash.yaml or configs/recipes/qwen3_8b_eagle3.yaml and replace the Target path:

aspec --config configs/recipes/qwen3_8b_eagle3.yaml --dry-run \
  model.target_model_path=/path/to/Qwen3-8B
RAY_ADDRESS=local aspec --config configs/recipes/qwen3_8b_eagle3.yaml \
  model.target_model_path=/path/to/Qwen3-8B

DSpark retains CE/L1/Markov/confidence semantics; DFlash does not use those auxiliary targets. EAGLE3 uses recurrent TTT and its selected distillation objective. Its pruned vocabulary preserves the checkpoint's d2t/t2d mapping across recovery/export. Teacher argmax outside the selected vocabulary is filtered; omitted probability mass is not reassigned to the reduced head.

The full-vocabulary recipe sets training.eagle3_target_cache=logits. This projects the frozen Target head once per microbatch and reuses the resulting BF16 logits across TTT depths and checkpoint recomputation; each depth still performs the same FP32 softmax and distillation loss. The optimization is supported for padded sdpa and flex_attention. Use lazy for pruned-vocabulary or FA4/THD execution; unsupported combinations fail during Plan compilation rather than falling back.

Backbone and loss checkpointing are separate. The full-vocabulary recipe keeps training.gradient_checkpointing=true for the Draft backbone but sets training.eagle3_loss_gradient_checkpointing=false, retaining the loss graph so backward does not repeat the full-vocabulary projection and reductions. This changes activation-memory use, not dtype or loss mathematics. The optimized setting is supported on the same padded full-vocabulary path; use loss checkpointing for pruned-vocabulary or FA4/THD execution. When omitted or null, the loss-checkpoint setting inherits gradient_checkpointing, preserving the behavior of existing configurations. Plan and runtime observations report the resolved boolean.

For a pruned EAGLE3 packed CP example, change the original recipe as follows:

aspec --config configs/recipes/qwen3_8b_eagle3.yaml --dry-run \
  model.draft_model_config=aspec/config/eagle3_qwen3_8b_pruned_draft_config.json \
  training.attention_backend=fa4 training.dflash_packing=true \
  training.eagle3_target_cache=lazy \
  training.eagle3_loss_gradient_checkpointing=true \
  training.draft_context_parallel_size=2 output_dir=outputs/eagle3-pruned-cp2

dflash_packing is the shared configuration field name; it does not change EAGLE into DFlash. TTT shifts, teacher halos and supervision remain document-local. Unsupported factorized/ambiguous heads fail export rather than producing an unfaithful serving asset.

P-EAGLE core prerequisite

The P-EAGLE model/loss API provides a dense unsampled Qwen3 parallel Draft and forward-KL objective with independent numerical checks. Public training, COD sampling, recovery, export and consumer validation remain pending.

Domino

The Domino model/loss API adds a GRU-conditioned causal correction head on the retained DFlash block backbone and mixes corrected with backbone-only cross-entropy through lambda_base. Both documented label layouts are explicit: the unshifted DFlash convention and the official shifted convention (shift_label=true, pure_draft_prefix_len=1). Training now selects the family through aspec/config/domino_qwen3_8b_draft_config.json; start from the Domino examples (FlexAttention, CP1, non-packing, Store/TCP). The trainer supports a linear lambda_base curriculum and held-out corrected/backbone per-position observations. Scope is dense full attention with padded inputs only. Native export, recipe catalog promotion, Target bindings and consumer/acceptance validation remain pending.

EAGLE4: two stages

The Draft stage trains the full recurrent model. The candidate stage freezes the entire Draft, including its full-vocabulary head, and trains two low-rank retrieval projections. The candidate objective uses frozen-head Top-K soft targets and forward-KL with full-vocabulary normalization; SVD is initialization only. This is not claimed as an unpublished official training recipe.

The default Dense example uses three NVLink GPUs. Train and export the Draft before the candidate stage:

RAY_ADDRESS=local aspec --config configs/recipes/qwen3_8b_eagle4.yaml \
  model.target_model_path=/path/to/Qwen3-8B
python -m tools.convert_to_hf --format aspec \
  --input-dir /path/to/published-draft-checkpoint \
  --output-dir outputs/qwen3-8b-eagle4-asset
RAY_ADDRESS=local aspec --config configs/recipes/qwen3_8b_eagle4_candidate.yaml \
  model.target_model_path=/path/to/Qwen3-8B \
  model.initial_draft_model_path=outputs/qwen3-8b-eagle4-asset

Use the complete checkpoint published by the first stage; normal training defaults to three data passes, so the iteration number depends on the admitted data and batch schedule. Export the candidate checkpoint with --format aspec too. Native assets retain the full head, projections, feature/norm/RoPE/SWA settings and MoE control state. Candidate scoring exactly rescores retrieved rows with the full head; low-rank logits are not final scores.

Cross-stage initialization is weights-only. Within a stage, exact resume preserves stage, rank, supervision strategy, frozen weights and all optimizer/RNG/work state. Set model.initial_draft_model_path=null with training.load_path, retain lr_total_steps, and choose a fresh output directory. Candidate loss chunk size controls workspace and can change; candidate rank and stage semantics cannot. Candidate recall/teacher mass are not decode acceptance metrics.

DFlash2

configs/examples/qwen3_8b_dflash2.yaml illustrates the experimental objective. Select aspec/config/dflash2_qwen3_8b_swa_draft_config.json through model.draft_model_config for SWA; packing and CP use the normal training overrides. Full/causal/SWA semantics differ from DSpark's anchor-shared window. FA4 preserves convolution, selector, document boundaries and CP ownership. Functional results do not establish official-recipe reproduction or long-term quality.

JetSpec

The JetSpec workflow combines the retained DFlash block head with causal intra-block attention and a temperature-scaled forward-KL objective against frozen Target features. JetSpecConfig forces that causal contract and rejects incompatible structures. The ASpec training CLI selects the algorithm through a shipped Qwen3-8B Draft config and a JetSpec trainer that reuses the DFlash optimizer/checkpoint path. FlexAttention, CP1, padded/non-packing execution and exact recovery are the initial scope. SGLang/native export, strict reload, a proposal consumer and bounded verifier-acceptance runs are supported; tree construction and long-run convergence evidence remain pending.

Native MTP conditioning for DSpark/DFlash

configs/recipes/qwen3_5_9b_dmtp.yaml uses the native Qwen3.5 predictor as a frozen condition for a DSpark Draft. DFlash uses the corresponding DMTP Draft JSON. The ordinary trainer owns fusion parameters, optimizer, recovery and native assets. With feature_source: target, the Target publishes document-aligned frozen MTP features for online, shared or offline consumption; the Draft does not load the predictor. Existing policies without that field retain Draft-side execution. Dense full GQA, CP1, MBS1, REPLICATE, one node and non-packing are the initial scope. Other combinations fail Plan validation. Follow the workflow and timing contract. Given teacher-forced T1, only unknown suffix positions receive supervision. Suffix acceptance observations are conditional; native export requires an MTP-aware downstream consumer and does not certify generic SGLang serving.

Native Qwen3.5 MTP

configs/recipes/qwen3_5_9b_mtp.yaml initializes the actual native predictor and binds frozen embeddings/head from the same Target. Final post-norm feature at position t plus token t+1 predicts token t+2; later rollout depths reuse normalized predictor state. It is not an independently randomized EAGLE model.

Use the normal CLI and recovery workflow. SDPA is CP1; the FA4 packed path can use CP with sufficient Draft GPUs and compatible geometry. Export/stitch preserves the shared Target bindings:

python -m tools.convert_to_hf --input-dir /path/to/complete/iter_checkpoint \
  --output-dir outputs/native-mtp-export
python -m tools.stitch_native_mtp --target /path/to/Qwen3.5-9B \
  --draft outputs/native-mtp-export --output outputs/verifier-with-trained-mtp

The original Target is not overwritten. Official SGLang consumption selects EAGLE, not a MTP flag. A format manifest does not replace testing the particular exported asset with its consumer.

Medusa heads-only

aspec/config/medusa_qwen3_8b_draft_config.json trains K parallel heads on the frozen Target's post-norm final state; head i at position t is supervised by token t+2+i. The objective is the sum of per-head mean cross-entropies (assistant tokens only): each head's CE is averaged within a microbatch, and microbatches are weighted equally by gradient accumulation rather than pooled by token count. The heads own trainable full-vocabulary projections. Start from configs/recipes/medusa_qwen3_8b.yaml (SDPA, CP1, MBS1, non-packing, REPLICATE, Store/TCP). The loss automatically selects a fused Triton CE/argmax/dlogits epilogue with one dW GEMM per head (or bounded per-chunk accumulation for long selections) when CUDA BF16 and Triton are available, and falls back to the reference path otherwise; gradient_checkpointing still bounds the dominant vocabulary-logit memory through an internal retained-logits budget. Native export, strict reload and per-head held-out reporting are implemented, as is greedy and typical/nucleus sampling candidate-tree acceptance through a standalone Hugging Face evaluator; SGLang integration and production serving remain future work; see details.