QA: Fall back to the import name when a distribution is missing - #48144
Open
tarekziade wants to merge 1 commit into
Open
QA: Fall back to the import name when a distribution is missing#48144tarekziade wants to merge 1 commit into
tarekziade wants to merge 1 commit into
Conversation
…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
Collaborator
Author
|
run-slow: ggml |
Contributor
|
This comment contains models: [] |
|
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. |
Contributor
CI recapDashboard: View test results in Grafana |
Collaborator
Author
|
related #42050 |
Contributor
CI ResultsCommit Info
The test failure analysis could not be completed. Please check the workflow run for details. |
1 similar comment
Contributor
CI ResultsCommit Info
The test failure analysis could not be completed. Please check the workflow run for details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
_is_package_availablelooks the import name up inPACKAGE_DISTRIBUTION_MAPPING, which is built fromimportlib.metadata.packages_distributions(). That call can miss an installed distribution whose dist-info carries no usable top-level record. The resultingKeyErrorwas lumped in withPackageNotFoundErrorand sent execution down the import fallback, which returnsgetattr(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:which raises
InvalidVersion. In the quantization CI image this madetests/quantization/ggml/test_ggml.pyunable to even be collected, despitepip freezereportinggguf==0.19.0:Handle the
KeyErroron 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 twentyis_*_availablehelpers 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