Skip to content

Adaptive DSpark verification ​

Use this advanced guide to configure adaptive verification for a supported DeepSeek V4.1 DSpark deployment, estimate its startup costs, and verify its runtime behavior. Adaptive verification selects a query budget using draft confidence and measured graph costs. It keeps the normal token acceptance checks and can use full verification when shortening is not beneficial.

Prerequisites ​

Before enabling adaptive verification, configure the deployment as follows:

  • Use a native DeepSeek V4.1 DSpark model with --speculative-algorithm DSPARK. Other DSpark models don't support adaptive verification or DP-local CUDA graphs.
  • Enable CUDA graphs and set --disable-prefill-graph. Don't use --enforce-eager.
  • Keep pipeline parallelism (PP), KV parallelism (KVP), decode context parallelism (DCP), and query context parallelism (QCP) at 1. Disable DP sampling and head TP, and set LM-head TP equal to attention TP.
  • Use real chain acceptance with TP synchronization. Synthetic acceptance, speculative draft trees, and --full-vocab-top-k are unsupported.
  • For sampled verification, use NVIDIA SM90 or newer and attention TP1. Keep --speculative-rejection-sample-method standard, which is the default.

Enable adaptive verification ​

  1. Add the options for your sampling mode to the existing ts serve command. Keep the existing model, draft, and parallelism arguments. Replace 4 with the positive integer local batch threshold that you want, or omit --dsv41-dspark-min-batch-size to use the default of 32.

    For greedy sampling, add:

    bash
    --speculative-algorithm DSPARK --sampling-backend greedy \
    --disable-prefill-graph --enable-dsv41-adaptive-dspark \
    --dsv41-dspark-min-batch-size 4

    Greedy sampling uses the target argmax verifier. Don't combine this configuration with --enable-speculative-sampling.

    For sampled verification, add:

    bash
    --speculative-algorithm DSPARK --sampling-backend flashinfer \
    --enable-speculative-sampling --enable-dsv41-adaptive-dspark \
    --sampling-stream per-request --disable-prefill-graph \
    --dsv41-dspark-min-batch-size 4

    In a prefill/decode (PD) deployment, add the sampled options to the decode worker only. The prefill worker retains its existing configuration.

  2. Start the server and wait for CUDA graph capture and startup profiling to finish. No calibration dataset is required. Extra graph captures and profiling can increase startup time and graph memory use; see Capture and startup overhead and Startup costs and cache in this document.

The threshold uses actual local batch size, not client concurrency. With shared graph capacities, adaptation is permitted when the largest actual local batch among attention ranks reaches the threshold. With DP-local graphs, each rank uses its own actual batch size. For balanced DP8, client concurrency 32 gives local batch size 4. For TP8 with DP1, client concurrency 32 gives local batch size 32. Reaching the threshold permits adaptation but doesn't guarantee that the service selects a shorter graph.

Runtime requirements ​

Adaptive selection requires a globally decode-or-idle step. Mixed prefill/decode steps retain the existing full-width path. With shared graph capacities, DP ranks share a physical graph capacity even when their actual request counts differ, including empty ranks. The shared V4.1 target-model DP fixes also apply without adaptive verification; fused EP retains its own dispatch/count exchange.

Missing confidence feedback or unavailable cost coverage selects full verification. There is no online exploration or per-step timing calibration. Confidence feedback is updated asynchronously, and weight reload invalidates the costs.

Greedy sampling uses the target argmax verifier. Sonic chain verification (--sampling-backend sonic, without --enable-speculative-sampling) uses Sonic's packed CSR (query_start_loc) kernels for target-distribution verification. Sampled speculative verification uses the FlashInfer / CuTe DSL probability sampler and DeepInfer-style chain rejection. For proposal distribution, acceptance, rejection, and random-number details, see Sampled verification behavior.

Sampled verification behavior ​

The draft applies the request's temperature, top-k, and top-p filters and records its proposal distribution in RuntimeStates. The first decode after a PD landing has no local proposal distribution, so it draws from the full target distribution before generating local proposals. Retraction carries the recorded distributions with the existing slot state.

Both full-width and packed execution use the same verifier. It accepts a proposal with probability min(1, p(token)/q(token)), samples a rejection from max(p - exp(-5e-5)*q, 0), and samples the final bonus from p. The residual adjustment follows DeepInfer's numerical safeguard and is a small approximation to exact rejection sampling. A zero sampling mass falls back to the lowest-index target argmax. Probability preparation uses the existing FlashInfer temperature and sequential top-k/top-p renormalization. The CuTe kernels consume packed probability rows without expanding them to the original fixed-width target tensor.

Random draws use request seeds, positions, and separate Philox namespaces for draft, acceptance, rejection, and bonus. They don't consume the legacy per-round coin buffers. The stream is stable under batch reordering, but isn't bitwise identical to DeepInfer's TileLang RNG or the native FlashInfer stream. For the counter definition and floating-point sampling contract, see the packed probability sampling documentation.

Grammar masks and output logprobs ​

All three adaptive verifiers (greedy, Sonic chain, and sampled FlashInfer) support --grammar-backend xgrammar and --enable-output-logprobs, including attention DP with DP-local CUDA graphs. The grammar mask is applied before target argmax or probability filtering; ordinary prefill sampling applies the same mask. Output logprobs are selected-token FP32 log-softmax values over those grammar-masked target logits. --enable-output-cumulative-probs remains unsupported and is rejected at startup.

DP-local CUDA graph capacities ​

By default, attention-DP ranks retain shared-capacity behavior. To let each rank choose its decode graph capacity from its own request count, add --enable-dp-local-cuda-graph on an aggregated or decode worker:

bash
--enable-dp-local-cuda-graph

This option has the following additional requirements:

  • Use the native DeepSeek V4.1 DSpark drafter.
  • Set --moe-backend mega_moe for the target. Set --draft-moe-backend mega_moe for the draft, or omit the draft option to inherit the target selection. The legacy deep_gemm_mega_moe name is also accepted for both.
  • Set attention, dense, MoE, and LM-head TP to 1. Don't use head TP, PP, KVP, DCP, QCP, or DP sampling.
  • Enable CUDA graphs. Prefill-only and encode workers reject the option.

Each rank uses its own actual batch size and omits cross-DP budget agreement. MegaMoE retains expert communication across ranks, including ranks with no local requests. An idle rank uses the smallest configured capture bucket, including custom capture-size lists that omit batch size 1.

Fixed-width greedy verification, fixed-width Sonic verification, and fixed-width Sonic sampled verification (--sampling-backend sonic --enable-speculative-sampling) can use the flag without adaptive verification. Sampled adaptive verification uses the existing requirements above, including recorded proposals and the per-request sampling stream. With adaptive DSpark enabled at attention TP1, DP-local graphs evaluate the budget policy directly on GPU in finish_round (dsv41.select_verify_budget) using a 3-int32 pinned ring transfer and replay the captured verify_layout graph against live confidence_scores without score copies or Gloo collectives. The flag does not enable adaptive verification by itself. Validate correctness and performance on the intended workload and hardware.

Capture and startup overhead ​

For an eligible local batch size B and verify width W, adaptive capacities span B to B*W in steps of min(B,16), including full capacity. For example, B=256 and W=6 add 80 shortened graphs per sampling variant in addition to the full-capacity graph. DP8 client concurrency 256 normally corresponds to local B=32, not 256.

Extra captures consume startup time and graph memory. Actual time and memory depend on the model, hardware, and configured capture ladder. Serving, memory, and CUDA graph limits still apply.

Startup costs and cache ​

After graph capture, the service measures each eligible batch size with synthetic contexts and disjoint cache blocks. Each uncached eligible (batch, capacity, context) tuple uses two warmup replays and eight measured replays. A compatible cost cache avoids profiling, not graph capture.

Context endpoints are 8K, 32K, 128K, 512K, and the configured limit, clipped and deduplicated. Shared-capacity serving selects the interval containing the largest feedback context bound across active attention ranks, including the existing lookahead margin. DP-local graphs use each rank's own bound. Mixed lengths use the selected endpoint's costs; they need not all lie in one interval. A missing interval or an upper bound beyond the configured limit retains full verification. Uniform endpoint timings are a representative estimate for a mixed batch, not a bound on its latency or on the benefit of shortening.

Wall-clock timings run through GPU completion, use the slowest rank, and include target verification, sampling, and drafting. Shortened verification also uses the serving budget policy and DP/TP agreement, including host selection and layout submission. DP-local serving omits cross-DP budget agreement, but still uses these synchronized, balanced startup measurements as a cost estimate. The native full-width tier omits budget selection. Metadata preparation, barriers, cache initialization, and post-graph feedback collection/publication are excluded, including finish_round's pinned D2H copies and events. At the position limit, profiling reserves space for the following draft block.

Costs are cached in the following directory:

text
$XDG_CACHE_HOME/tokenspeed/adaptive-dspark

If XDG_CACHE_HOME is unset, the root is ~/.cache. This is a disk cost cache, not a prefix/KV cache or a setting for all compiler caches. Compatible entries are reused; hardware, model, topology, graph, or software changes can invalidate them. Regions without enough cache capacity or valid samples are skipped. The cache stores an identity digest and measurements rather than raw runtime or environment settings. Older cache formats are misses; existing files aren't rewritten or deleted during loading.

Verification layout ​

A captured Triton kernel assigns per-request prefix lengths and builds packed row indexes and CSR boundaries. Ties preserve request/token order. Under attention DP, it reads current GPU confidence by request slot and uses historical scores when a current row is non-finite. A device-resident live request count excludes padding from draft allocation. Padding keeps one physical anchor for existing CSR and sampling conventions; its state writes use the runtime's dummy slot and its outputs are discarded. Budget rewards count real requests only, while costs use the selected physical graph capacity.

The packed row indexes also gather the request-major xgrammar bitmask into the target-logit order before sampling. Acceptance indexes retain the normal flat request * width + column layout. To score an emitted token's output logprob, the sampler subtracts that request base and adds the request's CSR start; it never indexes the packed tensor with the flat acceptance index directly. An unused -1 tail entry scores against the request's anchor and is excluded from the emitted output by its accepted length.

Shared-capacity graphs require all ranks, including idle ranks, to participate in the same host budget agreement. DP-local graphs select independently.

The kernel requires:

  • GPU inputs with unit column stride for confidence scores.
  • local_batch_size * (draft_width + 1) <= 4096.

With five draft tokens, the layout supports up to 682 requests per attention rank. Larger capture buckets retain native full-width verification and skip adaptive layout capture; smaller supported buckets remain adaptive. Direct unsupported layout calls raise an error; there is no production PyTorch fallback. A PyTorch reference is retained only in tests.

Verify adaptive behavior ​

  1. Inspect the startup logs. For regions reusing a compatible cost cache, confirm that the log reports Adaptive DSpark loaded and calibration regions. For regions that require profiling, confirm that Adaptive DSpark startup profile complete reports the local_bs, context, full_ms, and adaptive_ms fields. Adaptive DSpark startup profile unavailable means that the affected region retains full verification.

  2. Generate decode-only traffic that reaches the configured local batch threshold, and then inspect the Adaptive DSpark budget decisions log on the lead verification rank. The log appears every 1024 eligible decisions and keys counts by (request_capacity, query_capacity, reason):

    • packed confirms selection of a shortened graph.
    • full confirms selection of full verification with available feedback and calibration.
    • feedback_unavailable indicates missing confidence feedback.
    • uncalibrated indicates unavailable cost coverage.

    context_bounds spans the available feedback seen so far. Startup clears these counters before serving. Steps below admission thresholds aren't counted, and the last log can omit up to 1023 trailing decisions. These host-only counters don't read GPU tensors or add collectives. With DP-local graphs, each rank records its own decisions.

  3. Compare paired application measurements with adaptive verification enabled and disabled on the intended workload and hardware. Validate both correctness and performance. Synthetic startup timings don't reproduce every workload's routing, acceptance, or memory locality, so startup logs alone don't demonstrate a serving benefit.

TokenSpeed documentation