sglang icon indicating copy to clipboard operation
sglang copied to clipboard

Sampler gets all tokens

Open CallmeZhangChenchen opened this issue 10 months ago • 1 comments

the Sampler compute in this project, need all the generated tokens

class Sampler(nn.Module):
    def __init__(self):
        super().__init__()
        self.use_nan_detectioin = global_server_args_dict["enable_nan_detection"]

    def forward(
        self,
        logits_output: LogitsProcessorOutput,
        sampling_info: SamplingBatchInfo,
        return_logprob: bool,
        top_logprobs_nums: List[int],
    ):

So, how do I modify the code here to get all the tokens that have been generated Thanks

CallmeZhangChenchen avatar Feb 18 '25 09:02 CallmeZhangChenchen

You’ll need to modify the forward function so that—as it generates each token—it saves it (for example, by appending it to a list) and then returns that list. In many cases the sampling loop is where the token‐by‐token generation happens.

jhinpan avatar Feb 18 '25 17:02 jhinpan

I added decode_token_list: list = field(default_factory=list) to class SamplingBatchInfo: Perfect. It should be working

CallmeZhangChenchen avatar Mar 13 '25 06:03 CallmeZhangChenchen

This issue has been automatically closed due to inactivity. Please feel free to reopen it if needed.

github-actions[bot] avatar May 13 '25 00:05 github-actions[bot]