I am trying to use Sequential model from keras of tensorflow. When I am executing following statement:
model.fit(x_train, y_train, epochs=20, verbose=True, validation_data=(x_dev, y_dev), batch_size=10)
I am getting following errors:
I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
W tensorflow/core/platform/profile_utils/cpu_utils.cc:126] Failed to get CPU frequency: 0 Hz
F tensorflow/core/grappler/costs/op_level_cost_estimator.cc:710] Check failed: 0 < gflops (0 vs. 0)type: "CPU"
I am not able to understand how to fix it. Can anyone please help me.
From this issue on github, I understood that device.frequency() returned 0 probably because NominalCPUFrequency() returned 1. However, this information seems too abstract for me and I cannot understand.
Conclusion. Today you've successfully installed TensorFlow with GPU support on an M1 Pro MacBook. The above step-by-step guide should work on any Apple Silicon device, from Mac Mini to M1 Max.
*NOTE: TO USE KERAS YOU MUST FIRST INSTALL TENSORFLOW. Click here for How to Install TensorFlow on Mac. Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow.
Big Sur and M1 Macs do not run 32-bit apps or games. Apple dropped support for 32-bit applications in macOS Catalina and the last macOS to support them was Mojave. You can only install 64-bit apps on Big Sur and Catalina which for most people isn’t a problem as almost all major software is now 64-bit.
On Intel Macs you can then run an older 32 bit compatible version of macOS such as macOS Mojave or run Windows on your Mac (if the app or game you want to play also works on Windows of course). On M1 Macs you can’t install an older version of macOS but you can install an M1 ARM chip compatible version of Windows instead.
The latest Apple Silicon M1 chip Macs are also incompatible with 32-bit games or apps and if you’re trying to run 32-bit an M1 Mac, we recommend you skip to the section on 32 bit games and apps on M1 Macs.
Not only this, but Parallels works on M1 Macs and by allowing you to install Windows 10 on a Mac, it allows you to run 32 bit Windows games and apps on an M1 Mac. Parallels is now so well integrated with macOS that you can launch 32-bit apps from the Dock as if they were installed on your Mac natively.
First two ones are nothing to worry about.
The third one is a problem. You have installed an improper version of TensorFlow. Use one that supports the Mac M1 chip.
Run the following bash script to download and install TensorFlow.
#!/bin/bash
set -e
VERSION=0.1alpha3
INSTALLER_PACKAGE=tensorflow_macos-$VERSION.tar.gz
INSTALLER_PATH=https://github.com/apple/tensorflow_macos/releases/download/v$VERSION/$INSTALLER_PACKAGE
INSTALLER_SCRIPT=install_venv.sh
echo
# Check to make sure we're good to go.
if [[ $(uname) != Darwin ]] || [[ $(sw_vers -productName) != macOS ]] || [[ $(sw_vers -productVersion) != "11."* ]] ; then
echo "ERROR: TensorFlow with ML Compute acceleration is only available on macOS 11.0 and later."
exit 1
fi
# This
echo "Installation script for pre-release tensorflow_macos $VERSION. Please visit https://github.com/apple/tensorflow_macos "
echo "for instructions and license information."
echo
echo "This script will download tensorflow_macos $VERSION and needed binary dependencies, then install them into a new "
echo "or existing Python 3.8 virtual environment."
# Make sure the user knows what's going on.
read -p 'Continue [y/N]? '
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
exit 1
fi
echo
echo "Downloading installer."
tmp_dir=$(mktemp -d)
pushd $tmp_dir
curl -LO $INSTALLER_PATH
echo "Extracting installer."
tar xf $INSTALLER_PACKAGE
cd tensorflow_macos
function graceful_error () {
echo
echo "Error running installation script with default options. Please fix the above errors and proceed by running "
echo
echo " $PWD/$INSTALLER_SCRIPT --prompt"
echo
echo
exit 1
}
bash ./$INSTALLER_SCRIPT --prompt || graceful_error
popd
rm -rf $tmp_dir
ref: https://github.com/apple/tensorflow_macos
I've done as follows on macOS 11.4 (Even though the ref says "OS Requirements macOS 12.0+"), python==3.8.2 and worked [ref: https://developer.apple.com/metal/tensorflow-plugin/]:
Create a venv on x86 terminal, i.e. Rosetta Terminal (see: https://dev.to/courier/tips-and-tricks-to-setup-your-apple-m1-for-development-547g) i.e. Environment Setup: x86 : AMD Create venv: python3 -m venv ~/PATH/tensorflow-metal (Substitute PATH with your real PATH) Activate the venv: source ~/PATH/tensorflow-metal/bin/activate Update pip: python -m pip install -U pip
Install any library/package you need. For instance: For instance: pip install matplotlib jupyterlab
Install base tensorflow: python -m pip install tensorflow-macos
Install metal plugin: python -m pip install tensorflow-metal
Good Luck & Cheers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With