[Continous Batching] fix do_Sample=True in continuous batching #40692
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.
This pull request introduces improvements to sampling support in continuous batching generation, enhances tensor shape handling for logit processors, and expands test coverage for batch generation with sampling. The main changes are grouped below:
Sampling and Generation Behavior:
batch_generate
by settingdo_sample=True
and configuringtemperature
andtop_p
parameters, allowing for more diverse outputs during batch generation.Tensor Shape Handling and Sampling Logic:
continuous_api.py
to handle 3D logits produced by continuous batching, reshaping them as needed for compatibility with logit processors and restoring original shapes after processing._sample
to ensure correct tensor dimensions when sampling tokens, making the method robust for both sampling and greedy decoding.Paged Attention and Integration:
flash_attn_varlen_func
in the attention implementation to ensure compatibility and prevent errors during paged attention forward passes.Testing and Validation:
generated_tokens
instead ofstatic_outputs
for accuracy.test_generate_batch_with_sampling
to verify that batch generation with sampling enabled works correctly across different attention implementations and configurations. The test checks for successful completion, non-empty outputs, and actual sampling behavior.