【问题标题】:python3 install of Tensorflow on Apple silicon M1python3 在 Apple 硅 M1 上安装 Tensorflow
【发布时间】:2021-04-22 11:48:01
【问题描述】:

我在 Apple Silicon M1 上安装了 macOS Big Sur,但无法在 python3 中安装 Tensorflow。 我删除了 xcode python3 并安装了 brew arm64 python3 (x86 python3 也不行)

我检查成功 64 bis 版本

python3 -c "import sys; print(sys.version)" or python -c "import struct; print(struct.calcsize('P')*8)"

3.8.7(默认,2020 年 12 月 30 日,02:09:32) [Clang 12.0.0 (clang-1200.0.32.28)]

这无论如何都可以工作,或者谁知道,如何做到这一点?

【问题讨论】:

  • 目前还没有 Tensorflow 的通用轮子,因此您将无法通过pip install 安装它。查看github.com/apple/tensorflow_macos 以安装 Apple 提供的用于 M1 的 Tensorflow 的分支。根据自述文件,快捷方式是/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/apple/tensorflow_macos/master/scripts/download_and_install.sh)"

标签: python-3.x tensorflow pip


【解决方案1】:

现在使用 TensorFlow Metal 插件应该会更好。

截至 2021 年 10 月 25 日,macOS 12 Monterey 为 generally available

为 TensorFlow 设置 M1 的步骤:

将您的机器升级到 Monterey。

如果您安装了 conda,请将其卸载。

然后按照 Apple here 的说明进行操作。

在下面清理:

从 Miniforge 下载并安装 Conda:

chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate

在活动的 conda 环境中,安装 TensorFlow 依赖项、基础 TensorFlow 和 TensorFlow metal:

conda install -c apple tensorflow-deps
pip install tensorflow-macos
pip install tensorflow-metal

你应该很高兴。

【讨论】:

    【解决方案2】:

    Apple M1 是一款采用 ARM64 架构的处理器,而 TensorFlow 的所有 pip 包都是针对 x86_64 架构编译的。 (不包括 raspberry pi 包,但它们无论如何都不会与 MacO 兼容)。

    如果我们查看 TensorFlow 的 install page 上的 pip 包的名称,其中大部分包含 x86_64amd64,这表明它们是针对 x86_64 架构构建的。

    如果您想在 M1 上运行 TensorFlow,您需要:

    • 通过 Rosetta 2 从针对 x86_64 的源代码编译 TensorFlow。不幸的是,根据this issue on github,Rosetta 2 不支持在 TensorFlow 的 pip 构建中启用的 AVX 指令集,因此需要从源代码重新构建。
    • 使用 Apple 开发的对 TensorFlow on M1 的实验性支持,您可以在 this github repository 上找到它。请注意,如果采用这种方式,某些 python 包可能与 M1 不兼容/不可用。

    请注意,截至 2021 年 1 月 4 日,the Apple M1 is not a supported architecture by the TensorFlow team

    我们目前不支持 Mac ARM。能够专注于所有 3 个操作系统上的构建问题的开发人员不足 1 人。

    因此,支持必须来自社区。 SIG Build 专注于其他几个平台上的构建相关问题,让我们只关注我们正式祝福的 pip 包。

    【讨论】:

      猜你喜欢
      • 2022-02-09
      • 2021-07-22
      • 2021-05-17
      • 1970-01-01
      • 2021-08-14
      • 2021-05-08
      • 1970-01-01
      • 2022-06-11
      • 2022-01-22
      相关资源
      最近更新 更多