GPU not detected by torch

varunGitBoi: <pre><code class="lang-auto">import torch

dtype = torch.float
device = torch.device("cpu")
#dtype = torch.device("cuda:0") # Uncomment this to run on GPU

# N is batch size; D_in is input dimension;
# H is hidden dimension; D_out is output dimension.
N, D_in, H, D_out = 64, 1000, 100, 10

# Create random input and output data
x = torch.randn(N, D_in, device=dtype, dtype=torch.float)
y = torch.randn(N, D_out, device=dtype, dtype=torch.float)

# Randomly initialize weights
w1 = torch.randn(D_in, H, device=dtype, dtype=torch.float)
w2 = torch.randn(H, D_out, device=dtype, dtype=torch.float)

learning_rate = 1e-6
for t in range(100000):
    # Forward pass: compute predicted y
    h = x.mm(w1)
    h_relu = h.clamp(min=0)
    y_pred = h_relu.mm(w2)

    # Compute and print loss
    loss = (y_pred - y).pow(2).sum().item()
    print(t, loss)

    # Backprop to compute gradients of w1 and w2 with respect to loss
    grad_y_pred = 2.0 * (y_pred - y)
    grad_w2 = h_relu.t().mm(grad_y_pred)
    grad_h_relu = grad_y_pred.mm(w2.t())
    grad_h = grad_h_relu.clone()
    grad_h[h &lt; 0] = 0
    grad_w1 = x.t().mm(grad_h)

    # Update weights using gradient descent
    w1 -= learning_rate * grad_w1
    w2 -= learning_rate * grad_w2
</code></pre>
<p>To check if the gpu was doing its job, I decided to compare performance with and without gpu.<br>
It worked equally slow in both the cases. Then, I ran this:</p>
<pre><code class="lang-auto">if torch.cuda.device_count() &gt; 1:
    print("Let's use", torch.cuda.device_count(), "GPUs!")
else:
    print("no usable gpus")
</code></pre>
<p>Output:</p>
<pre><code class="lang-auto">no usable gpus
</code></pre>
<p>I have cuda installed properly and Nvidia GeForce 930M. Why doesn’t it find any gpus??</p>

albanD: <p>How did you installed pytorch? Which version of CUDA do you have installed?</p>

varunGitBoi: <p>installed pytorch with pip on windows 10. have CUDA  9.1</p>

albanD: <p>I don’t know how these work on windows, <a class="mention" href="/u/peterjc123">@peterjc123</a> might.</p>

peterjc123: <p><a class="mention" href="/u/varungitboi">@varunGitBoi</a> What error does it throw if you explicitly create a new tensor on GPU?</p>
<pre><code class="lang-python">import torch
a = torch.cuda.FloatTensor([1.])
</code></pre>

varunGitBoi: <p>seems to be some problem with the installation…It returns not found error…but when I go to install torch, it says all packages already exist…although I uninstalled pytorch earlier…can you tell me how to completely remove pytorch??</p>

peterjc123: <p>Either one should do. I don’t which one you used in your previous uninstallation.</p>
<pre><code class="lang-auto">conda uninstall pytorch
pip uninstall torch
</code></pre>

varunGitBoi: <p>It took like forever but didnt sjow any error message<br>
then i ran:<br>
<code>a</code><br>
it returned :</p>
<pre><code class="lang-auto">tensor([ 1.], device='cuda:0')

</code></pre>
<p>does cuda:0 mean that i dont have any usable GPUs??</p>

varunGitBoi: <p>also, this:<br>
`model = Model(input_size, output_size)<br>
if torch.cuda.device_count() &gt; 1:<br>
print(“Let’s use”, torch.cuda.device_count(), “GPUs!”)</p>
<h1>dim = 0 [30, xxx] -&gt; [10, …], [10, …], [10, …] on 3 GPUs</h1>
<p>model = nn.DataParallel(model)</p>
<p>model.to(device)`<br>
outputs:</p>
<pre><code class="lang-auto">  (fc): Linear(in_features=5, out_features=2, bias=True)
)
</code></pre>
<p>where “Model()” is:</p>
<pre><code class="lang-auto">    # Our model

    def __init__(self, input_size, output_size):
        super(Model, self).__init__()
        self.fc = nn.Linear(input_size, output_size)

    def forward(self, input):
        output = self.fc(input)
        print("\tIn Model: input size", input.size(),
              "output size", output.size())

        return output
type or paste code here
</code></pre>

peterjc123: <p>No, it means the data is on the first GPU.</p>

varunGitBoi: <p>all the set up done, i tried comparing the time gpu and cpu codes take to execute. Founf out the the gpu one was taking more or comparable time everytime.</p>

fernando23296: <p>Disabling the secure boot in bios helped me</p>