在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):mrdbourke/m1-machine-learning-test开源软件地址(OpenSource Url):https://github.com/mrdbourke/m1-machine-learning-test开源编程语言(OpenSource Language):Jupyter Notebook 99.8%开源软件介绍(OpenSource Introduction):M1, M1 Pro, M1 Max Machine Learning Speed Test ComparisonThis repo contains some sample code to benchmark the new M1 MacBooks (M1 Pro and M1 Max) against various other pieces of hardware. It also has steps below to setup your M1, M1 Pro, M1 Max, M1 Ultra or M2 Mac to run the code. Who is this repo for?You: have a new M1, M1 Pro, M1 Max, M1 Ultra or M2 Mac and would like to get started doing machine learning and data science on it. This repo: teaches you how to install the most common machine learning and data science packages (software) on your machine and make sure they run using sample code. Machine Learning Experiments ConductedAll experiments were run with the same code. For Apple devices, TensorFlow environments were created with the steps below.
ResultsSee the results directory. Steps (how to test your Apple Silicon machine)
How to setup a TensorFlow environment on M1, M1 Pro, M1 Max, M1 Ultra, M2 using Miniforge (shorter version)If you're experienced with making environments and using the command line, follow this version. If not, see the longer version below.
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
mkdir tensorflow-test
cd tensorflow-test
conda create --prefix ./env python=3.8
conda activate ./env
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
python -m pip install tensorflow-datasets
conda install jupyter pandas numpy matplotlib scikit-learn
jupyter notebook
import numpy as np
import pandas as pd
import sklearn
import tensorflow as tf
import matplotlib.pyplot as plt
# Check for TensorFlow GPU access
print(f"TensorFlow has access to the following devices:\n{tf.config.list_physical_devices()}")
# See TensorFlow version
print(f"TensorFlow version: {tf.__version__}") If it all worked, you should see something like: TensorFlow has access to the following devices:
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
TensorFlow version: 2.8.0 How to setup a TensorFlow environment on M1, M1 Pro, M1 Max, M1 Ultra, M2 using Miniforge (longer version)If you're new to creating environments, using a new M1, M1 Pro, M1 Max machine and would like to get started running TensorFlow and other data science libraries, follow the below steps.
Installing package managers (Homebrew and Miniforge)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" It will explain what it's doing and what you need to do as you go.
If you're using an M1 variant Mac, it's "Miniforge3-MacOSX-arm64" <- click for direct download. Clicking the link above will download a shell file called
To do so, we'll run the command We'll then execute (run) the program using chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
To check this, we can try to activate the source ~/miniforge3/bin/activate If it worked, you should see something like the following in your terminal window. (base) daniel@Daniels-MBP ~ %
Creating a TensorFlow environmentNow we've got the package managers we need, it's time to install TensorFlow. Let's setup a folder called
We can do so with the mkdir tensorflow-test
We can do this with the cd tensorflow-test
We do so using For example, if I didn't use the conda create --prefix ./env
Short version: conda activate ./env Long version: conda activate /Users/daniel/tensorflow-test/env
If activating your environment went correctly, your terminal window prompt should look something like: (/Users/daniel/tensorflow-test/env) daniel@Daniels-MBP tensorflow-test %
Let's start by installing various TensorFlow dependencies (TensorFlow is a large piece of software and depends on many other pieces of software). Rather than list these all out, Apple have setup a quick command so you can install almost everything TensorFlow needs in one line. conda install -c apple tensorflow-deps The above stands for "hey conda install all of the TensorFlow dependencies from the Apple Conda channel" ( If it worked, you should see a bunch of stuff being downloaded and installed for you.
Apple have created a fork (copy) of TensorFlow specifically for Apple Macs. It has all the features of TensorFlow with some extra functionality to make it work on Apple hardware. This Apple fork of TensorFlow is called python -m pip install tensorflow-macos Depending on your internet connection the above may take a few minutes since TensorFlow is quite a large piece of software.
Why? Machine learning models often benefit from GPU acceleration. And the M1, M1 Pro and M1 Max chips have quite powerful GPUs. TensorFlow allows for automatic GPU acceleration if the right software is installed. And Metal is Apple's framework for GPU computing. So Apple have created a plugin for TensorFlow (also referred to as a TensorFlow PluggableDevice) called We can install it using: python -m pip install tensorflow-metal If the above works, we should now be able to leverage our Mac's GPU cores to speed up model training with TensorFlow.
TensorFlow Datasets provides a collection of common machine learning datasets to test out various machine learning code. python -m pip install tensorflow-datasets
To install those in the current environment run: conda install jupyter pandas numpy matplotlib scikit-learn
# Start a Jupyter notebook
jupyter notebook Once the notebook is started, in the first cell: import numpy as np
import pandas as pd
import sklearn
import tensorflow as tf
import matplotlib.pyplot as plt
# Check for TensorFlow GPU access
print(tf.config.list_physical_devices())
# See TensorFlow version
print(tf.__version__) If it all worked, you should see something like: TensorFlow has access to the following devices:
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
TensorFlow version: 2.5.0
And then compare your results to the benchmarks above. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论