Search code examples
python-poetry

poetry sys_plattform markers for different mac platforms


I am trying to use the poetry install package for installing pytorch on mac and I want to specify different wheel files for different platforms.

Pytorch has wheels for intel and ARM based macs. It seems I can specify the intel platform using markers="sys_platform == 'macosx'". How can one specify the arm based system?

I also wonder if macosx identifier will select both the platforms? I only have access to intel based mac to do the tests at the moment.


Solution

  • UPDATE

    Tested on latest Poetry 1.3.1, I succeed simply using this now:

    [tool.poetry.dependencies]
    python = "3.10.x"
    torch = "1.13.1"
    

    Poetry picked right version.


    Original Answer

    To answer your question, it would be

    markers = "sys_platform == 'darwin' and platform_machine == 'arm64'"
    markers = "sys_platform == 'darwin' and platform_machine == 'x86_64'"
    

    Here is final version:

    [tool.poetry.dependencies]
    python = "3.10.x"
    torch = [
      {markers = "sys_platform == 'darwin' and platform_machine == 'arm64'", url = "https://files.pythonhosted.org/packages/79/b3/eaea3fc35d0466b9dae1e3f9db08467939347b3aaa53c0fd81953032db33/torch-1.13.0-cp310-none-macosx_11_0_arm64.whl"},
      {markers = "sys_platform == 'darwin' and platform_machine == 'x86_64'", url = "https://files.pythonhosted.org/packages/b6/79/ead6840368f294497591af143980372ff956fc4c982c457a8b5610a5a1f3/torch-1.13.0-cp310-none-macosx_10_9_x86_64.whl"},
      {markers = "sys_platform == 'linux'", url="https://files.pythonhosted.org/packages/5c/61/b0303b8810c1300e75e8e665d043f6c2b272a4da60e9cc33416cde8edb76/torch-1.13.0-cp310-cp310-manylinux2014_aarch64.whl"}
    ]
    
    • arm64 is for macOS with M1/M2 chip. x86_64 is for macOS with Intel chip.
    • For Linux, you can also define platform_machine if you are using multiple architectures (In the demo above, it is using aarch64 wheel).

    You can find all wheel URLs at either one of

    You can find your current platform and architecture by using Python command:

    > python
    >>> import sys
    >>> sys.platform
    'darwin'
    >>> import platform
    >>> platform.machine()
    'arm64'
    

    You can find the list of sys.platform at here.

    (Wish Poetry can be smarter for PyTorch in future so that we do not need manually set them)