8

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.

xxx
  • 1,153
  • 1
  • 11
  • 23
Ankita
  • 159
  • 1
  • 3
  • 10

3 Answers3

5

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

Zabir Al Nazi
  • 10,298
  • 4
  • 33
  • 60
  • 1
    This differs somewhat from the script at https://github.com/apple/tensorflow_macos/blob/master/scripts/download_and_install.sh , which may be more correct ! – ti7 May 04 '21 at 06:10
  • @zabir can you please direct me where to look for the explanation of W, I, F? – Ankita May 04 '21 at 14:08
  • I am getting errors about following packages not having compatible versions: grpcio, numpy, protobuf, tensorflow-estimator. should I be worried? Should I uninstall the currently installed versions and install exact versions? Although, my ipynb file runs perfectly as of now. – Ankita May 04 '21 at 14:50
  • 3
    I ran this and got "ERROR: TensorFlow with ML Compute acceleration is only available on macOS 11.0 and later." but I am using Monterey 12.0.1 – Shep Bryan Nov 15 '21 at 22:53
  • @ShepBryan I have the same error. have you found the answer? – Irfan Yaqub Dec 06 '21 at 10:50
  • @MR.Robot Yes, evidently you cannot use your system python and you are forced to use miniconda. I was trying to avoid that, but in the end I decided to just do the easiest thing. I followed this tutorial and got it to work: https://www.youtube.com/watch?v=_CO-ND1FTOU – Shep Bryan Dec 07 '21 at 15:02
  • You should use the steps on developer.apple.com/metal/tensorflow-plugin, not on GitHub. Then it is working on macOS 12 Monterey – Howard Dec 25 '21 at 10:16
  • Trying all of the above on a Mac M1 with Monterey but nothing works. The apple channel does not have a tensorflow-deps, nor a tensorflow-macos package anymore. – Robert Alexander Jan 12 '22 at 13:13
  • I use Anaconda and installing it as `conda create -n name tensorflow` (as this video suggest: https://www.youtube.com/watch?v=tGkZ9EARwzk) worked for me. Note that the new environment is with Python 3.7.11 and tf version will be 2.0.0. – solopiu Jan 20 '22 at 15:58
  • I'd appreciate an explanation of the first two, just to understand what's happening – Rafs Aug 11 '22 at 14:40
2

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/]:

  1. 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

  2. Install any library/package you need. For instance: For instance: pip install matplotlib jupyterlab

  3. Install base tensorflow: python -m pip install tensorflow-macos

  4. Install metal plugin: python -m pip install tensorflow-metal

Good Luck & Cheers!

xxx
  • 1,153
  • 1
  • 11
  • 23
0

This might not help at all, but since I was running into the same problem I managed to get the model to train without the solutions provided here (that I will soon try), simply by changing my Y_test (0s and 1s) like this when making the train_test_split: (to_categorical(label). So:

X_train, X_test, Y_train, Y_test = train_test_split(
    dataset,
    to_categorical(label),
    test_size=.2,
    random_state=42
)

Then, when training the model, I get the following message - that I do not understand fully:

2022-04-03 23:10:08.941296: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112] Plugin optimizer for device_type GPU is enabled.

So, this is not really a solution, but more a temporary workaround - or it might give insight in where it goes wrong.

xxx
  • 1,153
  • 1
  • 11
  • 23
pottele
  • 13
  • 3