Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import name 'cached_path' from 'transformers.file_utils' #344

Closed
2 of 4 tasks
Arouniversal opened this issue Aug 10, 2022 · 5 comments · Fixed by #368
Closed
2 of 4 tasks

cannot import name 'cached_path' from 'transformers.file_utils' #344

Arouniversal opened this issue Aug 10, 2022 · 5 comments · Fixed by #368
Assignees
Labels
bug Something isn't working

Comments

@Arouniversal
Copy link

System Info

from optimum.onnxruntime import ORTQuantizer, ORTModelForTextClassification

then:

RuntimeError: Failed to import optimum.onnxruntime.quantization because of the following error (look up to see its traceback):
cannot import name 'cached_path' from 'transformers.file_utils'

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from optimum.onnxruntime import ORTQuantizer, ORTModelForTextClassification

Expected behavior

this would not be fail

@Arouniversal Arouniversal added the bug Something isn't working label Aug 10, 2022
@Arouniversal
Copy link
Author

transformers-4.21.1 won't fail

@nbroad1881
Copy link
Contributor

nbroad1881 commented Aug 12, 2022

I believe this will need to be patched to work for two versions of transformers: before 4.22.0 and after 4.22.0

The file utils were modified in this pull request: huggingface/transformers#18497 and a few later ones.

Since many functions were removed and modified in 4.22.0, I looked into which functions would need to change. Below, the left side has the names that work for < 4.22.0, and the right side has the names of the new functions that can be used for >= 4.22.0. This was only from a brief skim of the old and new code:

cached_path -> cached_file

get_list_of_files -> (unsure)

hf_bucket_url/is_remote_url -> get_file_from_repo

@echarlaix @michaelbenayoun

@echarlaix
Copy link
Collaborator

Thanks for the detailed answer @nbroad1881 ! I opened #368 to fix the issues you listed.

@neonwatty
Copy link

This is still an issue for me using transformers 4.31.0 - downgrading to 4.21 solved as a workaround.

@fxmarty
Copy link
Contributor

fxmarty commented Aug 21, 2023

Hi @jermwatt, this issue should not happen anymore:

from transformers.utils import cached_path, hf_bucket_url
Which version of optimum are you running?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants