2
$\begingroup$

I am trying to run a github deep learning repository in Colab but I can not connect the python files to colab GPU.

I can connect to GPU when writing a script in the colab notebook e.g. when I run this cod from a notebook cell :

import os, torch
print('Torch', torch.__version__, 'CUDA', torch.version.cuda)
print('Device:', torch.device('cuda:0'))
print(torch.cuda.is_available())  

I get:

Torch 1.4.0 CUDA 10.1
Device: cuda:0
True

but when I run it from a file called myExample.py e.g. using

!python myExample.py

I get:

Torch 1.4.0 CUDA 10.1
Device: cuda:0
False

Is there any solution to this?

$\endgroup$

1 Answer 1

1
$\begingroup$

Why dont you import the file into notebook and run your function.

Eg: if your example.py has something like this

if __name__ == '__main__':
    myfunction()

Then in your colab,

import os
os.chdir("path/to/cloned/dir/")
import example
example.myfunction()
$\endgroup$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.