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 Windows and Linux TensorFlow Package #1

Merged
merged 57 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 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
6bdfba9
Remove unnecessary code
roomrys Sep 11, 2024
99d1918
Use correct version number & reset build number
roomrys Sep 11, 2024
1c80e55
Merge branch 'main' of https://github.com/talmolab/sleap-deps into el…
roomrys Sep 11, 2024
84c6d32
Use anaconda password instead of token
roomrys Sep 11, 2024
220ac77
Use ' instaead of " in if statements
roomrys Sep 11, 2024
fb301ba
Document manual win/linux pacakge testing
roomrys Sep 11, 2024
a872855
Consolidate workflow and separate build and upload jobs
Sep 12, 2024
40655b2
Ensure build job runs before upload job
Sep 12, 2024
72fb5bf
Use powershell to build Windows packages
roomrys Sep 12, 2024
43164a5
Do not use jinja templating in name
roomrys Sep 12, 2024
39b4275
Make conda prefix directory shorter again
roomrys Sep 12, 2024
57f42cb
Use ' not "
roomrys Sep 12, 2024
67c8e92
Use jinja formatting for shell
roomrys Sep 12, 2024
8e6b49b
Split build into windows and not windows
roomrys Sep 12, 2024
d01872e
Add back check for runner in build conda step
roomrys Sep 12, 2024
3484d39
Change output folder to build
roomrys Sep 12, 2024
4568310
Retry download (w/o build)
roomrys Sep 12, 2024
53d2a62
Always run set-up miniconda and upload to anaconda
roomrys Sep 12, 2024
8e0aa8e
Add a repo checkout before setup miniconda
roomrys Sep 12, 2024
0419f8f
Always run checkout
roomrys Sep 12, 2024
4d2047c
List items in current directory
roomrys Sep 12, 2024
96962bc
Move checkout to the top and list to bottom
roomrys Sep 12, 2024
a3f8935
List current working directory
roomrys Sep 12, 2024
a4b464d
Move set-up python and miniconda before download
roomrys Sep 12, 2024
8833e8b
Separate upload for windows and not windows
roomrys Sep 12, 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/bld.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@echo off

set PIP_NO_INDEX=False
set PIP_NO_DEPENDENCIES=False
set PIP_IGNORE_INSTALLED=False

pip install --no-cache-dir -r .\requirements.tensorflow.txt
15 changes: 15 additions & 0 deletions .conda.tensorflow/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/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.txt

# Copy the activate scripts to $PREFIX/etc/conda/activate.d.
# This will allow them to be run on environment activation.
for CHANGE in "activate" "deactivate"
do
mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d"
cp "${RECIPE_DIR}/tensorflow_${CHANGE}.sh" "${PREFIX}/etc/conda/${CHANGE}.d/tensorflow_${CHANGE}.sh"
done
51 changes: 51 additions & 0 deletions .conda.tensorflow/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Ref: https://docs.conda.io/projects/conda-build/en/latest/resources/define-metadata.html

package:
name: tensorflow
version: 2.9.2

about:
home: https://tensorflow.org
license: Apache License
summary: 'TensorFlow conda package based on the PyPI wheels.

For GPU support, install cudatoolkit 11.3.1 and cudnn 8.2.1 which are available as conda packages on the default channel.'

build:
number: 0

source:
path: ../

requirements:
build:
- '{{ compiler("c") }}'
- '{{ compiler("cxx") }}'

host:
- python>=3.10.0,<3.11.0
- numpy
- h5py
- protobuf
- certifi
- importlib-metadata
- six
- typing-extensions
- zipp
- pip

run:
- python>=3.10.0,<3.11.0
- numpy
- h5py
- protobuf
- certifi
- importlib-metadata
- six
- typing-extensions
- zipp
- pip

test:
imports:
- tensorflow
6 changes: 6 additions & 0 deletions .conda.tensorflow/tensorflow_activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

# Remember the old library path for when we deactivate
export SLEAP_OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
# Help CUDA find GPUs!
export LD_LIBRARY_PATH=$CONDA_PREFIX/lib:$LD_LIBRARY_PATH
4 changes: 4 additions & 0 deletions .conda.tensorflow/tensorflow_deactivate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

# Reset to the old library path for when deactivating the environment
export LD_LIBRARY_PATH=$SLEAP_OLD_LD_LIBRARY_PATH
126 changes: 114 additions & 12 deletions .github/workflows/build_tensorflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,156 @@ on:
push:
branches:
- main
- elizabeth/add-tensorflow-macos-conda-package
- elizabeth/add-windows-linux-tensorflow-conda-package

paths:
- ".github/workflows/build_tensorflow.yml"
- ".conda.tensorflow/**"
- ".conda.tensorflow_macos/**"
- "environment.tensorflow.yml"
- "requirements.tensorflow.txt"
- "requirements.tensorflow_macos.txt"

# If RUN_BUILD_JOB is set to true, then RUN_ID will be overwritten to the current run id
env:
RUN_BUILD_JOB: false # TODO(LM): Set to true
RUN_ID: 10824742361 # Only used if RUN_BUILD_JOB is false (to dowload build artifact)

jobs:
build:
name: Build package (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
fail-fast: true
matrix:
os: ["macos-14"]
os: ["ubuntu-22.04", "windows-2022", "macos-14"]
include:
- os-folder: linux-64
- build-folder: .conda.tensorflow
- os: "windows-2022"
os-folder: win-64
env-prefix: C:\c\
- os: "macos-14"
os-folder: osx-arm64
build-folder: .conda.tensorflow_macos
steps:
# Checkout the repository
- name: Checkout
if: env.RUN_BUILD_JOB == 'true'
uses: actions/checkout@v4

- name: Setup Miniconda (Ubuntu and MacOS)
if: matrix.os == 'macos-14'
- name: Make conda prefix directory (Windows)
if: matrix.os == 'windows-2022'
shell: powershell
run: |
New-Item -ItemType Directory -Force -Path ${{ matrix.env-prefix }}

- name: Setup Miniconda
if: env.RUN_BUILD_JOB == 'true'
uses: conda-incubator/setup-miniconda@v3.0.3
with:
python-version: "3.10"
environment-file: environment.tensorflow.yml
activate-environment: tf
activate-environment: ${{ matrix.env-prefix }}tf

- name: Print environment info
if: env.RUN_BUILD_JOB == 'true'
shell: bash -l {0}
run: |
which python
conda info
conda list

- name: Build conda package (MacOS)
if: matrix.os == 'macos-14'
- name: Build conda package (Windows)
if: (runner.os == 'Windows') && (env.RUN_BUILD_JOB == 'true')
shell: powershell
run: |
conda build --debug ${{ matrix.build-folder }} --output-folder ${{ matrix.env-prefix }}build -c conda-forge

- name: Build conda package (not Windows)
if: (runner.os != 'Windows') && (env.RUN_BUILD_JOB == 'true')
shell: bash -l {0}
run: |
conda build --debug .conda.tensorflow_macos --output-folder build.tensorflow_macos -c conda-forge
conda build --debug ${{ matrix.build-folder }} --output-folder build -c conda-forge

# Upload the build artifact incase anaconda upload fails
- name: Upload conda package artifact
if: env.RUN_BUILD_JOB == 'true'
uses: actions/upload-artifact@v4
with:
name: tensorflow-build-${{ matrix.os-folder }}
path: ${{ matrix.env-prefix }}build # Upload entire build directory
retention-days: 1

upload:
name: Upload package (${{ matrix.os }})
runs-on: ${{ matrix.os }}
needs: build
strategy:
fail-fast: false # TODO(LM): Set to true
matrix:
os: ["ubuntu-22.04", "windows-2022", "macos-14"]
include:
- os-folder: win-64
- os: "ubuntu-22.04"
os-folder: linux-64
- os: "macos-14"
os-folder: osx-arm64

steps:
# Checkout the repository
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.pyver }}

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v3.0.3
with:
python-version: "3.10"
environment-file: environment.tensorflow.yml
activate-environment: tf

- name: Use current run id for conda package download
shell: bash -l {0}
if: env.RUN_BUILD_JOB == 'true'
run: echo "RUN_ID=${{ github.run_id }}" >> $GITHUB_ENV

# https://github.com/actions/download-artifact?tab=readme-ov-file#usage
- name: Download conda package artifact
uses: actions/download-artifact@v4
id: download
with:
name: tensorflow-build-${{ matrix.os-folder }}
path: build
run-id: ${{ env.RUN_ID }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: List items in current directory
shell: bash -l {0}
run: |
ls .
ls -R build

- name: Upload to Anaconda (Windows)
if: runner.os == 'Windows'
env:
ANACONDA_PASSWORD: ${{ secrets.ANACONDA_PASSWORD }}
shell: bash -l {0}
run: |
anaconda login --username sleap-deps --password "$ANACONDA_PASSWORD"
anaconda -v upload "build/${{ matrix.os-folder }}/*.tar.bz2" --label dev --user sleap-deps
anaconda logout

- name: Upload to Anaconda (MacOS)
if: matrix.os == 'macos-14'
- name: Upload to Anaconda (not Windows)
if: runner.os != 'Windows'
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 -v upload build/${{ matrix.os-folder }}/*.tar.bz2 --label dev --user sleap-deps
anaconda logout
34 changes: 19 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@ There is a Github Actions workflow `build_tensorflow.yml` that uses Github runne

1. Create the tensorflow build environment:

```bash
mamba env create -f environment.tensorflow.yml -n tf
```
```bash
mamba env create -f environment.tensorflow.yml -n tf
```

2. Activate the tensorflow build environment:

```bash
mamba activate tf
```
```bash
mamba activate tf
```

3. Build the tensorflow conda package:

#### Mac
#### Windows or Linux

```bash
conda build --debug.conda.tensorflow_macos --output-folder build.tensorflow_macos -c conda-forge
```
```bash
conda build --debug .conda.tensorflow --output-folder build.tensorflow -c conda-forge
```

4. Test the conda package:
#### Mac

```bash
conda build --debug .conda.tensorflow_macos --output-folder build.tensorflow -c conda-forge
```

#### Mac
4. Test the conda package:

```bash
mamba create -n tf_macos -c ./build.tensorflow_macos -c conda-forge tensorflow
```
```bash
mamba create -n tf_build -c ./build.tensorflow -c conda-forge tensorflow
```
4 changes: 4 additions & 0 deletions requirements.tensorflow.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# tensorflow==2.10.1 # https://github.com/talmolab/sleap/issues/1721
# tensorflow==2.7.0 # 2.7.0 worked in the past
# tensorflow==2.9.0 # Trying to match the version of tensorflow-macos filename too long?
tensorflow==2.9.2 # 2.9.2 is the latest version in the 2.9 series
Loading