Skip to content

sampling : optimize dist sampler - #15704

Merged
ggerganov merged 1 commit into
masterfrom
gg/sampling-dist-opt
Sep 3, 2025
Merged

ggerganov merged 1 commit into
masterfrom
gg/sampling-dist-opt

Conversation

@ggerganov

@ggerganov ggerganov commented Aug 31, 2025 •

Copy link
Copy Markdown
Member

cont #15665

When the dist sampler runs on the full vocabulary (e.g. top-p = 1, top-k = 0, min-p = 0), the sampling time can have a non-negligible effect. This PR fuses the probability normalization loop with the inverse transform sampling.

On M2 Ultra, the tg with gpt-oss-120b goes from ~70t/s -> 78t/s at empty context.

@ggerganov
ggerganov merged commit cdedb70 into master Sep 3, 2025
@ggerganov
ggerganov deleted the gg/sampling-dist-opt branch September 3, 2025 15:16
gabe-l-hart added a commit to gabe-l-hart/llama.cpp that referenced this pull request Sep 4, 2025
…upport

* origin/master: (72 commits)
metal : Add template specialization for mul_mm_id w/ ne20 == 10 (ggml-org#15799)
llama : set n_outputs to 1 to avoid 0 outputs mean-pooling (ggml-org#15791)
CANN: Refactor ND to NZ workspace to be per-device (ggml-org#15763)
server: add exceed_context_size_error type (ggml-org#15780)
Document the new max GPU layers default in help (ggml-org#15771)
ggml: add ops for WAN video model (cuda && cpu) (ggml-org#15669)
CANN: Fix precision issue on 310I DUO multi-devices (ggml-org#15784)
opencl: add hs=40 to FA (ggml-org#15758)
CANN: fix acl_rstd allocation size in ggml_cann_rms_norm (ggml-org#15760)
vulkan: fix mmv subgroup16 selection (ggml-org#15775)
vulkan: don't use std::string in load_shaders, to improve compile time (ggml-org#15724)
vulkan : update ggml_vk_instance_validation_ext_available (ggml-org#15666)
ggml vulkan: add hardsigmoid and hardswish operations (ggml-org#15762)
CUDA: Optimize `rms_norm_f32` kernel and its fused variants, giving 1-6% perf E2E (ggml-org#15715)
model-conversion : fix pyright errors (ggml-org#15770)
sampling : optimize dist sampler (ggml-org#15704)
llama : fix incorrect model type for Gemma 270M (ggml-org#15764)
model-conversion : remove hardcoded /bin/bash shebangs [no ci] (ggml-org#15765)
CANN: Add RoPE contiguous check for 310I DUP device (ggml-org#15735)
ggml-cpu : optimize RVV kernels (ggml-org#15720)
...
walidbr pushed a commit to walidbr/llama.cpp that referenced this pull request Sep 7, 2025
blime4 referenced this pull request in blime4/llama.cpp Feb 5, 2026
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
my-other-github-account pushed a commit to my-other-github-account/llama.cpp that referenced this pull request May 15, 2026
Comment thread src/llama-sampling.cpp
if (!found) {
// accumulate probs until we reach the target sum
sum_run += cur_p->data[i].p;
if (sum_run >= sum_tgt) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line makes an assumption that cur_p->sorted is true. At least in the unit-test this is not the case (adding an assertion would fail). Do we have a potential issue here when cur_p is not sorted? I have not tested with actual models yet.

fukuro-kun pushed a commit to fukuro-kun/fukuro-llama-cpp-turboquant that referenced this pull request Jul 5, 2026
MrLordCat referenced this pull request in MrLordCat/llama.cpp-rdna-lab Jul 16, 2026
AMD-melliott pushed a commit to AMD-melliott/llama.cpp that referenced this pull request Aug 4, 2026
zommiommy pushed a commit to zommiommy/llama.cpp that referenced this pull request Aug 18, 2026
frostyautumnleaf pushed a commit to frostyautumnleaf/llama.cpp that referenced this pull request Oct 5, 2026
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.

2 participants