microsoft / tensorflow-directml-plugin

DirectML PluggableDevice plugin for TensorFlow 2
Apache License 2.0
179 stars 23 forks source link

use AMD gpu with tensorflow 2.10 but no output with a simple CNN script #296

Closed thinksmert closed 1 year ago

thinksmert commented 1 year ago

my environment: windows 10 64bit python 3.9 64bit tensorflow 2.10 tensorflow-directml-plugin 0.0.1.dev220621 AMD Radeon RX 640 miniConda CP39-4.12

I build the environment with above software and hardware.And I write a simple CNN script and tried to run it hoping using GPU.Actually it found the GPU and load successfully,but output some warnings and no result shown. Follow is my script which I run: import tensorflow as tf import tensorflow.keras as keras from keras import layers, optimizers, datasets, Sequential import os

os.environ['TF_CPP_MIN_LOG_LEVEL']='2' tf.random.set_seed(2345)

conv_layers = [ layers.Conv2D(64, kernel_size=[3, 3], padding='same', activation=tf.nn.relu), layers.Conv2D(64, kernel_size=[3, 3], padding='same', activation=tf.nn.relu), layers.MaxPool2D(pool_size=[2, 2], strides=2, padding='same'),

layers.Conv2D(128, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.Conv2D(128, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.MaxPool2D(pool_size=[2, 2], strides=2, padding='same'),

layers.Conv2D(256, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.Conv2D(256, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.MaxPool2D(pool_size=[2, 2], strides=2, padding='same'),

layers.Conv2D(512, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.Conv2D(512, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.MaxPool2D(pool_size=[2, 2], strides=2, padding='same'),

layers.Conv2D(512, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.Conv2D(512, kernel_size=[3, 3], padding='same', activation=tf.nn.relu),
layers.MaxPool2D(pool_size=[2, 2], strides=2, padding='same'),    

]

def main(): conv_net = Sequential(conv_layers) conv_net.build(input_shape=[None, 32, 32, 3]) x = tf.random.normal([4, 32, 32, 3]) out = conv_net(x) print(out.shape)

if name == 'main': main()

These are the outputs: python .\Vgg13.py 2022-09-29 15:51:26.582547: I tensorflow/c/logging.cc:34] Successfully opened dynamic library D:\Miniconda3\envs\tfdml_plugin\lib\site-packages\tensorflow-plugins/directml/directml.0de2b4431c6572ee74152a7ee0cd3fb1534e4a95.dll 2022-09-29 15:51:26.583060: I tensorflow/c/logging.cc:34] Successfully opened dynamic library dxgi.dll 2022-09-29 15:51:26.585193: I tensorflow/c/logging.cc:34] Successfully opened dynamic library d3d12.dll 2022-09-29 15:51:26.711875: I tensorflow/c/logging.cc:34] DirectML device enumeration: found 1 compatible adapters. 2022-09-29 15:51:27.050898: I tensorflow/core/platform/cpu_feature_guard.cc:193] 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-09-29 15:51:27.051802: I tensorflow/c/logging.cc:34] DirectML: creating device on adapter 0 (AMD Radeon RX 640) 2022-09-29 15:51:27.119403: I tensorflow/c/logging.cc:34] Successfully opened dynamic library Kernel32.dll 2022-09-29 15:51:27.120322: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2022-09-29 15:51:27.120383: W tensorflow/core/common_runtime/pluggable_device/pluggable_device_bfc_allocator.cc:28] Overriding allow_growth setting because force_memory_growth was requested by the device. 2022-09-29 15:51:27.120442: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3164 MB memory) -> physical PluggableDevice (device: 0, name: DML, pci bus id: )

After I uninstall the tensorflow-directml-plugin and use CPU to run this script,it shows the right result: python .\Vgg13.py (4, 1, 1, 512)

Is this a bug with the pluging?How can I make it to work correct?Please help! Thank you

PatriceVignola commented 1 year ago

Hi @thinksmert,

We just released version 0.1.0.dev220928 which should fix this problem.

thinksmert commented 1 year ago

@PatriceVignola Ok,I will try it.Thank you

thinksmert commented 1 year ago

@PatriceVignola Hi, I have tried and it works right now.Thank you.