Skip to content

dspark POC - #1

Draft
Ankk98 wants to merge 33 commits into
masterfrom
ft-dspark
Draft

dspark POC#1
Ankk98 wants to merge 33 commits into
masterfrom
ft-dspark

Conversation

@Ankk98

@Ankk98 Ankk98 commented Jun 29, 2026

Copy link
Copy Markdown
Owner

This is a work in progress.

This is a proof of concept branch, meant for validating and benchmarking dspark algo. The plan to to create a new branch and PR once the validation is complete. This PR is just for viewing diff.

Here, I am trying to implement DSpark Speculative Decoding Algo for Gemma 4 12B QAT variant.

Key Benchmarking Results

Workload Fair best
Coding 1.57x (-c 512)
Agentic 1.40x

  • Vanilla TGP 25 TPS to 39 TGP with speculation for coding use
  • Accept/step ~ 2.50

Notes

  • Quantized draft model from BF16 to Q4_0 (6.9 GB to ~1.8 GB) (Quantization led to almost no difference in output quality)
  • Using 4 draft token fixed generation led to best speedup in tgp
  • PP has slowed down, Need to look into it.
  • Confidence-Scheduled Verification degraded performance. Need to look into it.

Testing Hardware

  1. Strix Halo with 32GB shared dram with fedora 44 (ROG Flow Z13) (AMD RYZEN AI MAX 390 (24) @ 5.06 GHz) (AMD Radeon 8050S Graphics [Integrated]) (Linux 7.0.13-200.fc44.x86_64) (using Vulkan)
  2. Nvidia RTX 3090 based VPS - 24 GB VRAM - Ubuntu 22 - Cuda 12.

References

Contact

Feel free to reach out to me for anything at https://x.com/ankk98

Ankk98 and others added 30 commits June 29, 2026 11:58
* Add new command-line options for DSpark, including --input-ids, --dspark-confidence-threshold, and --dspark-disable-markov.
* Introduce common_load_input_ids_json function to load token IDs from a JSON array.
* Extend common_params_speculative structure to include DSpark-specific parameters.
* Implement DSpark speculative decoding logic in common_speculative.cpp.
* Add Gemma4DSparkModel class for model conversion and integration.
* Update documentation to outline DSpark implementation plan and validation steps.

This commit lays the groundwork for integrating DSpark speculative decoding into the llama.cpp framework, enhancing model performance and flexibility.
…eculative.cpp

* Introduced conditional logging to display draft and target IDs during the speculative decoding process when the DSPARK_DEBUG environment variable is set and the number of propose steps is 12 or fewer.
* This enhancement aids in debugging and understanding the acceptance process in speculative decoding.
* Introduced a new structure for managing GPU resources for the DSpark Markov head, allowing heavy computations to be offloaded to the GPU when available.
* Added initialization and cleanup functions for GPU resources in llama-model.cpp.
* Updated common_speculative_impl_draft_dspark to utilize GPU for bias calculations, improving performance during speculative decoding.
* Modified tests to ensure compatibility with the new GPU offloading feature, enhancing the overall robustness of the speculative decoding process.
* Enhanced the handling of logits by introducing a softcap mechanism and integrating Markov bias calculations into the greedy sampling path.
* Improved performance by conditionally applying softcap and Markov bias based on temperature and draft probabilities.
* Streamlined the process for sampling tokens, ensuring efficient computation during speculative decoding.
* convert: add dsv4 conversion

* add basic setup

* add llm_graph_input_dsv4

* add save-load state

* add sinkhorn eps - correction by @fairydreaming

* add rope fix

* cleanup dead code

* fix bugs

* support pro model: added by @fairydreaming

* remove redundant V cache

* Chat template

* remove debugging leftovers

* Add mechanism for inlining templates based on architecture

* s/deepseek-v4-flash/deepseek4/g

* s/deepseek-v4-flash/deepseek4/g continued

* enable graph reuse

* enable FA

* fix test llama archs

* rename

* compatibility with antirez ds4 GGUFs

* simplified set_gguf_parameters() by calling super class method, replaced moe.score_func with expert_gating_func.

* reserve worst-case kv-cache

* revert max split inputs

* address review comments

* add padding to enable FA

* pad only the final value of plan.n_kv to 256

* remove built-in cpp chat template

* cont: remove cpp built-in template

* rm outdated test

* replace ggml_view_3d() with ggml_reshape_3d()

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* only support n_seq=1 for now

* remove unused var

* cont: remove unused var

* use scale bias

* use correct ptr for can_reuse

* remove gen-chat-inline-templates.py

* simplify graph reuse

* cont: cleanup

* remove unused inputs

* enable partial checkpointing

* add correct shape for kq_mask + set llama_model_n_swa to 0 for dsv4

* precompute source_idx + add comment about dummy write

* support multi-seq

* remove restored_trim_pos

* use split_equal when possible

* fix indent

* address review comments

* use LLM_KV

* fix ci

---------

Co-authored-by: Piotr Wilkin <piotr.wilkin@syndatis.com>
Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
Co-authored-by: fairydreaming <166155368+fairydreaming@users.noreply.github.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
* Introduced a new GPU-based block sampling mechanism that fuses the Markov chain processing into a single graph dispatch, significantly improving performance during speculative decoding.
* Added profiling capabilities to track performance metrics for draft-forward and sampling steps.
* Updated the common_speculative_impl_draft_dspark structure to accommodate the new block sampling logic and integrated it into the decoding process.
* Enhanced the llama-ext.h and llama-model.cpp files with new functions for initializing and managing the GPU block sampler.
* Modified tests to include timing statistics for draft and verification steps, aiding in performance evaluation.
* Updated the handling of the `common_speculative_process` function across multiple test files to ensure it processes the correct batch of tokens.
* Introduced new timing metrics for target decoding, acceptance, and processing steps to enhance performance profiling.
* Adjusted output logging to provide clearer insights into the timing of various speculative decoding phases, aiding in performance evaluation.
Single-pass batched target verify with post-decode sync, truncated
process() on the committed prefix, and consolidated verify_batched API.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
- Single GPU sync for multi-layer feature reads (no_sync layer inp API)
- Optional split verify via ctx_tgt_feat + shared KV (DSPARK_SPLIT_VERIFY=1)
- Benchmark harness: spec-first, warmup, draft-max 5 for smaller verify batch

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Cap draft decode at n_draft+1 (keeping fused block_gpu per length), shrink
proposals adaptively on low hit-rate prompts, default n_max=4, dedupe verify
sync, and run vanilla before spec in compare_vanilla_speculative.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Expand adaptive n_max when hit rate > 72%, add decode_submit_ms to verify
timing, restore spec-first bench order, default n_max=3 (best coding sweep),
and add docs/dspark-benchmark-experiments.md for experiment tracking.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Print vanilla vs spec prefill and generation tok/s in compare harness, skip
redundant process() GPU fence on short verify batches, tune adaptive n_max
thresholds (0.50/0.65), and expand benchmark doc with measured pp/tgp numbers.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Run vanilla before spec with KV reset and 3s cooldown, document actual pp/tgp
for both paths, retract spec-first inflated speedups, set n_max=4 as fair
coding sweet spot (1.61x, token match YES).

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
…tic (ggml-org#25005)

* vulkan: extract flops calculation into function

* use flops instead of matmul src0 tensor size for submission threshold

* use unsigned ints
Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
…g#25131)

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
Fix defer-layer D2H to copy only accepted rows from the full verify batch.
Continue generation when confidence truncation yields an empty proposal.
Document confidence-threshold sweep (-c 512) and add opt-in fused verify argmax.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Introduce a new document for DSpark benchmark experiments on NVIDIA CUDA, detailing the environment setup, performance metrics, and comparisons with Vulkan. Update the existing benchmark experiments document to reference the new CUDA results, highlighting a ~2.0x coding speedup on RTX 3090.
Default sequential target verify on CUDA builds (batched multi-token
forward diverged from vanilla). Add shared prefill API, committed
re-decode path for non-defer backends, and CUDA-aligned vanilla prefill
in the compare harness.

Assisted-by: Claude Sonnet
Co-authored-by: Cursor <cursoragent@cursor.com>
…park`

Introduce a new comprehensive reference document comparing NVIDIA's upstream vLLM DSpark integration with the llama.cpp port on branch `ft-dspark`. The document outlines architectural choices, performance metrics, and key differences between the two implementations, providing insights into their respective approaches to non-causal attention, CUDA graph usage, and model coverage. Related documentation links are also included for further context.
…org#24588)

* HIP: keep MMQ for gfx900 MoE and Q8_0, use hipBLAS for dense K-quants

Assisted-by: GitHub Copilot CLI

* HIP: tighten conditional block to be explicitly for gfx900

* HIP: Further simplified gfx900 conditional block

* removed unnecessary comment
* vulkan: roll bk loop in matmul for asahi linux

* vulkan: fix inline comment

* vulkan: revert BK-loop unroll change

* vulkan: edit spirv directly for asahi roll bk loop

* vulkan: remove trailing whitespace at the end of comments
Make greedy verify sequential by default for token-match correctness;
keep batched defer/fast paths behind DSPARK_VERIFY_FAST=1 with KV tail
trim and committed-batch process fixes. Add CUDA VPS setup script, P0
batched-logits repro harness, and benchmark/docs updates.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
Ankk98 and others added 3 commits June 30, 2026 16:37
…itional options. Introduce flags for skipping sync, model downloads, builds, and verification, along with a reboot option for GPU issues. Update usage documentation to reflect new capabilities.
Keep DSpark layer taps enabled during batched verify decode, process
accepted rows without a second target re-decode, and fall back to
sequential verify on CUDA when DSPARK_VERIFY_FAST is set.

Assisted-by: Auto
Co-authored-by: Cursor <cursoragent@cursor.com>
@Ankk98
Ankk98 marked this pull request as draft July 22, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants