Skip to content

Commit

Permalink
Adds package and requirement spec output to version check exception (h…
Browse files Browse the repository at this point in the history
…uggingface#18702)

* Adds package and requirement spec output to version check exception

It's difficult to understand what package is affected when `got_ver`
here comes back None, so output the requirement and the package. The
requirement probably contains the package but let's output both for good
measure.

Non-exhaustive references for this problem aside from my own encounter:

* https://stackoverflow.com/questions/70151167/valueerror-got-ver-is-none-when-importing-tensorflow
* https://discuss.huggingface.co/t/valueerror-got-ver-is-none/17465
* UKPLab/sentence-transformers#1186
* huggingface#13356

I speculate that the root of the error comes from a conflict of
conda-managed and pip-managed Python packages but I've not yet proven
this.

* Combines version presence check and streamlines exception message

See also: huggingface#18702 (comment)

Co-authored-by: Stas Bekman <stas@stason.org>
  • Loading branch information
2 people authored and oneraghavan committed Sep 26, 2022
1 parent b61430a commit 4e13365
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/transformers/utils/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@


def _compare_versions(op, got_ver, want_ver, requirement, pkg, hint):
if got_ver is None:
raise ValueError("got_ver is None")
if want_ver is None:
raise ValueError("want_ver is None")
if got_ver is None or want_ver is None:
raise ValueError(
f"Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider"
f" reinstalling {pkg}."
)
if not ops[op](version.parse(got_ver), version.parse(want_ver)):
raise ImportError(
f"{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}"
Expand Down

0 comments on commit 4e13365

Please sign in to comment.