diff --git a/.conda.tensorflow_macos/build.sh b/.conda.tensorflow_macos/build.sh new file mode 100644 index 0000000..0f2cb43 --- /dev/null +++ b/.conda.tensorflow_macos/build.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +export PIP_NO_INDEX=False +export PIP_NO_DEPENDENCIES=False +export PIP_IGNORE_INSTALLED=False + +pip install --no-cache-dir -r ./requirements.tensorflow_macos.txt \ No newline at end of file diff --git a/.conda.tensorflow_macos/meta.yaml b/.conda.tensorflow_macos/meta.yaml new file mode 100644 index 0000000..f10fe31 --- /dev/null +++ b/.conda.tensorflow_macos/meta.yaml @@ -0,0 +1,101 @@ +# Ref: https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html + +package: + name: tensorflow + version: 2.12.0 + +about: + home: https://tensorflow.org + license: Apache License + summary: "TensorFlow conda package based on the PyPI wheels for Apple Silicon Macs." + +build: + number: 4 + +source: + # can't find requirements.tensorflow_macos.txt without this + path: ../ + +requirements: + host: + - conda-forge::absl-py >=1.0.0 + - conda-forge::astunparse >=1.6.0 + - conda-forge::cachetools <6.0,>=2.0.0 + - conda-forge::certifi >=2017.4.17 + - conda-forge::charset-normalizer <4,>=2 + - conda-forge::gast <=0.4.0,>=0.2.1 + - conda-forge::google-auth <3,>=1.6.3 + - conda-forge::google-auth-oauthlib <0.5,>=0.4.1 + - conda-forge::google-pasta >=0.1.1 + - conda-forge::grpcio <2.0,>=1.24.3 + - conda-forge::h5py >=2.9.0 + - conda-forge::idna <4,>=2.5 + - conda-forge::keras <2.13.0,>=2.12.0 # Required for tensorflow-macos + - conda-forge::keras-preprocessing >=1.1.1 + - anaconda::markdown >=2.6.8 + - conda-forge::MarkupSafe >=2.1.1 + - conda-forge::numpy >=1.16.5,<2.0 # tensorflow compiled with numpy 1.x + - conda-forge::oauthlib >=3.0.0 + - conda-forge::opt-einsum >=2.3.2 + - conda-forge::packaging + - conda-forge::pip + - conda-forge::protobuf >3.20 # Needed for pyside6, opencv, and tf compatibility + - conda-forge::pyasn1 <0.7.0,>=0.4.6 + - conda-forge::pyasn1-modules >=0.2.1 + - conda-forge::python >=3.10.0,<3.11.0 + - conda-forge::requests <3,>=2.21.0 + - conda-forge::requests-oauthlib >=0.7.0 + - conda-forge::rsa <5,>=3.1.4 + - conda-forge::termcolor >=1.1.0 + - conda-forge::typing-extensions >=3.6.6 + - conda-forge::urllib3 <3,>=1.21.1 + - conda-forge::werkzeug >=1.0.1 + - conda-forge::wrapt >=1.11.0,<1.15.0 # https://github.com/tensorflow/tensorflow/issues/59869 + + run: + - conda-forge::absl-py >=1.0.0 + - conda-forge::astunparse >=1.6.0 + - conda-forge::cachetools <6.0,>=2.0.0 + - conda-forge::certifi >=2017.4.17 + - conda-forge::charset-normalizer <4,>=2 + - conda-forge::gast <=0.4.0,>=0.2.1 + - conda-forge::google-auth <3,>=1.6.3 + - conda-forge::google-auth-oauthlib <0.5,>=0.4.1 + - conda-forge::google-pasta >=0.1.1 + - conda-forge::grpcio <2.0,>=1.24.3 + - conda-forge::h5py >=2.9.0 + - conda-forge::idna <4,>=2.5 + - conda-forge::keras >=2.12.0,<2.13.0 # Required for tensorflow-macos==2.12.0 + - conda-forge::keras-preprocessing >=1.1.1 + - anaconda::markdown >=2.6.8 + - conda-forge::MarkupSafe >=2.1.1 + - conda-forge::numpy >=1.16.5,<2.0 # tensorflow compiled with numpy 1.x + - conda-forge::oauthlib >=3.0.0 + - conda-forge::opt-einsum >=2.3.2 + - conda-forge::packaging + - conda-forge::pip + - conda-forge::protobuf >3.20 # Needed for pyside6, opencv, and tf compatibility + - conda-forge::pyasn1 <0.7.0,>=0.4.6 + - conda-forge::pyasn1-modules >=0.2.1 + - conda-forge::python >=3.10.0,<3.11.0 + - conda-forge::requests <3,>=2.21.0 + - conda-forge::requests-oauthlib >=0.7.0 + - conda-forge::rsa <5,>=3.1.4 + - conda-forge::termcolor >=1.1.0 + - conda-forge::typing-extensions >=3.6.6 + - conda-forge::urllib3 <3,>=1.21.1 + - conda-forge::werkzeug >=1.0.1 + - conda-forge::wrapt >=1.11.0,<1.15.0 # https://github.com/tensorflow/tensorflow/issues/59869 + + # the following are pip installed, even when conda-forge versions are available + # - conda-forge::flatbuffers <2,>=1.12 + # - conda-forge::libclang >=13.0.0 + # - conda-forge::six >=1.12.0 + # - conda-forge::tensorboard <2.10,>=2.9 + # - conda-forge::tensorboard-data-server <0.7.0,>=0.6.0 + # - conda-forge::tensorboard-plugin-wit >=1.6.0 + # - conda-forge::tensorflow-estimator <2.10.0,>=2.9.0rc0 + +test: + imports: + - tensorflow diff --git a/.github/workflows/build_tensorflow.yml b/.github/workflows/build_tensorflow.yml new file mode 100644 index 0000000..c4489b8 --- /dev/null +++ b/.github/workflows/build_tensorflow.yml @@ -0,0 +1,57 @@ +name: Build TensorFlow + +on: + push: + branches: + - main + - elizabeth/add-tensorflow-macos-conda-package + + paths: + - ".github/workflows/build_tensorflow.yml" + - ".conda.tensorflow_macos/**" + - "environment.tensorflow.yml" + - "requirements.tensorflow_macos.txt" + +jobs: + build: + name: Build package (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: ["macos-14"] + steps: + # Checkout the repository + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Miniconda (Ubuntu and MacOS) + if: matrix.os == 'macos-14' + uses: conda-incubator/setup-miniconda@v3.0.3 + with: + python-version: "3.10" + environment-file: environment.tensorflow.yml + activate-environment: tf + + - name: Print environment info + shell: bash -l {0} + run: | + which python + conda info + conda list + + - name: Build conda package (MacOS) + if: matrix.os == 'macos-14' + shell: bash -l {0} + run: | + conda build --debug .conda.tensorflow_macos --output-folder build.tensorflow_macos -c conda-forge + + - name: Upload to Anaconda (MacOS) + if: matrix.os == 'macos-14' + env: + ANACONDA_PASSWORD: ${{ secrets.ANACONDA_PASSWORD }} + shell: bash -l {0} + run: | + anaconda login --username sleap-deps --password "$ANACONDA_PASSWORD" + anaconda -v upload build.tensorflow_macos/osx-arm64/*.tar.bz2 --label dev --user sleap-deps + anaconda logout diff --git a/.gitignore b/.gitignore index 82f9275..73a7596 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ parts/ sdist/ var/ wheels/ +pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -49,7 +50,6 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ -cover/ # Translations *.mo @@ -72,7 +72,6 @@ instance/ docs/_build/ # PyBuilder -.pybuilder/ target/ # Jupyter Notebook @@ -83,9 +82,7 @@ profile_default/ ipython_config.py # pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version +.python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. @@ -94,24 +91,7 @@ ipython_config.py # install all needed dependencies. #Pipfile.lock -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/latest/usage/project/#working-with-version-control -.pdm.toml -.pdm-python -.pdm-build/ - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +# PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff @@ -148,15 +128,5 @@ dmypy.json # Pyre type checker .pyre/ -# pytype static type analyzer -.pytype/ -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +build.*/ \ No newline at end of file diff --git a/README.md b/README.md index 0de8678..ae060ea 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,34 @@ # sleap-deps Packages necessary for sleap build maintained by the SLEAP team. + +## tensorflow + +There is a Github Actions workflow `build_tensorflow.yml` that uses Github runners to build packages for us (and upload them to the `sleap-deps/label/dev` channel). But, if you would like to locally build and test the tensorflow package: + +1. Create the tensorflow build environment: + +```bash +mamba env create -f environment.tensorflow.yml -n tf +``` + +2. Activate the tensorflow build environment: + +```bash +mamba activate tf +``` + +3. Build the tensorflow conda package: + +#### Mac + +```bash +conda build --debug.conda.tensorflow_macos --output-folder build.tensorflow_macos -c conda-forge +``` + +4. Test the conda package: + +#### Mac + +```bash +mamba create -n tf_macos -c ./build.tensorflow_macos -c conda-forge tensorflow +``` diff --git a/environment.tensorflow.yml b/environment.tensorflow.yml new file mode 100644 index 0000000..c2a03ea --- /dev/null +++ b/environment.tensorflow.yml @@ -0,0 +1,12 @@ +name: tf + +channels: + - conda-forge + - anaconda + - defaults + +dependencies: +- conda-build +- anaconda-client +- conda-verify +- pip diff --git a/requirements.tensorflow_macos.txt b/requirements.tensorflow_macos.txt new file mode 100644 index 0000000..442893c --- /dev/null +++ b/requirements.tensorflow_macos.txt @@ -0,0 +1,4 @@ +tensorflow-macos>=2.12.0,<2.13.0; sys_platform == 'darwin' and platform_machine == 'arm64' # lowest version with protobuf>3.20 +tensorflow-metal; sys_platform == 'darwin' and platform_machine == 'arm64' +tensorflow-hub; sys_platform == 'darwin' and platform_machine == 'arm64' +protobuf>3.20; sys_platform == 'darwin' and platform_machine == 'arm64' \ No newline at end of file