Skip to content

Misleading ImportError error #33604

@davidgilbertson

Description

@davidgilbertson

System Info

  • transformers version: 4.42.3
  • Platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
  • Python version: 3.10.12
  • Huggingface_hub version: 0.23.4
  • Safetensors version: 0.4.3
  • Accelerate version: 0.32.1
  • Accelerate config: not found
  • PyTorch version (GPU?): 2.4.1+cu121 (True)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using distributed or parallel set-up in script?: No
  • Using GPU in script?: No
  • GPU type: NVIDIA GeForce RTX 3090

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

This GitHub issue is not about resolving the errors below, it's about a logical error in the code that produces the errors.

I get the following error running some code:

ImportError: This modeling file requires the following packages that were not found in your environment: flash_attn.

But I have flash_attn installed. The underlying problem is that when importing flash_attn, some other code throws an ImportError, but that error is swallowed by transformers code.

To be specific, the logical mistake is in the check_imports function. It assumes that if you get an ImportError when trying to import a package, it means that the package isn't installed.

That's probably a fine assumption most of the time, but when something's going wrong like in my case, it makes it hard to find out what because the real error is being swallowed and replaced. This is the real error, by the way:

ImportError: libcudart.so.11.0: cannot open shared object file: No such file or directory

To reiterate, this issue is not about resolving these errors, it's about fixing the code that masks useful errors (although it someone happens to know the fix, great).

Expected behavior

You should show the original error and then if you want to, also show the hand-written "missing packages" message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UsageGeneral questions about the librarybug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions