[Feature]Support tag phase token enforce generation - #6034
Merged
Merged
Conversation
|
Thanks for your contribution! |
| line_break_id: int, | ||
| ): | ||
| """ | ||
| reasoning_phase_token_constraint |
There was a problem hiding this comment.
函数缺少docstring说明。作为新增的公共API,应该添加详细的文档字符串,包括:
- 函数的功能描述
- 各个参数的含义和预期类型
- 返回值说明
- 使用示例(如果适用)
这对于API的可维护性和可用性非常重要。
Suggested change
| reasoning_phase_token_constraint | |
| Apply reasoning-phase token constraints to the logits for next-token prediction. | |
| This function wraps a device-specific backend operator that enforces constraints | |
| on the token distribution during the reasoning (or "thinking") phase. It updates | |
| ``logits`` in place according to the current decoding step, allowed tokens, and | |
| reasoning status, then returns the same tensor for convenience. | |
| Args: | |
| logits (paddle.Tensor): Logits for candidate tokens at the current decoding | |
| step. Shape is typically ``[batch_size, vocab_size]`` or a similar | |
| 2-D tensor. This tensor is modified in place. | |
| pre_token_ids (paddle.Tensor): Previously generated token ids for each | |
| sequence in the batch. Typically a 2-D integer tensor of shape | |
| ``[batch_size, seq_len]``. | |
| stop_flags (paddle.Tensor): Boolean or integer tensor indicating which | |
| sequences have already met their stop conditions and should no longer | |
| produce new tokens. Shape: ``[batch_size]``. | |
| seq_lens_this_time (paddle.Tensor): Effective sequence lengths for the | |
| current decoding step (after padding is removed). Shape: ``[batch_size]``. | |
| seq_lens_encoder (paddle.Tensor): Encoder-side sequence lengths associated | |
| with each sequence in the batch. Shape: ``[batch_size]``. | |
| step_idx (paddle.Tensor): Current decoding step index, usually a scalar or | |
| a 1-D tensor with a single element. | |
| reasoning_allowed_tokens (paddle.Tensor): Tensor containing the ids of | |
| tokens that are allowed to be generated during the reasoning phase. | |
| The exact shape depends on how allowed tokens are represented but is | |
| typically integer-typed. | |
| reasoning_status (paddle.Tensor): Tensor indicating the reasoning status | |
| for each sequence (for example, whether the sequence is currently in | |
| reasoning mode or in normal generation). Shape: ``[batch_size]``. | |
| output_padding_offset (paddle.Tensor): Tensor used to map from padded | |
| batch positions to compacted positions after removing padding. | |
| output_cum_offsets (paddle.Tensor): Cumulative offsets associated with | |
| ``output_padding_offset`` for efficient indexing on the device. | |
| think_end_id (int): Special token id that marks the end of the reasoning | |
| phase. When this id is generated, constraints may change or be lifted. | |
| line_break_id (int): Token id corresponding to a line break (such as | |
| ``"\\n"``). This can be used as a constraint boundary for reasoning | |
| or output formatting. | |
| Returns: | |
| paddle.Tensor: The same ``logits`` tensor after in-place modification by | |
| the backend operator. Returned for API convenience and potential chaining. | |
| Example: | |
| .. code-block:: python | |
| logits = reasoning_phase_token_constraint( | |
| logits=logits, | |
| pre_token_ids=pre_token_ids, | |
| stop_flags=stop_flags, | |
| seq_lens_this_time=seq_lens_this_time, | |
| seq_lens_encoder=seq_lens_encoder, | |
| step_idx=step_idx, | |
| reasoning_allowed_tokens=reasoning_allowed_tokens, | |
| reasoning_status=reasoning_status, | |
| output_padding_offset=output_padding_offset, | |
| output_cum_offsets=output_cum_offsets, | |
| think_end_id=think_end_id, | |
| line_break_id=line_break_id, | |
| ) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #6034 +/- ##
==========================================
Coverage ? 67.33%
==========================================
Files ? 349
Lines ? 45069
Branches ? 6939
==========================================
Hits ? 30345
Misses ? 12486
Partials ? 2238
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
freeliuzc
added a commit
to freeliuzc/FastDeploy
that referenced
this pull request
Jan 27, 2026
* support tag phase token enforce generation * optimize note and some feature * fix sampler unit test --------- Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com>
LLSGYN
pushed a commit
to LLSGYN/FastDeploy
that referenced
this pull request
Feb 2, 2026
* support tag phase token enforce generation * optimize note and some feature * fix sampler unit test --------- Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com>
chang-wenbin
pushed a commit
to chang-wenbin/FastDeploy
that referenced
this pull request
Mar 2, 2026
* support tag phase token enforce generation * optimize note and some feature * fix sampler unit test --------- Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com>
xiaoguoguo626807
pushed a commit
to xiaoguoguo626807/FastDeploy
that referenced
this pull request
May 7, 2026
* support tag phase token enforce generation * optimize note and some feature * fix sampler unit test --------- Co-authored-by: YuBaoku <49938469+EmmonsCurse@users.noreply.github.com>
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.
Motivation
[Feature]Support tag phase token enforce generation #6031
Modifications
Usage or Command
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.