Problem in running training code 'tensorflow-metal' on M1

Dear Developers,

I am a newbie on the TensorFlow business. I have however managed to install TensorFlow (macOS and metal) on M1 MacBook Air as detailed in this website (https://developer.apple.com/metal/tensorflow-plugin/)

However, when I try to run an example code (https://github.com/keras-team/keras-io/blob/master/examples/vision/mnist_convnet.py), I got issues that I cannot understand

`2021-08-01 00:28:43.807922: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)

2021-08-01 00:28:43.808097: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz

Epoch 1/15

2021-08-01 00:28:43.911127: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112] Plugin optimizer for device_type GPU is enabled.

2021-08-01 00:28:43.984 python[20105:3940931] -[MPSNDArrayIdentity encodeToCommandEncoder:commandBuffer:sourceArrays:resultState:destinationArray:kernelDAGObject:]: unrecognized selector sent to instance 0x1682e8560

2021-08-01 00:28:43.987 python[20105:3940931] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MPSNDArrayIdentity encodeToCommandEncoder:commandBuffer:sourceArrays:resultState:destinationArray:kernelDAGObject:]: unrecognized selector sent to instance 0x1682e8560'

*** First throw call stack:

(

0   CoreFoundation                      0x0000000180de2320 __exceptionPreprocess + 240

1   libobjc.A.dylib                     0x0000000180b10c04 objc_exception_throw + 60

2   CoreFoundation                      0x0000000180e71020 -[NSObject(NSObject) __retain_OA] + 0

3   CoreFoundation                      0x0000000180d44184 ___forwarding___ + 1444

4   CoreFoundation                      0x0000000180d43b30 _CF_forwarding_prep_0 + 96

5   libmetal_plugin.dylib               0x0000000150a55db4 ___ZN12metal_plugin14MPSApplyAdamOpIfE7ComputeEPNS_15OpKernelContextE_block_invoke.115 + 92

6   libdispatch.dylib                   0x0000000180abd420 _dispatch_client_callout + 20

7   libdispatch.dylib                   0x0000000180acba98 _dispatch_lane_barrier_sync_invoke_and_complete + 60

8   libmetal_plugin.dylib               0x0000000150a533c0 _ZN12metal_plugin14MPSApplyAdamOpIfE7ComputeEPNS_15OpKernelContextE + 4884

9   libmetal_plugin.dylib               0x0000000150a51e78 _ZN12metal_pluginL15ComputeOpKernelINS_14MPSApplyAdamOpIfEEEEvPvP18TF_OpKernelContext + 44

10  _pywrap_tensorflow_internal.so      0x0000000130076460 _ZN10tensorflow15PluggableDevice7ComputeEPNS_8OpKernelEPNS_15OpKernelContextE + 148

11  libtensorflow_framework.2.dylib     0x0000000123a78664 _ZN10tensorflow12_GLOBAL__N_113ExecutorStateINS_15PropagatorStateEE7ProcessENS2_10TaggedNodeEx + 3080

12  libtensorflow_framework.2.dylib     0x0000000123a79dbc _ZNSt3__110__function6__funcIZN10tensorflow12_GLOBAL__N_113ExecutorStateINS2_15PropagatorStateEE7RunTaskIZNS6_13ScheduleReadyEPN4absl14lts_2020_09_2313InlinedVectorINS5_10TaggedNodeELm8ENS_9allocatorISB_EEEEPNS5_20TaggedNodeReadyQueueEEUlvE0_EEvOT_EUlvE_NSC_ISL_EEFvvEEclEv + 56

13  _pywrap_tensorflow_internal.so      0x00000001307aa230 _ZN5Eigen15ThreadPoolTemplIN10tensorflow6thread16EigenEnvironmentEE10WorkerLoopEi + 1508

14  _pywrap_tensorflow_internal.so      0x00000001307a9b28 _ZZN10tensorflow6thread16EigenEnvironment12CreateThreadENSt3__18functionIFvvEEEENKUlvE_clEv + 80

15  libtensorflow_framework.2.dylib     0x0000000124014b08 _ZN10tensorflow12_GLOBAL__N_17PThread8ThreadFnEPv + 120

16  libsystem_pthread.dylib             0x0000000180c6a06c _pthread_start + 320

17  libsystem_pthread.dylib             0x0000000180c64da0 thread_start + 8

)

libc++abi.dylib: terminating with uncaught exception of type NSException`

Do you have an idea what could be the reason? I would like also to benefit from GPU acceleration. I am running on macOS Big Sur 11.2.3.

Many thanks, All the best

It is recommended to install macOS 12.0 beta to use TensorFlow Metal Plugin. That should correct this problem.

As mentioned in the official Apple docs,

OS Requirements : macOS 12.0+

You can watch more in the WWDC 2021 session here : https://developer.apple.com/videos/play/wwdc2021/10152/

Same to my error, cannot fix it until now.

Problem in running training code 'tensorflow-metal' on M1
 
 
Q