How to install CUDA in Google Colab - Cannot initialize CUDA without ATen_cuda library












0














I am trying to use cuda in Goolge Colab but while running my program I get the following error.




RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.




I have the following libraries installed.



from os.path import exists
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*.([0-9]*).([0-9]*)$/cu12/'
accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-

{platform}-linux_x86_64.whl torchvision
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

import matplotlib.pyplot as plt
import time
import torch
from torch import nn
from torch import optim
import torch.nn.functional as F
from torchvision import datasets, transforms, models
!pip install Pillow==5.3.0
# import the new one
import PIL


And I am trying to run the following code.



for device in ['cpu', 'cuda']:

criterion = nn.NLLLoss()
# Only train the classifier parameters, feature parameters are frozen
optimizer = optim.Adam(model.classifier.parameters(), lr=0.001)

model.to(device)

for ii, (inputs, labels) in enumerate(trainloader):

# Move input and label tensors to the GPU
inputs, labels = inputs.to(device), labels.to(device)

start = time.time()

outputs = model.forward(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()

if ii==3:
break

print(f"Device = {device}; Time per batch: {(time.time() - start)/3:.3f} seconds")









share|improve this question





























    0














    I am trying to use cuda in Goolge Colab but while running my program I get the following error.




    RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.




    I have the following libraries installed.



    from os.path import exists
    from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
    platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
    cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*.([0-9]*).([0-9]*)$/cu12/'
    accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

    !pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-

    {platform}-linux_x86_64.whl torchvision
    %matplotlib inline
    %config InlineBackend.figure_format = 'retina'

    import matplotlib.pyplot as plt
    import time
    import torch
    from torch import nn
    from torch import optim
    import torch.nn.functional as F
    from torchvision import datasets, transforms, models
    !pip install Pillow==5.3.0
    # import the new one
    import PIL


    And I am trying to run the following code.



    for device in ['cpu', 'cuda']:

    criterion = nn.NLLLoss()
    # Only train the classifier parameters, feature parameters are frozen
    optimizer = optim.Adam(model.classifier.parameters(), lr=0.001)

    model.to(device)

    for ii, (inputs, labels) in enumerate(trainloader):

    # Move input and label tensors to the GPU
    inputs, labels = inputs.to(device), labels.to(device)

    start = time.time()

    outputs = model.forward(inputs)
    loss = criterion(outputs, labels)
    loss.backward()
    optimizer.step()

    if ii==3:
    break

    print(f"Device = {device}; Time per batch: {(time.time() - start)/3:.3f} seconds")









    share|improve this question



























      0












      0








      0







      I am trying to use cuda in Goolge Colab but while running my program I get the following error.




      RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.




      I have the following libraries installed.



      from os.path import exists
      from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
      platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
      cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*.([0-9]*).([0-9]*)$/cu12/'
      accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

      !pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-

      {platform}-linux_x86_64.whl torchvision
      %matplotlib inline
      %config InlineBackend.figure_format = 'retina'

      import matplotlib.pyplot as plt
      import time
      import torch
      from torch import nn
      from torch import optim
      import torch.nn.functional as F
      from torchvision import datasets, transforms, models
      !pip install Pillow==5.3.0
      # import the new one
      import PIL


      And I am trying to run the following code.



      for device in ['cpu', 'cuda']:

      criterion = nn.NLLLoss()
      # Only train the classifier parameters, feature parameters are frozen
      optimizer = optim.Adam(model.classifier.parameters(), lr=0.001)

      model.to(device)

      for ii, (inputs, labels) in enumerate(trainloader):

      # Move input and label tensors to the GPU
      inputs, labels = inputs.to(device), labels.to(device)

      start = time.time()

      outputs = model.forward(inputs)
      loss = criterion(outputs, labels)
      loss.backward()
      optimizer.step()

      if ii==3:
      break

      print(f"Device = {device}; Time per batch: {(time.time() - start)/3:.3f} seconds")









      share|improve this question















      I am trying to use cuda in Goolge Colab but while running my program I get the following error.




      RuntimeError: Cannot initialize CUDA without ATen_cuda library. PyTorch splits its backend into two shared libraries: a CPU library and a CUDA library; this error has occurred because you are trying to use some CUDA functionality, but the CUDA library has not been loaded by the dynamic linker for some reason. The CUDA library MUST be loaded, EVEN IF you don't directly use any symbols from the CUDA library! One common culprit is a lack of -Wl,--no-as-needed in your link arguments; many dynamic linkers will delete dynamic library dependencies if you don't depend on any of their symbols. You can check if this has occurred by using ldd on your binary to see if there is a dependency on *_cuda.so library.




      I have the following libraries installed.



      from os.path import exists
      from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
      platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
      cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*.([0-9]*).([0-9]*)$/cu12/'
      accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu'

      !pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.4.1-

      {platform}-linux_x86_64.whl torchvision
      %matplotlib inline
      %config InlineBackend.figure_format = 'retina'

      import matplotlib.pyplot as plt
      import time
      import torch
      from torch import nn
      from torch import optim
      import torch.nn.functional as F
      from torchvision import datasets, transforms, models
      !pip install Pillow==5.3.0
      # import the new one
      import PIL


      And I am trying to run the following code.



      for device in ['cpu', 'cuda']:

      criterion = nn.NLLLoss()
      # Only train the classifier parameters, feature parameters are frozen
      optimizer = optim.Adam(model.classifier.parameters(), lr=0.001)

      model.to(device)

      for ii, (inputs, labels) in enumerate(trainloader):

      # Move input and label tensors to the GPU
      inputs, labels = inputs.to(device), labels.to(device)

      start = time.time()

      outputs = model.forward(inputs)
      loss = criterion(outputs, labels)
      loss.backward()
      optimizer.step()

      if ii==3:
      break

      print(f"Device = {device}; Time per batch: {(time.time() - start)/3:.3f} seconds")






      python runtime-error pytorch google-colaboratory






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 27 at 15:42









      talonmies

      59.1k17128196




      59.1k17128196










      asked Dec 27 at 14:08









      Kavin Raju S

      536




      536
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Have you selected the runtime as GPU?
          check runtime> change runtime type > select hardware accelerator as GPU






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53946404%2fhow-to-install-cuda-in-google-colab-cannot-initialize-cuda-without-aten-cuda-l%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Have you selected the runtime as GPU?
            check runtime> change runtime type > select hardware accelerator as GPU






            share|improve this answer


























              0














              Have you selected the runtime as GPU?
              check runtime> change runtime type > select hardware accelerator as GPU






              share|improve this answer
























                0












                0








                0






                Have you selected the runtime as GPU?
                check runtime> change runtime type > select hardware accelerator as GPU






                share|improve this answer












                Have you selected the runtime as GPU?
                check runtime> change runtime type > select hardware accelerator as GPU







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 27 at 17:12









                Sherlock

                325




                325






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53946404%2fhow-to-install-cuda-in-google-colab-cannot-initialize-cuda-without-aten-cuda-l%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'