common : refactor common_sampler + grammar logic changes #17937
+370
−291
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.