Skip to content

tests : add speculative rejection draft sampling test - #30213

Merged
ggerganov merged 5 commits into
ggml-org:masterfrom
danbev:speculative-draft-test
Oct 24, 2026
Merged

ggerganov merged 5 commits into
ggml-org:masterfrom
danbev:speculative-draft-test

Conversation

@danbev

@danbev danbev commented Oct 9, 2026

Copy link
Copy Markdown
Member

Overview

This commit adds a test for speculative rejection sampling test that excercises the speculative rejection sampling mechanism in common/speculative.cpp.

Additional information

The motivation for this is have a test that verifies that the speculative draft models emitts tokens that match the target models distribution. So when rejection sampling occurs it should still produce the same probability distribution as if we directly sampled from the target model.

Running the test:

$ ctest --test-dir build -R "^test-speculative-rejection-sampling$" \
    --n_trials 5000 -V

This will generate two models, one target and one draft model.

For subsequent runs use the "fixture exclude any" option to avoid recreating the models:

$ ctest --test-dir build-cpu-debug -R \
    "^test-speculative-rejection-sampling$" \
    -FA "^speculative-models$" --n_trails 5000 -V

Requirements

This commit adds a test for speculative rejection sampling test that
excercises the speculative rejection sampling mechanism in
common/speculative.cpp.

The motivation for this is have a test that verifies that the
speculative draft models emitts tokens that  match the target models
distribution. So when rejection sampling occurs it should still
produce the same probability distribution as if we directly sampled
from the target model.

Running the test:
```console
$ ctest --test-dir build -R "^test-speculative-rejection-sampling$" \
    --n_trials 5000 -V
```
This will generate two models, one target and one draft model.

For subsequent runs use the "fixture exclude any" option to avoid
recreating the models:
```console
$ ctest --test-dir build-cpu-debug -R \
"^test-speculative-rejection-sampling$" \
    -FA "^speculative-models$" --n_trails 5000 -V
```
@github-actions github-actions Bot added the testing Everything test related label Oct 9, 2026
@ggerganov ggerganov self-assigned this Oct 9, 2026
@danbev
danbev marked this pull request as ready for review October 19, 2026 06:15
@danbev
danbev requested a review from ggerganov as a code owner October 19, 2026 06:15

@ggerganov ggerganov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify and speed-up the test by skipping the entire draft model logic. The idea is to generate random distributions result_q - they don't need to necessarily come from a draft model. For the purpose of the test, the Q distribution can be anything. This will avoid the need to create a common_speculative context and should make the test much faster.

The basic idea is to validate the common_sampler_sample_and_accept_n_rejection logic and for that purpose it does not actually matter where the draft probability distributions come from.

@ggerganov
ggerganov merged commit 3642238 into ggml-org:master Oct 24, 2026
27 checks passed
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
* tests : add speculative rejection draft sampling test

This commit adds a test for speculative rejection sampling test that
excercises the speculative rejection sampling mechanism in
common/speculative.cpp.

The motivation for this is have a test that verifies that the
speculative draft models emitts tokens that  match the target models
distribution. So when rejection sampling occurs it should still
produce the same probability distribution as if we directly sampled
from the target model.

Running the test:
```console
$ ctest --test-dir build -R "^test-speculative-rejection-sampling$" \
    --n_trials 5000 -V
```
This will generate two models, one target and one draft model.

For subsequent runs use the "fixture exclude any" option to avoid
recreating the models:
```console
$ ctest --test-dir build-cpu-debug -R \
"^test-speculative-rejection-sampling$" \
    -FA "^speculative-models$" --n_trails 5000 -V
```

* remove draft model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants