{
  "id": 341077,
  "title": "Pytorch LSTM not using GPU",
  "url": "/competitions/amex-default-prediction/discussion/341077",
  "author_name": "Varun Jagannath",
  "post_date": "2022-08-01T05:57:24.309000",
  "votes": 2,
  "comment_count": 10,
  "views": 0,
  "content": "<p>I am trying a to build a LSTM model but while training it is only using CPu but not using GPU.<br>\nAny ideas ?<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1856617%2Fcb67f065d7ab2f161f02eff8c305d9c1%2FGPU.JPG?generation=1659333429572123&amp;alt=media\" alt=\"\"></p>\n<p>Update:<br>\nNotebook <a href=\"https://www.kaggle.com/vjagannath786/pytorch-lstm\" target=\"_blank\">https://www.kaggle.com/vjagannath786/pytorch-lstm</a></p>",
  "messages": [
    {
      "id": 1880600,
      "postDate": "2022-08-01T21:04:18.807Z",
      "content": "<p>idk if this can help but i got the same problem while training a CNN, found out that <strong>preprocessing</strong> was slowing down the entire process and GPU was idling most of the time, waiting for the data from CPU</p>",
      "rawMarkdown": "idk if this can help but i got the same problem while training a CNN, found out that **preprocessing** was slowing down the entire process and GPU was idling most of the time, waiting for the data from CPU",
      "votes": 1
    },
    {
      "id": 1879742,
      "postDate": "2022-08-01T08:20:13.373Z",
      "content": "<p>Maybe you want to see <a href=\"https://www.kaggle.com/code/voix97/amex-pytorch-gru-training\" target=\"_blank\">this notebook</a> to know how to train an RNN on GPU.</p>",
      "rawMarkdown": "Maybe you want to see [this notebook](https://www.kaggle.com/code/voix97/amex-pytorch-gru-training) to know how to train an RNN on GPU.",
      "votes": 1,
      "replies": [
        {
          "id": 1880147,
          "postDate": "2022-08-01T13:48:00.650Z",
          "content": "<p>I am just using output layer of LSTM and i think you are using hidden layers.<br>\nWill try to post the notebook in some time.<br>\nplease try to look and let me know if any issues.</p>",
          "rawMarkdown": "I am just using output layer of LSTM and i think you are using hidden layers.\nWill try to post the notebook in some time.\nplease try to look and let me know if any issues."
        },
        {
          "id": 1880733,
          "postDate": "2022-08-02T02:24:39.630Z",
          "content": "<p>I think the most time-consuming step is this:<br>\n<code>\ntk0 = tqdm(data_loader, total=len(data_loader))\nfor data in tk0:\n</code><br>\nmaybe you could test the wall time consumption of each step in model training (i.e. check the function train_fn)</p>",
          "rawMarkdown": "I think the most time-consuming step is this:\n`\ntk0 = tqdm(data_loader, total=len(data_loader))\nfor data in tk0:\n`\nmaybe you could test the wall time consumption of each step in model training (i.e. check the function train_fn)"
        },
        {
          "id": 1881327,
          "postDate": "2022-08-02T12:50:21.813Z",
          "content": "<p>I removed tqdm and was just using enumerate or simple for dataloader, <br>\nlooke like dataloader is the bottleneck.<br>\nEven with small set like 20k samples loader is very slow.</p>",
          "rawMarkdown": "I removed tqdm and was just using enumerate or simple for dataloader, \nlooke like dataloader is the bottleneck.\nEven with small set like 20k samples loader is very slow."
        }
      ]
    },
    {
      "id": 1880329,
      "postDate": "2022-08-01T16:11:43.860Z",
      "content": "<p>did you send model and data to GPU? (.to('cuda'))</p>",
      "rawMarkdown": "did you send model and data to GPU? (.to('cuda'))",
      "votes": 2,
      "replies": [
        {
          "id": 1880425,
          "postDate": "2022-08-01T17:56:24.117Z",
          "content": "<p><a href=\"https://www.kaggle.com/titericz\" target=\"_blank\">@titericz</a> , yes and updated the topic with notebook , any ideas ?</p>",
          "rawMarkdown": "@titericz , yes and updated the topic with notebook , any ideas ?"
        }
      ]
    },
    {
      "id": 1879555,
      "postDate": "2022-08-01T05:57:24.310Z",
      "content": "<p>I am trying a to build a LSTM model but while training it is only using CPu but not using GPU.<br>\nAny ideas ?<br>\n<img src=\"https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1856617%2Fcb67f065d7ab2f161f02eff8c305d9c1%2FGPU.JPG?generation=1659333429572123&amp;alt=media\" alt=\"\"></p>\n<p>Update:<br>\nNotebook <a href=\"https://www.kaggle.com/vjagannath786/pytorch-lstm\" target=\"_blank\">https://www.kaggle.com/vjagannath786/pytorch-lstm</a></p>",
      "rawMarkdown": "I am trying a to build a LSTM model but while training it is only using CPu but not using GPU.\nAny ideas ?\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1856617%2Fcb67f065d7ab2f161f02eff8c305d9c1%2FGPU.JPG?generation=1659333429572123&alt=media)\n\n\nUpdate:\nNotebook https://www.kaggle.com/vjagannath786/pytorch-lstm",
      "votes": 2
    },
    {
      "id": 1879659,
      "postDate": "2022-08-01T07:29:48.543Z",
      "content": "<p>did you select GPU on on the right?</p>",
      "rawMarkdown": "did you select GPU on on the right?",
      "replies": [
        {
          "id": 1879719,
          "postDate": "2022-08-01T08:06:32.007Z",
          "content": "<p>Yes <a href=\"https://www.kaggle.com/raddar\" target=\"_blank\">@raddar</a> ,I have selected the GPU. But, still it uses CPU. As you can see it is taking around 35 mins to complete one fold.</p>",
          "rawMarkdown": "Yes @raddar ,I have selected the GPU. But, still it uses CPU. As you can see it is taking around 35 mins to complete one fold."
        }
      ]
    },
    {
      "id": 1879736,
      "postDate": "2022-08-01T08:15:43.573Z",
      "rawMarkdown": "",
      "isDeleted": true
    }
  ],
  "comments": [
    {
      "id": 1880600,
      "author_name": "Nick Dubenco",
      "author_url": "",
      "post_date": "2022-08-01T21:04:18.807000",
      "content": "<p>idk if this can help but i got the same problem while training a CNN, found out that <strong>preprocessing</strong> was slowing down the entire process and GPU was idling most of the time, waiting for the data from CPU</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1879742,
      "author_name": "Xiang Sheng",
      "author_url": "",
      "post_date": "2022-08-01T08:20:13.373000",
      "content": "<p>Maybe you want to see <a href=\"https://www.kaggle.com/code/voix97/amex-pytorch-gru-training\" target=\"_blank\">this notebook</a> to know how to train an RNN on GPU.</p>",
      "votes": 1,
      "replies": [
        {
          "id": 1880147,
          "author_name": "Varun Jagannath",
          "author_url": "",
          "post_date": "2022-08-01T13:48:00.650000",
          "content": "<p>I am just using output layer of LSTM and i think you are using hidden layers.<br>\nWill try to post the notebook in some time.<br>\nplease try to look and let me know if any issues.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1880733,
          "author_name": "Xiang Sheng",
          "author_url": "",
          "post_date": "2022-08-02T02:24:39.630000",
          "content": "<p>I think the most time-consuming step is this:<br>\n<code>\ntk0 = tqdm(data_loader, total=len(data_loader))\nfor data in tk0:\n</code><br>\nmaybe you could test the wall time consumption of each step in model training (i.e. check the function train_fn)</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1881327,
          "author_name": "Varun Jagannath",
          "author_url": "",
          "post_date": "2022-08-02T12:50:21.813000",
          "content": "<p>I removed tqdm and was just using enumerate or simple for dataloader, <br>\nlooke like dataloader is the bottleneck.<br>\nEven with small set like 20k samples loader is very slow.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1880329,
      "author_name": "Giba",
      "author_url": "",
      "post_date": "2022-08-01T16:11:43.860000",
      "content": "<p>did you send model and data to GPU? (.to('cuda'))</p>",
      "votes": 2,
      "replies": [
        {
          "id": 1880425,
          "author_name": "Varun Jagannath",
          "author_url": "",
          "post_date": "2022-08-01T17:56:24.117000",
          "content": "<p><a href=\"https://www.kaggle.com/titericz\" target=\"_blank\">@titericz</a> , yes and updated the topic with notebook , any ideas ?</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1879659,
      "author_name": "raddar",
      "author_url": "",
      "post_date": "2022-08-01T07:29:48.543000",
      "content": "<p>did you select GPU on on the right?</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1879719,
          "author_name": "Varun Jagannath",
          "author_url": "",
          "post_date": "2022-08-01T08:06:32.007000",
          "content": "<p>Yes <a href=\"https://www.kaggle.com/raddar\" target=\"_blank\">@raddar</a> ,I have selected the GPU. But, still it uses CPU. As you can see it is taking around 35 mins to complete one fold.</p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1879736,
      "author_name": "",
      "author_url": "",
      "post_date": "2022-08-01T08:15:43.573000",
      "content": "",
      "votes": 0,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1880600": "idk if this can help but i got the same problem while training a CNN, found out that **preprocessing** was slowing down the entire process and GPU was idling most of the time, waiting for the data from CPU",
    "1879742": "Maybe you want to see [this notebook](https://www.kaggle.com/code/voix97/amex-pytorch-gru-training) to know how to train an RNN on GPU.",
    "1880329": "did you send model and data to GPU? (.to('cuda'))",
    "1879555": "I am trying a to build a LSTM model but while training it is only using CPu but not using GPU.\nAny ideas ?\n![](https://www.googleapis.com/download/storage/v1/b/kaggle-forum-message-attachments/o/inbox%2F1856617%2Fcb67f065d7ab2f161f02eff8c305d9c1%2FGPU.JPG?generation=1659333429572123&alt=media)\n\n\nUpdate:\nNotebook https://www.kaggle.com/vjagannath786/pytorch-lstm",
    "1879659": "did you select GPU on on the right?",
    "1879736": ""
  }
}