Skip to content

Commit f6d0950

Browse files
authored
Merge pull request #378 from saudet/upgrade-tensorflow-260
Upgrade for TensorFlow 2.6.0
2 parents 5e775e1 + 9932aa9 commit f6d0950

File tree

1,388 files changed

+9135
-5317
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,388 files changed

+9135
-5317
lines changed

CONTRIBUTING.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ the `dev` profile in your Maven command to use those artifacts instead of buildi
2121
Modifying the native op generation code (not the annotation processor) or the JavaCPP configuration (not the abstract Pointers) will require a
2222
complete build could be required to reflect the changes, otherwise `-Pdev` should be fine.
2323

24-
## JDK 16+
24+
### JDK 16+
2525

2626
If you're using JDK 16+, you need to add some exports for the formatter plugin:
2727

@@ -98,6 +98,63 @@ Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.0:tes
9898
This is because the native code crashed (i.e. because of a segfault), and it should have created a dump file somewhere in the project that you can use
9999
to tell what caused the issue.
100100

101+
## Upgrading TensorFlow Version
102+
103+
To upgrade the version of TensorFlow that is embedded within TensorFlow Java, please follow carefully these steps.
104+
105+
### Upgrading TensorFlow Runtime Library
106+
107+
You can upgrade the version of the TensorFlow library by updating the archive downloadeded in the Bazel
108+
[workspace](https://github.com/tensorflow/java/blob/master/tensorflow-core/tensorflow-core-api/WORKSPACE#L19) at build time. Make sure to
109+
update the `urls`, `sha256` and `strip_prefix` fields of the `org_tensorflow` archive rule to reflect the values for the new version.
110+
111+
### Ops Classification
112+
113+
After building with the version of TensorFlow, you might notice that a lot of new operations appeared in the `org.tensorflow.ops.core`
114+
package of the [generated sources](https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/op/core) of
115+
the `tensorflow-core-api` module. Many of these ops must be reclassified manually after running this initial build.
116+
117+
The actual classification process is a bit arbitrary and based on the good jugement of the developer. The reason is that most ops in Python
118+
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
119+
the users.
120+
121+
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)
122+
for this purpose, redefining optionally its endpoints or its visibility.
123+
124+
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`
125+
has been created to help you with this task. This utility is available under the `bazel-bin` folder of `tensorflow-core-api` after the
126+
initial build. Here is how to invoke it:
127+
128+
```
129+
cd tensorflow-core/tensorflow-core-api
130+
./bazel-bin/java_api_import \
131+
--java_api_dir=src/bazel/api_def \
132+
--tf_src_dir=bazel-tensorflow-core-api/external/org_tensorflow \
133+
--tf_lib_path=bazel-bin/external/org_tensorflow/tensorflow/libtensorflow_cc.<version>.<ext>
134+
```
135+
136+
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
137+
package names that can be a good match for its classification (unless a "perfect match" has been found in the Python code, in which case the utility
138+
will automatically classify the op). It is also possible to enter manually the name of the package to use, and the package can have multiple levels (e.g. `linalg.sparse`). The utility
139+
application will then take care to write the `api_def` proto for each operation classified.
140+
141+
Make sure to erase completely the generated source folder of the `tensorflow-core-api` module before rerunning the build so you can see
142+
if your ops have been classified properly.
143+
144+
#### Ops Kernel Upgrade
145+
146+
Some operations might be just an upgrade of another existing operations. For instance, there are many version of the `BatchMatMul` kernel (V1, V2, V3...).
147+
When you see that a new op is just an upgrade from another other one, make sure that the latest version has a valid endpoint and that all other
148+
previous versions of this operation are marked as `VISIBILITY: SKIP`.
149+
150+
### Java Protos Classification
151+
152+
TensorFlow Java distributes a large number proto definitions found in the TensorFlow Runtime Library as Java classes. Again, new protos might not
153+
be classified properly since they may be lacking the `option java_*` statements at the beginning of their definition. If you notice in the
154+
[generated protos](https://github.com/tensorflow/java/tree/master/tensorflow-core/tensorflow-core-api/src/gen/java/org/tensorflow/proto) of the `tensorflow-core-api`
155+
that some new proto classes seems to be in the wrong package, create a Bazel patch at this effect to add the missing options.
156+
See [existing patches](https://github.com/tensorflow/java/blob/master/tensorflow-core/tensorflow-core-api/external/tensorflow-proto.patch) for examples.
157+
101158
## Contributing
102159

103160
### Formatting

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ This table shows the mapping between different version of TensorFlow for Java an
148148
| 0.3.1 | 2.4.1 |
149149
| 0.3.2 | 2.4.1 |
150150
| 0.3.3 | 2.4.1 |
151-
| 0.4.0-SNAPSHOT | 2.5.0
151+
| 0.4.0-SNAPSHOT | 2.6.0
152152

153153
## How to Contribute?
154154

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</modules>
3737

3838
<properties>
39-
<project.build.sourceEncoding>ASCII</project.build.sourceEncoding>
39+
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
4040
<maven.compiler.source>1.8</maven.compiler.source>
4141
<maven.compiler.target>1.8</maven.compiler.target>
4242
<junit.version>5.6.2</junit.version>

tensorflow-core/tensorflow-core-api/WORKSPACE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ http_archive(
99
name = "org_tensorflow",
1010
patches = [
1111
":tensorflow-visibility.patch",
12-
":tensorflow-macosx.patch",
12+
# ":tensorflow-macosx.patch",
1313
# ":tensorflow-windows.patch", # https://github.com/tensorflow/tensorflow/issues/25213
1414
":tensorflow-proto.patch",
1515
],
1616
patch_tool = "patch",
1717
patch_args = ["-p1"],
1818
patch_cmds = ["grep -rl 'java_package' tensorflow/core | xargs sed -i.bak 's/^\(.* java_package = \"org\.tensorflow\.\)\(.*\"\)/\\1proto.\\2'/"],
1919
urls = [
20-
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.5.0.tar.gz",
20+
"https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.6.0.tar.gz",
2121
],
22-
sha256 = "233875ea27fc357f6b714b2a0de5f6ff124b50c1ee9b3b41f9e726e9e677b86c",
23-
strip_prefix = "tensorflow-2.5.0"
22+
sha256 = "41b32eeaddcbc02b0583660bcf508469550e4cd0f86b22d2abe72dfebeacde0f",
23+
strip_prefix = "tensorflow-2.6.0"
2424
)
2525

2626
# START: Upstream TensorFlow dependencies

0 commit comments

Comments
 (0)