ray-project / tutorial

778 stars 212 forks source link

How to turn class involving super() into a remote actor? #175

Open MrNeoBlue opened 4 years ago

MrNeoBlue commented 4 years ago

Hello, there I'm new to using Ray. After completing the tutorial, I was trying to do some more exercise myself. Tensorflow tutorial seems a good choice for me. So I changed part of neural_network.py into the following lines:

# Create TF Model.
# TODO: change the NeuralNet class into an actor
@ray.remote
class NeuralNet(Model):
    # Set layers.
    def __init__(self):
        super(NeuralNet, self).__init__()
        # First fully-connected hidden layer.
        self.fc1 = layers.Dense(n_hidden_1, activation=tf.nn.relu)
        # First fully-connected hidden layer.
        self.fc2 = layers.Dense(n_hidden_2, activation=tf.nn.relu)
        # Second fully-connecter hidden layer.
        self.out = layers.Dense(num_classes, activation=tf.nn.softmax)
        print("Init NerualNet finished")

    # Set forward pass.
    def call(self, x, is_training=False):
        x = self.fc1(x)
        x = self.out(x)
        if not is_training:
            # tf cross entropy expect logits without softmax, so only
            # apply softmax when not training.
            x = tf.nn.softmax(x)
        return x

# Build neural network model.
# this will be an object with certain ID----actor handler
neural_net = NeuralNet.remote()

===================================================================== The output shows that when executing super(NeuralNet,self).init() failed.

(pid=23354) 2020-02-26 16:04:09.469796: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory
(pid=23354) 2020-02-26 16:04:09.469906: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory
(pid=23354) 2020-02-26 16:04:09.469920: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.

2020-02-26 16:04:15,131 ERROR worker.py:998 -- Possible unhandled error from worker: ray::NeuralNet.__init__() (pid=23354, ip=192.168.124.128)
  File "python/ray/_raylet.pyx", line 452, in ray._raylet.execute_task
  File "python/ray/_raylet.pyx", line 430, in ray._raylet.execute_task.function_executor
  File "<ipython-input-17-f79ce8a34c46>", line 7, in __init__
TypeError: super() argument 1 must be type, not ActorClass(NeuralNet)

OS: ubuntu18.04 python3: 3.7.6 tensorflow: 2.0

Best regards neoBlue