Skip to content

QA: Fall back to the import name when a distribution is missing - #48144

Open
tarekziade wants to merge 1 commit into
mainfrom
fix/gguf-version-detection
Open

QA: Fall back to the import name when a distribution is missing#48144
tarekziade wants to merge 1 commit into
mainfrom
fix/gguf-version-detection

Conversation

@tarekziade

@tarekziade tarekziade commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

CI

What does this PR do?

_is_package_available looks the import name up in PACKAGE_DISTRIBUTION_MAPPING, which is built from importlib.metadata.packages_distributions(). That call can miss an installed distribution whose dist-info carries no usable top-level record. The resulting KeyError was lumped in with PackageNotFoundError and sent execution down the import fallback, which returns getattr(module, "__version__", "N/A") -- so a perfectly installed package could be reported as version "N/A".

Callers then feed that sentinel straight to packaging.version.parse:

return is_available and version.parse(gguf_version) >= version.parse(min_version)

which raises InvalidVersion. In the quantization CI image this made tests/quantization/ggml/test_ggml.py unable to even be collected, despite pip freeze reporting gguf==0.19.0:

tests/quantization/ggml/test_ggml.py:40: in <module>
    if is_gguf_available():
packaging.version.InvalidVersion: Invalid version: 'N/A'

Handle the KeyError on its own and fall back to the import name, which is the correct distribution name for the large majority of packages, before giving up on metadata entirely. Around twenty is_*_available helpers parse a version this way, so the fix belongs at this choke point rather than in each of them.

Note that the "N/A" sentinel can still reach those helpers when a package has neither metadata nor __version__ (an editable install, say). Narrowing that is left out of this change.

See https://github.com/huggingface/transformers/actions/runs/32347015888

…the packages mapping

`_is_package_available` looks the import name up in `PACKAGE_DISTRIBUTION_MAPPING`, which is built
from `importlib.metadata.packages_distributions()`. That call can miss an installed distribution whose
dist-info carries no usable top-level record. The resulting `KeyError` was lumped in with
`PackageNotFoundError` and sent execution down the import fallback, which returns
`getattr(module, "__version__", "N/A")` -- so a perfectly installed package could be reported as
version `"N/A"`.

Callers then feed that sentinel straight to `packaging.version.parse`:

    return is_available and version.parse(gguf_version) >= version.parse(min_version)

which raises `InvalidVersion`. In the quantization CI image this made
`tests/quantization/ggml/test_ggml.py` unable to even be *collected*, despite `pip freeze` reporting
`gguf==0.19.0`:

    tests/quantization/ggml/test_ggml.py:40: in <module>
        if is_gguf_available():
    packaging.version.InvalidVersion: Invalid version: 'N/A'

Handle the `KeyError` on its own and fall back to the import name, which is the correct distribution
name for the large majority of packages, before giving up on metadata entirely. Around twenty
`is_*_available` helpers parse a version this way, so the fix belongs at this choke point rather than
in each of them.

Note that the `"N/A"` sentinel can still reach those helpers when a package has neither metadata nor
`__version__` (an editable install, say). Narrowing that is left out of this change.

See https://github.com/huggingface/transformers/actions/runs/32347015888
@tarekziade

Copy link
Copy Markdown
Collaborator Author

run-slow: ggml

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: []
quantizations: ["quantization/ggml"]

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 32351765281:1
Result: success | Jobs: 16 | Tests: 182,068 | Failures: 0 | Duration: 16h 26m

@tarekziade

Copy link
Copy Markdown
Collaborator Author

related #42050

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 4827e45d workflow commit (merge commit)
PR 4a7773bf branch commit (from PR)
main 94f09cfe base commit (on main)

⚠️ Quantization CI failed to report results

The test failure analysis could not be completed. Please check the workflow run for details.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 4827e45d workflow commit (merge commit)
PR 4a7773bf branch commit (from PR)
main 94f09cfe base commit (on main)

⚠️ Quantization CI failed to report results

The test failure analysis could not be completed. Please check the workflow run for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants