This pre-release delivers hardware-accelerated TensorFlow and TensorFlow Addons for macOS 11.0+. Native hardware acceleration is supported on Macs with M1 and Intel-based Macs through Apple’s ML Compute framework.
An archive containing Python packages and an installation script can be downloaded from the releases.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"
This will verify your system, ask you for confirmation, then create a virtual environment (https://docs.python.org/3.8/tutorial/venv.html) with TensorFlow for macOS installed.
For Macs with M1, the following packages are currently unavailable:
Please submit feature requests or report issues via GitHub Issues.
It is not necessary to make any changes to your existing TensorFlow scripts to use ML Compute as a backend for TensorFlow and TensorFlow Addons.
There is an optional
mlcompute.set_mlc_device(device_name=’any') API for ML Compute device selection. The default value for
'any’, which means ML Compute will select the best available device on your system, including multiple GPUs on multi-GPU configurations. Other available options are
‘gpu’. Please note that in eager mode, ML Compute will use the CPU. For example, to choose the CPU device, you may do the following:
``` # Import mlcompute module to use the optional set_mlc_device API for device selection with ML Compute. from tensorflow.python.compiler.mlcompute import mlcompute
# Select CPU device. mlcompute.set_mlc_device(device_name=‘cpu’) # Available options are 'cpu', 'gpu', and ‘any'. ```
Logging provides more information about what happens when a TensorFlow model is optimized by ML Compute. Turn logging on by setting the environment variable
TF_MLC_LOGGING=1 when executing the model script. The following is the list of information that is logged in graph mode:
Unlike graph mode, logging in eager mode is controlled by
TF_CPP_MIN_VLOG_LEVEL. The following is the list of information that is logged in eager mode:
MLCInferencegraph. This key is used to retrieve the graph and run a backward pass or an optimizer update.
MLCSubgraphOp, can execute concurrently. As a result, there may be overlapping logging information. To avoid this during the debugging process, set TensorFlow to execute operators sequentially by setting the number of threads to 1 (see
size_tand search for it in log entries with the pattern
MemoryLogTensorAllocation ... true ptr: <(size_t)ptr>. You may also need to modify the
OpKernelContext::input()to print out the input pointer so that you can see the entire use-def chain in the log.
TF_DISABLE_MLC_EAGER=“;Op1;Op2;...”. The gradient op may also need to be disabled by modifying the file
$PYTHONHOME/site-packages/tensorflow/python/ops/_grad.py(this avoids TensorFlow recompilation).