Skip to content

Commit 82e473a

Browse files
poinwaterrhdong
authored andcommitted
[cicd]Enhance project's compatibility
1 parent bc082b7 commit 82e473a

36 files changed

+304
-159
lines changed

.github/workflows/make_wheel_Linux_x86.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ else
1111
export TF_NAME='tensorflow'
1212
fi
1313

14-
if [ $TF_VERSION == "2.6.3" ] || [ $TF_VERSION == "2.8.3" ] ; then
14+
# if tensorflow version >= 2.6.0 and <= 2.11.9
15+
if [[ "$TF_VERSION" =~ ^2\.([6-9]|10|11)\.[0-9]$ ]] ; then
1516
export BUILD_IMAGE="tfra/nosla-cuda11.2.1-cudnn8-ubuntu20.04-manylinux2014-python$PY_VERSION"
1617
export TF_CUDA_VERSION="11.2"
1718
export TF_CUDNN_VERSION="8.1"

.github/workflows/make_wheel_macOS_arm64.sh

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,37 @@
22
#
33
# Making wheel for macOS arm64 architecture
44
# Requirements:
5-
# MacOS Monterey 12.0.0 +, Tensorflow-macos 2.6.0 or 2.8.0, ARM64 Apple Silicon, Bazel 4.1.0 +
5+
# MacOS Monterey 12.0.0 +, Tensorflow-macos 2.6.0 - 2.11.0, ARM64 Apple Silicon, Bazel 5.1.1
66
# Please don't install tensorflow-metal, it may cause incorrect GPU devices detection issue.
77
set -e -x
88

9+
export TF_NEED_CUDA=0
10+
if [ -z $HOROVOD_VERSION ] ; then
11+
export HOROVOD_VERSION='0.28.1'
12+
fi
13+
14+
# For TensorFlow version 2.12 or earlier:
15+
export PROTOBUF_VERSION=3.19.6
16+
export TF_NAME="tensorflow-macos"
17+
918
python --version
19+
python -m pip install --default-timeout=1000 delocate==0.10.3 wheel setuptools
20+
# For TensorFlow version 2.13 or later:
21+
if [[ "$TF_VERSION" =~ ^2\.1[3-9]\.[0-9]$ ]] ; then
22+
export PROTOBUF_VERSION=3.20.3
23+
export TF_NAME="tensorflow"
24+
fi
25+
26+
python -m pip install \
27+
--platform=macosx_12_0_arm64 \
28+
--target=$(python -c 'import site; print(site.getsitepackages()[0])') \
29+
--upgrade \
30+
--only-binary=:all: \
31+
protobuf~=$PROTOBUF_VERSION $TF_NAME==$TF_VERSION
1032

1133
python configure.py
34+
# Setting DYLD_LIBRARY_PATH to help delocate finding tensorflow after the rpath invalidation
35+
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(python -c 'import configure; print(configure.get_tf_shared_lib_dir())')
1236

1337
bazel build \
1438
--cpu=darwin_arm64 \
@@ -20,5 +44,5 @@ bazel build \
2044
--test_output=errors \
2145
build_pip_pkg
2246

23-
# Output the wheel file to the artifacts directory
24-
bazel-bin/build_pip_pkg artifacts $NIGHTLY_FLAG
47+
bazel-bin/build_pip_pkg artifacts "--plat-name macosx_11_0_arm64 $NIGHTLY_FLAG"
48+
delocate-wheel -w wheelhouse -v --ignore-missing-dependencies artifacts/*.whl

.github/workflows/make_wheel_macOS_x86.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,39 @@ set -e -x
22

33
export TF_NEED_CUDA=0
44
if [ -z $HOROVOD_VERSION ] ; then
5-
export HOROVOD_VERSION='0.23.0'
5+
export HOROVOD_VERSION='0.28.1'
66
fi
77
python --version
88

99
brew install open-mpi
10-
python -m pip install numpy==1.20.0
11-
python -m pip install --default-timeout=1000 delocate==0.9.1 wheel==0.36.2 setuptools tensorflow==$TF_VERSION
10+
python -m pip install --default-timeout=1000 delocate==0.10.3 wheel==0.36.2 setuptools tensorflow==$TF_VERSION
1211
python -m pip install tensorflow-io
1312
python -m pip install --upgrade protobuf==3.20.0
1413

1514
bash tools/docker/install/install_horovod.sh $HOROVOD_VERSION --only-cpu
1615

17-
bash tools/testing/build_and_run_tests.sh
16+
# Test
17+
bash tools/testing/build_and_run_tests.sh $SKIP_CUSTOM_OP_TESTS
18+
19+
# Clean
20+
bazel clean
21+
22+
# Build
23+
python configure.py
1824

1925
bazel build \
2026
-c opt \
21-
--copt -mmacosx-version-min=10.13 \
22-
--linkopt -mmacosx-version-min=10.13 \
27+
--copt -mmacosx-version-min=10.15 \
28+
--linkopt -mmacosx-version-min=10.15 \
2329
--noshow_progress \
2430
--noshow_loading_progress \
2531
--verbose_failures \
2632
--test_output=errors \
2733
build_pip_pkg
2834

2935
bazel-bin/build_pip_pkg artifacts $NIGHTLY_FLAG
30-
delocate-wheel -w wheelhouse artifacts/*.whl
36+
37+
# Setting DYLD_LIBRARY_PATH to help delocate finding tensorflow after the rpath invalidation
38+
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$(python -c 'import configure; print(configure.get_tf_shared_lib_dir())')
39+
delocate-wheel -w wheelhouse -v --ignore-missing-dependencies artifacts/*.whl
3140

.github/workflows/release.yml

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616

1717
env:
1818
MIN_PY_VERSION: '3.7'
19-
MAX_PY_VERSION: '3.9'
19+
MAX_PY_VERSION: '3.10'
2020
HOROVOD_VERSION: '0.23.0'
2121

2222
jobs:
@@ -25,12 +25,12 @@ jobs:
2525
runs-on: ubuntu-20.04
2626
steps:
2727
- uses: actions/checkout@v2
28-
- uses: actions/setup-python@v1
28+
- uses: actions/setup-python@v2
2929
with:
30-
python-version: ${{ env.MIN_PY_VERSION }}
30+
python-version: ${{ env.MAX_PY_VERSION }}
3131
- name: Build wheels
3232
run: |
33-
pip install --default-timeout=1000 -r tools/install_deps/pytest.txt -r tools/install_deps/tensorflow-cpu.txt -r requirements.txt
33+
pip install --default-timeout=1000 -r tools/install_deps/pytest.txt -r tools/install_deps/tensorflow.txt -r requirements.txt
3434
sudo apt install -y redis > /dev/null 2> /dev/null
3535
bash tools/install_deps/install_bazelisk.sh ./
3636
python -m pip install tensorflow-io
@@ -39,29 +39,22 @@ jobs:
3939
bazel test --local_ram_resources=4096 -c opt -k --test_timeout 300,450,1200,3600 --test_output=errors //tensorflow_recommenders_addons/...
4040
release-wheel:
4141
name: Build release wheels
42-
runs-on: ${{ matrix.os }}
4342
strategy:
4443
matrix:
4544
# TODO: add back 'windows-latest' when it can be compiled.
4645
os: ['macos-12', 'ubuntu-20.04']
47-
py-version: ['3.7', '3.8', '3.9']
48-
tf-version: ['2.6.3', '2.8.3']
49-
tf-need-cuda: ['1', '0']
46+
py-version: ['3.7', '3.8', '3.9', '3.10']
47+
tf-version: ['2.8.3', '2.11.0']
48+
tf-need-cuda: ['0', '1']
5049
tf-cuda-version: ['11.2']
5150
tf-cudnn-version: ['8.1']
5251
cpu: ['x86']
53-
# TODO(poinwater): add macOS CI once GitHub supports macOS 12.0.0 +
54-
# include:
55-
# - os: 'macos-11'
56-
# cpu: 'arm64'
57-
# tf-version: '2.5.0'
58-
# py-version: '3.9'
59-
# tf-need-cuda: '0'
6052
exclude:
6153
# excludes cuda on macOS
6254
- os: 'macos-12'
6355
tf-need-cuda: '1'
6456
fail-fast: false
57+
runs-on: ${{ matrix.os }}
6558
steps:
6659
- name: clear cache folder
6760
run: rm -rf /usr/share/dotnet /opt/ghc "/usr/local/share/boost"
@@ -72,11 +65,14 @@ jobs:
7265
script: |
7366
const commit_details = await github.git.getCommit({owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha});
7467
return commit_details.data.author.date
68+
- if: matrix.tf-version != '2.11.0'
69+
shell: bash
70+
run: echo "SKIP_CUSTOM_OP_TESTS=--skip-custom-ops" >> $GITHUB_ENV
7571
- if: github.event_name == 'push'
7672
shell: bash
7773
run: echo "NIGHTLY_FLAG=--nightly" >> $GITHUB_ENV
7874
- uses: actions/checkout@v2
79-
- uses: actions/setup-python@v1
75+
- uses: actions/setup-python@v2
8076
with:
8177
python-version: ${{ matrix.py-version }}
8278
- name: Setup Bazel
@@ -94,7 +90,11 @@ jobs:
9490
NIGHTLY_TIME: ${{ steps.author-date.outputs.result }}
9591
CPU: ${{ matrix.cpu }}
9692
shell: bash
97-
run: bash .github/workflows/make_wheel_${OS}_${CPU}.sh
93+
run: |
94+
if [[ "$TF_VERSION" =~ ^2\.(9|10|11)\.[0-9]$ ]] ; then
95+
export HOROVOD_VERSION="0.28.1"
96+
fi
97+
bash .github/workflows/make_wheel_${OS}_${CPU}.sh
9898
- uses: haya14busa/action-cond@v1
9999
id: device
100100
with:
@@ -113,17 +113,9 @@ jobs:
113113
matrix:
114114
# TODO: add back 'Windows' when it can be compiled.
115115
os: ['macOS', 'Linux']
116-
py-version: ['3.7', '3.8', '3.9']
117-
tf-version: ['2.8.3']
118-
tf-need-cuda: ['1', '0']
116+
py-version: ['3.7', '3.8', '3.9', '3.10']
117+
tf-need-cuda: ['0', '1']
119118
cpu: ['x86']
120-
# TODO(poinwater): add macOS CI once GitHub supports macOS 12.0.0 +
121-
# include:
122-
# - os: 'macOS'
123-
# cpu: 'arm64'
124-
# tf-version: '2.5.0'
125-
# py-version: '3.9'
126-
# tf-need-cuda: '0'
127119
exclude:
128120
# excludes cuda on macOS
129121
- os: 'macOS'
@@ -155,7 +147,7 @@ jobs:
155147
runs-on: ubuntu-20.04
156148
strategy:
157149
matrix:
158-
py-version: ['3.7', '3.8', '3.9']
150+
py-version: ['3.7', '3.8', '3.9', '3.10']
159151
if: (github.event_name == 'push' && github.ref == 'refs/heads/master')
160152
steps:
161153
- uses: actions/checkout@v2

README.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,36 +192,26 @@ pip install artifacts/tensorflow_recommenders_addons_gpu-*.whl
192192
Requirements:
193193

194194
- macOS 12.0.0+
195-
- Python 3.8 or 3.9
196-
- tensorflow-macos 2.6.0
197-
- bazel 4.1.0+
195+
- Python 3.9
196+
- tensorflow-macos 2.9.0
197+
- bazel 5.1.1
198198

199199
The natively supported TensorFlow is maintained by Apple. Please see the instruction [Get started with tensorflow-metal](https://developer.apple.com/metal/tensorflow-plugin/) to install the Tensorflow on apple silicon devices.
200200

201201

202-
```sh
203-
# Install TensorFlow macOS dependencies
204-
conda install -c apple tensorflow-deps==2.6.0
205-
206-
# Install base TensorFlow
207-
python -m pip install tensorflow-macos==2.6.0
208-
```
209-
210-
If you see any issue with installing `tensorflow-macos`, please contact the [Apple Developer Forums: tensorflow-metal](https://developer.apple.com/forums/tags/tensorflow-metal) for help.
211-
212202
**Install TFRA on Apple Silicon via PIP**
213203
```sh
214204
python -m pip install tensorflow-recommenders-addons --no-deps
215205
```
216206

217-
**Install TFRA on Apple Silicon from Source**
207+
**Build TFRA on Apple Silicon from Source**
218208

219209
```sh
220-
export TF_VERSION="2.6.0" # Specify your Tensorflow version here, 2.8.0 is well tested.
221-
export PY_VERSION="3.8" # Specify your python version here, "3.9" is well tested.
210+
# Install bazelisk
211+
brew install bazelisk
222212

223-
# Building TFRA wheel
224-
PY_VERSION=$PY_VERSION TF_VERSION=$TF_VERSION TF_NEED_CUDA="0" sh .github/workflows/make_wheel_macOS_arm64.sh
213+
# Build wheel from source
214+
PY_VERSION=3.9.0 TF_VERSION=2.9.0 TF_NEED_CUDA="0" sh .github/workflows/make_wheel_macOS_arm64.sh
225215

226216
# Install the wheel
227217
python -m pip install --no-deps ./artifacts/*.whl

configure.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,24 @@
2121
import logging
2222

2323
import tensorflow as tf
24+
try:
25+
from packaging.version import Version
26+
except: # make it compatible for python 3.7
27+
from distutils.version import LooseVersion as Version
2428

2529
_TFRA_BAZELRC = ".bazelrc"
2630

2731

2832
# Maping TensorFlow version to valid Bazel version.
2933
def _VALID_BAZEL_VERSION(tf_version):
30-
if is_macos() and is_arm64():
31-
target_bazel = "4.1.0"
32-
return target_bazel
33-
elif tf_version < "2.0.0":
34+
if Version(tf_version) < Version("2.0.0"):
3435
target_bazel = "0.26.1"
3536
logging.warn(
3637
'There is only limited support for TensorFlow under version 2.0.0 '
3738
'because its Bazel version, and requiring users to make some Bazel script changes '
3839
'refering to the previous COMMIT to compile properly by themselves.')
3940
return target_bazel
40-
elif tf_version >= "2.0.0":
41+
elif Version(tf_version) >= Version("2.0.0"):
4142
target_bazel = "5.1.1"
4243
logging.info(
4344
'To ensure code compatibility with Bazel rules_foreign_cc component, '
@@ -78,6 +79,13 @@ def is_raspi_arm():
7879
return os.uname()[4] == "armv7l"
7980

8081

82+
def get_cpp_version():
83+
cpp_version = "c++14"
84+
if Version(tf.__version__) >= Version("2.10"):
85+
cpp_version = "c++17"
86+
return cpp_version
87+
88+
8189
def get_tf_header_dir():
8290
if get_tf_version_integer() >= 2000:
8391
tf_header_dir = tf.sysconfig.get_compile_flags()[0][2:]
@@ -104,7 +112,10 @@ def get_tf_shared_lib_dir():
104112
# Converts the linkflag namespec to the full shared library name
105113
def get_shared_lib_name():
106114
namespec = tf.sysconfig.get_link_flags()
107-
if is_macos():
115+
if is_macos() and is_arm64():
116+
# MacOS arm64
117+
return "libtensorflow_framework.2.dylib"
118+
elif is_macos():
108119
# MacOS
109120
return "libtensorflow_framework.dylib"
110121
elif is_windows():
@@ -177,14 +188,9 @@ def _get_installed_and_valid_bazel_version():
177188
def check_bazel_version(is_macos_arm64: bool = False):
178189
installed_bazel_version, valid_bazel_version = _get_installed_and_valid_bazel_version(
179190
)
180-
if installed_bazel_version < valid_bazel_version:
181-
if is_macos_arm64:
182-
raise ValueError(
183-
'Bazel version is {}. For macOS arm64 platform, the Bazel version must be at least {}.'
184-
.format(installed_bazel_version, valid_bazel_version))
185-
else:
186-
raise ValueError('Bazel version is {}, but {} is needed.'.format(
187-
installed_bazel_version, valid_bazel_version))
191+
if Version(installed_bazel_version) < Version(valid_bazel_version):
192+
raise ValueError('Bazel version is {}, but {} is needed.'.format(
193+
installed_bazel_version, valid_bazel_version))
188194

189195

190196
def extract_tf_header():
@@ -227,7 +233,7 @@ def create_build_configuration():
227233
else:
228234
tf_cxx_standard_compile_flag = None
229235
if tf_cxx_standard_compile_flag is None:
230-
tf_cxx_standard = "c++14"
236+
tf_cxx_standard = get_cpp_version()
231237
else:
232238
tf_cxx_standard = tf_cxx_standard_compile_flag.split("-std=")[-1]
233239
write_action_env("TF_CXX_STANDARD", tf_cxx_standard)

demo/dynamic_embedding/amazon-video-games-keras-eager/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import tensorflow as tf
44

55
from tensorflow_recommenders_addons import dynamic_embedding as de
6+
try:
7+
from tensorflow.keras.optimizers.legacy import Adam
8+
except:
9+
from tensorflow.keras.optimizers import Adam
610

711
from absl import flags
812
from absl import app
@@ -29,7 +33,7 @@ def train(num_steps):
2933
# Create a model
3034
model = video_game_model.VideoGameDnn(batch_size=FLAGS.batch_size,
3135
embedding_size=FLAGS.embedding_size)
32-
optimizer = tf.keras.optimizers.Adam(1E-3, clipnorm=None)
36+
optimizer = Adam(1E-3, clipnorm=None)
3337
optimizer = de.DynamicEmbeddingOptimizer(optimizer)
3438
auc = tf.keras.metrics.AUC(num_thresholds=1000)
3539
accuracy = tf.keras.metrics.BinaryAccuracy(dtype=tf.float32)

demo/dynamic_embedding/movielens-1m-keras-ps/movielens-1m-keras-ps.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from absl import flags
66
from absl import app
77
from tensorflow_recommenders_addons import dynamic_embedding as de
8+
try:
9+
from tensorflow.keras.optimizers.legacy import Adam
10+
except:
11+
from tensorflow.keras.optimizers import Adam
812

913
flags = tf.compat.v1.app.flags
1014
FLAGS = flags.FLAGS
@@ -141,7 +145,7 @@ def train(self):
141145
model = DualChannelsDeepModel(
142146
self.ps_devices, self.embedding_size, self.embedding_size,
143147
tf.keras.initializers.RandomNormal(0.0, 0.5))
144-
optimizer = tf.keras.optimizers.Adam(1E-3)
148+
optimizer = Adam(1E-3)
145149
optimizer = de.DynamicEmbeddingOptimizer(optimizer)
146150

147151
auc = tf.keras.metrics.AUC(num_thresholds=1000)

0 commit comments

Comments
 (0)