跳至主要內容

环境安装

大约 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 llm python=3.9
conda activate llm

查看环境

conda info --envs | grep "*"

删除环境

conda remove --name llm --all

安装 modelscope

audio,cv 版本不兼容需要单独环境安装

# audio,cv == 1.25.0
# nlp,multi-modal,science == 1.6.1
# cv,audio,nlp,multi-modal,science

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

pip install "modelscope[audio]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

pip install "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html

安装Mac Pytorc

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

#pip install torch==2.6.0 torchaudio==2.6.0 torchvision==0.21.0
pip install torch torchaudio torchvision

验证是否支持 GPU 加速

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

安装 tensorflow

python -m pip install tensorflow-macos tensorflow-metal
#python -m pip install tensorflow-macos==2.16.2
#python -m pip install tensorflow-metal==1.2.0
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

# jax==0.4.30 flax==0.8.5
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 2.6.1

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

python -c "from modelscope.pipelines import pipeline;print(pipeline('word-segmentation', device='gpu')('今天天气不错,适合 出去游玩'))"

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