Skip to content

Conversation

@Rocketknight1
Copy link
Member

Our framework detection code calls _is_package_available() for TensorFlow, but this code fails when only the tensorflow-cpu package is present. The failure occurs because importlib_metadata.version("tensorflow") throws an error in the version detection branch of _is_package_available unless the core tensorflow package is installed.

I solved this by just calling importlib.util.find_spec("tensorflow") instead of _is_package_available(). However, we could also resolve this issue by rewriting _is_package_available() so that it only takes the version check branch when return_version is True. The importlib_metadata.version() call is only used to get the package version, but it causes the entire _is_package_available() call to fail if it can't find a version, even if the importlib.util.find_spec() call was a success.

ccing @sgugger because there's a TODO above that function requesting his attention, so I'd like his input on the right approach here!

Fixes #24253

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, thanks for fixing!

Copy link
Contributor

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing so quickly!

@Rocketknight1
Copy link
Member Author

cc @apbard as well since I think the issue was introduced in #23163, but thankfully it's a relatively easy fix!

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jun 13, 2023

The documentation is not available anymore as the PR was closed or merged.

@Rocketknight1 Rocketknight1 merged commit b979a20 into main Jun 13, 2023
@Rocketknight1 Rocketknight1 deleted the tf_is_package_available branch June 13, 2023 17:57
sgugger pushed a commit that referenced this pull request Jun 13, 2023
* Fix how we detect the TF package

* Add a comment as a talisman warding against future harm

* Actually put the comment in the right place
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
* Fix how we detect the TF package

* Add a comment as a talisman warding against future harm

* Actually put the comment in the right place
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.

transformers does not detect Tensorflow when installing tensorflow-cpu package

5 participants