Skip to content

Commit 75e1d37

Browse files
CNugterenTombana
andauthored
Update Tensorflow to 2.16.1 (#805)
* Update TensorFlow to v2.16.1 * Update Bazel and bazelrc file * Update WORKSPACE with TF changes Uses hermetic Python * Update MLIR build target paths * Rename `--remote_http_cache` to `--remote_cache` Disable read-only cache on PR * Add explicit Python package requirements * Remove `pip install` because of Hermetic Python * Update filecheck test patterns * Replace `llvm::Optional` by `std::optional` * TF_USE_LEGACY_KERAS in bazel * Update Android NDK configuration in `configure.py` * Update `build_lce_aar.sh` * Update MLIR passes * Fix release macOS runners * Fix artifact v4 actions * Simplify upload-wheels job * Run `pip-compile` in Windows release * Add `disable_forced_mkl.patch` * Use Github actions temp disk as bazel root * Use an even shorter bazel root dir on Windows * Shorten workspace name on Windows * Add `addBenefit` for quantization pattern --------- Co-authored-by: Tom Bannink <tombannink@gmail.com>
1 parent 3f57a37 commit 75e1d37

38 files changed

+1017
-355
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.3.0
1+
6.5.0

.github/tools/release_linux.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ set -e -x
33

44
python configure.py
55

6-
# Build
7-
bazel build :build_pip_pkg \
6+
# Inside the docker container on github actions there is not
7+
# enough space for the bazel cache, but a larger disk is mounted at /github_disk
8+
# so we tell bazel to store everything there
9+
10+
# `release_cpu_linux` will activate absolute paths to files that only exist in the tensorflow/build:2.16-pythonXX docker container
11+
bazel --output_user_root=/github_disk/bazel_root \
12+
build :build_pip_pkg \
13+
-c opt \
14+
--config=release_cpu_linux \
815
--copt=-fvisibility=hidden \
9-
--copt=-mavx \
10-
--distinct_host_configuration=false \
11-
--verbose_failures \
12-
--crosstool_top=@ubuntu20.04-gcc9_manylinux2014-cuda11.2-cudnn8.1-tensorrt7.2_config_cuda//crosstool:toolchain
16+
--verbose_failures
1317

1418
# Package Whl
1519
bazel-bin/build_pip_pkg artifacts

.github/workflows/release.yml

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
if: steps.cache.outputs.cache-hit != 'true'
3737
run: ./third_party/install_android.sh
3838
- name: Configure Bazel
39-
run: LCE_SET_ANDROID_WORKSPACE=1 ANDROID_SDK_HOME="/tmp/lce_android" ANDROID_NDK_HOME="/tmp/lce_android/ndk/21.4.7075529" ./configure.py
39+
run: LCE_SET_ANDROID_WORKSPACE=1 ANDROID_SDK_HOME="/tmp/lce_android" ANDROID_API_LEVEL=30 ANDROID_NDK_HOME="/tmp/lce_android/ndk/25.2.9519653" ANDROID_NDK_API_LEVEL=30 ANDROID_BUILD_TOOLS_VERSION=31.0.0 ./configure.py
4040
shell: bash
4141
- run: mkdir benchmark-binaries
4242
- name: Build Benchmark utility for AArch64
@@ -108,7 +108,7 @@ jobs:
108108
if: steps.cache.outputs.cache-hit != 'true'
109109
run: ./third_party/install_android.sh
110110
- name: Configure Bazel
111-
run: LCE_SET_ANDROID_WORKSPACE=1 ANDROID_SDK_HOME="/tmp/lce_android" ANDROID_NDK_HOME="/tmp/lce_android/ndk/21.4.7075529" ./configure.py
111+
run: LCE_SET_ANDROID_WORKSPACE=1 ANDROID_SDK_HOME="/tmp/lce_android" ANDROID_API_LEVEL=30 ANDROID_NDK_HOME="/tmp/lce_android/ndk/25.2.9519653" ANDROID_NDK_API_LEVEL=30 ANDROID_BUILD_TOOLS_VERSION=31.0.0 ./configure.py
112112
shell: bash
113113
- name: Build LCE AAR
114114
run: BUILDER=bazelisk ./larq_compute_engine/tflite/java/build_lce_aar.sh
@@ -134,10 +134,10 @@ jobs:
134134

135135
macos-release-wheel:
136136
name: Build release wheels for macOS
137-
runs-on: macos-latest
137+
runs-on: macos-13
138138
strategy:
139139
matrix:
140-
python-version: [3.9, "3.10", 3.11]
140+
python-version: ["3.10", 3.11]
141141
fail-fast: false
142142
steps:
143143
- uses: actions/checkout@v4
@@ -154,33 +154,35 @@ jobs:
154154
python -m pip install delocate wheel setuptools numpy six --no-cache-dir
155155
156156
./configure.py
157-
export MACOSX_DEPLOYMENT_TARGET=10.14
157+
# This matches `release_macox_x86` in .tensorflow.bazelrc
158+
export MACOSX_DEPLOYMENT_TARGET=10.15
158159
159160
if [[ -n $GOOGLE_APPLICATION_CREDENTIALS ]]; then
160-
echo -e 'build --remote_http_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-macos-python${{ matrix.python-version }}' >> .bazelrc.user
161+
echo -e 'build --remote_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-macos-python${{ matrix.python-version }}' >> .bazelrc.user
161162
echo -e 'build --google_default_credentials' >> .bazelrc.user
162163
fi
163164
164-
bazelisk build :build_pip_pkg --copt=-fvisibility=hidden --copt=-mavx --linkopt=-dead_strip --distinct_host_configuration=false
165-
bazel-bin/build_pip_pkg artifacts --plat-name macosx_10_14_x86_64
165+
bazelisk build :build_pip_pkg --config=release_macos_x86 --config=release_cpu_macos --copt=-fvisibility=hidden --linkopt=-dead_strip
166+
bazel-bin/build_pip_pkg artifacts --plat-name macosx_10_15_x86_64
166167
167168
for f in artifacts/*.whl; do
168169
delocate-wheel -w wheelhouse $f
169170
done
170171
env:
171172
LCE_RELEASE_VERSION: ${{ github.event.inputs.version }}
173+
TF_PYTHON_VERSION: ${{ matrix.python-version }}
172174
shell: bash
173175
- uses: actions/upload-artifact@v4
174176
with:
175-
name: ${{ runner.os }}-wheels
177+
name: ${{ runner.os }}-wheels-${{ matrix.python-version }}
176178
path: wheelhouse
177179

178180
macos-arm-release-wheel:
179181
name: Build release arm wheels for macOS
180-
runs-on: macos-11
182+
runs-on: macos-14
181183
strategy:
182184
matrix:
183-
python-version: [3.9, "3.10", 3.11]
185+
python-version: ["3.10", 3.11]
184186
fail-fast: false
185187
steps:
186188
- uses: actions/checkout@v4
@@ -197,33 +199,35 @@ jobs:
197199
python -m pip install delocate wheel setuptools numpy six --no-cache-dir
198200
199201
./configure.py
200-
export MACOSX_DEPLOYMENT_TARGET=11.0
202+
# This matches `release_macox_arm64` in .tensorflow.bazelrc
203+
export MACOSX_DEPLOYMENT_TARGET=12.0
201204
202205
if [[ -n $GOOGLE_APPLICATION_CREDENTIALS ]]; then
203-
echo -e 'build --remote_http_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-macos-arm-python${{ matrix.python-version }}' >> .bazelrc.user
206+
echo -e 'build --remote_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-macos-arm-python${{ matrix.python-version }}' >> .bazelrc.user
204207
echo -e 'build --google_default_credentials' >> .bazelrc.user
205208
fi
206209
207-
bazelisk build :build_pip_pkg --copt=-fvisibility=hidden --linkopt=-dead_strip --config=macos_arm64
208-
bazel-bin/build_pip_pkg artifacts --plat-name macosx_11_0_arm64
210+
bazelisk build :build_pip_pkg --config=release_macos_arm64 --copt=-fvisibility=hidden --linkopt=-dead_strip
211+
bazel-bin/build_pip_pkg artifacts --plat-name macosx_12_0_arm64
209212
210213
for f in artifacts/*.whl; do
211214
delocate-wheel -w wheelhouse $f
212215
done
213216
env:
214217
LCE_RELEASE_VERSION: ${{ github.event.inputs.version }}
218+
TF_PYTHON_VERSION: ${{ matrix.python-version }}
215219
shell: bash
216220
- uses: actions/upload-artifact@v4
217221
with:
218-
name: ${{ runner.os }}-arm-wheels
222+
name: ${{ runner.os }}-arm-wheels-${{ matrix.python-version }}
219223
path: wheelhouse
220224

221225
manylinux-release-wheel:
222226
name: Build release wheels for manylinux2014
223227
runs-on: ubuntu-latest
224228
strategy:
225229
matrix:
226-
python-version: [3.9, "3.10", 3.11]
230+
python-version: ["3.10", 3.11]
227231
fail-fast: false
228232
steps:
229233
- uses: actions/checkout@v4
@@ -237,15 +241,17 @@ jobs:
237241
- name: Build manylinux2014 wheels
238242
run: |
239243
if [[ -n $GOOGLE_APPLICATION_CREDENTIALS ]]; then
240-
echo -e 'build --remote_http_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-manylinux-python${{ matrix.python-version }}' >> .bazelrc.user
244+
echo -e 'build --remote_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-manylinux-python${{ matrix.python-version }}' >> .bazelrc.user
241245
echo -e 'build --google_default_credentials' >> .bazelrc.user
242246
fi
243247
244248
docker run -e LCE_RELEASE_VERSION=${{ github.event.inputs.version }} \
245249
-e GOOGLE_APPLICATION_CREDENTIALS=/tmp/gcloud-credentials.json \
250+
-e TF_PYTHON_VERSION=${{ matrix.python-version }} \
246251
-v $GOOGLE_APPLICATION_CREDENTIALS:/tmp/gcloud-credentials.json:ro \
247252
-v ${PWD}:/compute-engine -w /compute-engine \
248-
tensorflow/build:2.13-python${{ matrix.python-version }} \
253+
-v /mnt:/github_disk \
254+
tensorflow/build:2.16-python${{ matrix.python-version }} \
249255
.github/tools/release_linux.sh
250256
251257
sudo apt-get -y -qq install patchelf --no-install-recommends
@@ -258,15 +264,15 @@ jobs:
258264
ls -al wheelhouse/
259265
- uses: actions/upload-artifact@v4
260266
with:
261-
name: ${{ runner.os }}-wheels
267+
name: ${{ runner.os }}-wheels-${{ matrix.python-version }}
262268
path: wheelhouse
263269

264270
windows-release-wheel:
265271
name: Build release wheels for Windows
266272
runs-on: windows-2019
267273
strategy:
268274
matrix:
269-
python-version: [3.9, "3.10", 3.11]
275+
python-version: ["3.10", 3.11]
270276
fail-fast: false
271277
steps:
272278
- name: Configure Pagefile
@@ -294,18 +300,24 @@ jobs:
294300
$Env:CC_OPT_FLAGS = "/O2"
295301
296302
python --version
297-
python -m pip install wheel setuptools numpy six --no-cache-dir
303+
python -m pip install wheel setuptools numpy six pip-tools --no-cache-dir
304+
# This is needed because the requirements on windows are different than on other systems
305+
pip-compile --strip-extras --no-emit-index-url --allow-unsafe larq_compute_engine/requirements.in
306+
307+
# Fix for path length limit: replace workspace name by 'lce'
308+
(Get-Content WORKSPACE).Replace('workspace(name = "larq_compute_engine")', 'workspace(name = "lce")') | Set-Content WORKSPACE
298309
299310
"" | python configure.py
300311
301-
bazelisk --output_base=C:\build_output build :build_pip_pkg --enable_runfiles --local_ram_resources=4096 --remote_http_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-windows-python${{ matrix.python-version }} --google_default_credentials
312+
bazelisk --output_base=C:\bzl build :build_pip_pkg --enable_runfiles --local_ram_resources=4096 --remote_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-release-windows-python${{ matrix.python-version }} --google_default_credentials
302313
bazel-bin/build_pip_pkg wheelhouse
303314
env:
304315
LCE_RELEASE_VERSION: ${{ github.event.inputs.version }}
316+
TF_PYTHON_VERSION: ${{ matrix.python-version }}
305317
shell: pwsh
306318
- uses: actions/upload-artifact@v4
307319
with:
308-
name: ${{ runner.os }}-wheels
320+
name: ${{ runner.os }}-wheels-${{ matrix.python-version }}
309321
path: wheelhouse
310322

311323
upload-wheels:
@@ -322,31 +334,11 @@ jobs:
322334
steps:
323335
- uses: actions/download-artifact@v4
324336
with:
325-
name: Linux-wheels
326-
path: Linux-wheels
327-
if: ${{ needs.manylinux-release-wheel.result == 'success' }}
328-
- uses: actions/download-artifact@v4
329-
with:
330-
name: macOS-wheels
331-
path: macOS-wheels
332-
if: ${{ needs.macos-release-wheel.result == 'success' }}
333-
- uses: actions/download-artifact@v4
334-
with:
335-
name: macOS-arm-wheels
336-
path: macOS-arm-wheels
337-
if: ${{ needs.macos-arm-release-wheel.result == 'success' }}
338-
- uses: actions/download-artifact@v4
339-
with:
340-
name: Windows-wheels
341-
path: Windows-wheels
342-
if: ${{ needs.windows-release-wheel.result == 'success' }}
337+
pattern: "*wheels*"
338+
path: dist
339+
merge-multiple: true
343340
- run: |
344341
set -x
345-
mkdir -p dist
346-
cp Linux-wheels/*.whl dist/ || true
347-
cp macOS-wheels/*.whl dist/ || true
348-
cp macOS-arm-wheels/*.whl dist/ || true
349-
cp Windows-wheels/*.whl dist/ || true
350342
ls -la dist/
351343
sha256sum dist/*.whl
352344
- uses: pypa/gh-action-pypi-publish@master

.github/workflows/unittests.yml

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212

13+
env:
14+
TF_PYTHON_VERSION: "3.11"
15+
1316
jobs:
1417
TFLite:
1518
runs-on: ubuntu-latest
@@ -19,16 +22,8 @@ jobs:
1922
with:
2023
submodules: true
2124
fetch-depth: 0
22-
- uses: actions/setup-python@v5
23-
with:
24-
python-version: 3.9
25-
- name: Configure Bazel
26-
run: ./configure.py
27-
shell: bash
28-
- name: Install pip dependencies
29-
run: pip install numpy --no-cache-dir
3025
- name: Run C++ Unit Tests
31-
run: bazelisk test larq_compute_engine/tests:cc_tests --distinct_host_configuration=false --test_output=all
26+
run: bazelisk test larq_compute_engine/tests:cc_tests --test_output=all
3227
- name: Build TF Lite Static Library with CMake
3328
run: |
3429
mkdir build
@@ -45,14 +40,6 @@ jobs:
4540
run: |
4641
sudo apt-get update
4742
sudo apt-get install -y --no-install-recommends qemu-user
48-
- uses: actions/setup-python@v5
49-
with:
50-
python-version: 3.9
51-
- name: Configure Bazel
52-
run: ./configure.py
53-
shell: bash
54-
- name: Install pip dependencies
55-
run: pip install numpy six --no-cache-dir
5643
- name: "TF Lite Arm32: Cross-compile and run unit tests in qemu"
5744
run: bazelisk test larq_compute_engine/tests:arm32_tests --config=rpi3 --test_output=all --test_filter="-*BigTest*" --copt=-O1
5845
- name: "TF Lite Aarch64: Cross-compile and run unit tests in qemu"
@@ -69,32 +56,21 @@ jobs:
6956
continue-on-error: true
7057
with:
7158
credentials_json: ${{ secrets.gcs_bazel_cache }}
72-
- uses: actions/setup-python@v5
73-
with:
74-
python-version: 3.9
7559
- name: Configure Bazel
7660
run: |
77-
./configure.py
78-
echo -e 'build --distinct_host_configuration=false' >> .bazelrc.user
7961
if [[ -n $GOOGLE_APPLICATION_CREDENTIALS ]]; then
80-
echo -e 'build --remote_http_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-ubuntu' >> .bazelrc.user
62+
echo -e 'build --remote_cache=https://storage.googleapis.com/plumerai-bazel-cache/lce-ubuntu' >> .bazelrc.user
8163
echo -e 'build --google_default_credentials' >> .bazelrc.user
8264
fi
8365
shell: bash
84-
- name: Set bazel cache
85-
run: echo -e 'build --remote_upload_local_results=false' >> .bazelrc.user
86-
if: github.ref != 'refs/heads/main'
87-
shell: bash
88-
- name: Install pip dependencies
89-
run: pip install tensorflow-cpu~=2.13.0 larq~=0.13 pytest tensorflow_datasets~=4.9 flatbuffers==23.1.21 tqdm --no-cache-dir
9066
- name: Run Interpreter test
9167
run: bazelisk test larq_compute_engine/tflite/tests:interpreter_test --test_output=all
9268
- name: Run FileCheck tests
9369
run: bazelisk test larq_compute_engine/mlir/tests:all --test_output=all
9470
- name: Run End2End tests
95-
run: bazelisk test larq_compute_engine/tests:end2end_test --test_output=all
71+
run: bazelisk test larq_compute_engine/tests:end2end_test --test_output=all --test_env=TF_USE_LEGACY_KERAS=1
9672
- name: Run Strip dequantize op tests
97-
run: bazelisk test larq_compute_engine/tests:strip_lcedequantize_test --test_output=all
73+
run: bazelisk test larq_compute_engine/tests:strip_lcedequantize_test --test_output=all --test_env=TF_USE_LEGACY_KERAS=1
9874

9975
ConverterPython:
10076
runs-on: ubuntu-latest
@@ -109,6 +85,10 @@ jobs:
10985
python-version: 3.11
11086
flatbuffers-version: 23.1.21
11187
protobuf-version: 4.23.4
88+
- tf-version: 2.16.1
89+
python-version: 3.11
90+
flatbuffers-version: 24.3.25
91+
protobuf-version: 4.25.3
11292
if: "!contains(github.event.head_commit.message, 'ci-skip')"
11393
steps:
11494
- uses: actions/checkout@v4
@@ -117,14 +97,17 @@ jobs:
11797
python-version: ${{ matrix.python-version }}
11898
- name: Install TensorFlow
11999
run: pip install tensorflow==${{matrix.tf-version}} --no-cache-dir
100+
- name: Install legacy tf-keras
101+
if: matrix.tf-version == '2.16.1'
102+
run: pip install tf-keras==2.16.0
120103
- name: Install flatbuffers
121104
run: pip install flatbuffers==${{matrix.flatbuffers-version}} --no-cache-dir
122105
- name: Install protobuf
123106
run: pip install protobuf==${{matrix.protobuf-version}} --no-cache-dir
124107
- name: Install other dependencies
125108
run: pip install larq~=0.13.3 packaging tqdm --no-cache-dir
126109
- name: Run Converter test
127-
run: PYTHONPATH=./ python larq_compute_engine/mlir/python/converter_test.py
110+
run: TF_USE_LEGACY_KERAS=1 PYTHONPATH=./ python larq_compute_engine/mlir/python/converter_test.py
128111

129112
Android_AAR:
130113
runs-on: ubuntu-latest
@@ -142,15 +125,13 @@ jobs:
142125
with:
143126
path: /tmp/lce_android
144127
key: ${{ runner.os }}-${{ hashFiles('**/third_party/install_android.sh') }}
145-
- name: Install pip dependencies
146-
run: pip install numpy six --no-cache-dir
147128
- name: Set Java version
148129
run: echo "JAVA_HOME=${JAVA_HOME_8_X64}" >> $GITHUB_ENV
149130
- name: Download and install Android NDK/SDK
150131
if: steps.cache.outputs.cache-hit != 'true'
151132
run: ./third_party/install_android.sh
152133
- name: Configure Bazel
153-
run: LCE_SET_ANDROID_WORKSPACE=1 ANDROID_SDK_HOME="/tmp/lce_android" ANDROID_NDK_HOME="/tmp/lce_android/ndk/21.4.7075529" ./configure.py
134+
run: LCE_SET_ANDROID_WORKSPACE=1 ANDROID_SDK_HOME="/tmp/lce_android" ANDROID_API_LEVEL=30 ANDROID_NDK_HOME="/tmp/lce_android/ndk/25.2.9519653" ANDROID_NDK_API_LEVEL=30 ANDROID_BUILD_TOOLS_VERSION=31.0.0 ./configure.py
154135
shell: bash
155136
- name: Build LCE AAR
156137
run: BUILDER=bazelisk ./larq_compute_engine/tflite/java/build_lce_aar.sh

0 commit comments

Comments
 (0)