Skip to content

Define non-positive top_k; top_k range check#779

Merged
ggerganov merged 2 commits intoggml-org:masterfrom
ivanstepanovftw:non-positive-topk
Apr 5, 2023
Merged

Define non-positive top_k; top_k range check#779
ggerganov merged 2 commits intoggml-org:masterfrom
ivanstepanovftw:non-positive-topk

Conversation

@ivanstepanovftw
Copy link
Copy Markdown
Contributor

  1. With --top_k 0 expected that all logits will be sampled (by top_p)
  2. Range check added to prevent from resizing logits more than vocab have. Resizing to more than vocab have causes token 0 to be appended to logits to be sampled

Comment thread llama.cpp Outdated
@ggerganov ggerganov merged commit 5a8c4f6 into ggml-org:master Apr 5, 2023
@ivanstepanovftw ivanstepanovftw deleted the non-positive-topk branch April 5, 2023 16:20
@Piezoid
Copy link
Copy Markdown
Contributor

Piezoid commented Apr 6, 2023

@ivanstepanovftw @ggerganov
Correct me if I'm mistaken, but I think the top_p filter needs the logits to be sorted. With this PR, disabling the top_k filter bypasses the sorting.

Instead, the whole array should be sorted when there is no top_k filtering:

sample_top_k(logits_id, top_k > 0 ? std::min(top_k, n_logits) : n_logits);

@ivanstepanovftw
Copy link
Copy Markdown
Contributor Author

You are right!

Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* Define non-positive top_k; top_k range check

* minor : brackets

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
* Define non-positive top_k; top_k range check

* minor : brackets

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
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.

3 participants