【发布时间】:2022-12-10 04:00:04
【问题描述】:
因此,我尝试在 Apple 芯片(M1 Max)上的 Jupyter 笔记本(在 Miniforge 虚拟环境中)中运行 ray[rllib]。尽管我可以import ray正常进入笔记本,但紧接着的下一步(运行ray.init())导致笔记本挂起。不返回任何错误--ray.init() 永远不会完成。有解决办法吗?
这是我第一次使用 Ray。我不认为笔记本或我输入的命令是问题,因为笔记本是教师预制的,我已经设法让一个相同的笔记本在 Windows 10 的 Miniforge 环境中正常运行。
我听从了 Ray M1 Mac (Apple Silicon) Support 开发人员的建议,安装了 Miniforge for the M1 并创建了一个虚拟环境。我还利用这个线程 What is the proper way to install TensorFlow on Apple M1 in 2022 设计了一个策略来安装强化学习应用程序所需的应用程序。以下是我用来设置 Miniforge 虚拟环境的 environment.yml 文件的内容:
name: tf-metal
channels:
- apple
- conda-forge
dependencies:
- python=3.9
- gym-all=0.21.0
- pip
- tensorflow-deps
## uncommented for use with Jupyter
- ipykernel
## PyPI packages
- pip:
- jupyterlab
- ray[rllib]==1.11
- tensorflow-macos
- tensorflow-metal
我在终端中用于创建虚拟环境的步骤如下:
# Download Miniforge3-MacOSX-arm64.sh and make it executable:
chmod u+x ./Miniforge3-MacOSX-arm64.sh
# run Miniforge
./Miniforge3-MacOSX-arm64.sh
# (or update it) ./Miniforge3-MacOSX-arm64.sh -u
# accept terms and conditions...
# run 'conda init' by entering 'yes'
# configure conda (then close and reopen Terminal):
conda config --set auto_activate_base false
# confirm '~/.bash_profile' reflects miniforge settings
# good-to-go...
# set up virtual environment
conda create --name rl_course2 # (choose any name you want)
# confirm acceptability of location (enter 'yes')
# activate env:
conda activate rl_course2
# configure channels (settings recommended by an instructor)
conda config --env --add channels conda-forge
conda config --env --set channel_priority strict
# install dependencies using environment.yml file shown above:
conda env update --name rl_course2 --file '/Users/.../environment.yml'
# check output for errors...(none found via text search)
因此,据我所知,我创建了虚拟环境并安装了所有依赖项,没有出现任何错误:
Successfully installed MarkupSafe-2.1.1 PyWavelets-1.4.1 Send2Trash-1.8.0 absl-py-1.3.0 anyio-3.6.2 argon2-cffi-21.3.0 argon2-cffi-bindings-21.2.0 astunparse-1.6.3 async-timeout-4.0.2 attrs-22.1.0 babel-2.11.0 beautifulsoup4-4.11.1 bleach-5.0.1 cachetools-5.2.0 certifi-2022.9.24 cffi-1.15.1 charset-normalizer-2.1.1 click-8.1.3 contourpy-1.0.6 cycler-0.11.0 defusedxml-0.7.1 dm-tree-0.1.7 fastjsonschema-2.16.2 filelock-3.8.0 flatbuffers-22.10.26 fonttools-4.38.0 gast-0.4.0 google-auth-2.14.1 google-auth-oauthlib-0.4.6 google-pasta-0.2.0 grpcio-1.43.0 idna-3.4 imageio-2.22.4 importlib-metadata-5.0.0 ipython-genutils-0.2.0 jinja2-3.1.2 json5-0.9.10 jsonschema-4.17.1 jupyter-server-1.23.3 jupyterlab-3.5.0 jupyterlab-pygments-0.2.2 jupyterlab-server-2.16.3 keras-2.10.0 keras-preprocessing-1.1.2 kiwisolver-1.4.4 libclang-14.0.6 markdown-3.4.1 matplotlib-3.6.2 mistune-2.0.4 msgpack-1.0.4 nbclassic-0.4.8 nbclient-0.7.0 nbconvert-7.2.5 nbformat-5.7.0 networkx-2.8.8 notebook-6.5.2 notebook-shim-0.2.2 oauthlib-3.2.2 opt-einsum-3.3.0 pandas-1.5.1 pandocfilters-1.5.0 pillow-9.3.0 prometheus-client-0.15.0 pyasn1-0.4.8 pyasn1-modules-0.2.8 pycparser-2.21 pyrsistent-0.19.2 pytz-2022.6 pyyaml-6.0 ray-1.11.0 redis-4.3.5 requests-2.28.1 requests-oauthlib-1.3.1 rsa-4.9 scikit-image-0.19.3 sniffio-1.3.0 soupsieve-2.3.2.post1 tabulate-0.9.0 tensorboard-2.10.1 tensorboard-data-server-0.6.1 tensorboard-plugin-wit-1.8.1 tensorboardX-2.5.1 tensorflow-estimator-2.10.0 tensorflow-macos-2.10.0 tensorflow-metal-0.6.0 termcolor-2.1.1 terminado-0.17.0 tifffile-2022.10.10 tinycss2-1.2.1 tomli-2.0.1 typing-extensions-4.4.0 urllib3-1.26.12 webencodings-0.5.1 websocket-client-1.4.2 werkzeug-2.2.2 wrapt-1.14.1 zipp-3.10.0
最后一步(在 rl_course2 环境中工作时)使用终端:启动 Jupyter...
(rl_course2) MacBook-Pro ~$ jupyter notebook
现在,在 Jupyter/Python 笔记本(Chrome 浏览器)中:
import ray # works!
ray.init() # never completes (no errors)!
因此,我使用终端(无笔记本)在同一环境中尝试了类似的步骤:
(rl_course2) MacBook-Pro ~$ python3
Python 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 08:48:25)
[Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> import ray
>>> ray.init()
[no errors, but never completes]
有没有办法解决这个问题并在我的 Jupyter 环境中正常运行 Ray?
更新 1:刚才,我能够使用上面讨论的虚拟环境运行 Apple 推荐的简单 TensorFlow 测试脚本(参见Get started with tensorflow-metal),并且在 M1 Max 上大约两分钟内完成了五个训练周期,没有错误64 GB 内存,所以环境看起来运行良好。也许这个问题涉及雷?
【问题讨论】:
标签: python tensorflow apple-m1 ray mini-forge