Skip to content

Commit fd1cc19

Browse files
committed
Add Javadoc to DispatchingGradientAdapter
Document purpose as Java-side gradient dispatcher mirroring TF-Python, clarify raw vs typed gradient registration contract, and note duplicate registration rejection.
1 parent 1240293 commit fd1cc19

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@
2626
import org.tensorflow.Output;
2727
import org.tensorflow.internal.c_api.TFJ_Scope;
2828

29+
/**
30+
* Dispatching adapter for Java-side custom gradient registration.
31+
*
32+
* <p>This class mirrors the behavior of TensorFlow Python's {@code tf.RegisterGradient} mechanism
33+
* by providing a centralized dispatch layer for custom gradients in the Java API.
34+
*
35+
* <p>Gradients may be registered in one of two forms for a given op type:
36+
*
37+
* <ul>
38+
* <li>A raw gradient ({@link RawCustomGradient}) operating directly on {@link GraphOperation} and
39+
* {@link Output} objects.
40+
* <li>A typed gradient ({@link CustomGradient}) operating on generated {@link RawOpInputs}
41+
* subclasses.
42+
* </ul>
43+
*
44+
* <p>For any given op type, exactly one gradient definition is permitted: either raw or typed.
45+
* Duplicate registrations, or attempts to mix raw and typed gradients for the same op type, are
46+
* rejected to prevent ambiguous dispatch behavior.
47+
*
48+
* <p>At runtime, {@link #apply(Graph, TFJ_Scope, GraphOperation, List)} determines the operation
49+
* type and dispatches to the corresponding registered gradient implementation.
50+
*/
2951
final class DispatchingGradientAdapter extends AbstractGradientAdapter {
3052

3153
private final ConcurrentMap<String, RawCustomGradient> raw = new ConcurrentHashMap<>();

0 commit comments

Comments
 (0)