Deeplearning On Macos M-Series Processors

CoreML
darling
hackintosh
paddlepaddle
Swift
This article covers deep learning on MacOS, exploring the use of M-series processors and AMD GPUs for training. It discusses training with a MacBook Air, using TensorFlow Metal and PyTorch with MPS. The article also delves into CoreML image analysis techniques and AutoML for Apple’s M1 chips. Additionally, it covers image/video analysis methods, Optical Flow, Person Segmentation, NLP APIs, sentiment analysis, speech recognition, and sound classification using DNNs.
Published

August 6, 2022


it is funny that macOS still supports AMD GPUs, means any intel Mac (not M-series!) can now utilize internal/external AMD GPUs as long as frameworks like jax and pytorch support MPS/Metal.


calling python code from swift using pythonkit:

func downloadVideo(link: String){
let sys = Python.import("sys")
sys.path.append(dirPath)
let example = Python.import("sample")
let response = example.downloadVideo(link, dirPath)
videoPath = String(response)
}

run macos in docker with kvm

neural engine

it is used for coreml inference, not training

run coreml on hackintosh

first, download macos montery using the mac.

then, install it on hackintosh, with associated nvidia drivers.

next test gpu avalibility via system info panel.

then install xcode commandline tools and check coreml avalibility

run coreml with swift on linux

darling is at its very premature stage, just like the wine. now it is testing something called “darlingserver” which is a full userspace implementation and is prone to tons of problems. swift repl is not working and installing xcode commandline tools 14 will hang this thing. i suggest you to do light model training on macbook air and convert it to onnx if want to use it everywhere.

before reinstallation of darling, make sure you have removed all darling related files by checking updatedb; locate darling | grep -v <compile directory>

visit here to install darling from source (maybe that’s the only way)

if want to install darling on kali, you must outsource all deeplearning models to other disks, and collect all other big files to somewhere else or trash them. use systemwide user broadcast method to warn me if any of the disk is missing. use automatic symlink change method to adapt the external disk mountpoint changes.

darling can install xcode commandline tools with macos sdk, so maybe it can run coreml models with swift using cpu. gpu support is currently not known. maybe that requires metal support.

thermal and battery life concerns, and more

consider using external gpus (eGPUs) with thunderbolt 3 and AMD GPUs to avoid overheating. currently that can only be done with intel Macs.

battery life is currently bad for intel/amd notebooks of x86/64 architecture.

heavy lifting jobs are likely to be run on Mac Studio with M1 Ultra and 128GB RAM. Macbook Air M1 with 8GB RAM is simply not feasible.

aside of Apple platforms, these APIs are virtually useless.

to run these on other non-apple machines, you need to tweak and install macOS on x86-64 platforms with macOS supported GPUs(may have low performance), which will definitely not taking any advantage of huge shared RAM with CPU, and may run poorly on CoreML/CreateML, may not support deepspeed stage 2/3 or BMI(big model inference)

Non-Supported NVIDIA Cards, use AMD GPU instead

High Sierra no longer supports NVIDIA Mac.

Mojave – Catalina – BigSur only works with AMD graphics and Intel onboard graphics and only a very small number of old NVIDIA products. Suppose you have GTX 1070, 1080, and the like, you can not use High Sierra onwards because Nvidia does not provide any updates for Mac and can not be used in any other way.

In general, the graphics of the Turing, Pascal, and Maxwell series will never be supported again. The latest Mac version that can use this series of graphics is High Sierra.

tensorflow with m1 support

using tensorflow metal plugin, which sets up miniforge and install tensorflow-metal within.

install without miniforge(works!)

pip3 install tensorflow-macos tensorflow-metal

validation:

python3 -c "import tensorflow as tf; physical_devices = tf.config.list_physical_devices('GPU'); print('Num GPUs:', len(physical_devices)); print(physical_devices)"

pytorch with m1 support, using MPS (Metal performance shader)

install from nightly release channel, with minimum system version requirements 12.3 (which this machine had been qualified after system update, now 12.5)

# MPS acceleration is available on MacOS 12.3+
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

validation

python3 -c "import torch; print('MPS avaliable:',torch.backends.mps.is_available()); print('Built with MPS:',torch.backends.mps.is_built())"

run python inside swift

use pythonkit

automatic machine learning using CreateML

import CreateML

CreateML is similar to any other AutoML tools, like AutoKeras, AutoTrain by Huggingface (works by training against a selected set of user-provided models)

using CoreML

curated, largest coreml models collection

CoreML models can be created by CreateML and some customization can be done via protocol MLCustomLayer.

onnxruntime can run onnx models on CoreML, via c#, since that library is maintained by microsoft.

to install c# on macos:

brew install dotnet-sdk

to install and launch dotnet repl:

dotnet tool install -g dotnet-repl
dotnet repl

paddlepaddle support

convert into onnx first, then run on onnxruntime.

paddlepaddle itself currently only supports running on M1 CPU only via rosetta 2.