_EagerConst: Dst tensor is not initialized

Hello

I am running a simple image classification deep learning model using tensor flow.

For installation of tensor flow , I have followed the instructions as per the below link :-
Install TensorFlow with pip

But when I am trying to fit the model, its giving me following error :-

InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized.

My model summary is as shown below :-

Model: “sequential”


Layer (type) Output Shape Param #

dense (Dense) (None, 100) 15052900

dense_1 (Dense) (None, 1) 101

=================================================================
Total params: 15,053,001
Trainable params: 15,053,001
Non-trainable params: 0

Please note that when I am running the same model after hiding GPU from visible devices using below command , my model is training but training time is very high
tf.config.set_visible_devices([], ‘GPU’)

I am using windows 11 OS, and I have NVIDA GeForce GTX 1650 Ti GPU present on my laptop. RAM is 32 GB.

I have also tried to restrict the GPU memory to 1 GB using below commands :-

gpus = tf.config.experimental.list_physical_devices(‘GPU’)
if gpus:
# Restrict TensorFlow to only allocate 1GB of memory on the first GPU
try:
tf.config.experimental.set_virtual_device_configuration(gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
logical_gpus = tf.config.experimental.list_logical_devices(‘GPU’)
print(len(gpus), “Physical GPUs,”, len(logical_gpus), “Logical GPUs”)
except RuntimeError as e:
# Virtual devices must be set before GPUs have been initialized
print(e)

But still I am getting the same error while training the model

So I want to understand that what steps are required to resolve this error for GPU ?

Can you try reducing batch size? This error message is generated if the memory is not sufficient to manage the batch size.

Note: TensorFlow with GPU access is supported for WSL2 on Windows 10 19044 or higher. Please refer step by step instructions. Thank you!

Hello chunduriv

I have tried reducing the batch size to 2 but still I am getting the same error.

WSL is installed on my windows laptop. So hopefully it should not be a problem.

Have you tried to read one batch of data from the disk into the memory? If the issue continues try to increase RAM Size (Or) Use the CPU for data loading and pre-processing and train model on GPU. Thank you!

How can I do that can I have any reference for that process.

@Srinivas_Allanki,

You can use tf.device. For more details please refer to tf.device  |  TensorFlow v2.11.0

Thank you!

I am able to shift between GPU and CPU only once while I am running my code.