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

Failed to import transformers.models.timm_wrapper.configuration_timm_wrapper #509

Closed
TimoReusch opened this issue Jan 26, 2025 · 6 comments

Comments

@TimoReusch
Copy link

I installed the package using pip on an Apple Silicon Mac. I get the following error when trying to run marker_single myfile.pdf:

RuntimeError: Failed to import transformers.models.timm_wrapper.configuration_timm_wrapper because of the following error (look up to see its traceback):
cannot import name 'ImageNetInfo' from 'timm.data'

This is the full stack-trace:

Loaded layout model datalab-to/surya_layout on device mps with dtype torch.float16
Traceback (most recent call last):
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/utils/import_utils.py", line 1817, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/.pyenv/versions/3.12.6/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/models/timm_wrapper/configuration_timm_wrapper.py", line 25, in <module>
    from timm.data import ImageNetInfo, infer_imagenet_subset
ImportError: cannot import name 'ImageNetInfo' from 'timm.data' (/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/timm/data/__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/timoreusch/myapp/.venv/bin/marker_single", line 8, in <module>
    sys.exit(convert_single_cli())
             ^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/marker/scripts/convert_single.py", line 25, in convert_single_cli
    models = create_model_dict()
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/marker/models.py", line 81, in create_model_dict
    "texify_model": setup_texify_model(device, dtype),
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/marker/models.py", line 57, in setup_texify_model
    texify_model = load_texify_model(checkpoint=settings.TEXIFY_MODEL_NAME, device=settings.TORCH_DEVICE_MODEL, dtype=settings.TEXIFY_DTYPE)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/texify/model/model.py", line 54, in load_model
    model = GenerateVisionEncoderDecoderModel.from_pretrained(checkpoint, config=config, torch_dtype=dtype)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/models/vision_encoder_decoder/modeling_vision_encoder_decoder.py", line 376, in from_pretrained
    return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/modeling_utils.py", line 4090, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/texify/model/model.py", line 26, in __init__
    encoder = AutoModel.from_config(config.encoder)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 422, in from_config
    has_local_code = type(config) in cls._model_mapping.keys()
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 781, in keys
    self._load_attr_from_module(key, name)
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 777, in _load_attr_from_module
    return getattribute_from_module(self._modules[module_name], attr)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 693, in getattribute_from_module
    if hasattr(module, attr):
       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/utils/import_utils.py", line 1805, in __getattr__
    module = self._get_module(self._class_to_module[name])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/transformers/utils/import_utils.py", line 1819, in _get_module
    raise RuntimeError(
RuntimeError: Failed to import transformers.models.timm_wrapper.configuration_timm_wrapper because of the following error (look up to see its traceback):
cannot import name 'ImageNetInfo' from 'timm.data' (/Users/timoreusch/myapp/.venv/lib/python3.12/site-packages/timm/data/__init__.py)
@Mitya11
Copy link

Mitya11 commented Jan 29, 2025

try reinstall timm
pip install timm==1.0.13
its help for me

@Leviboy98
Copy link

try reinstall timm pip install timm==1.0.13 its help for me

it didnt solve it for me :(

@VikParuchuri
Copy link
Owner

Marker doesn't require timm - I would make a clean virtualenv and only install marker. I think your other packages are causing issues (transformers tries to import timm if it's installed)

@TimoReusch
Copy link
Author

I tried reinstalling in a fresh venv - it really seems like there was a conflict with another package. Works now - thanks.

@daniel347x
Copy link

Quick hint in case this works for someone else; below is the path to a file to modify if you don't NEED ImageNet in timm:

Shown is code before hack, and code after hack

/usr/local/lib/python3.9/site-packages/transformers/models/timm_wrapper/configuration_timm_wrapper.py
 24 if is_timm_available():
 25     from timm.data import ImageNetInfo, infer_imagenet_subset
---
 24 # if is_timm_available():
 25 #   from timm.data import ImageNetInfo, infer_imagenet_subset

...in case this helps

@volcott
Copy link

volcott commented Feb 1, 2025

With this method, I solved the problem.

I just logged in to say thank you. Happy New Year, and may all the luck be with you.
As we say in Korean, “새해 복 많이 받으세요”

Quick hint in case this works for someone else; below is the path to a file to modify if you don't NEED ImageNet in timm:

Shown is code before hack, and code after hack

/usr/local/lib/python3.9/site-packages/transformers/models/timm_wrapper/configuration_timm_wrapper.py
 24 if is_timm_available():
 25     from timm.data import ImageNetInfo, infer_imagenet_subset
---
 24 # if is_timm_available():
 25 #   from timm.data import ImageNetInfo, infer_imagenet_subset

...in case this helps

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

No branches or pull requests

6 participants