Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion python/sglang/srt/disaggregation/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,21 @@ def pop_transferred(self) -> List[Req]:
: decode_req.req.top_logprobs_num
].tolist()
)

if hasattr(decode_req.kv_receiver, "clear"):
decode_req.kv_receiver.clear()
transferred_reqs.append(decode_req.req)

# special handling for sampling_params.max_new_tokens == 1
if decode_req.req.sampling_params.max_new_tokens == 1:
# finish immediately
decode_req.req.check_finished()
self.scheduler.stream_output(
[decode_req.req], decode_req.req.return_logprob
)
self.tree_cache.cache_finished_req(decode_req.req)
Comment on lines +612 to +618
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider extracting the code block that starts at line 618 and ends at line 624 into a separate function to improve code modularity and readability. This new function could be named something like handle_max_new_tokens_equals_one.

def handle_max_new_tokens_equals_one(decode_req):
    decode_req.req.check_finished()
    self.scheduler.stream_output(
        [decode_req.req], decode_req.req.return_logprob
    )
    self.tree_cache.cache_finished_req(decode_req.req)

if decode_req.req.sampling_params.max_new_tokens == 1:
    # finish immediately
    handle_max_new_tokens_equals_one(decode_req)

else:
transferred_reqs.append(decode_req.req)

indices_to_remove.add(i)
elif poll in [
KVPoll.Bootstrapping,
Expand Down
Loading