Skip to content

Commit fdaa8a8

Browse files
committed
[cli] Fix startup ImportError, remove heavy deps, clean up build config
- Make openai import lazy in bench/engine_bench (request_sender, config): any lmcache command (including --help) no longer crashes with ImportError when openai is not installed; error is deferred to lmcache bench engine invocation with a clear install hint - Remove transformers from requirements/cli.txt (already a lazy optional import with try/except fallback in prompt.py) - Revert lmcache/cli/request.py to dev (ttft_s = -1.0 when no token) - pyproject_cli.toml: drop ninja (not needed for pure-Python wheel), relax setuptools to >=68.0.0 Signed-off-by: deng451e <838677410@qq.com>
1 parent e1bde6f commit fdaa8a8

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

lmcache/cli/commands/bench/engine_bench/config.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import urllib.error
1010
import urllib.request
1111

12-
# Third Party
13-
from openai import OpenAI
14-
1512
# First Party
1613
from lmcache.logging import init_logger
1714

@@ -76,6 +73,15 @@ def auto_detect_model(engine_url: str) -> str:
7673
api_key = os.getenv("OPENAI_API_KEY", "sk-dummy")
7774
logger.debug("Auto-detecting model from %s/models", base_url)
7875

76+
try:
77+
# Third Party
78+
from openai import OpenAI # noqa: PLC0415
79+
except ImportError as e:
80+
raise ImportError(
81+
"The 'openai' package is required for 'lmcache bench'. "
82+
"Install it with: pip install openai"
83+
) from e
84+
7985
try:
8086
client = OpenAI(base_url=base_url, api_key=api_key)
8187
models = client.models.list()

lmcache/cli/commands/bench/engine_bench/request_sender.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import os
88
import time
99

10-
# Third Party
11-
from openai import AsyncOpenAI
12-
1310
# First Party
1411
from lmcache.cli.commands.bench.engine_bench.stats import RequestResult
1512
from lmcache.logging import init_logger
@@ -86,6 +83,15 @@ def __init__(
8683
else:
8784
logger.debug("API key source: OPENAI_API_KEY env var")
8885

86+
try:
87+
# Third Party
88+
from openai import AsyncOpenAI # noqa: PLC0415
89+
except ImportError as e:
90+
raise ImportError(
91+
"The 'openai' package is required for 'lmcache bench'. "
92+
"Install it with: pip install openai"
93+
) from e
94+
8995
self._client = AsyncOpenAI(
9096
base_url=base_url,
9197
api_key=api_key,

lmcache/cli/request.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ def _stream(
202202
# Match V2RequestSender: server count if present, else max_tokens cap.
203203
num_generated = num_completion if num_completion > 0 else max_tokens
204204
if first_token_t is None:
205-
# No non-empty content token observed (e.g. model emitted only EOS).
206-
# Use total round-trip as a conservative TTFT approximation.
207-
ttft_s = t1 - t0
205+
ttft_s = -1.0
208206
decode_time = 0.0
209207
else:
210208
ttft_s = first_token_t - t0

pyproject_cli.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
# Thus, we will still lock a torch version here because we can choose to release wheels
99
# in sync with vllm and update our torch version accordingly
1010
requires = [
11-
"ninja",
1211
"packaging>=24.2",
13-
"setuptools>=77.0.3,<81.0.0",
12+
"setuptools>=68.0.0",
1413
"setuptools_scm>=8",
1514
"wheel",
1615
]

requirements/cli.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
transformers>=4.51.1

0 commit comments

Comments
 (0)