ImportError: Tensorflow 2.0 GPU Recursion Error
See original GitHub issueSystem information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 18.04
- Ray installed from (source or binary): binary
- Ray version: 0.7.3
- Python version: 3.7
- Tensorflow version: tensorflow-gpu 2.0.0rc0
- Exact command to reproduce:
# Importing packages
from time import time
import gym
import tensorflow as tf
import ray
# Creating our initial model
model = tf.keras.Sequential([
tf.keras.layers.Dense(64, input_shape=(24,), activation='relu'),
tf.keras.layers.Dense(4, activation='softmax')
])
# Setting parameters
episodes = 64
env_name = 'BipedalWalker-v2'
# Initializing ray
ray.init(num_cpus=8, num_gpus=1)
# Creating our ray function
@ray.remote
def play(weights):
actor = tf.keras.Sequential([
tf.keras.layers.Dense(64, input_shape=(24,), activation='relu'),
tf.keras.layers.Dense(4, activation='softmax')
])
actor = actor.set_weights(weights)
env = gym.make('BipedalWalker-v2').env
env._max_episode_steps=1e20
obs = env.reset()
for _ in range(1200):
action = actor.predict_classes(obs).flatten()[0]
action = env.action_space.sample()
obs, rt, done, info = env.step(action)
return rt
# Testing ray
start = time()
weights = model.get_weights()
weights = ray.put(weights)
results = ray.get([play.remote(weights) for i in range(episodes)])
ray.shutdown()
print('Ray done after:',time()-start)`
Describe the problem
I am trying to use Ray to parallelize rollouts of OpenAI gym environments using a Tensorflow 2.0-gpu Keras actor. Every time I try to instantiate a Keras model using @ray.remote it raises a recursion depth reached error. I am following the documentation outlined by Ray, where it is suggested to pass weights instead of models. I am not sure what I am doing wrong here, any thoughts?
Source code / logs
File “/home/jacob/anaconda3/envs/tf-2.0-gpu/lib/python3.7/site-packages/tensorflow/init.py”, line 50, in getattr module = self._load() File “/home/jacob/anaconda3/envs/tf-2.0-gpu/lib/python3.7/site-packages/tensorflow/init.py”, line 44, in _load module = _importlib.import_module(self.name) RecursionError: maximum recursion depth exceeded
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Keras giving error "ModuleNotFoundError: No module named ...
I have tensorflow-gpu and keras installed in Python 3.6.8. But when I tried importing keras, it is giving the the error of Module...
Read more >PyInstaller+Tensorflow+Sonnet - General Discussion
The following fixes a different pyinstaller issue due to recursion. import sys sys.setrecursionlimit(5000). block_cipher = None. a = Analysis([' ...
Read more >Source code for transformers.modeling_utils - Hugging Face
Licensed under the Apache License, Version 2.0 (the "License"); ... except ImportError: logger.error( "Loading a TensorFlow model in PyTorch, requires both ...
Read more >Tensorflow Owner - Stack Exchange Data Explorer
'TensorFlow (GPU) libcudart.so.7.5 error -- cannot open shared object ... 'Tensorflow successfully installs on mac but gets ImportError on ...
Read more >Setting up Ubuntu 16.04 + CUDA + GPU for deep learning ...
Today, we will configure Ubuntu + NVIDIA GPU + CUDA with ... That's it — assuming you didn't have an import error, then...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think generally just if I’ve run into pickling errors with a library, importing inside the function works for me. It’s hard to give a standard answer mainly because external libraries/packages are not very transparent in how they depend on global state.
Here’s a quick fix. Import tensorflow inside the remote function: