Skip to content

Commit 3d4c32d

Browse files
committed
Increase version for next iteration
1 parent a905d07 commit 3d4c32d

14 files changed

Lines changed: 89 additions & 17 deletions

File tree

MIGRATING.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Migrating Between TensorFlow Java Releases
2+
3+
TensorFlow Java is still in an alpha stage, therefore is subject to contain breaking changes between the different releases. This guide explain in detail
4+
how to migrate your code from a previous version to a new one that includes some changes that are not backward compatible.
5+
6+
## Migrating to 0.3.0
7+
8+
### Non-parameterized Typed Tensors
9+
10+
In previous versions, the `Tensor` class was parameterized with its tensor type interface, which is part of the `TType` family. To access directly the memory
11+
tensor from the JVM, an explicit conversion between `Tensor` and its tensor type was required by calling `tensor.data()`.
12+
13+
In 0.3.0, tensors are always typed, making this generic parameter and explicit mapping obsolete. As soon as you get a handle to a tensor, you are able to
14+
access directly its memory for reading (or writing for most tensor types) and no convertion is required. Any instances of a class in the `TType` family
15+
can also now be manipulated directly as a `Tensor` (e.g. to be passed to a session for inference).
16+
17+
Steps:
18+
1. Replace a parameterized `Tensor` by its parameter (e.g. `Tensor<TFloat32>` -> `TFloat32`)
19+
2. Replace instance of `Tensor<?>` with unknown parameter by `Tensor`
20+
3. Remove any invocation to `Tensor.data()` (e.g. `tensor.data().getFloat()` -> `tensor.getFloat()`)
21+
4. Replace any invocation to `Operand.data()` by `Operand.asTensor()`
22+
23+
### Use of Java Type System instead of DataType
24+
25+
In previous versions, the `DataType` class was used to carry information about the type of a `Tensor`, that can then be converted back to a tensor of that
26+
type (see previous section). Since there were a exact parity between interfaces of the `TType` family and an instance of `DataType`, the latter has been dropped
27+
in 0.3.0 to leverage instead the standard type system in Java, for a better idiomatic experience.
28+
29+
Steps:
30+
1. Replace all accesses to the `DTYPE` field of a `TType` interface by its class (e.g. `TFloat32.DTYPE` -> `TFloat32.class`)
31+
2. Use Java type system for checking tensor types at runtime (e.g. using `instanceof` or `isAssignableFrom`)
32+
3. Replace any invocation to `Tensor.expect()` by an explicit cast (e.g. `tensor.expect(TFloat32.DTYPE)` -> `(TFloat32)tensor`)
33+
34+
### Example
35+
36+
0.2.0:
37+
```
38+
Session session = ...;
39+
40+
try (Tensor<TFloat32> tensor = TFloat32.tensorOf(Shape.of(1, 2))) {
41+
TFloat32 tensorData = tensor.data();
42+
tensorData.setFloat(10.0f, 0);
43+
tensorData.setFloat(20.0f, 1);
44+
45+
try (Tensor<?> result = session.runner().feed("x", tensor).fetch("y").run().get(0)) {
46+
if (result.dataType() == TFloat32.DTYPE) {
47+
Tensor<TFloat32> typedResult = result.expect(TFloat32.DTYPE);
48+
TFloat32 resultData = typedResult.data();
49+
System.out.println("Result is " + resultData.getFloat());
50+
}
51+
}
52+
}
53+
```
54+
55+
0.3.0:
56+
```
57+
Session session = ...;
58+
59+
try (TFloat32 tensor = TFloat32.tensorOf(Shape.of(1, 2))) {
60+
tensor.setFloat(10.0f, 0);
61+
tensor.setFloat(20.0f, 1);
62+
63+
try (Tensor result = session.runner().feed("x", tensor).fetch("y").run().get(0)) {
64+
if (result instanceof TFloat32) {
65+
TFloat32 typedResult = (TFloat32)result;
66+
System.out.println("Result is " + typedResult.getFloat());
67+
}
68+
}
69+
}
70+
```
71+

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ to add Sonatype OSS repository in your pom.xml, like the following
137137
<dependency>
138138
<groupId>org.tensorflow</groupId>
139139
<artifactId>tensorflow-core-platform</artifactId>
140-
<version>0.3.0-SNAPSHOT</version>
140+
<version>0.4.0-SNAPSHOT</version>
141141
</dependency>
142142
</dependencies>
143143
```
@@ -150,6 +150,7 @@ This table shows the mapping between different version of TensorFlow for Java an
150150
| ------------- | ------------- |
151151
| 0.2.0 | 2.3.1 |
152152
| 0.3.0 | 2.4.1 |
153+
| 0.4.0-SNAPSHOT | 2.4.1
153154

154155
## How to Contribute?
155156

ndarray/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To import the NdArray library in your project, simply add the following dependen
1111
<dependency>
1212
<groupId>org.tensorflow</groupId>
1313
<artifactId>ndarray</artifactId>
14-
<version>0.2.0-SNAPSHOT</version>
14+
<version>0.3.0</version>
1515
</dependency>
1616
```
1717

ndarray/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>org.tensorflow</groupId>
2424
<artifactId>tensorflow-java</artifactId>
25-
<version>0.3.0</version>
25+
<version>0.4.0-SNAPSHOT</version>
2626
</parent>
2727
<artifactId>ndarray</artifactId>
2828
<packaging>jar</packaging>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.tensorflow</groupId>
77
<artifactId>tensorflow-java</artifactId>
8-
<version>0.3.0</version>
8+
<version>0.4.0-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010

1111
<name>TensorFlow Java Parent</name>

tensorflow-core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>org.tensorflow</groupId>
2424
<artifactId>tensorflow-java</artifactId>
25-
<version>0.3.0</version>
25+
<version>0.4.0-SNAPSHOT</version>
2626
</parent>
2727
<artifactId>tensorflow-core</artifactId>
2828
<packaging>pom</packaging>

tensorflow-core/tensorflow-core-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.tensorflow</groupId>
88
<artifactId>tensorflow-core</artifactId>
9-
<version>0.3.0</version>
9+
<version>0.4.0-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>tensorflow-core-api</artifactId>
1212
<packaging>jar</packaging>

tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,14 @@ public final class Ops {
354354

355355
public final SparseOps sparse;
356356

357-
public final TpuOps tpu;
358-
359357
public final BitwiseOps bitwise;
360358

361-
public final MathOps math;
359+
public final TpuOps tpu;
362360

363361
public final AudioOps audio;
364362

363+
public final MathOps math;
364+
365365
public final SignalOps signal;
366366

367367
public final TrainOps train;
@@ -385,10 +385,10 @@ private Ops(Scope scope) {
385385
random = new RandomOps(this);
386386
strings = new StringsOps(this);
387387
sparse = new SparseOps(this);
388-
tpu = new TpuOps(this);
389388
bitwise = new BitwiseOps(this);
390-
math = new MathOps(this);
389+
tpu = new TpuOps(this);
391390
audio = new AudioOps(this);
391+
math = new MathOps(this);
392392
signal = new SignalOps(this);
393393
train = new TrainOps(this);
394394
quantization = new QuantizationOps(this);

tensorflow-core/tensorflow-core-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>org.tensorflow</groupId>
77
<artifactId>tensorflow-core</artifactId>
8-
<version>0.3.0</version>
8+
<version>0.4.0-SNAPSHOT</version>
99
</parent>
1010
<artifactId>tensorflow-core-generator</artifactId>
1111
<packaging>jar</packaging>

tensorflow-core/tensorflow-core-platform-gpu/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>org.tensorflow</groupId>
2424
<artifactId>tensorflow-core</artifactId>
25-
<version>0.3.0</version>
25+
<version>0.4.0-SNAPSHOT</version>
2626
</parent>
2727
<artifactId>tensorflow-core-platform-gpu</artifactId>
2828
<name>TensorFlow Core API Library Platform GPU</name>

0 commit comments

Comments
 (0)