[Refactor] Minor Improvement for import utils#11161
[Refactor] Minor Improvement for import utils#11161yiyixuxu merged 6 commits intohuggingface:mainfrom
Conversation
|
@bot /style |
|
Style fixes have been applied. View the workflow run here. |
|
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. |
ccd99a1 to
6bb876f
Compare
hlky
left a comment
There was a problem hiding this comment.
Thanks for the iteration. Looks like packages_distributions was only added in 3.10
https://docs.python.org/3/library/importlib.metadata.html#importlib.metadata.packages_distributions
Can you look into alternatives?
|
Couldn't find alternatives, but pulled out some code from packages_distribution from Let me know if this looks good to you ? I have tested works fine for python [3.8, 3.9, 3.10] |
|
LGTM, thanks! |
656a19f to
68bb955
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the _is_package_available function to handle the case where the package name used for import differs from the distribution name used for installation. It also consolidates the logic for determining package version and updates the optimum_quanto check accordingly.
- Updated _is_package_available signature to return a tuple (availability, version) and added an optional get_dist_name parameter.
- Integrated a fallback mechanism for package distribution lookup and refactored the optimum_quanto availability check.
- Added necessary imports and extended the collections import for defaultdict.
Comments suppressed due to low confidence (1)
src/diffusers/utils/import_utils.py:87
- [nitpick] Consider using a separate variable (e.g., 'dist_name') instead of overwriting 'pkg_name' when get_dist_name is True. This improves code clarity by distinguishing between the module name and the distribution name.
pkg_name = package_map[pkg_name][0]
What does this PR do?
At times pkg_name (used for import) and dist_name (used for install) are different. The
_is_package_availablefunction doesnt work for that see here. This PR helps resolve this through_is_package_availablefunction.Who can review?
@DN6 @hlky