Skip to content

Commit d08b38b

Browse files
committed
Add documentation about dangerousGradientBuilder
Signed-off-by: Ryan Nett <JNett96@gmail.com>
1 parent 8c40b8c commit d08b38b

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ protected static GraphOperation getGraphOp(Graph g, Node node) {
7878
}
7979
}
8080

81+
/**
82+
* Use builders without locking. This should only be used during custom gradient building.
83+
*
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.
86+
*/
8187
protected static void useDangerousLockedBuilders(Graph g, boolean dangerous) {
8288
g.setDangerousGradientBuilder(dangerous);
8389
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,12 @@ synchronized SaverDef saverDef() {
904904
private final Set<Operation> initializers = Collections.synchronizedSet(new LinkedHashSet<>());
905905
private boolean newInitializers = false;
906906

907+
/**
908+
* Use builders without locking. This should only be used during custom gradient building.
909+
*
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.
912+
*/
907913
synchronized void setDangerousGradientBuilder(boolean dangerous) {
908914
dangerousGradientBuilder = dangerous;
909915
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,13 @@ public OperationBuilder setAttr(String name, AttrValue value) {
400400
private TF_OperationDescription unsafeNativeHandle;
401401
private final Graph graph;
402402
private final Scope scope;
403+
404+
/**
405+
* Use builders without locking. This should only be used during custom gradient building.
406+
*
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.
409+
*/
403410
private final boolean dangerousGradientBuilder;
404411

405412
private static void requireHandle(Pointer handle) {

0 commit comments

Comments
 (0)