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

ImportError: cannot import name 'Mapping' from 'collections' #4

Closed
NickLucche opened this issue Mar 11, 2024 · 3 comments · Fixed by #21
Closed

ImportError: cannot import name 'Mapping' from 'collections' #4

NickLucche opened this issue Mar 11, 2024 · 3 comments · Fixed by #21

Comments

@NickLucche
Copy link

Hey, thanks a lot for sharing this great accomplishment with the community!
I have just tried running the cli_chat on Python3.11 and I get ImportError: cannot import name 'Mapping' from 'collections' at https://github.com/deepseek-ai/DeepSeek-VL/blob/main/deepseek_vl/models/modeling_vlm.py#L21.
I believe this is due to attrdict being broken with python3.10+ https://stackoverflow.com/questions/72361026/how-can-i-get-attrdict-module-working-in-python.

Easiest thing would be to update Readme/requirements to specify >=python3.8, <3.10.

@Fodark
Copy link
Contributor

Fodark commented Mar 11, 2024

I solved it by patching collections before loading deepseek_vl

Something like:

# Monkey patch collections
import collections
import collections.abc
for type_name in collections.abc.__all__:
    setattr(collections, type_name, getattr(collections.abc, type_name))

from deepseek_vl.models import VLChatProcessor, MultiModalityCausalLM

if you want to stay on Python 3.10.

@insightbuilder
Copy link

I did a bit of hardway... went to each of the files in the lib folders and moded it...

  • aimachine/lib/python3.10/site-packages/attrdict/default.py
  • aimachine/lib/python3.10/site-packages/attrdict/merge.py
  • aimachine/lib/python3.10/site-packages/attrdict/mixins.py
  • aimachine/lib/python3.10/site-packages/attrdict/mapping.py

After doing it, came for posting the solution to find that, there is a smarter solution. Thanks to Fodark.

import collections.abc
for type_name in collections.abc.__all__:
    setattr(collections, type_name, getattr(collections.abc, type_name))

@Fodark
Copy link
Contributor

Fodark commented Mar 14, 2024

Fixed in #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants