How Can I Define Only the Gradient for a Tensorflow Subgraph?

black_puppydog

First: I am only a few days in with Tensorflow, so please bear with me.

I started out from the cifar10 tutorial code and I am now using a combination of convolutions and eigenvalue decompositions that break the symbolic differentiation. I.e. the graph gets built, then upon calling train() the script halts with "No gradient defined for operation [...] (op type: SelfAdjointEig)". No surprise there.

The inputs to the subgraph in question are still only the input feature maps and the filters being used, and I have the formulas for the gradients at hand and they should be straight-forward to implement given the inputs to the subgraph and the gradient with respect to its output.

From what I can see in the docs, I can register a gradient method for custom Ops with RegisterGradient or override them with the experimental gradient_override_map. Both of those should give me access to exactly the things I need. For example, searching on Github I find a lot of examples that access the op's inputs as op.input[0] or such.

The problem I have is that I want to essentially "shortcut" a whole subgraph, not a single op, so I have no single op to decorate. Since this is happening in one of the convolutional layers of the cifar example I tried using the scope object for that layer. Conceptually, what enters and exits that scope's graph is exactly what I want so if I could somehow override the whole scope's gradients that would "already" do it.

I saw tf.Graph.create_op which (I think) I could use to register a new type of operation and I could then override that Operation type's gradient computation with aforementioned methods. But I don't see a way of defining that op's forward pass without writing it in C++...

Maybe I am approaching this the wrong way entirely? Since all of my forward or backward operations can be implemented with the python interface I obviously want to avoid implementing anything in C++.

Yaroslav Bulatov

Here's a trick from Sergey Ioffe:

Suppose you want group of ops that behave as f(x) in forward mode, but as g(x) in the backward mode. You implement it as

t = g(x)
y = t + tf.stop_gradient(f(x) - t)

So in your case your g(x) could be an identity op, with a custom gradient using gradient_override_map

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I assemble a new Operation from a subgraph, and apply gradient to the newly assembled operation

From Dev

In tensorflow how can I rescale gradient before it propagates to the next layer?

From Dev

In tensorflow how can I rescale gradient before it propagates to the next layer?

From Dev

Tensorflow -- how can I process in numpy op outputs in py_func gradient?

From Dev

How can i use tensorflow object detection to only detect persons?

From Dev

How can I define such an array?

From Dev

How I can define this constraint?

From Dev

How can I define such an array?

From Dev

Define jacobian with tensorflow custom_gradient

From Dev

How can I rotate a linear gradient?

From Dev

How can I bind to a gradient stop WPF

From Dev

How can I create a custom gradient in android?

From Dev

How can I set the UINavigationbar with gradient color?

From Dev

How can I bind to a gradient stop WPF

From Dev

How can I create a custom gradient in android?

From Dev

Android How can i make a gradient of this EditText

From Dev

How can i make gradient sphere on glsl?

From Dev

How do I get the gradient of the loss at a TensorFlow variable?

From Dev

In R, how can I generate a subgraph from a igraph object based on multiple attribute scores?

From Dev

How to define gradient color globally?

From Dev

How can I define an Elisp widget type that only accepts positive numbers?

From Dev

How can I define a function which bind only xvalue OR prvalue but not both

From Dev

How do I define a samba share so that every user can only see its own home?

From Dev

How can i use define preprocessor to define function-pointer?

From Java

How to apply gradient clipping in TensorFlow?

From Dev

Tensorflow: How to replace or modify gradient?

From Dev

How to stop gradient of LSTMStateTuple in tensorflow

From Dev

How to define loss that can't be expressed by tensors in tensorflow

From Java

How i can define chatset for serialization in Quarkus?

Related Related

  1. 1

    How can I assemble a new Operation from a subgraph, and apply gradient to the newly assembled operation

  2. 2

    In tensorflow how can I rescale gradient before it propagates to the next layer?

  3. 3

    In tensorflow how can I rescale gradient before it propagates to the next layer?

  4. 4

    Tensorflow -- how can I process in numpy op outputs in py_func gradient?

  5. 5

    How can i use tensorflow object detection to only detect persons?

  6. 6

    How can I define such an array?

  7. 7

    How I can define this constraint?

  8. 8

    How can I define such an array?

  9. 9

    Define jacobian with tensorflow custom_gradient

  10. 10

    How can I rotate a linear gradient?

  11. 11

    How can I bind to a gradient stop WPF

  12. 12

    How can I create a custom gradient in android?

  13. 13

    How can I set the UINavigationbar with gradient color?

  14. 14

    How can I bind to a gradient stop WPF

  15. 15

    How can I create a custom gradient in android?

  16. 16

    Android How can i make a gradient of this EditText

  17. 17

    How can i make gradient sphere on glsl?

  18. 18

    How do I get the gradient of the loss at a TensorFlow variable?

  19. 19

    In R, how can I generate a subgraph from a igraph object based on multiple attribute scores?

  20. 20

    How to define gradient color globally?

  21. 21

    How can I define an Elisp widget type that only accepts positive numbers?

  22. 22

    How can I define a function which bind only xvalue OR prvalue but not both

  23. 23

    How do I define a samba share so that every user can only see its own home?

  24. 24

    How can i use define preprocessor to define function-pointer?

  25. 25

    How to apply gradient clipping in TensorFlow?

  26. 26

    Tensorflow: How to replace or modify gradient?

  27. 27

    How to stop gradient of LSTMStateTuple in tensorflow

  28. 28

    How to define loss that can't be expressed by tensors in tensorflow

  29. 29

    How i can define chatset for serialization in Quarkus?

HotTag

Archive