最新预览版支持M1 MacBook pro的加速培训。此功能目前仅支持最新的预览版(每晚)构建:
要开始,只需安装最新的预览(Nightly)构建你的苹果硅片Mac运行macOS 12.3或更高版本的本机Python的arm64版本
根据文档,这是如何通过pip
安装最新的预览版本:
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
但是我正在使用Poetry来管理我的Python项目依赖项。
似乎Poetry不支持--pre
选项:
$ poetry add --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
Stack trace:
11 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:123 in run
io = io_factory(
10 ~/.poetry/lib/poetry/console/config/application_config.py:221 in create_io
resolved_command = application.resolve_command(args)
9 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/console_application.py:110 in resolve_command
return self._config.command_resolver.resolve(args, self)
8 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/resolver/default_resolver.py:34 in resolve
return self.create_resolved_command(result)
7 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/resolver/default_resolver.py:166 in create_resolved_command
if not result.is_parsable():
6 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/resolver/resolve_result.py:43 in is_parsable
self._parse()
5 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/resolver/resolve_result.py:49 in _parse
self._parsed_args = self._command.parse(self._raw_args)
4 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/api/command/command.py:113 in parse
return self._config.args_parser.parse(args, self._args_format, lenient)
3 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/args/default_args_parser.py:53 in parse
self._parse(args, _fmt, lenient)
2 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/args/default_args_parser.py:101 in _parse
self._parse_long_option(token, tokens, fmt, lenient)
1 ~/.poetry/lib/poetry/_vendor/py3.9/clikit/args/default_args_parser.py:247 in _parse_long_option
self._add_long_option(name, None, tokens, fmt, lenient)
NoSuchOptionException
The "--pre" option does not exist.
at ~/.poetry/lib/poetry/_vendor/py3.9/clikit/args/default_args_parser.py:300 in _add_long_option
296│ def _add_long_option(
297│ self, name, value, tokens, fmt, lenient
298│ ): # type: (str, Optional[str], List[str], ArgsFormat, bool) -> None
299│ if not fmt.has_option(name):
→ 300│ raise NoSuchOptionException(name)
301│
302│ option = fmt.get_option(name)
303│
304│ if value is False:
我如何使用诗歌添加PyTorch的最新预览(夜间)构建?
与pip
命令等价的诗歌命令是:
poetry source add --priority explicit pytorch https://download.pytorch.org/whl/nightly/cpu
然后:
poetry add --source pytorch torch torchvision
第一个命令为explicit
优先级的包添加一个新的源URL(默认只有PyPI),这意味着如果在使用poetry add
时没有显式指定源,则使用PyPI。第二个命令从指定的源添加torch
和torchvision
。
但是,由于依赖解决问题,我无法通过这种方式每晚安装PyTorch。
还有第二个解决方案,但是它需要您手动为您的体系结构和环境选择合适的转轮。
首先,访问https://download.pytorch.org/whl/nightly/torch/并找到与您的架构和环境相匹配的最新车轮。例如,如果你在苹果芯片上使用Python 3.10,这将是torch-2.1.0.dev20230417-cp310-none-macosx_11_0_arm64.whl
。注意cp310
,macosx
和arm64
部分。
当你完成了第一步,为火炬视觉重复它。然后您可以使用poetry add
:
poetry add "https://download.pytorch.org/whl/nightly/cpu/torch-2.1.0.dev20230416-cp310-none-macosx_11_0_arm64.whl" "https://download.pytorch.org/whl/nightly/cpu/torchvision-0.16.0.dev20230416-cp310-cp310-macosx_11_0_arm64.whl"
或直接在pyproject.toml
:
[tool.poetry.dependencies]
torch = {url = "https://download.pytorch.org/whl/nightly/cpu/torch-2.1.0.dev20230416-cp310-none-macosx_11_0_arm64.whl"}
torchvision = {url = "https://download.pytorch.org/whl/nightly/cpu/torchvision-0.16.0.dev20230416-cp310-cp310-macosx_11_0_arm64.whl"}
我通过在https://docs.conda.io/en/latest/miniconda.html (m1 64位)上安装minicoda获得了它的工作