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

Colab notebook gives Keras multi_gpu_model error #231

Closed
peterfarted opened this issue May 25, 2021 · 10 comments
Closed

Colab notebook gives Keras multi_gpu_model error #231

peterfarted opened this issue May 25, 2021 · 10 comments

Comments

@peterfarted
Copy link

Hi, the Collab notebook linked on the main page no longer works. I submitted the tensorflow cell and then the the "!pip install" cell, and it downloaded some kind of wheel (which I've never seen it do before). Then it burped out the following error:

ImportError: cannot import name 'multi_gpu_model' from 'tensorflow.keras.utils' (/usr/local/lib/python3.7/dist-packages/tensorflow/keras/utils/init.py)

It appears some people have solved this by downgrading keras to 2.2.4, but either it didn't work for me - or more likely, I don't know how/where to do this in the notebook. Any ideas?

@francescoboc
Copy link

Yea, I have the same problem. I have also tried to downgrade keras to 2.2.4 but still have the same ImportError.

@rubbishgee
Copy link

rubbishgee commented May 31, 2021

Same problem here, nobody knows a solution?

Edit:
I maybe found a solution:

after the error open the textgennrn.py, by clicking on the blue path, and replace "from tensorflow.keras.utils import multi_gpu_model" to from keras.utils import multi_gpu_utils
(you need to copy the notebook to your own drive to do that)

now you should be able to rerun the cell.

I can't guarantee that it now works perfect, I am a total novice with this stuff....
hope I could help

Edit 2:
It works, the output is the same as before.
But its slower imho, so maybe the multi gpu stuff isnt really working.
But it's working, slow but working.

@peterfarted
Copy link
Author

peterfarted commented Jun 1, 2021

Thanks rubbish, it is indeed slower, almost like it's using the cpu instead, but I'll take slow over non-working any day. Thanks for finding this workaround.

Clarification: Issue still open, would still love to find a solution that restores the multi-gpu functionality or whatever it is that leads to optimal speed.

@mbrav
Copy link

mbrav commented Jun 4, 2021

from keras.utils import multi_gpu_utils

Tried that but get the following error:

2021-06-04 23:17:09.820817: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "/home/Desktop/F/Insta-text/train.py", line 1, in <module>
    from textgenrnn import textgenrnn
  File "/home/Desktop/F/Insta-text/venv/lib/python3.9/site-packages/textgenrnn/__init__.py", line 1, in <module>
    from .textgenrnn import textgenrnn
  File "/home/Desktop/F/Insta-text/venv/lib/python3.9/site-packages/textgenrnn/textgenrnn.py", line 6, in <module>
    from keras.utils import multi_gpu_utils
  File "/home/Desktop/F/Insta-text/venv/lib/python3.9/site-packages/keras/__init__.py", line 20, in <module>
    from . import initializers
  File "/home/Desktop/F/Insta-text/venv/lib/python3.9/site-packages/keras/initializers/__init__.py", line 124, in <module>
    populate_deserializable_objects()
  File "/home/Desktop/F/Insta-text/venv/lib/python3.9/site-packages/keras/initializers/__init__.py", line 82, in populate_deserializable_objects
    generic_utils.populate_dict_with_module_objects(
AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'

@krigeta
Copy link

krigeta commented Jun 5, 2021

SOLUTION:

Goto
/usr/local/lib/python3.7/dist-packages/textgenrnn/textgenrnn.py

Change line 5 to keras.utils import multi_gpu_model and then hope it will work.

@rubbishgee
Copy link

just figured out: you can just delete line 5 and it works (with slow cpu)

@msewell
Copy link

msewell commented Jun 9, 2021

If you have managed to modify the "Interactive textgenrnn Demo w/ GPU" Colaboratory Notebook referenced in the repository's README.md in a way that does not error on the cell containing from textgenrnn import textgenrnn with ImportError: cannot import name 'multi_gpu_model' from 'tensorflow.keras.utils' , and that still allows usage of GPU-based training despite the modifications you have made, please share your modified, working Colaboratory Notebook.

@xNPx3
Copy link

xNPx3 commented Jun 10, 2021

In the other issue thread, someone suggested to install from git:
pip3 install git+git://github.com/minimaxir/textgenrnn.git
and this worked for me (colab)

@francescoboc
Copy link

In the other issue thread, someone suggested to install from git:
pip3 install git+git://github.com/minimaxir/textgenrnn.git
and this worked for me (colab)

Yes, it works for me as well! Thank you!
Apparently, the github version of textgenrnn uses TF2, so the first cell of the notebook %tensorflow_version 1.x is now useless.

@peterfarted
Copy link
Author

Verified. I commented out the %tensorflow line and replaced the !pip line with the pip3 jazz above (with a ! in front) and it worked. Thanks xNPx3! Closing the issue.

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

7 participants