{
  "id": 77743,
  "title": "CuDNN GRU invalid argument error ",
  "url": "/competitions/quora-insincere-questions-classification/discussion/77743",
  "author_name": "Ajay  Hayagreeve",
  "post_date": "2019-01-16T09:01:38.116000",
  "votes": 1,
  "comment_count": 8,
  "views": 0,
  "content": "<p>Hi, \n    In settings I have enabled my GPU. \n    I was trying to implement the CuDNNGRU keras on kaggle. This is my model,</p>\n\n<pre><code>inp = kl.Input(shape=(max_words,))\nm = kl.Embedding(input_dim = cl+1, output_dim = EMBEDDING_DIM, weights=[embedding_matrix], trainable = False)(inp)\n#del(embedding_matrix);\nm = kl.SpatialDropout1D(rate = 0.25)(m)\nm = kl.Bidirectional(kl.CuDNNGRU(128, kernel_initializer=glorot_normal(seed=1029), \n       recurrent_initializer=orthogonal(gain=1.0, seed=1029), name = 'bi_gru'))(m)\nm = kl.Dense(32, activation=\"relu\")(m)\nm = kl.Dropout(0.2)(m)\nm = kl.Dense(1, activation=\"sigmoid\")(m)\nmodel = Model(inputs=inp, outputs=m)\n\nmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\nprint(model.summary())\n\nnum_epochs = 5;  batchSize = 128;\n</code></pre>\n\n<p>After this this is my output.</p>\n\n<pre><code>(33927, 300)\n_________________________________________________________________\nLayer (type)                 Output Shape              Param #   \n=================================================================\ninput_1 (InputLayer)         (None, 52)                0         \n_________________________________________________________________\nembedding_1 (Embedding)      (None, 52, 300)           10178100  \n_________________________________________________________________\nspatial_dropout1d_1 (Spatial (None, 52, 300)           0         \n_________________________________________________________________\nbidirectional_1 (Bidirection (None, 256)               330240    \n_________________________________________________________________\ndense_1 (Dense)              (None, 32)                8224      \n_________________________________________________________________\ndropout_1 (Dropout)          (None, 32)                0         \n_________________________________________________________________\ndense_2 (Dense)              (None, 1)                 33        \n=================================================================\nTotal params: 10,516,597\nTrainable params: 338,497\nNon-trainable params: 10,178,100\n</code></pre>\n\n<p>But when i fit my model, \nmodel.fit(x_train, y_train, validation_data=(x_val, y_val), batch_size = batch_size,  epochs=num_epochs, verbose = True);</p>\n\n<p>It is showing this error,</p>\n\n<p>Train on 1044898 samples, validate on 261224 samples</p>\n\n<h2>Epoch 1/5</h2>\n\n<p>InvalidArgumentError                      Traceback (most recent call last)\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)\n   1333     try:\n-&gt; 1334       return fn(*args)\n   1335     except errors.OpError as e:</p>\n\n<p>/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)\n   1316       # Ensure any changes to the graph are reflected in the runtime.\n-&gt; 1317       self._extend_graph()\n   1318       return self._call_tf_sessionrun(</p>\n\n<p>/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _extend_graph(self)\n   1351     with self._graph._session_run_lock():  # pylint: disable=protected-access\n-&gt; 1352       tf_session.ExtendSession(self._session)\n   1353 </p>\n\n<p>InvalidArgumentError: No OpKernel was registered to support Op 'CudnnRNN' with these attrs.  Registered devices: [CPU,XLA_CPU], Registered kernels:</p>",
  "messages": [
    {
      "id": 456661,
      "postDate": "2019-01-16T09:01:38.117Z",
      "content": "<p>Hi, \n    In settings I have enabled my GPU. \n    I was trying to implement the CuDNNGRU keras on kaggle. This is my model,</p>\n\n<pre><code>inp = kl.Input(shape=(max_words,))\nm = kl.Embedding(input_dim = cl+1, output_dim = EMBEDDING_DIM, weights=[embedding_matrix], trainable = False)(inp)\n#del(embedding_matrix);\nm = kl.SpatialDropout1D(rate = 0.25)(m)\nm = kl.Bidirectional(kl.CuDNNGRU(128, kernel_initializer=glorot_normal(seed=1029), \n       recurrent_initializer=orthogonal(gain=1.0, seed=1029), name = 'bi_gru'))(m)\nm = kl.Dense(32, activation=\"relu\")(m)\nm = kl.Dropout(0.2)(m)\nm = kl.Dense(1, activation=\"sigmoid\")(m)\nmodel = Model(inputs=inp, outputs=m)\n\nmodel.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\nprint(model.summary())\n\nnum_epochs = 5;  batchSize = 128;\n</code></pre>\n\n<p>After this this is my output.</p>\n\n<pre><code>(33927, 300)\n_________________________________________________________________\nLayer (type)                 Output Shape              Param #   \n=================================================================\ninput_1 (InputLayer)         (None, 52)                0         \n_________________________________________________________________\nembedding_1 (Embedding)      (None, 52, 300)           10178100  \n_________________________________________________________________\nspatial_dropout1d_1 (Spatial (None, 52, 300)           0         \n_________________________________________________________________\nbidirectional_1 (Bidirection (None, 256)               330240    \n_________________________________________________________________\ndense_1 (Dense)              (None, 32)                8224      \n_________________________________________________________________\ndropout_1 (Dropout)          (None, 32)                0         \n_________________________________________________________________\ndense_2 (Dense)              (None, 1)                 33        \n=================================================================\nTotal params: 10,516,597\nTrainable params: 338,497\nNon-trainable params: 10,178,100\n</code></pre>\n\n<p>But when i fit my model, \nmodel.fit(x_train, y_train, validation_data=(x_val, y_val), batch_size = batch_size,  epochs=num_epochs, verbose = True);</p>\n\n<p>It is showing this error,</p>\n\n<p>Train on 1044898 samples, validate on 261224 samples</p>\n\n<h2>Epoch 1/5</h2>\n\n<p>InvalidArgumentError                      Traceback (most recent call last)\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)\n   1333     try:\n-&gt; 1334       return fn(*args)\n   1335     except errors.OpError as e:</p>\n\n<p>/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)\n   1316       # Ensure any changes to the graph are reflected in the runtime.\n-&gt; 1317       self._extend_graph()\n   1318       return self._call_tf_sessionrun(</p>\n\n<p>/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _extend_graph(self)\n   1351     with self._graph._session_run_lock():  # pylint: disable=protected-access\n-&gt; 1352       tf_session.ExtendSession(self._session)\n   1353 </p>\n\n<p>InvalidArgumentError: No OpKernel was registered to support Op 'CudnnRNN' with these attrs.  Registered devices: [CPU,XLA_CPU], Registered kernels:</p>",
      "rawMarkdown": "Hi, \n    In settings I have enabled my GPU. \n    I was trying to implement the CuDNNGRU keras on kaggle. This is my model,\n\n    inp = kl.Input(shape=(max_words,))\n    m = kl.Embedding(input_dim = cl+1, output_dim = EMBEDDING_DIM, weights=[embedding_matrix], trainable = False)(inp)\n    #del(embedding_matrix);\n    m = kl.SpatialDropout1D(rate = 0.25)(m)\n    m = kl.Bidirectional(kl.CuDNNGRU(128, kernel_initializer=glorot_normal(seed=1029), \n           recurrent_initializer=orthogonal(gain=1.0, seed=1029), name = 'bi_gru'))(m)\n    m = kl.Dense(32, activation=\"relu\")(m)\n    m = kl.Dropout(0.2)(m)\n    m = kl.Dense(1, activation=\"sigmoid\")(m)\n    model = Model(inputs=inp, outputs=m)\n    \n    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n    print(model.summary())\n    \n    num_epochs = 5;  batchSize = 128;\n\nAfter this this is my output.\n\n    (33927, 300)\n    _________________________________________________________________\n    Layer (type)                 Output Shape              Param #   \n    =================================================================\n    input_1 (InputLayer)         (None, 52)                0         \n    _________________________________________________________________\n    embedding_1 (Embedding)      (None, 52, 300)           10178100  \n    _________________________________________________________________\n    spatial_dropout1d_1 (Spatial (None, 52, 300)           0         \n    _________________________________________________________________\n    bidirectional_1 (Bidirection (None, 256)               330240    \n    _________________________________________________________________\n    dense_1 (Dense)              (None, 32)                8224      \n    _________________________________________________________________\n    dropout_1 (Dropout)          (None, 32)                0         \n    _________________________________________________________________\n    dense_2 (Dense)              (None, 1)                 33        \n    =================================================================\n    Total params: 10,516,597\n    Trainable params: 338,497\n    Non-trainable params: 10,178,100\n\nBut when i fit my model, \nmodel.fit(x_train, y_train, validation_data=(x_val, y_val), batch_size = batch_size,  epochs=num_epochs, verbose = True);\n\nIt is showing this error,\n\nTrain on 1044898 samples, validate on 261224 samples\nEpoch 1/5\n---------------------------------------------------------------------------\nInvalidArgumentError                      Traceback (most recent call last)\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)\n   1333     try:\n-&gt; 1334       return fn(*args)\n   1335     except errors.OpError as e:\n\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)\n   1316       # Ensure any changes to the graph are reflected in the runtime.\n-&gt; 1317       self._extend_graph()\n   1318       return self._call_tf_sessionrun(\n\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _extend_graph(self)\n   1351     with self._graph._session_run_lock():  # pylint: disable=protected-access\n-&gt; 1352       tf_session.ExtendSession(self._session)\n   1353 \n\nInvalidArgumentError: No OpKernel was registered to support Op 'CudnnRNN' with these attrs.  Registered devices: [CPU,XLA_CPU], Registered kernels:\n  ",
      "votes": 1
    },
    {
      "id": 457223,
      "postDate": "2019-01-17T05:17:10.920Z",
      "content": "<p>you must enable the GPU is on. in the settings.</p>",
      "rawMarkdown": "you must enable the GPU is on. in the settings.",
      "replies": [
        {
          "id": 457281,
          "postDate": "2019-01-17T07:25:53.017Z",
          "content": "<p>I have enabled my GPU and then only i tried. But i got this weird error. </p>",
          "rawMarkdown": "I have enabled my GPU and then only i tried. But i got this weird error. "
        },
        {
          "id": 457327,
          "postDate": "2019-01-17T08:32:58.483Z",
          "content": "<p>did you use 'tf.device(\"/cpu:0\"):'?</p>",
          "rawMarkdown": "did you use 'tf.device(\"/cpu:0\"):'?"
        },
        {
          "id": 458463,
          "postDate": "2019-01-19T17:44:41.217Z",
          "content": "<p>What is that ? And I opened a new Kernel and the gpu works there. Thanks.</p>",
          "rawMarkdown": "What is that ? And I opened a new Kernel and the gpu works there. Thanks."
        }
      ]
    },
    {
      "id": 456698,
      "postDate": "2019-01-16T10:26:50.900Z",
      "content": "<p>Did you enable GPU kernel?</p>",
      "rawMarkdown": "Did you enable GPU kernel?",
      "replies": [
        {
          "id": 457193,
          "postDate": "2019-01-17T04:07:52.003Z",
          "content": "<p>Yeah. </p>",
          "rawMarkdown": "Yeah. "
        }
      ]
    },
    {
      "id": 456707,
      "postDate": "2019-01-16T10:44:37.223Z",
      "rawMarkdown": "",
      "isDeleted": true,
      "replies": [
        {
          "id": 457194,
          "postDate": "2019-01-17T04:08:24.877Z",
          "content": "<p>Can you suggest me on how to make this error disappear ?</p>",
          "rawMarkdown": "Can you suggest me on how to make this error disappear ?\n"
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 457223,
      "author_name": "Bai",
      "author_url": "",
      "post_date": "2019-01-17T05:17:10.920000",
      "content": "<p>you must enable the GPU is on. in the settings.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 457281,
          "author_name": "Ajay  Hayagreeve",
          "author_url": "",
          "post_date": "2019-01-17T07:25:53.017000",
          "content": "<p>I have enabled my GPU and then only i tried. But i got this weird error. </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 457327,
          "author_name": "Bai",
          "author_url": "",
          "post_date": "2019-01-17T08:32:58.483000",
          "content": "<p>did you use 'tf.device(\"/cpu:0\"):'?</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 458463,
          "author_name": "Ajay  Hayagreeve",
          "author_url": "",
          "post_date": "2019-01-19T17:44:41.217000",
          "content": "<p>What is that ? And I opened a new Kernel and the gpu works there. Thanks.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 456698,
      "author_name": "Psi",
      "author_url": "",
      "post_date": "2019-01-16T10:26:50.900000",
      "content": "<p>Did you enable GPU kernel?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 457193,
          "author_name": "Ajay  Hayagreeve",
          "author_url": "",
          "post_date": "2019-01-17T04:07:52.003000",
          "content": "<p>Yeah. </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 456707,
      "author_name": "",
      "author_url": "",
      "post_date": "2019-01-16T10:44:37.223000",
      "content": "",
      "votes": 0,
      "replies": [
        {
          "id": 457194,
          "author_name": "Ajay  Hayagreeve",
          "author_url": "",
          "post_date": "2019-01-17T04:08:24.877000",
          "content": "<p>Can you suggest me on how to make this error disappear ?</p>",
          "votes": 0,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "456661": "Hi, \n    In settings I have enabled my GPU. \n    I was trying to implement the CuDNNGRU keras on kaggle. This is my model,\n\n    inp = kl.Input(shape=(max_words,))\n    m = kl.Embedding(input_dim = cl+1, output_dim = EMBEDDING_DIM, weights=[embedding_matrix], trainable = False)(inp)\n    #del(embedding_matrix);\n    m = kl.SpatialDropout1D(rate = 0.25)(m)\n    m = kl.Bidirectional(kl.CuDNNGRU(128, kernel_initializer=glorot_normal(seed=1029), \n           recurrent_initializer=orthogonal(gain=1.0, seed=1029), name = 'bi_gru'))(m)\n    m = kl.Dense(32, activation=\"relu\")(m)\n    m = kl.Dropout(0.2)(m)\n    m = kl.Dense(1, activation=\"sigmoid\")(m)\n    model = Model(inputs=inp, outputs=m)\n    \n    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n    print(model.summary())\n    \n    num_epochs = 5;  batchSize = 128;\n\nAfter this this is my output.\n\n    (33927, 300)\n    _________________________________________________________________\n    Layer (type)                 Output Shape              Param #   \n    =================================================================\n    input_1 (InputLayer)         (None, 52)                0         \n    _________________________________________________________________\n    embedding_1 (Embedding)      (None, 52, 300)           10178100  \n    _________________________________________________________________\n    spatial_dropout1d_1 (Spatial (None, 52, 300)           0         \n    _________________________________________________________________\n    bidirectional_1 (Bidirection (None, 256)               330240    \n    _________________________________________________________________\n    dense_1 (Dense)              (None, 32)                8224      \n    _________________________________________________________________\n    dropout_1 (Dropout)          (None, 32)                0         \n    _________________________________________________________________\n    dense_2 (Dense)              (None, 1)                 33        \n    =================================================================\n    Total params: 10,516,597\n    Trainable params: 338,497\n    Non-trainable params: 10,178,100\n\nBut when i fit my model, \nmodel.fit(x_train, y_train, validation_data=(x_val, y_val), batch_size = batch_size,  epochs=num_epochs, verbose = True);\n\nIt is showing this error,\n\nTrain on 1044898 samples, validate on 261224 samples\nEpoch 1/5\n---------------------------------------------------------------------------\nInvalidArgumentError                      Traceback (most recent call last)\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _do_call(self, fn, *args)\n   1333     try:\n-&gt; 1334       return fn(*args)\n   1335     except errors.OpError as e:\n\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)\n   1316       # Ensure any changes to the graph are reflected in the runtime.\n-&gt; 1317       self._extend_graph()\n   1318       return self._call_tf_sessionrun(\n\n/opt/conda/lib/python3.6/site-packages/tensorflow/python/client/session.py in _extend_graph(self)\n   1351     with self._graph._session_run_lock():  # pylint: disable=protected-access\n-&gt; 1352       tf_session.ExtendSession(self._session)\n   1353 \n\nInvalidArgumentError: No OpKernel was registered to support Op 'CudnnRNN' with these attrs.  Registered devices: [CPU,XLA_CPU], Registered kernels:\n  ",
    "457223": "you must enable the GPU is on. in the settings.",
    "456698": "Did you enable GPU kernel?",
    "456707": ""
  }
}