'migrating keras + tensorflow cpu to tensorflow-gpu keras modelling

I'm a beginner of data-science and by now, I'm trying to migrate old code keras cpu modelling to gpu-tensorflow.

fyi: I'm following instruction on prof.jeffheaton videos: https://www.youtube.com/watch?v=qrkEYf-YDyI | [2020, TensorFlow 2.0 GPU (CUDA), Keras, & Python 3.7 in Windows 10] and install environment as noticed here: https://github.com/jeffheaton/t81_558_deep_learning/blob/master/tensorflow-gpu.yml

and from nvidia, i had installed: ms.visual code 2019

  • cuda_11.5.1_496.13_windows -- include driver.exe
  • cudnn-windows-x86_64-8.3.1.22_cuda11.5-archive.zip

and as result on phyton: import tensorflow as tf
i got result:
2021-12-04 18:02:41.467262: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll

and for: tf.config.list_physical_devices('GPU')
it result:
2021-12-04 18:02:41.467262: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-12-04 18:04:50.986777: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1555] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: NVIDIA GeForce 920MX computeCapability: 5.0 coreClock: 0.993GHz coreCount: 2 deviceMemorySize: 2.00GiB deviceMemoryBandwidth: 13.41GiB/s
2021-12-04 18:04:50.986857: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-12-04 18:04:50.986900: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-12-04 18:04:50.986939: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-12-04 18:04:50.986978: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-12-04 18:04:50.987016: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-12-04 18:04:50.987054: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-12-04 18:04:50.987093: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-12-04 18:04:50.987155: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1697] Adding visible gpu devices: 0
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]


and here the cpu modeling code:

from keras.models import Sequential
from keras.layers import Dense, LSTM
###CPU Build from
import math
from keras.models import Sequential
from keras.layers import Dense, Activation, Conv1D ,MaxPooling1D, Dropout
from keras.layers.recurrent import LSTM
from keras.utils.vis_utils import plot_model
from keras.metrics import RootMeanSquaredError as rmse
from keras import optimizers

and it still run normal for cpu code line:

model = Sequential()
model.add(Conv1D(filters=256, kernel_size=2, activation='relu',padding = 'same',input_shape=(120,1)))
model.add(MaxPooling1D(pool_size=2))
model.add(LSTM(100, return_sequences = True))
model.add(Dropout(0.3))
model.add(LSTM(100, return_sequences = False))
model.add(Dropout(0.3))
model.add(Dense(units=1, activation = 'sigmoid'))
model.compile(optimizer='adam', loss= 'mse' , metrics = [rmse()])

migrate to tensorflow gpu keras

from tensorflow import keras ##GPU
from tensorflow.keras import layers ##GPU
from tensorflow.keras import Sequential ##GPU
from tensorflow.keras.layers import Dense, LSTM
import math
# from tensorflow import keras ##GPU
# from tensorflow.keras import layers ##GPU
# from tensorflow.keras.layers import Dense, LSTM

from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Activation, Conv1D ,MaxPooling1D, Dropout,LSTM
# from tensorflow.keras.layers import LSTM
from tensorflow.keras.utils import plot_model
from tensorflow.keras.metrics import RootMeanSquaredError as rmse
from tensorflow.keras import optimizers
# define model for GPU
model = Sequential()
model.add(Conv1D(filters=256, kernel_size=2, activation='relu',padding = 'same',input_shape=(120,1)))
model.add(MaxPooling1D(pool_size=2))
model.add(LSTM(100, return_sequences = True)) ##bermasalah
model.add(Dropout(0.3))
model.add(LSTM(100, return_sequences = False)) ##bermasalah
model.add(Dropout(0.3))
model.add(Dense(units=1, activation = 'sigmoid'))  ##aselinya
# model.add(tf.keras.layers.Dense(8, input_shape=(16,))) ##versipanjang

model.compile(optimizer='adam', loss= 'mse' , metrics = [rmse()])

and as far as i know., this line is make me stucked: model.add(LSTM(100, return_sequences = True))

and model.add(LSTM(100, return_sequences = False))

i've also already try to read lstm on tensorflow.. somebody please help me.. :)



Solution 1:[1]

2021-12-04 18:02:41.467262: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll

The above mentioned codes starts from I are just (I)information messages and are not errors.

you can surpass (I)informational messages and (W)warnings by using the code below:

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

I also replicated the above mentioned code in both CPU and GPU runtime mode in Google colab using TF 2.7, 2.8, which does not show any error.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer2