Hi everyone, to round back on this, I was able to run TF 2.18 with Metal 1.2.0 successfully on M3.
Post
Replies
Boosts
Views
Activity
Try following the instructions here - https://github.com/ianlokh/TensorFlow-macos
Try to install as per instructions here - https://github.com/ianlokh/TensorFlow-macos
Hi
I tried to upload the sample script but somehow wasn't able to. I am copying and pasting the sample script here
import os
import tensorflow as tf
import tensorflow_datasets as tfds
BATCH_SIZE = 256
EPOCHS = 100
AUTOTUNE = tf.data.AUTOTUNE
def set_gpu(gpu_ids_list):
gpus = tf.config.list_physical_devices('GPU')
if gpus:
try:
gpus_used = [gpus[i] for i in gpu_ids_list]
tf.config.set_visible_devices(gpus_used, 'GPU')
for gpu in gpus_used:
tf.config.experimental.set_memory_growth(gpu, True)
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPU")
except RuntimeError as e:
# Visible devices must be set before GPUs have been initialized
print(e)
set_gpu([0])
# load MNIST
print('\ndownloading mnist')
(ds_train, ds_test), ds_info = tfds.load(
'mnist',
split=['train', 'test'],
shuffle_files=True,
as_supervised=True,
with_info=True,
)
def normalize_img(image, label):
"""Normalize images: 'unit8' -> 'float32'."""
return tf.cast(image, tf.float32) / 255., label
ds_train = ds_train.map(normalize_img, num_parallel_calls=AUTOTUNE)
ds_train = ds_train.cache()
ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples)
ds_train = ds_train.batch(BATCH_SIZE, num_parallel_calls=AUTOTUNE)
ds_train = ds_train.prefetch(AUTOTUNE)
ds_test = ds_test.map(normalize_img, num_parallel_calls=AUTOTUNE)
ds_test = ds_test.cache()
ds_test = ds_test.batch(BATCH_SIZE, num_parallel_calls=AUTOTUNE)
print('\ncreate and compile model')
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(16, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Conv2D(32, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Conv2D(64, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10)
])
model.compile(
optimizer=tf.keras.optimizers.legacy.Adam(learning_rate=0.001),
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy']
)
model.fit(ds_train, epochs=EPOCHS, validation_data=ds_test, verbose=1)
Hi,
Thanks for the reply. I am using Ventura 13.1. Please find the code snippet here.
model.compile(
optimizer=tf.keras.optimizers.legacy.Adam(learning_rate=0.001),
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy']
)