Getting ModuleNotFoundError: No module named 'tensorflow.python.compiler.mlcompute' error

I'm trying to run Tensorflow 2.7 on Macbook M1 air, but I 'm getting error:

ModuleNotFoundError: No module named 'tensorflow.python.compiler.mlcompute'

My code is:

import tensorflow as tf from tensorflow.python.compiler.mlcompute import mlcompute

tf.compat.v1.disable_eager_execution() mlcompute.set_mlc_device(device_name='gpu') print("is_apple_mlc_enabled %s" % mlcompute.is_apple_mlc_enabled()) print("is_tf_compiled_with_apple_mlc %s" % mlcompute.is_tf_compiled_with_apple_mlc()) print(f"eagerly? {tf.executing_eagerly()}") print(tf.config.list_logical_devices())

I want to train my model using GPU, please help so that I can see whether my model is using GPU to train itself or not.

Thanks & Regards, Sushant

reformatting your code :

import tensorflow as tf 
from tensorflow.python.compiler.mlcompute import mlcompute

tf.compat.v1.disable_eager_execution() 
mlcompute.set_mlc_device(device_name='gpu') 
print("is_apple_mlc_enabled %s" % mlcompute.is_apple_mlc_enabled()) 
print("is_tf_compiled_with_apple_mlc %s" % mlcompute.is_tf_compiled_with_apple_mlc()) 
print(f"eagerly? {tf.executing_eagerly()}") 
print(tf.config.list_logical_devices())

it look like some seriously old code, just do this instead

import tensorflow as tf
print(tf.__version__)
physical_devices = tf.config.list_physical_devices('GPU')
tf.print(physical_devices)

ex :

2.7.0
Metal device set to: Apple M1

systemMemory: 8.00 GB
maxCacheSize: 2.67 GB

2021-12-20 23:11:09.001976: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2021-12-20 23:11:09.002466: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]


Getting ModuleNotFoundError: No module named 'tensorflow.python.compiler.mlcompute' error
 
 
Q