1

I believe my neural network model is only running on CPU because whenever It's training I check the task manager and the GPU utilization is 0%. I also tried printing the elapsed time before and after I went through the necessary packages installation and it's always the same. What am I doing wrong??

I have an RTX 3060 GPU, I have installed CUDA v11.6 and cuDNN v11.5, I added all the necessary paths to the environment variables, I also have tf-gpu and keras-gpu installed.

running this code

print(f"Tensor Flow Version: {tf.__version__}")
print(f"Keras Version: {tensorflow.keras.__version__}")
print()
print(f"Python {sys.version}")
print(f"Pandas {pd.__version__}")
gpu = len(tf.config.list_physical_devices('GPU'))>0
print("GPU is", "available" if gpu else "NOT AVAILABLE")
print(device_lib.list_local_devices())

prints

Tensor Flow Version: 2.6.0
Keras Version: 2.6.0

Python 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Pandas 1.4.1
GPU is available

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 13579942905822528038
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 3665166336
locality {
  bus_id: 1
  links {
  }
}
incarnation: 16782751195021072368
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6"
]

2022-03-28 16:03:59.493492: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-03-28 16:04:00.265191: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 3495 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6
2022-03-28 16:04:00.450856: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
2022-03-28 16:04:01.910615: I tensorflow/stream_executor/cuda/cuda_blas.cc:1760] TensorFloat-32 will be used for the matrix multiplication. This will only be logged once.
2022-03-28 16:19:08.490212: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1510] Created device /device:GPU:0 with 3495 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3060 Laptop GPU, pci bus id: 0000:01:00.0, compute capability: 8.6

And this my neural network model

import tensorflow as tf
from keras.models import Sequential
import keras.layers as layers
import keras.metrics as metrics
import pandas as pd
import glob
import time

model = Sequential()
model.add(layers.Dense(20, input_shape=(3,)))
model.add(layers.Dense(30))
model.add(layers.Dense(1))

model.compile(loss=['mean_absolute_error'],
              optimizer='adam',
              metrics=[metrics.MeanAbsoluteError()])

t1 = time.time()

model.fit(x_train, y_train, epochs=10, batch_size=None)

t2 = time.time()
print(t2-t1)
talonmies
  • 70,661
  • 34
  • 192
  • 269
mira
  • 41
  • 1
  • 5
  • from the logs you posted, the GPU is being used. – jkr Mar 28 '22 at 19:01
  • GPU is available: means that there is an GPU to run code of it. But to run your code on GPU you should set your device to GPU. By default it is CPU. – BarzanHayati Mar 28 '22 at 19:04
  • @BarzanHayati - the gpu should be used automatically if it is available. – jkr Mar 28 '22 at 19:06
  • How to set specific gpu in tensorflow?: https://stackoverflow.com/questions/40069883/how-to-set-specific-gpu-in-tensorflow – BarzanHayati Mar 28 '22 at 19:11
  • 2
    This has been asked hundreds of times, the GPU is being used, but your model is tiny compared to the amount of computation of a GPU, so the utilization is between 0% and 1%, which gets rounded to 0%. This is why you cannot trust the utilization to decide if the GPU is being used. – Dr. Snoopy Mar 28 '22 at 21:14
  • Also note that training tiny models on GPU will not be faster to a CPU, due to additional CPU-GPU overheads. You don't need a GPU to train this model. – Dr. Snoopy Mar 28 '22 at 21:16
  • @Dr.Snoopy I made this simple model just to test if it's running on the GPU. I will be using deeper models. Thank you. – mira Mar 29 '22 at 12:32
  • When you use a complex deep model, you will see utilization increase accordingly. – Dr. Snoopy Mar 29 '22 at 12:35

0 Answers0