common : refactor common_sampler + grammar logic changes#17937
Merged
common : refactor common_sampler + grammar logic changes#17937
Conversation
danbev
reviewed
Dec 12, 2025
danbev
reviewed
Dec 12, 2025
danbev
approved these changes
Dec 12, 2025
blime4
referenced
this pull request
in blime4/llama.cpp
Feb 5, 2026
* common : refactor common_sampler + grammar logic changes * tests : increase max_tokens to get needed response * batched : fix uninitialized samplers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
from #17004
Extracting some refactoring portions from #17004 to make the review easier:
common_init_resultnow also owns the sampler chains constructed duringcommon_init_from_params()common_init_resultare constructed before the model and the context - we will need this for sampling : add support for backend sampling #17004 in order to optionally pass the samplers during the construction of the contextref #17750 (comment)
Another change related to the grammar logic (the explanation is in the referenced comment):
common_samplerchainThe main reason for this change is to make the integration of #17004 compatible with grammar usage and to simplify the logic for handling the grammar when it is present. The main concern is that this will likely hurt the performance when grammar sampling is involved, since we no longer do the "rejection sampling" trick. I think it's better to put effort to optimize the performance of the grammar in general so we don't need to do the trick at all.