fix: kv_cache backend probe must not raise when optimum is absent

quantized_cache_backend_available() called importlib.util.find_spec
("optimum.quanto"), which imports the parent `optimum` package to resolve
the submodule and raises ModuleNotFoundError when optimum is not installed
(instead of returning None). CI (no optimum) hit this on every test cell;
the live `soup serve --kv-cache-type q8_0` advisory path would crash the
same way on any box without optimum. Wrap submodule probes in a _spec_exists
helper that treats ModuleNotFoundError/ValueError as "not available".
This commit is contained in:
Alpamys 2026-06-05 20:17:57 +05:00
parent 6ec36b5ff6
commit 0eb3fc1ed0
1 changed files with 18 additions and 3 deletions

View File

@ -151,15 +151,30 @@ def quantized_cache_backend_available() -> Optional[str]:
``optimum-quanto`` / ``quanto`` (2/4-bit). Returns the first found, else
``None`` (the ``q8_0`` path then surfaces a friendly install advisory).
"""
if importlib.util.find_spec("hqq") is not None:
if _spec_exists("hqq"):
return "hqq"
if importlib.util.find_spec("optimum.quanto") is not None:
if _spec_exists("optimum.quanto"):
return "quanto"
if importlib.util.find_spec("quanto") is not None:
if _spec_exists("quanto"):
return "quanto"
return None
def _spec_exists(name: str) -> bool:
"""``True`` if ``name`` is importable, ``False`` otherwise.
``importlib.util.find_spec`` imports the *parent* package to resolve a
dotted submodule (e.g. ``optimum.quanto`` imports ``optimum``); when the
parent is absent it raises ``ModuleNotFoundError`` rather than returning
``None``. Treat that and a malformed ``__path__`` (``ValueError``) as
"not available" so the probe never raises on a box missing the optional dep.
"""
try:
return importlib.util.find_spec(name) is not None
except (ModuleNotFoundError, ValueError):
return False
def _validate_compute_capability(
cc: object,
) -> Optional[Tuple[int, int]]: