跳至主要內容

环境安装

大约 2 分钟

环境安装

M1 Mac Anaconda

curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh
sh Miniconda3-latest-MacOSX-arm64.sh

不自动激活 conda config --set auto*activate*base false

撤销设置 conda init --reverse $SHELL

创建激活Conda环境

conda create -n modelscope python=3.9
conda activate modelscope

查看环境

conda info --envs | grep "*"

删除环境

conda remove --name modelscope --all

安装Mac Pytorc

PyTorch 从 1.12 起对 Apple 的 M 系列芯片供了支持Metal Performance Shaders(MPS)后端来达成 GPU 加速

#pip install torch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0
pip3 install torch torchvision torchaudio

验证是否支持 GPU 加速

python -c "import torch; print(torch.backends.mps.is_available())"

安装 tensorflow

conda install -c apple tensorflow-deps
GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1  python -m pip install tensorflow-macos==2.13.0
python -m pip install tensorflow-metal

TensorFlow 从2.4 版本开始支持 Mac M1 GPU 加速验证方法

python -c "import tensorflow as tf; print(len(tf.config.list_physical_devices('GPU')) > 0)"

安装 JAX

pip install jax flax
python -c "import jax; print(jax.devices())"

安装编译环境

Rust 和 Cargo

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

cv 需要安装 Cmake

brew install cmake

audio 需要安装 llvm

brew install llvm

安装 modelscope

# nlp,cv,audio,multi-modal,science
pip install "modelscope[nlp,multi-modal,science]" -f https://modelscope.oss-cn-lbeijing.aliyuncs.com/releases/repo.html

modelscope

AssertionError: device should be either cpu, cuda, gpu, gpu:X or cuda:X where X is the ordinal for gpu device.

Huggingface

Pipeline Apple silicon deviceopen in new window

qwen2 docopen in new window
Qwen/Qwen2.5-7B-Instructopen in new window

# pip install -U flash-attn --no-build-isolation
transformers-cli chat --model_name_or_path Qwen/Qwen2-7B-Instruct --torch_dtype auto --attn_implementation flash_attention_2 --device mps

翻译模型

m2m docopen in new window
facebook/m2m100_418Mopen in new window

nllb docopen in new window
facebook/nllb-200-distilled-600Mopen in new window, facebook/nllb-200-distilled-1.3Bopen in new window, acebook/nllb-200-1.3Bopen in new window, facebook/nllb-200-3.3Bopen in new window, facebook/nllb-moe-54bopen in new window

mbart docopen in new window
facebook/mbart-large-cc25open in new window, facebook/mbart-large-50-many-to-many-mmtopen in new window

madlad docopen in new window
google/madlad400-3b-mtopen in new window, google/madlad400-7b-mtopen in new window, google/madlad400-7b-mt-btopen in new window, google/madlad400-10b-mtopen in new window

ModelSpace/GemmaX2-28-2B-v0.1open in new window, ModelSpace/GemmaX2-28-9B-v0.1open in new window

alirezamsh/small100open in new window

GGUFopen in new window

Mac M1 安装 modelscope 深度学习库open in new window
Grpcio fails installation for Tensorflow 2.5 on arm64 Apple Siliconopen in new window