2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Apple Silicon MacにGPU対応のtensorflowとPyTorchをuvを使ってインストールする

Last updated at Posted at 2025-09-29

uvを使ってなるべく最新の機械学習環境を整える手順です(2025年9月現在)。
M2 Mac + MacOS Tahoeで動作確認しました。

インストール手順

これだけです。Python 3.13を指定するとエラーになるので注意。

% uv init -p 3.12 ml_test
% cd ml_test
% uv add tensorflow-macos tensorflow-metal tokenizers huggingface transformers torch tf-keras

PyTorchがGPU(mps)を使っていることを確認する

% uv run python -c "import torch;print(torch.backends.mps.is_available())"
True

mpsは,Metal Perfomance Shadersの略称です(参考ドキュメント)。

TensorflowがGPUを使っていることを確認する

% uv run python -c "import tensorflow as tf;print(tf.config.experimental.list_physical_devices('GPU'))"
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

Hugging Faceの動作確認

% uv run python -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('I love you'))"
No model was supplied, defaulted to distilbert/distilbert-base-uncased-finetuned-sst-2-english and revision 714eb0f (https://huggingface.co/distilbert/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
Device set to use mps:0
[{'label': 'POSITIVE', 'score': 0.9996141195297241}]
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?