Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/python/py/models/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ This folder contains the model builder for quickly creating optimized and quanti
- [Include Auxiliary Hidden States Output](#include-auxiliary-hidden-states-output)
- [Build with Paged Attention](#build-with-paged-attention)
- [Build a DFlash 2 Block Drafter](#build-a-dflash-2-block-drafter)
- [Build a DSpark Block Drafter](#build-a-dspark-block-drafter)
- [Disable Windowed KV Cache](#disable-windowed-kv-cache)
- [Enable Shared Embeddings](#enable-shared-embeddings)
- [Enable CUDA Graph Capture](#enable-cuda-graph-capture)
Expand Down Expand Up @@ -324,6 +325,20 @@ python -m onnxruntime_genai.models.builder -i path_to_target_model -o path_to_ou
python builder.py -i path_to_target_model -o path_to_output_folder -p fp16 -e cuda -c cache_dir_for_hf_files --extra_options use_paged_attention=true aux_hidden_state_layers=1,11,21 dflash2_path=path_to_dflash2_checkpoint dflash2_num_draft_tokens=4
```

#### Build a DSpark Block Drafter

Set `dspark_path` to a DSpark checkpoint to export an auxiliary `dspark.onnx` block drafter beside a Qwen3.5 or Qwen3.8 target model. The target must use paged attention. SpecForge identifies the target layers whose outputs are tapped, while `aux_hidden_state_layers` identifies residual streams entering layers, so each configured auxiliary layer must be one greater than the corresponding `target_layer_ids` entry in the DSpark checkpoint. The drafter reuses the target's embedding and LM-head initializers. `dspark_path` and `dflash2_path` are mutually exclusive.

`dspark_num_draft_tokens` optionally overrides how many tokens the drafter proposes per step and must be a positive integer. `dspark_top_k` controls how many candidates the lattice keeps per block slot; it defaults to `16` and must be a positive integer no greater than the drafter vocabulary size.

```bash
# From wheel:
python -m onnxruntime_genai.models.builder -i path_to_target_model -o path_to_output_folder -p fp16 -e cuda -c cache_dir_for_hf_files --extra_options use_paged_attention=true aux_hidden_state_layers=1,11,21 dspark_path=path_to_dspark_checkpoint dspark_num_draft_tokens=4 dspark_top_k=16

# From source:
python builder.py -i path_to_target_model -o path_to_output_folder -p fp16 -e cuda -c cache_dir_for_hf_files --extra_options use_paged_attention=true aux_hidden_state_layers=1,11,21 dspark_path=path_to_dspark_checkpoint dspark_num_draft_tokens=4 dspark_top_k=16
```

#### Disable Windowed KV Cache

By default, sliding-window layers use a reduced KV cache on supported execution providers. With paged attention, eligible local layers use a ring of blocks when the exported model also contains at least one full-context layer. Set `windowed_kv_cache=false` to give every layer a full-length KV cache, which is useful for performance comparisons or compatibility testing. The option defaults to `true` and applies to both paged and non-paged models.
Expand Down
9 changes: 9 additions & 0 deletions src/python/py/models/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,15 @@ def get_args():
aux_hidden_state_layers to match the drafter's `target_layer_ids`. Default is unset (disabled).
dflash2_num_draft_tokens = Override the number of draft tokens the DFlash 2 block
drafter proposes per step. Must be a positive integer. Default is taken from the draft checkpoint.
dspark_path = Path to a DSpark draft checkpoint. Exports an auxiliary `dspark.onnx`
block drafter beside the target model and adds a `dspark` section to
genai_config.json. Mutually exclusive with dflash2_path. Requires
use_paged_attention=true. SpecForge taps each target layer's output, so
aux_hidden_state_layers must be the drafter's `target_layer_ids` each plus one.
dspark_num_draft_tokens = Override the number of draft tokens the DSpark block
drafter proposes per step. Must be a positive integer. Default is taken from the draft checkpoint.
dspark_top_k = Candidates the DSpark lattice keeps per block slot. Must be a positive integer no
greater than the drafter vocabulary size. Default is 16.
mtp_quant_config = JSON object/file: Configure MTP I/O, dense weights, MoE, and runtime using the
structured QuantConfig schema independently from the main model.
linear_attn_op = linear_attention/gated_delta_net: Select the recurrent operator for non-paged
Expand Down
Loading
Loading