{
  "id": 271732,
  "title": "nnAudio CQT1992v2 fully on GPU?",
  "url": "/competitions/g2net-gravitational-wave-detection/discussion/271732",
  "author_name": "",
  "post_date": "2021-09-12T09:24:54.197464900Z",
  "votes": 7,
  "comment_count": 5,
  "views": 0,
  "content": "<p>I am trying to run <a href=\"https://kinwaicheuk.github.io/nnAudio/_autosummary/nnAudio.Spectrogram.CQT1992v2.html#nnAudio.Spectrogram.CQT1992v2\" target=\"_blank\">CQT1992v2</a> from the nnAudio library fully on GPU as a PyTorch layer. </p>\n<p>However, I am getting this error: </p>\n<p><code>RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same</code></p>\n<p>After a quick check of the source code, it seems indeed that the <code>self.cqt_kernels_real</code>is on CPU.</p>\n<p>Has anyone managed to fix this? Maybe there is another method I am missing?</p>\n<p>If I find a solution, I will share it. Cheers!</p>\n<p><strong>Update</strong>: </p>\n<p>Changing a bit the source code (by adding the device, here it is hardcoded), it seems to work:</p>\n<p><a href=\"https://ibb.co/N29pkfB\"><img src=\"https://i.ibb.co/WvkFd7J/changes-cqt.png\" alt=\"changes-cqt\"></a><br><a target=\"_blank\" href=\"https://imgbb.com/\">jpg en html</a><br></p>",
  "messages": [
    {
      "id": "1510305",
      "postDate": "09/12/2021 09:24:54",
      "content": "<p>I am trying to run <a href=\"https://kinwaicheuk.github.io/nnAudio/_autosummary/nnAudio.Spectrogram.CQT1992v2.html#nnAudio.Spectrogram.CQT1992v2\" target=\"_blank\">CQT1992v2</a> from the nnAudio library fully on GPU as a PyTorch layer. </p>\n<p>However, I am getting this error: </p>\n<p><code>RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same</code></p>\n<p>After a quick check of the source code, it seems indeed that the <code>self.cqt_kernels_real</code>is on CPU.</p>\n<p>Has anyone managed to fix this? Maybe there is another method I am missing?</p>\n<p>If I find a solution, I will share it. Cheers!</p>\n<p><strong>Update</strong>: </p>\n<p>Changing a bit the source code (by adding the device, here it is hardcoded), it seems to work:</p>\n<p><a href=\"https://ibb.co/N29pkfB\"><img src=\"https://i.ibb.co/WvkFd7J/changes-cqt.png\" alt=\"changes-cqt\"></a><br><a target=\"_blank\" href=\"https://imgbb.com/\">jpg en html</a><br></p>",
      "rawMarkdown": "I am trying to run [CQT1992v2](https://kinwaicheuk.github.io/nnAudio/_autosummary/nnAudio.Spectrogram.CQT1992v2.html#nnAudio.Spectrogram.CQT1992v2) from the nnAudio library fully on GPU as a PyTorch layer. \n\nHowever, I am getting this error: \n\n`RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same`\n\nAfter a quick check of the source code, it seems indeed that the `self.cqt_kernels_real `is on CPU.\n\nHas anyone managed to fix this? Maybe there is another method I am missing?\n\nIf I find a solution, I will share it. Cheers!\n\n\n**Update**: \n\nChanging a bit the source code (by adding the device, here it is hardcoded), it seems to work:\n\n\n<a href=\"https://ibb.co/N29pkfB\"><img src=\"https://i.ibb.co/WvkFd7J/changes-cqt.png\" alt=\"changes-cqt\" border=\"0\"></a><br /><a target='_blank' href='https://imgbb.com/'>jpg en html</a><br />",
      "votes": null
    },
    {
      "id": "1510349",
      "postDate": "09/12/2021 10:20:11",
      "content": "<p>The error says that your cqt weights are not on cuda.  Move your cqt to cuda then.</p>",
      "rawMarkdown": "The error says that your cqt weights are not on cuda.  Move your cqt to cuda then.",
      "votes": null
    },
    {
      "id": "1510358",
      "postDate": "09/12/2021 10:30:52",
      "content": "<p>Yes that's what I did as mentioned in the update however I was thinking if someone found a way to do it without changing the source code. </p>",
      "rawMarkdown": "Yes that's what I did as mentioned in the update however I was thinking if someone found a way to do it without changing the source code.",
      "votes": null
    },
    {
      "id": "1510359",
      "postDate": "09/12/2021 10:32:28",
      "content": "<p>Just use nnAudio.Spectrogram.CQT1992v2(**params).cuda() in your create_cqt_kernels function, since CQT1992v2 inherits from torch.nn.Module, you can move this layer just like any built-in Conv2d / Linear layer</p>",
      "rawMarkdown": "Just use nnAudio.Spectrogram.CQT1992v2(**params).cuda() in your create_cqt_kernels function, since CQT1992v2 inherits from torch.nn.Module, you can move this layer just like any built-in Conv2d / Linear layer",
      "votes": null
    },
    {
      "id": "1510360",
      "postDate": "09/12/2021 10:35:48",
      "content": "<p>Oh I didn't know this. Maybe that's what <a href=\"https://www.kaggle.com/cpmpml\" target=\"_blank\">@cpmpml</a> had in mind as well. Will give it a try. Thanks. </p>",
      "rawMarkdown": "Oh I didn't know this. Maybe that's what @cpmpml had in mind as well. Will give it a try. Thanks.",
      "votes": null
    },
    {
      "id": "1559701",
      "postDate": "10/27/2021 07:07:41",
      "content": "<p>Hey All,</p>\n<p>Thank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey <a href=\"https://forms.gle/QP9L16niPexozyhu5\" target=\"_blank\">https://forms.gle/QP9L16niPexozyhu5</a>.</p>\n<p>Thank you all,</p>\n<p>Regards,<br>\nChris</p>",
      "rawMarkdown": "Hey All,\n\nThank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey https://forms.gle/QP9L16niPexozyhu5.\n\nThank you all,\n\nRegards,\nChris",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1510349,
      "author_name": "cpmpml",
      "author_url": "",
      "post_date": "09/12/2021 10:20:11",
      "content": "<p>The error says that your cqt weights are not on cuda.  Move your cqt to cuda then.</p>",
      "votes": null,
      "replies": [
        {
          "id": 1510358,
          "author_name": "yassinealouini",
          "author_url": "",
          "post_date": "09/12/2021 10:30:52",
          "content": "<p>Yes that's what I did as mentioned in the update however I was thinking if someone found a way to do it without changing the source code. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1510359,
          "author_name": "martynoveduard",
          "author_url": "",
          "post_date": "09/12/2021 10:32:28",
          "content": "<p>Just use nnAudio.Spectrogram.CQT1992v2(**params).cuda() in your create_cqt_kernels function, since CQT1992v2 inherits from torch.nn.Module, you can move this layer just like any built-in Conv2d / Linear layer</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1510360,
          "author_name": "yassinealouini",
          "author_url": "",
          "post_date": "09/12/2021 10:35:48",
          "content": "<p>Oh I didn't know this. Maybe that's what <a href=\"https://www.kaggle.com/cpmpml\" target=\"_blank\">@cpmpml</a> had in mind as well. Will give it a try. Thanks. </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 1559701,
      "author_name": "zerafachris",
      "author_url": "",
      "post_date": "10/27/2021 07:07:41",
      "content": "<p>Hey All,</p>\n<p>Thank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey <a href=\"https://forms.gle/QP9L16niPexozyhu5\" target=\"_blank\">https://forms.gle/QP9L16niPexozyhu5</a>.</p>\n<p>Thank you all,</p>\n<p>Regards,<br>\nChris</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1510305": "I am trying to run [CQT1992v2](https://kinwaicheuk.github.io/nnAudio/_autosummary/nnAudio.Spectrogram.CQT1992v2.html#nnAudio.Spectrogram.CQT1992v2) from the nnAudio library fully on GPU as a PyTorch layer. \n\nHowever, I am getting this error: \n\n`RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same`\n\nAfter a quick check of the source code, it seems indeed that the `self.cqt_kernels_real `is on CPU.\n\nHas anyone managed to fix this? Maybe there is another method I am missing?\n\nIf I find a solution, I will share it. Cheers!\n\n\n**Update**: \n\nChanging a bit the source code (by adding the device, here it is hardcoded), it seems to work:\n\n\n<a href=\"https://ibb.co/N29pkfB\"><img src=\"https://i.ibb.co/WvkFd7J/changes-cqt.png\" alt=\"changes-cqt\" border=\"0\"></a><br /><a target='_blank' href='https://imgbb.com/'>jpg en html</a><br />",
    "1510349": "The error says that your cqt weights are not on cuda.  Move your cqt to cuda then.",
    "1510358": "Yes that's what I did as mentioned in the update however I was thinking if someone found a way to do it without changing the source code.",
    "1510359": "Just use nnAudio.Spectrogram.CQT1992v2(**params).cuda() in your create_cqt_kernels function, since CQT1992v2 inherits from torch.nn.Module, you can move this layer just like any built-in Conv2d / Linear layer",
    "1510360": "Oh I didn't know this. Maybe that's what @cpmpml had in mind as well. Will give it a try. Thanks.",
    "1559701": "Hey All,\n\nThank you all for taking part in our competition. The participation has been overwhelmingly positive. We are currently conducting a survey to gauge the demographic and outreach achieved. Kindly spare 2min and fill in this survey https://forms.gle/QP9L16niPexozyhu5.\n\nThank you all,\n\nRegards,\nChris"
  },
  "source": "meta"
}