diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index b4a129bb..cd7dea34 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -2,233 +2,126 @@ name: release-build on: workflow_dispatch: - create: - tags: 'v**' - -permissions: - id-token: write - contents: read env: - COS_ACCESS_KEY_ID: ${{ secrets.COS_ACCESS_KEY_ID }} - COS_SECRET_ACCESS_KEY: ${{ secrets.COS_SECRET_ACCESS_KEY }} - COS_BUCKET: ${{ secrets.COS_BUCKET }} - COS_ENDPOINT: ${{ secrets.COS_ENDPOINT }} + IBM_CLOUD_REGION: ${{ secrets.IBM_CLOUD_REGION }} + IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }} + IBM_CLOUD_RESOURCE_GROUP: ${{ secrets.IBM_CLOUD_RESOURCE_GROUP }} + COS_BUCKET: ${{ secrets.COS_BUCKET }} jobs: # ──────────────────────────── - # Test on Python 3.10 + # Stage: Build & Deploy Wheels # ──────────────────────────── - test-py310: - name: Test (Python 3.10) + build-and-deploy-linux: + name: Build & Deploy wheels (manylinux) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v5 + - uses: actions/cache@v4 with: - python-version: 3.10.17 - - - name: Install system dependencies - run: | - sudo apt-get -qq update - sudo apt-get install -y ca-certificates libopenblas-dev gcc-9 g++-9 - sudo update-alternatives \ - --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 \ - --slave /usr/bin/g++ g++ /usr/bin/g++-9 + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - - name: Build and install aihwkit wheel + - name: Cleanup runner run: | - pip install -r requirements.txt - make build_inplace + pip cache purge + sudo apt-get clean + sudo rm -rf /var/lib/apt/lists/* - - name: Run pytest - run: | - pip install -r requirements-dev.txt - make pytest + - name: Build wheels + uses: pypa/cibuildwheel@v2.8.1 env: - TEST_DATASET: true - - # ──────────────────────────── - # Lint on Python 3.10 - # ──────────────────────────── - lint-py310: - name: Lint (Python 3.10) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: Set up Python 3.10 - uses: actions/setup-python@v5 + CIBW_ENVIRONMENT: "TORCH_VERSION_SPECIFIER='==2.3.1' MAKEFLAGS='-j4'" + CIBW_BEFORE_BUILD: "pip install torch==2.3.1 torchvision -f https://download.pytorch.org/whl/torch_stable.html && pip install -r requirements.txt" + CIBW_MANYLINUX_X86_64_IMAGE: "aihwkit/manylinux2014_x86_64_aihwkit" + CIBW_REPAIR_WHEEL_COMMAND: "auditwheel repair -w {dest_dir} {wheel} --exclude libtorch_python.so" + CIBW_BUILD: "cp38-manylinux_x86_64 cp39-manylinux_x86_64 cp310-manylinux_x86_64" with: - python-version: 3.10.17 - - - name: Install system dependencies - run: | - sudo apt-get -qq update - sudo apt-get install -y ca-certificates libopenblas-dev gcc-9 g++-9 - sudo update-alternatives \ - --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 \ - --slave /usr/bin/g++ g++ /usr/bin/g++-9 + output-dir: wheelhouse - - name: Build and install aihwkit wheel + - name: Sync wheels to IBM COS + env: + IBM_CLOUD_REGION: ${{ secrets.IBM_CLOUD_REGION }} + IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }} + IBM_CLOUD_RESOURCE_GROUP: ${{ secrets.IBM_CLOUD_RESOURCE_GROUP }} + COS_BUCKET: ${{ secrets.COS_BUCKET }} run: | - pip install -r requirements.txt - make build_inplace - - - name: Run lint checks + curl -fsSL https://clis.cloud.ibm.com/install/linux | sh + ibmcloud plugin install cos + ibmcloud login --apikey "$IBM_CLOUD_API_KEY" -r "$IBM_CLOUD_REGION" -g "$IBM_CLOUD_RESOURCE_GROUP" + find "wheelhouse" -type f | while read filepath; do + relpath="${filepath#wheelhouse/}" + dest="$relpath" + echo "Uploading $filepath to $dest" + ibmcloud cos upload \ + --bucket "$COS_BUCKET" \ + --key "$dest" \ + --file "$filepath" \ + --region "$IBM_CLOUD_REGION" + done + + - name: Cleanup runner + if: always() run: | - pip install -r requirements-dev.txt - pip install -r requirements-examples.txt - make pycodestyle - make pylint - make mypy - # ──────────────────────────────────────── - # Stage: Test multiple Python versions - # ──────────────────────────────────────── - test-matrix: - name: Tests (3.8 & 3.9) - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8, 3.9] + pip cache purge + sudo apt-get clean + sudo rm -rf /var/lib/apt/lists/* /var/cache/apt/* + rm -rf wheelhouse build dist *.egg-info + + build-and-deploy-macos: + name: Build & Deploy wheels (macOS) + runs-on: macos-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: actions/cache@v4 with: - python-version: ${{ matrix.python-version }} - - - name: Install system deps - run: | - sudo apt-get -qq update - sudo apt-get install -y ca-certificates libopenblas-dev gcc-9 g++-9 - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 \ - --slave /usr/bin/g++ g++ /usr/bin/g++-9 - - - name: Build and install aihwkit wheel - run: | - pip install -r requirements.txt - make build_inplace + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - - name: Run pytest + - name: Set up Environment run: | - pip install -r requirements-dev.txt - make pytest - - # ──────────────────────────── - # Stage: Build & Deploy Wheels - # ──────────────────────────── - build-and-deploy-linux: - name: Build & Deploy wheels (manylinux) - runs-on: ubuntu-latest - services: - docker: - image: docker:20.10.16 - options: --privileged - env: - CIBW_ENVIRONMENT: "TORCH_VERSION_SPECIFIER='==2.3.1+cu121'" - CIBW_BEFORE_BUILD: "pip install torch==2.3.1+cu121 torchvision -f https://download.pytorch.org/whl/torch_stable.html && pip install -r requirements.txt" - CIBW_MANYLINUX_X86_64_IMAGE: "aihwkit/manylinux2014_x86_64_aihwkit_cuda" - CIBW_REPAIR_WHEEL_COMMAND: "auditwheel repair -w {dest_dir} {wheel} --exclude libtorch_python.so" - CIBW_BUILD: "cp39-manylinux_x86_64 cp310-manylinux_x86_64" - AIHWKIT_VERSION_SUFFIX: "+cuda121" - steps: - - uses: actions/checkout@v3 - - - name: Pull manylinux image - run: docker pull $CIBW_MANYLINUX_X86_64_IMAGE - - - name: Install cibuildwheel - run: python3 -m pip install cibuildwheel==2.23.3 + brew install openblas + brew link --force openblas + git clone -b aihwkit https://github.com/aihwkit-bot/delocate.git - name: Build wheels - run: python3 -m cibuildwheel --output-dir wheelhouse + uses: pypa/cibuildwheel@v2.8.1 + env: + CIBW_ENVIRONMENT: "TORCH_VERSION_SPECIFIER='==2.3.1'" + CIBW_BEFORE_BUILD: "pip install torch==2.3.1 torchvision -f https://download.pytorch.org/whl/torch_stable.html && pip install ./delocate && pip install -r requirements.txt" + CIBW_ARCHS: "x86_64" + CIBW_BUILD: "cp38-macosx_x86_64 cp39-macosx_x86_64 cp310-macosx_x86_64" + MACOSX_DEPLOYMENT_TARGET: "10.13" + with: + output-dir: wheelhouse - name: Sync wheels to IBM COS env: - AWS_ACCESS_KEY_ID: ${{ secrets.COS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.COS_SECRET_ACCESS_KEY }} - AWS_DEFAULT_REGION: us-south-1 + IBM_CLOUD_REGION: ${{ secrets.IBM_CLOUD_REGION }} + IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }} + IBM_CLOUD_RESOURCE_GROUP: ${{ secrets.IBM_CLOUD_RESOURCE_GROUP }} + COS_BUCKET: ${{ secrets.COS_BUCKET }} run: | - which aws || pip install awscli --upgrade - aws s3 sync wheelhouse/ s3://${{ env.COS_BUCKET }}/ \ - --acl public-read \ - --delete \ - --endpoint-url https://${{ env.COS_ENDPOINT }} - - # build-and-deploy-macos: - # name: Build & Deploy wheels (macOS) - # runs-on: macos-latest - # env: - # CIBW_ENVIRONMENT: "TORCH_VERSION_SPECIFIER='==2.0.1'" - # CIBW_BEFORE_BUILD: "pip install torch==2.0.1 torchvision && pip install ./delocate && pip install -r requirements.txt" - # CIBW_BUILD: "cp38-macosx_x86_64 cp39-macosx_x86_64" - # steps: - # - uses: actions/checkout@v3 - - # - name: Install Homebrew deps - # run: | - # brew update - # brew install openblas - - # - name: Clone delocate - # run: git clone -b aihwkit https://github.com/aihwkit-bot/delocate.git - - # - name: Install cibuildwheel - # run: python3 -m pip install cibuildwheel==2.8.1 - - # - name: Build wheels - # run: python3 -m cibuildwheel --output-dir wheelhouse --platform macos - - # - name: Sync wheels to IBM COS - # env: - # AWS_ACCESS_KEY_ID: ${{ secrets.COS_ACCESS_KEY_ID }} - # AWS_SECRET_ACCESS_KEY: ${{ secrets.COS_SECRET_ACCESS_KEY }} - # AWS_DEFAULT_REGION: us-south-1 - # run: | - # which aws || pip install awscli --upgrade - # aws s3 sync wheelhouse/ s3://${{ env.COS_BUCKET }}/ \ - # --acl public-read \ - # --delete \ - # --endpoint-url https://${{ env.COS_ENDPOINT }} - - # build-and-deploy-windows: - # name: Build & Deploy wheels (Windows) - # runs-on: windows-latest - # env: - # CIBW_ENVIRONMENT: "TORCH_VERSION_SPECIFIER='==2.4.1'" - # CIBW_BEFORE_BUILD: "pip install torch==2.4.1 && pip install -r requirements.txt" - # CIBW_BUILD: "cp38-win_amd64 cp39-win_amd64 cp310-win_amd64" - # OPENBLAS_ROOT: C:\\BLAS - # OPENBLAS_ROOT_DIR: C:\\BLAS - # steps: - # - uses: actions/checkout@v3 - - # - name: Install Python & BLAS - # run: | - # choco install python --version=3.8.6 -y - # SET PATH=C:\Python38;C:\Python38\Scripts;%PATH% - # mkdir C:\BLAS - # Invoke-WebRequest -Uri https://github.com/xianyi/OpenBLAS/releases/download/v0.3.12/OpenBLAS-0.3.12-x64.zip -OutFile openblas.zip - # Expand-Archive openblas.zip -DestinationPath C:\BLAS - - # - name: Install cibuildwheel - # run: python -m pip install cibuildwheel==2.8.1 - - # - name: Build wheels - # run: python -m cibuildwheel --output-dir wheelhouse - - # - name: Sync wheels to IBM COS - # env: - # AWS_ACCESS_KEY_ID: ${{ secrets.COS_ACCESS_KEY_ID }} - # AWS_SECRET_ACCESS_KEY: ${{ secrets.COS_SECRET_ACCESS_KEY }} - # AWS_DEFAULT_REGION: us-south-1 - # run: | - # which aws || pip install awscli --upgrade - # aws s3 sync wheelhouse/ s3://${{ env.COS_BUCKET }}/ \ - # --acl public-read \ - # --delete \ - # --endpoint-url https://${{ env.COS_ENDPOINT }} + curl -fsSL https://clis.cloud.ibm.com/install/osx | sh + ibmcloud plugin install cos + ibmcloud login --apikey "$IBM_CLOUD_API_KEY" -r "$IBM_CLOUD_REGION" -g "$IBM_CLOUD_RESOURCE_GROUP" + find "wheelhouse" -type f | while read filepath; do + relpath="${filepath#wheelhouse/}" + dest="$relpath" + echo "Uploading $filepath to $dest" + ibmcloud cos upload \ + --bucket "$COS_BUCKET" \ + --key "$dest" \ + --file "$filepath" \ + --region "$IBM_CLOUD_REGION" + done + - name: Cleanup runner + if: always() + run: | + pip cache purge + brew cleanup --prune=all + rm -rf ~/Library/Caches/Homebrew/* + rm -rf wheelhouse build dist *.egg-info diff --git a/README.md b/README.md index d22515bc..69ebd963 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # IBM Analog Hardware Acceleration Kit ![PyPI](https://img.shields.io/pypi/v/aihwkit) +[![test-and-lint](https://github.com/IBM/aihwkit/actions/workflows/test-and-lint.yml/badge.svg)](https://github.com/IBM/aihwkit/actions/workflows/test-and-lint.yml) +[![release-build](https://github.com/IBM/aihwkit/actions/workflows/release-build.yml/badge.svg)](https://github.com/IBM/aihwkit/actions/workflows/release-build.yml) [![Documentation Status](https://readthedocs.org/projects/aihwkit/badge/?version=latest)](https://aihwkit.readthedocs.io/en/latest/?badge=latest) ![PyPI - License](https://img.shields.io/pypi/l/aihwkit) [![arXiv](https://img.shields.io/badge/arXiv-2104.02184-green.svg)](https://arxiv.org/abs/2104.02184) diff --git a/pyproject.toml b/pyproject.toml index 26184e86..6dc61748 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ requires = [ "numpy>=1.22,<2", "protobuf>=4.21.6", "tqdm", - "mypy==0.991" + "mypy==0.991", + "ninja; platform_system!='Windows'", ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index e1098fa3..d1e01d85 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ from skbuild import setup INSTALL_REQUIRES = [ - "torch{}".format(os.getenv("TORCH_VERSION_SPECIFIER", ">=1.9")), + "torch{}".format(os.getenv("TORCH_VERSION_SPECIFIER", ">=1.9,<2.7")), "torchvision", "scipy", "requests>=2.25,<3", @@ -20,13 +20,12 @@ "protobuf>=4.21.6", ] - def get_version() -> str: - """Get the package version.""" + """Get the package version for CUDA enabled wheels.""" version_path = os.path.join(os.path.dirname(__file__), "src", "aihwkit", "VERSION.txt") with open(version_path, encoding="utf-8") as version_file: - return version_file.read().strip() - + version_number = version_file.read().strip() + return f"{version_number}{os.getenv('AIHWKIT_VERSION_SUFFIX', '')}" def get_long_description() -> str: """Get the package long description."""