Skip to content

Latest commit

 

History

History
177 lines (139 loc) · 4.55 KB

macos-arm64.md

File metadata and controls

177 lines (139 loc) · 4.55 KB

Build for macOS-arm64

Install Toolchains

  • cmake

    brew install cmake
    
  • clang

    install Xcode or Command Line Tools

    xcode-select --install
    

Install Dependencies

Install Dependencies for Model Converter

Please refer to get_started to install conda.

# install pytorch & mmcv
conda install pytorch==1.9.0 torchvision==0.10.0 -c pytorch
pip install -U openmim
mim install mmengine
mim install "mmcv>=2.0.0rc2"

Install Dependencies for SDK

You can skip this chapter if you are only interested in the model converter.

NAME INSTALLATION
OpenCV
(>=3.0)

brew install opencv

Install Inference Engines for MMDeploy

Both MMDeploy's model converter and SDK share the same inference engines.

You can select you interested inference engines and do the installation by following the given commands.

This document focus on Core ML. The installation of ONNX Runtime, ncnn and TorchScript is similar to the linux platform, please refer to the document linux-x86_64 for installation.

The TorchScript model is used as the IR in the conversion process of the Core ML model. In order to support the custom operator in some models like detection models in mmdet, libtorch needs to be installed.

NAME PACKAGE INSTALLATION
Core ML coremltools

pip install coremltools==6.3
TorchScript libtorch 1. Libtorch doesn't provide prebuilt arm library for macOS, so you need to compile it yourself. Please note that the version of libtorch must be consistent with the version of pytorch.
2. Take LibTorch 1.9.0 as an example. You can install it like this:

git clone -b v1.9.0 --recursive https://github.com/pytorch/pytorch.git
cd pytorch
mkdir build && cd build
cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DPYTHON_EXECUTABLE=`which python` \
    -DCMAKE_INSTALL_PREFIX=install \
    -DDISABLE_SVE=ON # low version like 1.9.0 of pytorch need DISABLE_SVE option
make -j4 && make install
export Torch_DIR=$(pwd)/install/share/cmake/Torch

Build MMDeploy

cd /the/root/path/of/MMDeploy
export MMDEPLOY_DIR=$(pwd)

Build Model Converter

  • Core ML

    Core ML uses torchscript as IR, to convert models in some codebases like mmdet, you need to compile torchscript custom operators

  • torchscript custom operators

    cd ${MMDEPLOY_DIR}
    mkdir -p build && cd build
    cmake -DMMDEPLOY_TARGET_BACKENDS=coreml -DTorch_DIR=${Torch_DIR} ..
    make -j4 && make install

Please check cmake build option.

Install Model Converter

# You should use `conda install` to install the grpcio in requirements/runtime.txt
conda install grpcio
cd ${MMDEPLOY_DIR}
mim install -v -e .

Note

  • Some dependencies are optional. Simply running pip install -e . will only install the minimum runtime requirements. To use optional dependencies, install them manually with pip install -r requirements/optional.txt or specify desired extras when calling pip (e.g. pip install -e .[optional]). Valid keys for the extras field are: all, tests, build, optional.

Build SDK and Demo

The following shows an example of building an SDK using Core ML as the inference engine.

  • cpu + Core ML

    cd ${MMDEPLOY_DIR}
    mkdir -p build && cd build
    cmake .. \
        -DMMDEPLOY_BUILD_SDK=ON \
        -DMMDEPLOY_BUILD_EXAMPLES=ON \
        -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \
        -DMMDEPLOY_TARGET_DEVICES=cpu \
        -DMMDEPLOY_TARGET_BACKENDS=coreml \
        -DTorch_DIR=${Torch_DIR}
    
    make -j4 && make install