tkipf / gcn

Implementation of Graph Convolutional Networks in TensorFlow
MIT License
7.11k stars 2k forks source link

Sending tensors to GPU #86

Open m-saksena opened 5 years ago

m-saksena commented 5 years ago

Hi there, I have access to GPU 0 on my system, and want to use this instead of the CPU. I've had a look at the tensorflow GPU documentation but can't seem to figure out how to send tensors to the GPU while using a placeholder dict. This is what my code looks like:

# Define placeholders
with tf.device('/gpu:0'):
    support_placeholder = [tf.sparse_placeholder(tf.float32) for _ in range(num_supports)]
    features_placeholder = tf.sparse_placeholder(tf.float32, shape=tf.constant(features[2], dtype=tf.int64))
    labels_placeholder = tf.placeholder(tf.int32, shape=(None, y_train.shape[1]))
    labels_mask_placeholder = tf.placeholder(tf.int32)
    dropout_placeholder = tf.placeholder_with_default(0., shape=())
    num_features_nonzero_placeholder = tf.placeholder(tf.int32)
placeholders = {
    'support': support_placeholder,
    'features': features_placeholder,
    'labels': labels_placeholder,
    'labels_mask': labels_mask_placeholder,
    'dropout':dropout_placeholder,
    'num_features_nonzero': num_features_nonzero_placeholder  # helper variable for sparse dropout
}

But I keep getting this error: InvalidArgumentError (see above for traceback): Cannot assign a device for operation PlaceholderWithDefault.

Really appreciate your help with this! Thanks so much for this fantastic repo.

tkipf commented 5 years ago

The code example should run out of the box on GPU in the TensorFlow Version that is specified in the Readme file. Maybe wrong TensorFlow version?

On Thu 14. Feb 2019 at 17:01 Malika Saksena notifications@github.com wrote:

Hi there, I have access to GPU 0 on my system, and want to use this instead of the CPU. I've had a look at the tensorflow GPU documentation but can't seem to figure out how to send tensors to the GPU while using a placeholder dict. This is what my code looks like:

Define placeholders

with tf.device('/gpu:0'): support_placeholder = [tf.sparseplaceholder(tf.float32) for in range(num_supports)] features_placeholder = tf.sparse_placeholder(tf.float32, shape=tf.constant(features[2], dtype=tf.int64)) labels_placeholder = tf.placeholder(tf.int32, shape=(None, y_train.shape[1])) labels_mask_placeholder = tf.placeholder(tf.int32) dropout_placeholder = tf.placeholder_with_default(0., shape=()) num_features_nonzero_placeholder = tf.placeholder(tf.int32) placeholders = { 'support': support_placeholder, 'features': features_placeholder, 'labels': labels_placeholder, 'labels_mask': labels_mask_placeholder, 'dropout':dropout_placeholder, 'num_features_nonzero': num_features_nonzero_placeholder # helper variable for sparse dropout }

But I keep getting this error: InvalidArgumentError (see above for traceback): Cannot assign a device for operation PlaceholderWithDefault.

Really appreciate your help with this! Thanks so much for this fantastic repo.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tkipf/gcn/issues/86, or mute the thread https://github.com/notifications/unsubscribe-auth/AHAcYMQ9WDgkxmHIEXbX0EMsRYwkSOnnks5vNYhZgaJpZM4a76Ld .