Skip to content

Commit a617fe9

Browse files
authored
Upgrade to TF 2.10.1, with macosx-arm64 support (tensorflow#481)
1 parent dc64755 commit a617fe9

File tree

1,571 files changed

+14790
-3877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,571 files changed

+14790
-3877
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
tar xzf $HOME/apache-maven-3.6.3-bin.tar.gz -C /opt/
114114
ln -sf /opt/apache-maven-3.6.3/bin/mvn /usr/bin/mvn
115115
echo Downloading Bazel
116-
curl -L https://github.com/bazelbuild/bazel/releases/download/5.0.0/bazel-5.0.0-installer-linux-x86_64.sh -o bazel.sh --retry 10
116+
curl -L https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-installer-linux-x86_64.sh -o bazel.sh --retry 10
117117
bash bazel.sh
118118
if [[ "${{ matrix.ext }}" == *-gpu ]]; then
119119
echo Installing CUDA
@@ -173,7 +173,7 @@ jobs:
173173
run: |
174174
python3 -m pip install numpy six
175175
echo Downloading Bazel
176-
curl -L https://github.com/bazelbuild/bazel/releases/download/5.0.0/bazel-5.0.0-installer-darwin-x86_64.sh -o bazel.sh --retry 10
176+
curl -L https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-installer-darwin-x86_64.sh -o bazel.sh --retry 10
177177
bash bazel.sh
178178
brew install libomp perl
179179
- name: Configure Java
@@ -227,7 +227,7 @@ jobs:
227227
bash.exe -lc "find 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/' -iname '14.1*' -exec rm -Rf {} \;"
228228
echo Downloading Bazel
229229
mkdir C:\bazel
230-
curl.exe -L https://github.com/bazelbuild/bazel/releases/download/5.0.0/bazel-5.0.0-windows-x86_64.exe -o C:/bazel/bazel.exe --retry 10
230+
curl.exe -L https://github.com/bazelbuild/bazel/releases/download/5.1.1/bazel-5.1.1-windows-x86_64.exe -o C:/bazel/bazel.exe --retry 10
231231
set "EXT=${{ matrix.ext }}"
232232
if "%EXT:~-4%" == "-gpu" (
233233
echo Removing some unused stuff to avoid running out of disk space

CONTRIBUTING.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ The `tensorflow-core/tensorflow-core-api/.bazelversion` file must be kept in syn
4848
This allows using [Bazelisk](https://github.com/bazelbuild/bazelisk) which runs the bazel version given in .bazelversion instead of having to
4949
physically reinstall a specific `bazel` version each time the TensorFlow version changes.
5050

51-
5251
### GPU Support
5352

5453
Currently, due to build time constraints, the GPU binaries only support compute capacities 3.5 and 7.0.
@@ -61,6 +60,17 @@ To build for GPU, pass `-Djavacpp.platform.extension=-gpu` to maven. By default,
6160
for more info. If you add `bazelrc` files, make sure the `TF_CUDA_COMPUTE_CAPABILITIES` value in them matches the value set elsewhere, as it will take
6261
precedence if present.
6362

63+
### Apple Silicon
64+
65+
The TensorFlow Java project relies on [GitHub-hosted runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners)
66+
to build and distribute the native binaries for TensorFlow. Unfortunately at the moment, GitHub Actions still does not support runners with a
67+
Apple Silicon chip (such as M1). Therefore, we cannot distribute the binaries for this platform, so they must be compiled and installed locally on such systems.
68+
69+
Please follow the present [procedure](CONTRIBUTING.md#building) for building TensorFlow Java from sources.
70+
71+
:warning: As of 12-16-2022, TensorFlow fails to build on XCode command line tools version 14+. If you have such version installed, it might
72+
be necessary to downgrade it to a [previous version](https://developer.apple.com/download/all/?q=Xcode), like 13.4.1.
73+
6474
## Running Tests
6575

6676
`ndarray` can be tested using the maven `test` target. `tensorflow-core` and `tensorflow-framework`, however, should be tested using
@@ -136,8 +146,8 @@ The actual classification process is a bit arbitrary and based on the good jugem
136146
are being wrapped by a higher-level API and therefore are left unclassified, while in Java they are exposed and can be used directly by
137147
the users.
138148

139-
For classifying an op, a `api_def` proto must be added to the `tensorflow-core-api` [folder](https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api/src/bazel/api_def)
140-
for this purpose, redefining optionally its endpoints or its visibility.
149+
For classifying an op, an `api_def` proto must be added to the [`tensorflow-core-api/src/bazel/api_def`](https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api/src/bazel/api_def)
150+
folder for this purpose, redefining optionally its endpoints or its visibility.
141151

142152
Writing these protos and trying the guess the right location for each new operation can become a tedious job so an utility program called `java_api_import`
143153
has been created to help you with this task. This utility is available under the `bazel-bin` folder of `tensorflow-core-api` after the
@@ -147,8 +157,7 @@ initial build. Here is how to invoke it:
147157
cd tensorflow-core/tensorflow-core-api
148158
./bazel-bin/java_api_import \
149159
--java_api_dir=src/bazel/api_def \
150-
--tf_src_dir=bazel-tensorflow-core-api/external/org_tensorflow \
151-
--tf_lib_path=bazel-bin/external/org_tensorflow/tensorflow/libtensorflow_cc.<version>.<ext>
160+
--tf_src_dir=bazel-tensorflow-core-api/external/org_tensorflow
152161
```
153162

154163
For each new operation detected (i.e. any operation that does not have a valid `api_def` proto yet), the utility will suggest you some possible
@@ -157,7 +166,9 @@ will automatically classify the op). It is also possible to enter manually the n
157166
application will then take care to write the `api_def` proto for each operation classified.
158167

159168
Make sure to erase completely the generated source folder of the `tensorflow-core-api` module before rerunning the build so you can see
160-
if your ops have been classified properly. Don't worry, that second run of the build will be fast ;)
169+
if your ops have been classified properly. Don't worry, that second run of the build will be faster! Please review the location of the new generated ops
170+
after rebuilding and make necessary adjustments to the `api_def`protos manually if some of them seems to be in the "wrong" place, making sure to repeat this process
171+
until satisfaction.
161172

162173
#### Ops Kernel Upgrade
163174

README.md

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,30 @@ See [CONTRIBUTING.md](CONTRIBUTING.md#building).
4343

4444
## Using Maven Artifacts
4545

46-
To include TensorFlow in your Maven application, you first need to add a dependency on either the
47-
`tensorflow-core` or `tensorflow-core-platform` artifacts. The former could be included multiple times
48-
for different targeted systems by their classifiers, while the later includes them as dependencies for
49-
`linux-x86_64`, `macosx-x86_64`, and `windows-x86_64`, with more to come in the future. There are also
50-
`tensorflow-core-platform-mkl`, `tensorflow-core-platform-gpu`, and `tensorflow-core-platform-mkl-gpu`
51-
artifacts that depend on artifacts with MKL and/or CUDA support enabled.
46+
There are two options for adding TensorFlow Java as a dependency to your Maven project: with individual dependencies
47+
for each targeted platforms or with a single dependency that target them all.
48+
49+
### Individual dependencies
50+
51+
With this option, you must first add an unclassified dependency to `tensorflow-core-api` and then add one or multiple
52+
native dependencies to this same artifact with a classifier targeting a specific platform. This option is preferred as
53+
it minimize the size of your application by only including the TensorFlow builds you need, at the cost of being more
54+
restrictive.
55+
56+
While TensorFlow Java can be compiled for [multiple platforms](https://github.com/tensorflow/java/blob/dc64755ee948c71f1321be27478828a51f1f3cf7/tensorflow-core/pom.xml#L54),
57+
only binaries for the followings are being **supported and distributed** by this project:
58+
59+
- `linux-x86_64`: Linux platforms on Intel chips
60+
- `linux-x86_64-gpu`: Linux platforms on Intel chips with Cuda GPU support
61+
- `macosx-x86_64`: MacOS X platforms on Intel chips
62+
- `windows-x86_64`: Windows platforms on Intel chips
63+
- `windows-x86_64-gpu`: Windows platforms on Intel chips with Cuda GPU support
64+
65+
*Note: No binaries are distributed to run TensorFlow Java on machines with Apple Silicon chips (`macosx-arm64`), these
66+
should be build from sources. See [here](CONTRIBUTING.md#apple-silicon) for more details.*
5267

5368
For example, for building a JAR that uses TensorFlow and is targeted to be deployed only on Linux
54-
systems, you should add the following dependencies:
69+
systems with no GPU support, you should add the following dependencies:
5570
```xml
5671
<dependency>
5772
<groupId>org.tensorflow</groupId>
@@ -62,7 +77,7 @@ systems, you should add the following dependencies:
6277
<groupId>org.tensorflow</groupId>
6378
<artifactId>tensorflow-core-api</artifactId>
6479
<version>0.4.2</version>
65-
<classifier>linux-x86_64${javacpp.platform.extension}</classifier>
80+
<classifier>linux-x86_64</classifier>
6681
</dependency>
6782
```
6883

@@ -78,37 +93,54 @@ native dependencies as follows:
7893
<groupId>org.tensorflow</groupId>
7994
<artifactId>tensorflow-core-api</artifactId>
8095
<version>0.4.2</version>
81-
<classifier>linux-x86_64${javacpp.platform.extension}</classifier>
96+
<classifier>linux-x86_64-gpu</classifier>
8297
</dependency>
8398
<dependency>
8499
<groupId>org.tensorflow</groupId>
85100
<artifactId>tensorflow-core-api</artifactId>
86101
<version>0.4.2</version>
87-
<classifier>macosx-x86_64${javacpp.platform.extension}</classifier>
102+
<classifier>macosx-x86_64</classifier>
88103
</dependency>
89104
<dependency>
90105
<groupId>org.tensorflow</groupId>
91106
<artifactId>tensorflow-core-api</artifactId>
92107
<version>0.4.2</version>
93-
<classifier>windows-x86_64${javacpp.platform.extension}</classifier>
108+
<classifier>windows-x86_64-gpu</classifier>
94109
</dependency>
95110
```
96111

97-
In some cases, pre-configured starter artifacts can help to automatically include all versions of
98-
the native library for a given configuration. For example, the `tensorflow-core-platform`,
99-
`tensorflow-core-platform-mkl`, `tensorflow-core-platform-gpu`, or `tensorflow-core-platform-mkl-gpu`
100-
artifact includes transitively all the artifacts above as a single dependency:
112+
Only one dependency can be added per platform, meaning that you cannot add native dependencies to both `linux-x86_64` and
113+
`linux-x86_64-gpu` within the same project.
114+
115+
### Single dependency
116+
117+
In some cases, it might be preferable to add a single dependency that includes transitively all the artifacts
118+
required to run TensorFlow Java on any [supported platforms](README.md#individual-dependencies)
119+
120+
- `tensorflow-core-platform`: Includes TenSupports for `linux-x86_64`, `macosx-x86_64` and `windows-x86_64`
121+
- `tensorflow-core-platform-gpu`: Supports `linux-x86_64-gpu` and `windows-x86_64-gpu`
122+
123+
For example, to run TensorFlow Java on any platform for which a binary is being distributed by this project, you can
124+
simply add this dependency to your application:
125+
```xml
126+
<dependency>
127+
<groupId>org.tensorflow</groupId>
128+
<artifactId>tensorflow-core-platform</artifactId>
129+
<version>0.4.2</version>
130+
</dependency>
131+
```
132+
or this dependency if you want to run it only on platforms with GPU support:
101133
```xml
102134
<dependency>
103135
<groupId>org.tensorflow</groupId>
104-
<artifactId>tensorflow-core-platform${javacpp.platform.extension}</artifactId>
136+
<artifactId>tensorflow-core-platform-gpu</artifactId>
105137
<version>0.4.2</version>
106138
</dependency>
107139
```
108140

109-
Be aware though that the native library is quite large and including too many versions of it may
110-
significantly increase the size of your JAR. So it is good practice to limit your dependencies to
111-
the platforms you are targeting. For this purpose the `-platform` artifacts include profiles that follow
141+
Be aware though that the builds of TensorFlow are quite voluminous and including too many native dependencies may
142+
significantly increase the size of your application. So it is good practice to limit your dependencies to
143+
the platforms you are targeting. For this purpose these artifacts include profiles that follow
112144
the conventions established on this page:
113145
* [Reducing the Number of Dependencies](https://github.com/bytedeco/javacpp-presets/wiki/Reducing-the-Number-of-Dependencies)
114146

0 commit comments

Comments
 (0)