From de111f32461bf751851c175af59e913fafaa16d1 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Fri, 17 Apr 2026 03:01:25 +0800 Subject: [PATCH] [Bugfix] Fix bench_serve UTF-8 decode crash on split multi-byte chars (#38732) --- vllm/benchmarks/lib/endpoint_request_func.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vllm/benchmarks/lib/endpoint_request_func.py b/vllm/benchmarks/lib/endpoint_request_func.py index 61af098f80..9c85ad686d 100644 --- a/vllm/benchmarks/lib/endpoint_request_func.py +++ b/vllm/benchmarks/lib/endpoint_request_func.py @@ -2,6 +2,7 @@ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project """The request function for API endpoints.""" +import codecs import io import json import os @@ -25,11 +26,12 @@ class StreamedResponseHandler: def __init__(self): self.buffer = "" + self._decoder = codecs.getincrementaldecoder("utf-8")() def add_chunk(self, chunk_bytes: bytes) -> list[str]: """Add a chunk of bytes to the buffer and return any complete messages.""" - chunk_str = chunk_bytes.decode("utf-8") + chunk_str = self._decoder.decode(chunk_bytes) self.buffer += chunk_str messages = []