English 中文(简体)
Google Colab - Using Free GPU
  • 时间:2024-12-27

Google Colab - Using Free GPU


Previous Page Next Page  

Google provides the use of free GPU for your Colab notebooks.

Enabpng GPU

To enable GPU in your notebook, select the following menu options −


Runtime / Change runtime type

You will see the following screen as the output −

Enabpng GPU

Select GPU and your notebook would use the free GPU provided in the cloud during processing. To get the feel of GPU processing, try running the sample apppcation from MNIST tutorial that you cloned earper.


!python3 "/content/drive/My Drive/app/mnist_cnn.py"

Try running the same Python file without the GPU enabled. Did you notice the difference in speed of execution?

Testing for GPU

You can easily check if the GPU is enabled by executing the following code −


import tensorflow as tf
tf.test.gpu_device_name()

If the GPU is enabled, it will give the following output −


 /device:GPU:0 

Listing Devices

If you are curious to know the devices used during the execution of your notebook in the cloud, try the following code −


from tensorflow.python.cpent import device_pb
device_pb.pst_local_devices()

You will see the output as follows −


[name: "/device:CPU:0"
   device_type: "CPU"
   memory_pmit: 268435456
   locapty { }
   incarnation: 1734904979049303143, name: "/device:XLA_CPU:0"
   device_type: "XLA_CPU" memory_pmit: 17179869184
   locapty { } 
   incarnation: 16069148927281628039
   physical_device_desc: "device: XLA_CPU device", name: "/device:XLA_GPU:0"
   device_type: "XLA_GPU"
   memory_pmit: 17179869184
   locapty { }
   incarnation: 16623465188569787091
   physical_device_desc: "device: XLA_GPU device", name: "/device:GPU:0"
   device_type: "GPU"
   memory_pmit: 14062547764
   locapty {
      bus_id: 1
      pnks { } 
   }
   incarnation: 6674128802944374158
physical_device_desc: "device: 0, name: Tesla T4, pci bus id: 0000:00:04.0, compute capabipty: 7.5"]

Checking RAM

To see the memory resources available for your process, type the following command −


!cat /proc/meminfo

You will see the following output −


MemTotal: 13335276 kB
MemFree: 7322964 kB
MemAvailable: 10519168 kB
Buffers: 95732 kB
Cached: 2787632 kB
SwapCached: 0 kB
Active: 2433984 kB
Inactive: 3060124 kB
Active(anon): 2101704 kB
Inactive(anon): 22880 kB
Active(file): 332280 kB
Inactive(file): 3037244 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 412 kB
Writeback: 0 kB
AnonPages: 2610780 kB
Mapped: 838200 kB
Shmem: 23436 kB
Slab: 183240 kB
SReclaimable: 135324 kB
SUnreclaim: 47916
kBKernelStack: 4992 kB
PageTables: 13600 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 6667636 kB
Committed_AS: 4801380 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 0 kB
VmallocChunk: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 303092 kB
DirectMap2M: 5988352 kB
DirectMap1G: 9437184 kB

You are now all set for the development of machine learning models in Python using Google Colab.

Advertisements