How to install the latest PyTorch preview (nightly) build via Poetry
Asked Answered
K

2

7

The latest preview build supports accelerated training on M1 MacBook Pros. This feature is currently only supported by the newest preview (nightly) build:

To get started, just install the latest Preview (Nightly) build on your Apple silicon Mac running macOS 12.3 or later with a native version (arm64) of Python.

According to the documentation, this is how to install the latest preview build via pip:

pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

But I'm using Poetry to manage my Python project dependencies.

It doesn't seem like Poetry supports the --pre option:

$ 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:

How can I use Poetry to add the latest preview (nightly) build of PyTorch?

Kalina answered 5/6, 2022 at 8:24 Comment(1)
Did you manage to get it working without --pre option?Implosive
H
1

The Poetry equivalent of your pip command would be:

poetry source add --priority explicit pytorch https://download.pytorch.org/whl/nightly/cpu

And then:

poetry add --source pytorch torch torchvision

The first command adds a new source URL for packages (by default there is only PyPI) with the explicit priority which means that PyPI is used if no source is specified explicitly while using poetry add. The second command adds torch and torchvision from the specified source.

However, I was not able to install PyTorch nightly by this mean because of dependency resolution issues.

There is a second solution, but it requires you to manually select the appropriated wheel for your architecture and environment.

First, visit https://download.pytorch.org/whl/nightly/torch/ and find a recent wheel matching your architecture and environment. For instance, if you are using Python 3.10 on apple silicon, this would be torch-2.1.0.dev20230417-cp310-none-macosx_11_0_arm64.whl. Notice the cp310, macosx and arm64 parts.

When you are done with this first step, repeat it for TorchVision. You can then add those dependencies with 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"

or directly in 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"}
Highkeyed answered 15/6, 2023 at 10:12 Comment(0)
H
-1

I got it working by installing minicoda for m1 arm at https://docs.conda.io/en/latest/miniconda.html (M1 64 bit)

Horatia answered 2/3, 2023 at 20:25 Comment(1)
Offering a step by step set of instructions that others can follow is really helpful.Apology

© 2022 - 2024 — McMap. All rights reserved.