DSparkDecodingConfig#
- class tensorrt_llm.llmapi.DSparkDecodingConfig(
- *,
- max_draft_len: Annotated[int, Ge(ge=0)] | None = None,
- max_total_draft_tokens: int | None = None,
- speculative_model: str | Path | None = None,
- moe_backend: Literal['AUTO', 'CUTLASS', 'CUTEDSL', 'CUTEDSL_FC12', 'TRTLLM', 'DEEPGEMM', 'DENSEGEMM', 'VANILLA', 'TRITON', 'MARLIN', 'MEGAMOE_DEEPGEMM', 'MEGAMOE_CUTEDSL'] | None = None,
- moe_tactic: str | None = None,
- max_concurrency: Annotated[int, Gt(gt=0)] | None = None,
- draft_len_schedule: dict[int, int] | None = None,
- load_format: str | None = None,
- acceptance_rate_window_size: Annotated[int, Ge(ge=0)] | None = None,
- acceptance_rate_threshold: Annotated[float | None, Ge(ge=0.0), Le(le=1.0)] = None,
- use_rejection_sampling: bool = False,
- allow_advanced_sampling: bool = False,
- advanced_sampling_mode: AdvancedSamplingMode = AdvancedSamplingMode.FULL,
- enable_penalty: bool = False,
- spec_dec_variant: Annotated[int, Gt(gt=0)] = 1,
- mask_token_id: int | None = None,
- target_layer_ids: List[int] | None = None,
- block_size: Annotated[int, Gt(gt=0)] | None = None,
- markov_rank: int | None = None,
- markov_head_type: Literal['vanilla', 'gated', 'rnn'] | None = None,
- enable_confidence_scheduling: bool = False,
- confidence_cost_table_path: str | None = None,
- confidence_calibration_path: str | None = None,
- confidence_min_predicted_gain: Annotated[float, Ge(ge=0)] = 0.04,
- enable_fused_confidence_scheduler: bool = True,
- decoding_type: Literal['DSpark'] = 'DSpark',
- attention_backend: Literal['AUTO', 'VANILLA', 'TRTLLM', 'CUTEDSL'] = 'AUTO',
Bases:
DecodingBaseConfigConfiguration for DSpark speculative decoding.
DSpark (DeepSeek) is a target-dependent, “semi-parallel” speculative decoding method. Like DFlash it captures hidden states from several target layers as cross-attention context and drafts a whole block in a single backbone forward, but it additionally refines the per-position draft logits with a lightweight sequential head (a low-rank Markov head, optionally an RNN head). A confidence head can score each draft position for verification scheduling without truncating the proposed block. Confidence scheduling is opt-in; the default configuration retains native full-block verification.
Key features: - Target-dependent: captures hidden states from
target_layer_ids. - Semi-parallel: one block backbone forward + cheap sequential head refine. - Full-block proposals: confidence scoring does not change the draft tokensor the standard target-verification acceptance rule.
Reference: DeepSeek DeepSpec (deepseek-ai/DeepSpec).
- field acceptance_rate_threshold: float | None = None#
The threshold for average true acceptance rate (accepted_draft_tokens / drafted_tokens); speculation will be disabled permanently once the rolling average over the last N speculation-enabled decoding iterations (N = acceptance_rate_window_size) drops below this value.
- Constraints:
ge = 0.0
le = 1.0
- field acceptance_rate_window_size: NonNegativeInt | None = None#
The rolling average window size (N) for acceptance rate across speculation-enabled decoding iterations. If not set or set to 0, the feature is disabled. PyTorch backend only.
- field advanced_sampling_mode: AdvancedSamplingMode = AdvancedSamplingMode.FULL#
Deploy-time specialization of the one-model advanced sampler that skips disabled filter kernels. FULL (default): per-row top_k/top_p/min_p in one fused kernel, the only mode accepting min_p. NO_TOPK: skip top_k. NO_TOPP: skip top_p. NO_TOPK_NO_TOPP: skip both.
- field allow_advanced_sampling: bool = False#
DEPRECATED: no-op kept for backward compatibility. Will be removed in a future release. Non-greedy sampling is now auto-detected per request; this flag no longer has any effect.
- field attention_backend: Literal['AUTO', 'VANILLA', 'TRTLLM', 'CUTEDSL'] = 'AUTO'#
Block-decode attention backend for a standalone DSpark drafter (one shipped as its own checkpoint, not inside the target’s mtp.* namespace). Ignored by the embedded DeepSeek-V4-Pro draft. Independent of the backend that builds the drafter’s own attention modules.
AUTO resolves per drafter family and is right unless you are pinning a kernel: TRTLLM for a GQA backbone, which degrades when its kernel is missing, and CUTEDSL for an MLA one, which raises. TRTLLM needs FlashInfer and SM100/SM103. CUTEDSL is MLA-only: one cute-dsl MLA decode pass over context and block, on SM100/SM103/SM107. Which kernel each name selects: MLADSparkForCausalLM.
- field block_size: Annotated[int, Gt(gt=0)] | None = None#
Number of draft positions produced per block. If None, read from the draft model config (dspark_block_size). Should equal max_draft_len.
- field confidence_calibration_path: str | None = None#
Path to a JSON file with per-position temperature-scaling values (key ‘sts_temperatures’ or ‘temperatures’) used to calibrate the confidence head. A vector longer than max_draft_len is truncated to its first max_draft_len entries, so one file serves every K. If None, the raw sigmoid is used.
- field confidence_cost_table_path: str | None = None#
Path to a DSpark cost table: measured decode step times per physical K, rank-local CUDA-graph batch size and verifier-token budget. One file may hold several K values; the entry for max_draft_len is used. Generate one with python -m tensorrt_llm.tools.dspark_profile_costs. Required when enable_confidence_scheduling=True.
- field confidence_min_predicted_gain: Annotated[float, Ge(ge=0)] = 0.04#
Minimum predicted relative goodput gain (expected accepted tokens per millisecond) a compact verifier budget needs over native verification before it is selected. Larger values keep native verification more often.
- Constraints:
ge = 0
- field decoding_type: Literal['DSpark'] = 'DSpark'#
- field draft_len_schedule: dict[int, int] | None = None#
Developer interface: dynamically adjust draft length based on active batch size in runtime.Maps batch size to draft lengths.For example: draft_len_schedule = {4:4, 8:2, 32:1} - Batch sizes 1-4: use draft_len=4 - Batch sizes 5-8: use draft_len=2 - Batch sizes 9-32: use draft_len=1 - Batch sizes 33+: use draft_len=0 (implicit, speculation disabled). Mutually exclusive with max_concurrency since draft_len_schedule implicitly support max concurrency control.
- field enable_confidence_scheduling: bool = False#
Enable confidence-guided selection of a measured verifier-token budget for decode-only batches. The full physical draft block is still proposed; target verification and acceptance rules are unchanged. Requires trained confidence-head weights and a cost table (confidence_cost_table_path). Native verification is kept whenever no compact budget is predicted to win by confidence_min_predicted_gain.
- field enable_fused_confidence_scheduler: bool = True#
Re-rank which draft positions are verified on the GPU, using the confidence of the block being verified rather than the previous step’s host copy. The verifier budget is still chosen on the host. On by default; set False to rank on the host only, which drops a device pass and a full input rebuild on compact steps. Only used when enable_confidence_scheduling=True and the overlap scheduler is on; with disable_overlap_scheduler=True, ranking stays on the host.
- field enable_penalty: bool = False#
If true, enables the occurrence penalties (repetition / presence / frequency) for one-model speculative decoding. Off by default because the penalties need a [num_seq_slots, vocab_size] occurrence-count workspace that is allocated up front (CUDA graphs capture fixed buffer addresses). While off, a request that asks for any of these penalties is rejected at admission rather than silently decoded without them.
- field load_format: str | None = None#
The load format of the speculative model.
- field markov_head_type: Literal['vanilla', 'gated', 'rnn'] | None = None#
Type of the sequential refinement head used within a block. If None, read from the draft model config (dspark_markov_head_type), defaulting to “vanilla”.
- field markov_rank: int | None = None#
Low-rank dimension of the Markov head logit-bias. If None, read from the draft model config (dspark_markov_rank). 0 disables the head.
- field mask_token_id: int | None = None#
Token ID used as the mask/noise token for parallel draft prediction. If None, read from the draft model config (dspark_noise_token_id).
- field max_concurrency: PositiveInt | None = None#
When specified (>0), speculation will be disabled at batch sizes above this value. Otherwise, speculation will always be on. PyTorch backend only. Mutually exclusive with max_concurrency since draft_len_schedule implicitly supports max concurrency control.
- field max_draft_len: NonNegativeInt | None = None#
The maximum number of draft tokens.
- field max_total_draft_tokens: int | None = None#
The number of draft tokens in the draft tokens tree. If it’s a linear tree, each draft layer will only generate one draft token. In this case, max_draft_len == max_total_draft_tokens. If it’s a static or dynamic tree, each draft layer may generate more than one draft token. In this case, max_total_draft_tokens >= max_draft_len.
- field moe_backend: _MoeBackend | None = None#
MoE backend for a neural draft model or embedded MTP layers (PyTorch backend); ignored without a neural draft model. Values other than AUTO are planned for deprecation where moe_tactic can replace them. With this and moe_tactic unset, the draft inherits the target’s backend, or resolves AUTO for its own weights when moe_config.tactic pins the target; set this to the target’s former backend to keep the draft on that family. AUTO is MEGAMOE_CUTEDSL when the draft shares the target’s per-layer dynamic EPLB. Nemotron-H embedded MTP layers must run VANILLA exactly when the target does.
- field moe_tactic: str | None = None#
MoE implementation to run for a neural draft model or embedded MTP layers (PyTorch backend); ignored without a neural draft model. The recommended interface for choosing it. Takes the values of moe_config.tactic: an id ‘provider.technique.kernel_name.quant’ or any dotted subset of its segments. The ids, the shortest tactic naming each, and the segment values are listed in the MoE implementation catalog of the MoE performance guide (https://nvidia.github.io/TensorRT-LLM/developer-guide/moe-perf-guide.html, docs/source/developer-guide/moe-perf-guide.md in the source tree). Requires moe_backend unset or AUTO. Unset, the draft selects as moe_backend describes.
- field spec_dec_variant: PositiveInt = 1#
Version of the algorithm within its decoding_type family (e.g. DFlash 1 vs. 2), for versions that share one decoding config. Resolved from the draft checkpoint where a family has versions. Do not set manually.
- Constraints:
gt = 0
- field speculative_model: str | Path | None = None#
The speculative (draft) model. Accepts either (1) a HuggingFace Hub model ID (e.g. ‘yuhuili/EAGLE3-LLaMA3.1-Instruct-8B’), which will be automatically downloaded, or (2) a local filesystem path to a downloaded model directory. For one-model MTP, a non-target checkpoint provides either replacement MTP heads or a complete external draft model, depending on the target model implementation. Pointing it at the target checkpoint uses the target’s embedded mtp.* weights.
- field target_layer_ids: List[int] | None = None#
Target model layer indices whose hidden states are captured for cross-attention in the draft model. If None, read from the draft model config (dspark_target_layer_ids).
- field use_rejection_sampling: bool = False#
If true, enables rejection sampling for one-model speculative decoding paths when the batch contains any non-greedy request. All-greedy batches always take the argmax fast path regardless of this flag. Set to false (default) to use exact-match verification on non-greedy batches. The non-dynamic-tree one-model path requires FlashInfer.
- __init__(**data: Any) None#
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- get_runtime_tokens_per_gen_step(
- runtime_draft_len: int,
Total tokens per gen request for the current runtime draft length.
- num_capture_layers() int#
- supports_backend(backend: str) bool[source]#
Override if the speculation algorithm does not support a subset of the possible backends.
- validator validate_draft_len_schedule_and_sort » draft_len_schedule#
Validate and sort draft_len_schedule by batch size thresholds.
- validator validate_max_concurrency_and_draft_len_schedule_mutually_exclusive » all fields#
- validator validate_moe_tactic_excludes_moe_backend » all fields#
- validator validate_moe_tactic_syntax » moe_tactic#
Check that
moe_tacticnames an implementation; lowercase it.
- validator validate_rejection_sampling_config » all fields#
Disable rejection sampling when SA-enhanced configurations are active.
Only silently disable a default-inherited value; an explicit
use_rejection_sampling=Trueis preserved soTorchLlmArgs.validate_speculative_configcan raise for the unsupported SA combination.
- property draft_is_embedded_in_target: bool#
True for the embedded (DeepSeek-V4-Pro) flavour of the DSpark draft.
DSpark ships in two shapes, and they need different runtime plumbing:
embedded: the draft is the
mtp.*namespace of the target checkpoint, built from full target decoder blocks, and served byDSv4DSparkWorkerwith its own rolling captured-context window.standalone: the draft is its own checkpoint with a registry-resolved backbone, served by
DFlashWorkerand its paged draft KV cache.
Both are
decoding_type: DSpark, so every dispatch that must tell them apart – draft-model builder, worker, spec metadata, and the separate-draft-KV-cache decision – reads this one flag instead of re-deriving it. That is what keeps those decisions from drifting apart: a builder and a worker that disagree produce a draft model whose attributes the worker does not have.The probe is the weight index rather than a config field because the index is authoritative and cannot be left unset;
model_typeis the fallback for a checkpoint whose index file is absent. Resolution is memoized here and warmed duringTorchLlmArgsvalidation, so the filesystem probe happens once in the main process – not per rank, and never at forward or CUDA-graph-capture time.
- property is_linear_tree: bool#
- property needs_separate_draft_weights: bool#
Whether draft weights must be loaded from
speculative_model.This includes external draft models and MTP head replacement checkpoints.
- property spec_dec_mode#
- property tokens_per_gen_step: int#
DSpark needs K+1 tokens per gen request (K drafts + 1 bonus).
The draft produces its own mask queries internally; passing mask fillers through the target is pure wasted work at large batch size.
- property uses_external_draft_model: bool#
Whether speculative_model contains an external draft model.
- property uses_replacement_heads: bool#
Whether speculative_model contains replacement MTP heads.