Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix streaming #437

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions python/sglang/srt/managers/router/infer_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ class FinishReason(IntEnum):
LENGTH = auto()
STOP_STR = auto()

def to_str(self):
if self == FinishReason.EOS_TOKEN:
@staticmethod
def to_str(reason):
if reason == FinishReason.EOS_TOKEN:
return None
elif self == FinishReason.LENGTH:
elif reason == FinishReason.LENGTH:
return "length"
elif self == FinishReason.STOP_STR:
elif reason == FinishReason.STOP_STR:
return "stop"
else:
raise ValueError(f"Invalid finish reason: {self}")
return None


class Req:
Expand Down
4 changes: 2 additions & 2 deletions python/sglang/srt/managers/router/model_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
FlushCacheReq,
TokenizedGenerateReqInput,
)
from sglang.srt.managers.router.infer_batch import Batch, ForwardMode, Req
from sglang.srt.managers.router.infer_batch import Batch, ForwardMode, Req, FinishReason
from sglang.srt.managers.router.model_runner import ModelRunner
from sglang.srt.managers.router.radix_cache import RadixCache
from sglang.srt.managers.router.scheduler import Scheduler
Expand Down Expand Up @@ -615,7 +615,7 @@ def handle_finished_requests(self, batch: Batch):
+ len(req.output_ids)
- req.prompt_tokens,
"completion_tokens_wo_jump_forward": req.completion_tokens_wo_jump_forward,
"finish_reason": req.finish_reason.to_str(),
"finish_reason": FinishReason.to_str(req.finish_reason),
"hit_stop_str": req.hit_stop_str,
}
if req.return_logprob:
Expand Down