Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tensorflow-macos conda package #2

Merged
merged 62 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
e9f376f
update .gitignore
eberrigan Jul 15, 2024
62ed72c
add windows/linux tensorflow conda package files from conda_packages …
eberrigan Jul 15, 2024
9352226
update environment name
eberrigan Jul 15, 2024
b73b2fe
add workflow to build tensorflow conda package
eberrigan Jul 15, 2024
7d49ee8
update environment file which is not building, possible because of co…
eberrigan Jul 15, 2024
4cb9e93
fix workflow: python version needs to be in quotes and each step shou…
eberrigan Jul 15, 2024
edf7054
try different minor version
eberrigan Jul 15, 2024
dafb8a0
add channel arg to upload
eberrigan Jul 15, 2024
c21f936
try to enable long path support in the windows runner
eberrigan Jul 16, 2024
0dba2f0
try 2.8.0
eberrigan Jul 16, 2024
1d5356e
try different github action checkout version
eberrigan Jul 16, 2024
8a4b53c
go back to 2.9.0
eberrigan Jul 16, 2024
2c01956
Try shorter env name
eberrigan Jul 16, 2024
5b5e770
enabling windows long path does not work locally or on the runner
eberrigan Jul 16, 2024
7ed35d2
try to shorten path using substitution
eberrigan Jul 16, 2024
4b3ac3e
need drive letter
eberrigan Jul 16, 2024
ba73c99
create shortened link on windows
eberrigan Jul 16, 2024
439d633
try substitution for input and output
eberrigan Jul 16, 2024
7fd0f6a
tf 2.9.2
eberrigan Jul 16, 2024
077a6c5
try to shorten environment path with `CONDA_PREFIX`
eberrigan Jul 16, 2024
f64be4a
correct conda prefix
eberrigan Jul 16, 2024
09c2ef6
debug build
eberrigan Jul 16, 2024
ce6f90b
add prefix to build command
eberrigan Jul 16, 2024
4cf6d97
try to config environment path
eberrigan Jul 16, 2024
f754b20
setup-miniconda supports paths as environment names
eberrigan Jul 16, 2024
fe8cc02
fix ubuntu environment path
eberrigan Jul 16, 2024
902e34a
fix version and try to test import
eberrigan Jul 16, 2024
9783bd3
setup Miniconda depends on os
eberrigan Jul 16, 2024
58274a0
try to upload using token
eberrigan Jul 16, 2024
17e5220
try to upload without a password
eberrigan Jul 16, 2024
8c1e17b
`ANACONDA_API_TOKEN` may automatically authenticate
eberrigan Jul 16, 2024
50f3871
remove windows long path support that doesn't work
eberrigan Jul 16, 2024
027421a
turnoff upload for now
eberrigan Jul 16, 2024
f947a3d
add macos initial files
eberrigan Jul 16, 2024
ffe29ff
login with `ANACONDA_PASSWORD instead of API token and upload Windows…
eberrigan Jul 17, 2024
3947b3a
add branch to action to test
eberrigan Jul 17, 2024
10a9dc8
user needs to enter "yes" for anaconda login to work
eberrigan Jul 17, 2024
fe891c1
fix build path and try `ANACONDA_LOGIN`
eberrigan Jul 17, 2024
8f1ae1a
troubleshoot login
eberrigan Jul 17, 2024
ffbcf9d
change password and troubleshoot login again
eberrigan Jul 17, 2024
261dea4
don't need echo yes when testing locally
eberrigan Jul 17, 2024
08768da
build conda packages
eberrigan Jul 17, 2024
3cdfe42
make build script for macos
eberrigan Jul 17, 2024
9ca243b
make minimal meta.yaml for tensorflow-macos to test
eberrigan Jul 17, 2024
b112905
add macos to workflow
eberrigan Jul 17, 2024
358bc74
add all packages installed via pip for requirements in macos meta.yam…
eberrigan Jul 18, 2024
2f705b3
remove tensorflow and tensorboard packages from meta.yaml for macos
eberrigan Jul 18, 2024
c208ade
can't find mac requirements
eberrigan Jul 18, 2024
2f82c47
numpy error since tensorflow is compiled with numpy 1.x
eberrigan Jul 18, 2024
65b261f
add comment for source path after can't find requirements in action
eberrigan Jul 18, 2024
9536714
change package name to tensorflow since sleap imports tensorflow
eberrigan Jul 18, 2024
f4e3917
remove packages were conda-forge not found and install markdown via a…
eberrigan Jul 18, 2024
e8823ad
clean up macos meta.yaml
eberrigan Jul 18, 2024
9967a90
see if we can upload to anaconda using API token on macos runner
eberrigan Jul 18, 2024
94782cc
fix build path for macos
eberrigan Jul 18, 2024
aac3d91
ANACONDA_API_TOKEN results in 401 error for macos as well as windows …
eberrigan Jul 18, 2024
1d53c72
Build a working tensorflow==2.12.0 for macos
Aug 31, 2024
cb4be54
Do use runner to build (already built manually)
Aug 31, 2024
37e2205
Remove all out-of-scope code
roomrys Sep 11, 2024
5414f2e
Add instructions for manually building/installing tensorflow on Mac
roomrys Sep 11, 2024
32fdc17
Increase build number and trigger action
roomrys Sep 11, 2024
66a73be
Actually trigger the build
roomrys Sep 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .conda.tensorflow_macos/build.sh
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions .conda.tensorflow_macos/meta.yaml
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions .github/workflows/build_tensorflow.yml
Original file line number Diff line number Diff line change
@@ -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
38 changes: 4 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
Expand Down Expand Up @@ -49,7 +50,6 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -72,7 +72,6 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.*/
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
12 changes: 12 additions & 0 deletions environment.tensorflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: tf

channels:
- conda-forge
- anaconda
- defaults

dependencies:
- conda-build
- anaconda-client
- conda-verify
- pip
4 changes: 4 additions & 0 deletions requirements.tensorflow_macos.txt
Original file line number Diff line number Diff line change
@@ -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'