Skip to content

Commit ed1da29

Browse files
committed
Update scope for fix review comments
Signed-off-by: Ryan Nett <JNett96@gmail.com>
1 parent 759a754 commit ed1da29

File tree

12 files changed

+54
-29
lines changed

12 files changed

+54
-29
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ public final class Ops {
367367

368368
public final SparseOps sparse;
369369

370-
public final BitwiseOps bitwise;
371-
372370
public final TpuOps tpu;
373371

372+
public final BitwiseOps bitwise;
373+
374374
public final MathOps math;
375375

376376
public final AudioOps audio;
@@ -398,8 +398,8 @@ public final class Ops {
398398
random = new RandomOps(this);
399399
strings = new StringsOps(this);
400400
sparse = new SparseOps(this);
401-
bitwise = new BitwiseOps(this);
402401
tpu = new TpuOps(this);
402+
bitwise = new BitwiseOps(this);
403403
math = new MathOps(this);
404404
audio = new AudioOps(this);
405405
signal = new SignalOps(this);

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/BaseGradientAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ protected static GraphOperation getGraphOp(Graph g, Node node) {
7979
}
8080

8181
/**
82-
* Use builders without locking. This should only be used during custom gradient building.
82+
* Use builders without locking. This should only be used during custom gradient building.
8383
*
84-
* The graph locks are not re-entrant, so attempting to add an op to a graph that has
85-
* been locked by the gradient builder will fail without this.
84+
* <p>The graph locks are not re-entrant, so attempting to add an op to a graph that has been
85+
* locked by the gradient builder will fail without this.
8686
*/
8787
protected static void useDangerousLockedBuilders(Graph g, boolean dangerous) {
8888
g.setDangerousGradientBuilder(dangerous);

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,10 +905,10 @@ synchronized SaverDef saverDef() {
905905
private boolean newInitializers = false;
906906

907907
/**
908-
* Use builders without locking. This should only be used during custom gradient building.
908+
* Use builders without locking. This should only be used during custom gradient building.
909909
*
910-
* The graph locks are not re-entrant, so attempting to add an op to a graph that has
911-
* been locked by the gradient builder will fail without this.
910+
* <p>The graph locks are not re-entrant, so attempting to add an op to a graph that has been
911+
* locked by the gradient builder will fail without this.
912912
*/
913913
synchronized void setDangerousGradientBuilder(boolean dangerous) {
914914
dangerousGradientBuilder = dangerous;

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/GraphOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ public Set<GraphOperation> controlConsumers() {
386386
/**
387387
* Get the native handle of this operation.
388388
*
389-
* No liveness or non-null checking is done, the operation may have been deallocated.
389+
* <p>No liveness or non-null checking is done, the operation may have been deallocated.
390390
*/
391391
public TF_Operation getUnsafeNativeHandle() {
392392
return unsafeNativeHandle;

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/GraphOperationBuilder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ public OperationBuilder setAttr(String name, AttrValue value) {
402402
private final Scope scope;
403403

404404
/**
405-
* Use builders without locking. This should only be used during custom gradient building.
405+
* Use builders without locking. This should only be used during custom gradient building.
406406
*
407-
* The graph locks are not re-entrant, so attempting to add an op to a graph that has
408-
* been locked by the gradient builder will fail without this.
407+
* <p>The graph locks are not re-entrant, so attempting to add an op to a graph that has been
408+
* locked by the gradient builder will fail without this.
409409
*/
410410
private final boolean dangerousGradientBuilder;
411411

@@ -437,10 +437,10 @@ private static TF_OperationDescription allocate(TF_Graph graphHandle, String typ
437437
}
438438

439439
/**
440-
* Use builders without locking. This should only be used during custom gradient building.
440+
* Use builders without locking. This should only be used during custom gradient building.
441441
*
442-
* The graph locks are not re-entrant, so attempting to add an op to a graph that has
443-
* been locked by the gradient builder will fail without this.
442+
* <p>The graph locks are not re-entrant, so attempting to add an op to a graph that has been
443+
* locked by the gradient builder will fail without this.
444444
*/
445445
private static TF_OperationDescription allocateDangerousGradient(
446446
TF_Graph graphHandle, String type, String name) {
@@ -462,10 +462,10 @@ private static TF_Operation finish(TF_OperationDescription handle) {
462462
}
463463

464464
/**
465-
* Use builders without locking. This should only be used during custom gradient building.
465+
* Use builders without locking. This should only be used during custom gradient building.
466466
*
467-
* The graph locks are not re-entrant, so attempting to add an op to a graph that has
468-
* been locked by the gradient builder will fail without this.
467+
* <p>The graph locks are not re-entrant, so attempting to add an op to a graph that has been
468+
* locked by the gradient builder will fail without this.
469469
*/
470470
private static TF_Operation finishDangerousGradient(TF_Graph g, TF_OperationDescription handle) {
471471
requireHandle(handle);

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/TensorFlow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private TensorFlow() {}
154154
/**
155155
* Keeps references to custom gradient functions to prevent them from being deallocated.
156156
*
157-
* <b>Required for correctness</b>
157+
* <p><b>Required for correctness</b>
158158
*/
159159
private static final Set<GradFunc> gradientFuncs =
160160
Collections.newSetFromMap(new IdentityHashMap<>());

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/GradientScope.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ExecutionEnvironment env() {
3838

3939
@Override
4040
public GradientScope withSubScope(String childScopeName) {
41-
return new GradientScope(nativeScope.NewSubScope(childScopeName), graph, childScopeName, device);
41+
return new GradientScope(nativeScope.NewSubScope(childScopeName), graph, null, device);
4242
}
4343

4444
@Override
@@ -48,12 +48,17 @@ public GradientScope withName(String opName) {
4848

4949
@Override
5050
public GradientScope withNameAsSubScope(String defaultName) {
51-
return withSubScope(opName);
51+
if (opName == null) {
52+
return withSubScope(defaultName);
53+
} else {
54+
return withSubScope(opName);
55+
}
5256
}
5357

5458
@Override
5559
public GradientScope withDevice(DeviceSpec newDevice) {
56-
return new GradientScope(nativeScope.WithDevice(newDevice.toString()), graph, newDevice.toString());
60+
return new GradientScope(
61+
nativeScope.WithDevice(newDevice.toString()), graph, newDevice.toString());
5762
}
5863

5964
@Override
@@ -90,7 +95,8 @@ public GradientScope withControlDependencies(Iterable<Op> controls) {
9095
.put(new NativeOperation(((GraphOperation) op).getUnsafeNativeHandle().node()));
9196
}
9297

93-
return new GradientScope(nativeScope.WithControlDependencies(new NativeOperation(ops)), graph, device);
98+
return new GradientScope(
99+
nativeScope.WithControlDependencies(new NativeOperation(ops)), graph, device);
94100
}
95101

96102
@Override
@@ -108,7 +114,8 @@ public Scope withControlDependencyOps(Iterable<Operation> controls) {
108114
.put(new NativeOperation(((GraphOperation) op).getUnsafeNativeHandle().node()));
109115
}
110116

111-
return new GradientScope(nativeScope.WithControlDependencies(new NativeOperation(ops)), graph, device);
117+
return new GradientScope(
118+
nativeScope.WithControlDependencies(new NativeOperation(ops)), graph, device);
112119
}
113120

114121
@Override
@@ -122,7 +129,8 @@ public void onOpCreated(Operation op) {}
122129
@Override
123130
public String getDeviceString() {
124131
if (device == null) {
125-
throw new UnsupportedOperationException("Can't get device string for gradient scope unless it has been explicitly set");
132+
throw new UnsupportedOperationException(
133+
"Can't get device string for gradient scope unless it has been explicitly set");
126134
} else {
127135
return device;
128136
}

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/RawGradientAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public NativeStatus call(
6161

6262
GraphOperation operation = BaseGradientAdapter.getGraphOp(g, op.node());
6363

64+
// The graph locks are not re-entrant, so attempting to add an op to a graph that has been
65+
// locked by the gradient builder will fail without this.
6466
BaseGradientAdapter.useDangerousLockedBuilders(g, true);
6567
List<Operand<?>> gradOutputs = gradient.call(tf, operation, gradInputs);
6668
BaseGradientAdapter.useDangerousLockedBuilders(g, false);

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/Scope.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ default OperationBuilder opBuilder(String type, String name) {
224224
return env().opBuilder(type, makeOpName(name), this);
225225
}
226226

227+
/** Check whether {@code name} is a valid name for an operation. */
227228
static boolean isValidOpName(String name) {
228229
return NameScope.isValidName(name);
229230
}

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/TypedGradientAdapter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public NativeStatus call(
6868

6969
T rawOp = ctor.newInstance(BaseGradientAdapter.getGraphOp(g, op.node()));
7070

71+
// The graph locks are not re-entrant, so attempting to add an op to a graph that has been
72+
// locked by the gradient builder will fail without this.
7173
BaseGradientAdapter.useDangerousLockedBuilders(g, true);
7274
List<Operand<?>> gradOutputs = gradient.call(tf, rawOp, gradInputs);
7375
BaseGradientAdapter.useDangerousLockedBuilders(g, false);

0 commit comments

Comments
 (0)