KeyError: 'optimum.quanto' for `_is_package_available`
Author: kaixuanliu
Pull request: no
Labels: name: bug

### System Info

When i run pytest -rA tests/models/video_llama_3/test_modeling_video_llama_3.py::VideoLlama3ModelTest::test_generate_with_quant_cache, it will fail and return error:
```
pkg_name = 'optimum.quanto', return_version = True

    def _is_package_available(pkg_name: str, return_version: bool = False) -> tuple[bool, str] | bool:
        """Check if `pkg_name` exist, and optionally try to get its version"""
        spec = importlib.util.find_spec(pkg_name)
        package_exists = spec is not None
        package_version = "N/A"
        if package_exists and return_version:
            try:
                # importlib.metadata works with the distribution package, which may be different from the import
                # name (e.g. `PIL` is the import name, but `pillow` is the distribution name)
>               distributions = PACKAGE_DISTRIBUTION_MAPPING[pkg_name]
E               KeyError: 'optimum.quanto'

src/transformers/utils/import_utils.py:56: KeyError
```
I suggest one approach to solve this is add `KeyError` to except line in [L61](https://github.com/huggingface/transformers/blob/main/src/transformers/utils/import_utils.py#L61), is it OK?

### Who can help?

@SunMarc FYI

### Information

- [x] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

1. git clone https://github.com/huggingface/transformers.git
2. pip install optimum-quanto
3. export RUN_SLOW=1
4. pytest -rA tests/models/video_llama_3/test_modeling_video_llama_3.py::VideoLlama3ModelTest::test_generate_with_quant_cache

### Expected behavior

The test case is expected to pass.

Comments:
transformers version: `transformers              5.0.0.dev0`(built from source)
info from `pip freeze`:
```
absl-py==2.3.1
accelerate==1.6.0
aiohappyeyeballs==2.6.1
aiohttp==3.13.0
aiosignal==1.4.0
annotated-doc==0.0.3
annotated-types==0.7.0
anyio==4.11.0
arrow==1.4.0
attrs==25.4.0
audioread==3.0.1
auto_round==0.7.0
autoawq==0.2.9
autopep8==2.3.2
av==15.1.0
babel==2.17.0
beautifulsoup4==4.14.2
binaryornot==0.4.4
bitsandbytes @ git+https://github.com/bitsandbytes-foundation/bitsandbytes.git@c3b8de268fdb55a88f92feada23fc811a1e6877a
black==25.9.0
certifi==2025.10.5
cffi==2.0.0
chardet==5.2.0
charset-normalizer==3.4.3
click==8.2.1
colorama==0.4.6
compressed-tensors==0.12.2
contourpy==1.3.3
cookiecutter==1.7.3
csvw==3.7.0
cycler==0.12.1
DataProperty==1.1.0
datasets==3.6.0
decorator==5.2.1
decord==0.6.0
device-smi==0.4.1
-e git+https://github.com/kaixuanliu/diffusers.git@ecd4c8b621b5a423278b3441b68243da4e277ab5#egg=diffusers
dill==0.3.4
Distance==0.1.3
distro==1.9.0
dlinfo==2.0.0
dpcpp-cpp-rt==2025.2.1
einops==0.8.1
essentia==2.1b6.dev1389
evaluate==0.4.6
execnet==2.1.1
faiss-cpu==1.12.0
fastapi==0.120.0
fastjsonschema==2.21.2
filelock==3.19.1
fire==0.7.1
fonttools==4.60.1
frozenlist==1.8.0
fsspec==2025.3.0
ftfy==6.3.1
g2p-en==2.1.0
galore-torch==1.0
gguf==0.17.1
gitdb==4.0.12
GitPython==3.1.18
gptqmodel==4.2.5
grpcio==1.76.0
h11==0.16.0
hf-doc-builder==0.5.0
hf-xet==1.2.0
hf_transfer==0.1.9
hjson==3.1.0
hqq==0.2.8
httpcore==1.0.9
httpx==0.28.1
huggingface-hub==1.0.0rc6
hypothesis==6.140.3
idna==3.10
immutables==0.21
impi-rt==2021.16.1
importlib_metadata==8.7.0
importlib_resources==6.5.2
inflect==7.5.0
iniconfig==2.1.0
intel-cmplr-lib-rt==2025.2.1
intel-cmplr-lib-ur==2025.2.1
intel-cmplr-lic-rt==2025.2.1
intel-opencl-rt==2025.2.1
intel-openmp==2025.2.1
intel-pti==0.13.1
intel-sycl-rt==2025.2.1
invisible-watermark==0.2.0
isodate==0.7.2
Jinja2==3.1.6
jinja2-time==0.2.0
jiter==0.11.1
joblib==1.5.2
jsonlines==4.0.0
jsonschema==4.25.1
jsonschema-specifications==2025.9.1
jupyter_core==5.8.1
kenlm==0.3.0
kernels==0.10.2
kiwisolver==1.4.9
language-tags==1.2.0
lazy_loader==0.4
Levenshtein==0.27.1
libcst==1.8.5
librosa==0.11.0
liger_kernel @ git+https://github.com/linkedin/Liger-Kernel.git@4d07b58dd11fd5d15fb04b0e86dfcceeeb472f9f
llvmlite==0.45.1
lm_eval==0.4.9.1
logbar==0.0.4
loguru==0.7.3
lxml==6.0.2
Markdown==3.9
markdown-it-py==4.0.0
MarkupSafe==3.0.2
matplotlib==3.10.7
maturin==1.9.6
mbstrdecoder==1.1.4
mdurl==0.1.2
mergekit @ git+https://github.com/arcee-ai/mergekit.git@2aa854265cf1a07f4ca9b615f9600e3016f38681
mido==1.3.3
mistral_common==1.8.5
mkl==2025.2.0
ml_dtypes==0.5.3
more-itertools==10.8.0
mpi4py==4.1.0
mpmath==1.3.0
msgpack==1.1.2
multidict==6.7.0
multiprocess==0.70.12.2
mypy_extensions==1.1.0
NATTEN==0.21.1
nbformat==5.10.4
networkx==3.5
ninja==1.13.0
nltk==3.8.1
numba==0.62.1
numexpr==2.13.1
numpy==2.2.6
oneccl==2021.16.1
oneccl-devel==2021.16.1
onemkl-sycl-blas==2025.2.0
onemkl-sycl-dft==2025.2.0
onemkl-sycl-lapack==2025.2.0
onemkl-sycl-rng==2025.2.0
onemkl-sycl-sparse==2025.2.0
onnx==1.19.0
openai==2.6.1
opencv-python==4.11.0.86
opencv-python-headless==4.12.0.88
optimum==2.0.0
optimum-quanto==0.2.7
packaging==25.0
pandas==2.3.3
parameterized==0.9.0
pathspec==0.12.1
pathvalidate==3.3.1
-e git+https://github.com/kaixuanliu/peft.git@eb4389234d3cc70e760d7a1a616da38ce1254c1e#egg=peft
phonemizer==3.3.0
pillow==11.3.0
platformdirs==4.5.0
pluggy==1.6.0
pooch==1.8.2
portalocker==2.0.0
poyo==0.5.0
pretty_midi==0.2.11
propcache==0.4.1
protobuf==6.32.1
psutil==7.1.0
py-cpuinfo==9.0.0
pyarrow==21.0.0
pybind11==3.0.1
pycodestyle==2.14.0
pycountry==24.6.1
pycparser==2.23
pyctcdecode==0.5.0
pydantic==2.10.6
pydantic-extra-types==2.10.6
pydantic_core==2.27.2
Pygments==2.19.2
pygtrie==2.5.0
pyparsing==3.2.5
pytablewriter==1.2.1
pytesseract==0.3.13
pytest==8.4.2
pytest-asyncio==1.2.0
pytest-order==1.3.0
pytest-rerunfailures==15.1
pytest-rich==0.2.0
pytest-timeout==2.4.0
pytest-xdist==3.8.0
python-dateutil==2.9.0.post0
python-slugify==8.0.4
pytokens==0.1.10
pytorch-msssim==1.0.0
pytorch-triton-xpu==3.5.0
pytz==2025.2
PyWavelets==1.9.0
PyYAML==6.0.3
random_word==1.0.13
RapidFuzz==3.14.1
rdflib==7.2.1
referencing==0.36.2
regex==2025.9.18
requests==2.32.5
requests-mock==1.12.1
resampy==0.4.3
rfc3986==1.5.0
rich==14.2.0
rjieba==0.1.13
rouge_score==0.1.2
rpds-py==0.27.1
ruff==0.13.1
sacrebleu==1.5.1
sacremoses==0.1.1
safetensors==0.5.3
schedulefree==1.4.1
scikit-learn==1.7.2
scipy==1.16.2
segments==2.3.0
sentence-transformers==5.1.1
sentencepiece==0.2.1
setuptools==78.1.0
shellingham==1.5.4
six==1.17.0
smmap==5.0.2
sniffio==1.3.1
sortedcontainers==2.4.0
soundfile==0.13.1
soupsieve==2.8
soxr==1.0.0
sqlitedict==2.1.0
starlette==0.48.0
sympy==1.14.0
tabledata==1.3.4
tabulate==0.9.0
tbb==2022.2.0
tcmlib==1.4.0
tcolorpy==0.1.7
tensorboard==2.20.0
tensorboard-data-server==0.7.2
termcolor==3.1.0
text-unidecode==1.3
threadpoolctl==3.6.0
tiktoken==0.12.0
timeout-decorator==0.5.0
timm==1.0.20
tokenicer==0.0.5
tokenizers==0.22.1
torch==2.9.0+xpu
torchao==0.14.0.dev20250922+xpu
torchaudio==2.9.0+xpu
torchdata==0.11.0
torchvision==0.24.0+xpu
tqdm==4.67.1
tqdm-multiprocess==0.0.11
traitlets==5.14.3
-e git+https://github.com/kaixuanliu/transformers.git@cf51ff39ec4ff31bfef57bb9babc42d0880e877e#egg=transformers
triton @ git+https://github.com/triton-lang/triton.git@7416ffcb92cdbe98d9f97e4e6f95247e46dfc9fd
-e git+https://github.com/huggingface/trl.git@928f5897464371cdb505f7bcf8759c44ab4f079e#egg=trl
typeguard==4.4.4
typepy==1.3.4
typer-slim==0.20.0
typing-inspection==0.4.2
typing_extensions==4.15.0
tzdata==2025.2
umf==0.11.0
uritemplate==4.2.0
urllib3==2.5.0
uvicorn==0.38.0
wcwidth==0.2.14
Werkzeug==3.1.3
wheel==0.45.1
word2number==1.1
xxhash==3.6.0
yarl==1.22.0
zipp==3.23.0
zstandard==0.25.0
```

cc @mekkcyber

~~Looks like @zucchini-nlp added this test? And later @SunMarc adds `@require_optimum_quanto`? But if @MekkCyber has the bandwidth to check this, go ahead.~~

I can reproduce the issue in our CI runner, which doesn't have `optimum-quanto` in it and I have to install it manually.



Hmm, turns out this happens after 

🚨 Bump to Python 3.10 and rework how we check 3rd-party libraries existence (#41268)

commit 55b172b8 failed but its parent 1ec0b544 doesn't have this issue.

cc @Cyrilvallez maybe 😢 

### To reproduce

> git checkout ... (commit) ... && pip install -e .

> RUN_SLOW=1 python3 -m pytest -v tests/models/llama/test_modeling_llama.py  -k "test_generate_with_quant_cache"