A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 17, 04:15 UTC
Replace `lstrip()` with `removeprefix()` to fix Ruff linter warning (#2958)
Ronen Schaffer committed
Mar 16, 2024 at 06:01 UTC
14e3f9a1b2711336ca2e68235eb53bf1b49880c5
2 files changed
+11
-6
benchmarks/backend_request_func.py
+11
-4
@@ -64,7 +64,7 @@ async def async_request_tgi(
64
output.ttft = ttft
65
output.latency = time.perf_counter() - st
66
67
- body = data.decode("utf-8").lstrip("data:")
67
+ body = remove_prefix(data.decode("utf-8"), "data:")
68
output.generated_text = json.loads(body)["generated_text"]
69
output.success = True
70
else:
@@ -158,7 +158,7 @@ async def async_request_trt_llm(
158
output.ttft = ttft
159
output.latency = time.perf_counter() - st
160
161
- body = data.decode("utf-8").lstrip("data:")
161
+ body = remove_prefix(data.decode("utf-8"), "data:")
162
output.generated_text = json.loads(body)["text_output"]
163
output.success = True
164
@@ -255,7 +255,7 @@ async def async_request_openai_completions(
255
if not chunk:
256
continue
257
258
- chunk = chunk.decode("utf-8").lstrip("data: ")
258
+ chunk = remove_prefix(chunk.decode("utf-8"), "data: ")
259
if chunk == "[DONE]":
260
latency = time.perf_counter() - st
261
else:
@@ -322,7 +322,7 @@ async def async_request_openai_chat_completions(
322
if not chunk:
323
continue
324
325
- chunk = chunk.decode("utf-8").lstrip("data: ")
325
+ chunk = remove_prefix(chunk.decode("utf-8"), "data: ")
326
if chunk == "[DONE]":
327
latency = time.perf_counter() - st
328
else:
@@ -344,6 +344,13 @@ async def async_request_openai_chat_completions(
344
return output
345
346
347
+# Since vllm must support Python 3.8, we can't use str.removeprefix(prefix) introduced in Python 3.9
348
+def remove_prefix(text: str, prefix: str) -> str:
349
+ if text.startswith(prefix):
350
+ return text[len(prefix):]
351
+ return text
352
+
353
+
354
ASYNC_REQUEST_FUNCS = {
355
"tgi": async_request_tgi,
356
"vllm": async_request_vllm,
pyproject.toml
-2
@@ -33,8 +33,6 @@ ignore = [
33
"F405", "F403",
34
# lambda expression assignment
35
"E731",
36
- # .strip() with multi-character strings
37
- "B005",
36
# Loop control variable not used within loop body
37
"B007",
38
]