Skip to content

fix(kernel): exact single-launch triton top-k/top-p sampling - #345

Open
jason-fxz wants to merge 1 commit into
mainfrom
fix/triton-topk-histogram
Open

fix(kernel): exact single-launch triton top-k/top-p sampling#345
jason-fxz wants to merge 1 commit into
mainfrom
fix/triton-topk-histogram

Conversation

@jason-fxz

Copy link
Copy Markdown
Collaborator

The Triton sampling fallback (used when flashinfer is not installed) estimated the top-k / top-p threshold from a fixed-size outlier buffer. Whenever one token holds more than ~40% of the probability the estimate collapses and top-k keeps the whole vocabulary; top-p was off by a few percent everywhere.

This replaces the estimator with an exact histogram search over the fp32 bit pattern and fuses each op into a single kernel launch.

Verified against a tie-aware torch reference (1.9M rows, 0 mismatches) and against flashinfer (identical kept sets).

Supersedes #329 — thanks @taking-lying-flat for catching this.

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.

1 participant