Skip to content

Calling AutoModel.from_config() method for a model requiring timm does not raise ImportError although it should #20671

@fxmarty

Description

@fxmarty

System Info

  • transformers version: 4.26.0.dev0
  • Platform: Linux-5.15.0-56-generic-x86_64-with-glibc2.35
  • Python version: 3.9.12
  • Huggingface_hub version: 0.11.0.dev0
  • PyTorch version (GPU?): 1.12.1+cu102 (True)
  • Tensorflow version (GPU?): 2.9.1 (True)
  • Flax version (CPU?/GPU?/TPU?): 0.5.2 (cpu)
  • Jax version: 0.3.14
  • JaxLib version: 0.3.14
  • Using GPU in script?:
  • Using distributed or parallel set-up in script?:

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

pip uninstall timm, and then:

from transformers import AutoModel, AutoConfig

cfg = AutoConfig.from_pretrained("hf-internal-testing/tiny-random-detr")
model = AutoModel.from_config(cfg)

raising:

Traceback (most recent call last):
  File "<tmp 1>", line 18, in <module>
    model = AutoModel.from_config(cfg)
  File "/home/fxmarty/hf_internship/transformers/src/transformers/models/auto/auto_factory.py", line 410, in from_config
    return model_class._from_config(config, **kwargs)
  File "/home/fxmarty/hf_internship/transformers/src/transformers/utils/import_utils.py", line 1008, in __getattribute__
    return super().__getattribute__(key)
AttributeError: type object 'DetrModel' has no attribute '_from_config'

Expected behavior

It should raise:

ImportError: 
DetrModel requires the timm library but it was not found in your environment. You can install it with pip:
`pip install timm`. Please note that you may need to restart your runtime after installation.

as in https://github.com/huggingface/transformers/blob/main/src/transformers/utils/dummy_timm_and_vision_objects.py#L78

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions