[PR #9669] [MERGED] sample: fix sorting order and top_k #75327

Closed
opened 2026-05-05 07:45:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/9669
Author: @ParthSareen
Created: 3/12/2025
Status: Merged
Merged: 3/12/2025
Merged by: @ParthSareen

Base: mainHead: parth/sample-fix-sorting


📝 Commits (3)

  • db10a7d sample: use container/heap for top_k
  • 8b1ae03 sample: simplify top_k=0 sorting
  • f257f1f sample: do all sorting in topK

📊 Changes

3 files changed (+92 additions, -135 deletions)

View changed files

📝 sample/samplers.go (+2 -5)
📝 sample/transforms.go (+46 -105)
📝 sample/transforms_test.go (+44 -25)

📄 Description

  • the existing min heap implementation would fail for maintaining the correct sorting order - added container/heap implementation

  • partial sorting instead of counting sort

  • added tests to ensure floats were checked correctly

  • vibe check the logits and model


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/9669 **Author:** [@ParthSareen](https://github.com/ParthSareen) **Created:** 3/12/2025 **Status:** ✅ Merged **Merged:** 3/12/2025 **Merged by:** [@ParthSareen](https://github.com/ParthSareen) **Base:** `main` ← **Head:** `parth/sample-fix-sorting` --- ### 📝 Commits (3) - [`db10a7d`](https://github.com/ollama/ollama/commit/db10a7da88118e3a4036bb1270d268e5644e46f8) sample: use container/heap for top_k - [`8b1ae03`](https://github.com/ollama/ollama/commit/8b1ae0330202a34c5bdcb8bbdf48da71e300a55a) sample: simplify top_k=0 sorting - [`f257f1f`](https://github.com/ollama/ollama/commit/f257f1fd04785c1ffe2e19826bc89b89a500adbc) sample: do all sorting in topK ### 📊 Changes **3 files changed** (+92 additions, -135 deletions) <details> <summary>View changed files</summary> 📝 `sample/samplers.go` (+2 -5) 📝 `sample/transforms.go` (+46 -105) 📝 `sample/transforms_test.go` (+44 -25) </details> ### 📄 Description - the existing min heap implementation would fail for maintaining the correct sorting order - added container/heap implementation - partial sorting instead of counting sort - added tests to ensure floats were checked correctly - [ ] vibe check the logits and model --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-05-05 07:45:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#75327