M1 上的 Tensorflow Mac:"Incorrect checksum for freed object"

Tensorflow on M1 Mac: "Incorrect checksum for freed object"

我最近开始使用 Apple Silicon mac。我通过 Anaconda 安装了 Tensorflow,版本 2.6.2,这是我能找到的最新版本。

当我 运行 训练代码时,训练似乎开始初始化,直到出现一些内存错误。然后它挂起,直到我手动停止它。

打印输出如下:

(machine_learning) eric@mac-mini cr_battle_predictor % python3 main.py
2021-12-25 22:11:24.286059: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  SSE4.1 SSE4.2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
  0%|                                                                                                                                                                                                    | 0/350 [00:00<?, ?epoch/s]2021-12-25 22:11:24.368779: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:185] None of the MLIR Optimization Passes are enabled (registered 2)
python3(48188,0x304135000) malloc: Incorrect checksum for freed object 0x7fe41cac4e80: probably modified after being freed.
Corrupt value: 0x7fe42c07e480
python3(48188,0x304135000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      python3 main.py
(machine_learning) eric@mac-mini cr_battle_predictor % /Users/eric/.conda/envs/machine_learning/lib/python3.9/multiprocessing/resource_tracker.py:216: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

由于某种原因,偶尔(大约 1/7 次尝试),错误没有出现,据我所知,训练正常进行,没有问题。

我承认similar problem has been asked here。但是,提供的唯一解决方案是确保我使用的是正确的解释器和最新版本的 tensorflow。我正在使用 Python 3.9.7 和 TensorFlow 2.6.2,我确保我的程序也在使用这些版本。

是什么导致了这个问题?我愿意分享任何需要的信息。

在 Mac M1 上安装 Tensorflow 真的很痛苦。我对你的问题的解决方案是重新安装 Tensorflow;我遇到了和你一样的问题,但无法解决。首先,我假设您在蒙特雷 (Mac 12);如果不是,则必须参考 https://github.com/apple/tensorflow_macos/issues/153,这似乎对某些人有用。

如果这不起作用,请升级到 Monetery,然后按照此处列出的步骤操作:https://developer.apple.com/metal/tensorflow-plugin/。在这里:

Download and install Conda env [you can get this from https://github.com/conda-forge/miniforge#miniforge3; download "arm64 (Apple Silicon)", because you run on M1]:

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

Install the TensorFlow dependencies:

conda install -c apple tensorflow-deps

然后安装基础 Tensorflow

python -m pip install tensorflow-macos

终于拿到了 Tensorflow Metal 插件

python -m pip install tensorflow-metal

Tensorflow 现在应该可以工作了(并且也可以使用 M1 GPU!)。