Apple Silicon Mac机器学习性能测试工具
mac-ml-speed-test是一个专为Apple Silicon Mac设计的机器学习性能测试项目。通过简单脚本对比不同Mac设备上的机器学习模型速度,涵盖计算机视觉和自然语言处理等领域。项目使用PyTorch、TensorFlow等主流框架,并提供详细配置指南,便于用户进行性能评估。测试内容包括图像分类、文本分类和LLM文本生成等任务,使用CIFAR100、Food101和IMDB等数据集。此外,项目还包括与NVIDIA TITAN RTX和Google Colab免费版的性能对比,为用户提供更全面的参考数据。
A collection of simple scripts focused on benchmarking the speed of various machine learning models on Apple Silicon Macs (M1, M2, M3).
Scripts should also ideally work with CUDA (for benchmarking on other machines/Google Colab).
Note: Scripts are not designed to achieved state-of-the-art results (e.g. accuracy), they are designed to be as simple as possible to run out of the box. Most are examples straight from PyTorch/TensorFlow docs I've tweaked for specific focus on MPS (Metal Performance Shaders - Apple's GPU acceleration framework) devices + simple logging of timing. They are scrappy and likely not the best way to do things, but they are simple and easy to run.
The focus of these experiments is to get a quick benchmark across various ML problems and see how the Apple Silicon Macs perform.
The focus is on hardware comparison rather than framework to framework comparison and measuring speed rather than accuracy.
This repo contains code/results for the following experiments:
While the focus is on Apple Silicon Macs, I've included my own deep learning PC (NVIDIA TITAN RTX) as well as a Google Colab free tier instance for comparison.
If you have a brand new machine, you'll need to setup a few things before running the experiments.
The following steps will get you ready to go for all experiments (and many future machine learning experiments).
However, if you've already got conda
, feel free to skip to the next section.
xcode-select --install
in terminal and skip to next step)Go to https://brew.sh/ and follow the main instructions on the front page.
Run the commands on the homebrew webpage in the terminal and follow the instructions when they appear.
brew install miniforge
or
Download Miniforge3 for macOS ARM64 from: https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh
~/Downloads
folder:chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
If conda is working, you should have a (base)
at the start of your terminal prompt.
For example: (base) daniel@Daniels-MacBook-Pro-3 ~ %
git clone https://github.com/mrdbourke/mac-ml-speed-test.git
cd mac-ml-speed-test
conda create --prefix ./env python=3.10
Note: You could also use conda create --name some-env-name python=3.10
but I prefer --prefix
as it's more explicit.
conda env list
conda activate ./env
Note: This may have a few extra packages that aren't 100% needed for speed tests but help to have (e.g. JupyterLab, PrettyTable).
conda install -c conda-forge pip pandas numpy matplotlib scikit-learn jupyterlab langchain prettytable py-cpuinfo tqdm
conda install pytorch::pytorch torchvision -c pytorch
Note: MPS (Metal Performance Shaders, aka using the GPU on Apple Silicon) comes standard with PyTorch on macOS, you don't need to install anything extra. MPS can be accessed via
torch.mps
, see more notes in the PyTorch documentation.
Experiment details:
Model | Dataset | Image Size | Epochs | Num Samples | Num Classes | Problem Type |
---|---|---|---|---|---|---|
ResNet50 | CIFAR100 | 32x32x3 | 5 | 50,000 train, 10,000 test | 100 | Image Classification |
Example usage of pytorch_test_computer_vision_cifar100.py
for 1 epoch and batch size of 32:
python pytorch_test_computer_vision_cifar100.py --epochs=1 --batch_sizes="32"
Batch sizes can be a comma-separated list of batch sizes, e.g. "32, 64, 128, 256"
.
Default behaviour is to test for 5
epochs and batch sizes of "16, 32, 64, 128, 256, 512, 1024"
.
The following:
python pytorch_test_computer_vision_cifar100.py
Is equivalent to:
python pytorch_test_computer_vision_cifar100.py --epochs=5 --batch_sizes="16, 32, 64, 128, 256, 512, 1024"
Results will be saved to results/results_pytorch_cv/[file_name].csv
where file_name
is a combination of information from the experiment (see pytorch_test_computer_vision_cifar100.py
for details).
Experiment details:
Model | Dataset | Image Size | Epochs | Num Samples | Num Classes | Problem Type |
---|---|---|---|---|---|---|
ResNet50 | Food101 | 224x224x3 | 5 | 75,750 train, 25,250 test | 101 | Image Classification |
Note: Download Hugging Face Datasets to download Food101 dataset.
python -m pip install datasets
Example usage of pytorch_test_computer_vision_food101.py
for 1 epoch and batch size of 32:
python pytorch_test_computer_vision_food101.py --epochs=1 --batch_sizes="32"
Batch sizes can be a comma-separated list of batch sizes, e.g. "32, 64, 128, 256"
.
Default behaviour is to test for 3
epochs and batch sizes of "32, 64, 128"
.
The following:
python pytorch_test_computer_vision_food101.py
Is equivalent to:
python pytorch_test_computer_vision_food101.py --epochs=3 --batch_sizes="32, 64, 128"
Results will be saved to results/results_pytorch_cv/[file_name].csv
where file_name
is a combination of information from the experiment (see pytorch_test_computer_vision_food101.py
for details).
Experiment details:
Model | Dataset | Sequence Size | Epochs | Num Samples | Num Classes | Problem Type |
---|---|---|---|---|---|---|
DistilBERT (fine-tune top 2 layers + top Transformer block) | IMDB | 512 | 5 | 25,000 train, 25,000 test | 2 | Text Classification |
Note: The
pytorch_test_nlp.py
uses Hugging Face Transformers/Datasets/Evaluate/Accelerate to help with testing. If you get into ML, you'll likely come across these libraries, they are very useful for NLP and ML in general. The model loaded from Transformers uses PyTorch as a backend.
python -m pip install transformers datasets evaluate accelerate
Example usage of pytorch_test_nlp.py
for 1 epoch and batch size of 32:
python pytorch_test_nlp.py --epochs=1 --batch_sizes="32"
Batch sizes can be a comma-separated list of batch sizes, e.g. "32, 64, 128, 256"
.
Default behaviour is to test for 3
epochs and batch sizes of "16, 32, 64, 128, 256, 512"
(note: without 24GB+ of RAM, running batch sizes of 256+ will likely error, for example my M1 Pro with 18GB of VRAM can only run "16, 32, 64, 128"
and fails on 256
with the model/data setup in python_test_nlp.py
).
The following:
python pytorch_test_nlp.py
Is equivalent to:
python pytorch_test_nlp.py --epochs=3 --batch_sizes="16, 32, 64, 128, 256, 512"
Results will be saved to results/results_pytorch_nlp/[file_name].csv
where file_name
is a combination of information from the experiment (see pytorch_test_nlp.py
for details).
For more on running TensorFlow on macOS, see Apple's developer guide.
Note: Install TensorFlow Datasets to access Food101 dataset with TensorFlow.
python -m pip install tensorflow python -m pip install tensorflow-metal python -m pip install tensorflow_datasets
Note: TensorFlow can be run on macOS without using the GPU via
pip install tensorflow
, however, if you're using an Apple Silicon Mac, you'll want to use the Metal plugin for GPU acceleration (pip install tensorflow-metal
).After installing
tensorflow-metal
and running the scripts, you should see something like:
2023-12-06 12:22:02.016745: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:117] Plugin optimizer for device_type GPU is enabled.
Experiment details:
Model | Dataset | Image Size | Epochs | Num Samples | Num Classes | Problem Type |
---|---|---|---|---|---|---|
ResNet50 | CIFAR100 | 32x32x3 | 5 | 50,000 train, 10,000 test | 100 | Image Classification |
Example usage of tensorflow_test_computer_vision_cifar100.py
for 1 epoch and batch size of 32:
python tensorflow_test_computer_vision_cifar100.py --epochs=1 --batch_sizes="32"
Batch sizes can be a comma-separated list of batch sizes, e.g. "32, 64, 128, 256"
.
Default behaviour is to test for 5
epochs and batch sizes of "16, 32, 64, 128, 256, 512, 1024"
.
The following:
python tensorflow_test_computer_vision_cifar100.py
Is equivalent to:
python tensorflow_test_computer_vision_cifar100.py --epochs=5 --batch_sizes="16, 32, 64, 128, 256, 512, 1024"
Results will be saved to results/results_tensorflow_cv/[file_name].csv
where file_name
is a combination of information from the experiment (see tensorflow_test_computer_vision_cifar100.py
for details).
Experiment details:
Model | Dataset | Image Size | Epochs | Num Samples | Num Classes | Problem Type |
---|---|---|---|---|---|---|
ResNet50 | Food101 | 224x224x3 | 5 | 75,750 train, 25,250 test | 101 | Image Classification |
Example usage of tensorflow_test_computer_vision_food101.py
for 1 epoch and batch size of 32:
python tensorflow_test_computer_vision_food101.py --epochs=1 --batch_sizes="32"
Batch sizes can be a comma-separated list of batch sizes, e.g. "32, 64, 128"
.
Default behaviour is to test for 3
epochs and batch sizes of "32, 64, 128"
.
The following:
python tensorflow_test_computer_vision_food101.py
Is equivalent to:
python tensorflow_test_computer_vision_food101.py --epochs=3 --batch_sizes="32, 64, 128"
Results will be saved to results/results_tensorflow_cv/[file_name].csv
where file_name
is a combination of information from the experiment (see tensorflow_test_computer_vision_food101.py
for details).
Experiment details:
Model | Dataset | Sequence Size | Epochs | Num Samples | Num Classes | Problem Type |
---|---|---|---|---|---|---|
SmallTransformer (custom) | IMDB | 200 | 5 | 25,000 train, 25,000 test | 2 | Text Classification |
Example usage of tensorflow_test_nlp.py
for 1 epoch and batch size of 32:
python tensorflow_test_nlp.py --epochs=1 --batch_sizes="32"
Batch sizes can be a comma-separated list of batch sizes, e.g. "32, 64, 128, 256"
.
Default behaviour is to test for 3
epochs and batch sizes of "16, 32, 64, 128"
.
The following:
python tensorflow_test_nlp.py
Is equivalent to:
python tensorflow_test_nlp.py --epochs=3 --batch_sizes="16, 32, 64, 128"
Results will be saved to results/results_tensorflow_nlp/[file_name].csv
where file_name
is a combination of information from the experiment (see tensorflow_test_nlp.py
for details).
Experiment details:
Model | Task | Num Questions | Num Answers | Total Generations |
---|---|---|---|---|
Llama 2 7B .gguf format | Text Generation | 20 | 5 | 20*5 = 100 |
CMAKE_ARGS="-DLLAMA_METAL=on" FORCE_CMAKE=1 python -m pip install llama-cpp-python
After installing llama-cpp-python
, you will need a .gguf
format model from Hugging Face.
.gguf
extension, e.g. https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/blob/main/llama-2-7b-chat.Q4_0.gguf
→字节跳动发布的AI编程神器IDE
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。
全能AI智能助手,随时解答生活与工作的多样问题
问小白,由元石科技研发的AI智能助手,快速准确地解答各种生活和工作问题,包括但不限于搜索、规划和社交互动,帮助用户在日常生活中提高效率,轻松管理个人事务。
实时语音翻译/同声传译工具
Transly是一个多场景的AI大语言模型驱动的同声传译、专业翻译助手,它拥有超精准的音频识别翻译能力,几乎零延迟的使用体验和支持多国语言可以让你带它走遍全球,无论你是留学生、商务人士、韩剧美剧爱好者,还是出国游玩、多国会议、跨国追星等等,都可以满足你所有需要同传的场景需求,线上线下通用,扫除语言障碍,让全世界的语言交流不再有国界。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使 用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。
AI助力,做PPT更简单!
咔片是一款轻量化在线演示设计工具,借助 AI 技术,实现从内容生成到智能设计的一站式 PPT 制作服务。支持多种文档格式导入生成 PPT,提供海量模板、智能美化、素材替换等功能,适用于销售、教师、学生等各类人群,能高效制作出高品 质 PPT,满足不同场景演示需求。
选题、配图、成文,一站式创作,让内容运营更高效
讯飞绘文,一个AI集成平台,支持写作、选题、配图、排版和发布。高效生成适用于各类媒体的定制内容,加速品牌传播,提升内容营销效果。
专业的AI公文写作平台,公文写作神器
AI 材料星,专业的 AI 公文写作辅助平台,为体制内工作人员提供高效的公文写作解决方案。拥有海量公文文库、9 大核心 AI 功能,支持 30 + 文稿类型生成,助力快速完成领导讲话、工作总结、述职报告等材料,提升办公效率,是体制打工人的得力写作神器。
OpenAI Agents SDK,助力开发者便捷使用 OpenAI 相关功能。
openai-agents-python 是 OpenAI 推出的一款强大 Python SDK,它为开发者提供了与 OpenAI 模型交互的高效工具,支持工具调用、结果处理、追踪等功能,涵盖多种应用场景,如研究助手、财务研究等,能显著提升开发效率,让开发者更轻松地利用 OpenAI 的技术优势。
最新AI工具、AI资讯
独家AI资源、AI项目落地
微信扫一扫关注公众号