File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
xllm/core/framework/sampling Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -26,10 +26,21 @@ class ConstrainedDecoding {
2626 public:
2727 virtual ~ConstrainedDecoding ();
2828
29+ // Precompute and cache fixed constraint masks (e.g., static vocabulary
30+ // whitelists) to avoid redundant calculations during token generation.
31+ // Returns: true if cache built successfully, false otherwise
2932 virtual bool build_mask_cache ();
3033
31- // Input generated_token_list: [sequence_num][generated_token_ids]
32- // Output: mask tensor[sequence_num,vocab_size]
34+ // Generate dynamic constraint mask based on already generated token
35+ // sequences. This mask will be applied to filter invalid tokens.
36+ //
37+ // Input: generated_token_list - 2D vector of token IDs, where each inner
38+ // vector represents the generated tokens for a single sequence in the batch
39+ // (format:[sequence_num][token_ids])
40+ // Output: tensor of shape [sequence_num, vocab_size], where 0.0f
41+ // indicates allowed tokens and a large negative number indicates forbidden
42+ // tokens for each sequence, the usage is to filter invalid tokens by adding
43+ // the mask to the model logits.
3344 virtual torch::Tensor generate_mask (
3445 const std::vector<std::vector<int32_t >>& generated_token_list);
3546};
Original file line number Diff line number Diff line change 1+ /* Copyright 2025 The xLLM Authors. All Rights Reserved.
2+
3+ Licensed under the Apache License, Version 2.0 (the "License");
4+ you may not use this file except in compliance with the License.
5+ You may obtain a copy of the License at
6+
7+ https://github.com/jd-opensource/xllm/blob/main/LICENSE
8+
9+ Unless required by applicable law or agreed to in writing, software
10+ distributed under the License is distributed on an "AS IS" BASIS,
11+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ See the License for the specific language governing permissions and
13+ limitations under the License.
14+ ==============================================================================*/
15+
116#include " rec_constrained_decoding.h"
217
318#include < c10/core/TensorOptions.h>
You can’t perform that action at this time.
0 commit comments