pytorch / ao

PyTorch native quantization and sparsity for training and inference
BSD 3-Clause "New" or "Revised" License
1.1k stars 112 forks source link

ARM builds in CI #335

Open msaroufim opened 3 months ago

msaroufim commented 3 months ago

Right now if I pip install torchao on my M1 laptop it'll install 0.1 binaries and not the latest release for 0.2

Similarly if I try to install the nightly binaries I get a hard error

(ao) pip install --pre torchao-nightly --index-url https://download.pytorch.org/whl/nightly/cpu
Looking in indexes: https://download.pytorch.org/whl/nightly/cpu
ERROR: Could not find a version that satisfies the requirement torchao-nightly (from versions: none)
ERROR: No matching distribution found for torchao-nightly
(ao) pip install --pre torchao --index-url https://download.pytorch.org/whl/nightly/ 
Looking in indexes: https://download.pytorch.org/whl/nightly/
Requirement already satisfied: torchao in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (0.1)
Requirement already satisfied: torch in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torchao) (2.2.2)
Requirement already satisfied: numpy in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torchao) (1.26.4)
Requirement already satisfied: sentencepiece in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torchao) (0.2.0)
Requirement already satisfied: packaging in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torchao) (24.0)
Requirement already satisfied: filelock in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torch->torchao) (3.13.4)
Requirement already satisfied: typing-extensions>=4.8.0 in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torch->torchao) (4.11.0)
Requirement already satisfied: sympy in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torch->torchao) (1.12)
Requirement already satisfied: networkx in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torch->torchao) (3.3)
Requirement already satisfied: jinja2 in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torch->torchao) (3.1.3)
Requirement already satisfied: fsspec in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from torch->torchao) (2024.3.1)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from jinja2->torch->torchao) (2.1.5)
Requirement already satisfied: mpmath>=0.19 in /opt/anaconda3/envs/ao/lib/python3.10/site-packages (from sympy->torch->torchao) (1.3.0)
(ao) pip list
Package                Version
---------------------- -----------
attrs                  23.2.0
bashlex                0.18
bitsandbytes           0.42.0
bracex                 2.4
certifi                2024.2.2
charset-normalizer     3.3.2
cibuildwheel           2.17.0
contourpy              1.2.1
cycler                 0.12.1
exceptiongroup         1.2.1
expecttest             0.2.1
filelock               3.13.4
fonttools              4.51.0
fsspec                 2024.3.1
git-filter-repo        2.38.0
huggingface-hub        0.23.0
hypothesis             6.100.5
idna                   3.7
iniconfig              2.0.0
Jinja2                 3.1.3
kiwisolver             1.4.5
lxml                   5.2.1
MarkupSafe             2.1.5
matplotlib             3.8.4
mpmath                 1.3.0
networkx               3.3
ninja                  1.11.1.1
numpy                  1.26.4
packaging              24.0
pandas                 2.2.2
parameterized          0.9.0
pillow                 10.3.0
pip                    23.3.1
platformdirs           4.2.0
pluggy                 1.5.0
pyparsing              3.1.2
pytest                 7.4.0
python-dateutil        2.9.0.post0
pytz                   2024.1
PyYAML                 6.0.1
qtorch                 0.3.0
regex                  2024.4.28
requests               2.31.0
safetensors            0.4.3
scipy                  1.13.0
sentencepiece          0.2.0
setuptools             68.2.2
six                    1.16.0
sortedcontainers       2.4.0
sympy                  1.12
tokenizers             0.19.1
tomli                  2.0.1
torch                  2.2.2
torchao                0.1
tqdm                   4.66.4
transformers           4.40.2
typing_extensions      4.11.0
tzdata                 2024.1
unittest-xml-reporting 3.2.0
urllib3                2.2.1
wheel                  0.41.2
(ao) 
gau-nernst commented 3 months ago

seems like this can be done by creating a build_wheels_macos.yml following this guide? https://github.com/pytorch/test-infra/wiki/Using-Nova-Reusable-Build-Workflows

It looks straight-forward enough, maybe I can make a PR for this. (Unless you want Meta people for CI stuff only)

msaroufim commented 3 months ago

You could give it a shot although not sure Nova has had non Meta people try it out - cc @atalman in case this is interesting

gau-nernst commented 3 months ago

oh ya realize I might not be able to test it. Will try and see.

gau-nernst commented 3 months ago

stuck at "Download artifact" step: https://github.com/gau-nernst/ao/actions/runs/9510166711/job/26214222390. Seems like due to some CI configs, since "Build Linux wheel" CI is also failing at this step in my fork.

I basically made a combination of torchvision CI (https://github.com/pytorch/vision/blob/main/.github/workflows/build-wheels-m1.yml) and our existing Linux wheel CI (https://github.com/pytorch/ao/blob/main/.github/workflows/build_wheels_linux.yml). Just paste it here for Meta people to take it from here (uncomment PYPI_API_TOKEN).

# From https://github.com/pytorch/test-infra/wiki/Using-Nova-Reusable-Build-Workflows
name: Build MacOS Wheels

on:
  pull_request:
    paths:
      - build/packaging/**
      - .github/workflows/build_wheels_m1.yml
  push:
    branches:
      - nightly
      - main
      - release/*
    tags:
        # NOTE: Binary build pipelines should only get triggered on release candidate builds
        # Release candidate tags look like: v1.11.0-rc1
        - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
  schedule:
    - cron: '0 0 * * *'  # Runs at midnight UTC every day
  workflow_dispatch:

jobs:
  generate-matrix:
    uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
    with:
      package-type: wheel
      os: macos-arm64

  build:
    needs: generate-matrix
    permissions:
      id-token: write
      contents: read
    uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@main
    with:
      # Set the ref to an empty string instead of the default nightly because
      # torchao doesn't have nightly branch setup yet, instead the build is
      # triggered daily from main with a schedule
      repository: pytorch/ao
      ref: ""
      build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
      # env-var-script: packaging/env_var_script_linux.sh
      pre-script: packaging/pre_build_script.sh
      post-script: packaging/post_build_script.sh
      smoke-test-script: packaging/smoke_test.py
      package-name: torchao
      trigger-event: ${{ github.event_name }}
      runner-type: macos-m1-stable
    # secrets:
    #   PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

Seems like it should work. The only thing that might break for MacOS is https://github.com/pytorch/ao/blob/main/packaging/post_build_script.sh since it looks Linux-specific.