Created
February 25, 2014 16:12
-
-
Save benanne/9212037 to your computer and use it in GitHub Desktop.
Theano consider constant op
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import theano | |
import theano.tensor as T | |
from theano.tensor.opt import register_canonicalize | |
class ConsiderConstant(theano.compile.ViewOp): | |
def grad(self, args, g_outs): | |
return [T.zeros_like(g_out) for g_out in g_outs] | |
consider_constant = ConsiderConstant() | |
register_canonicalize(theano.gof.OpRemove(consider_constant), name='remove_consider_constant') | |
# TODO: implement w.r.t.? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example:
g = T.grad((x * consider_constant(x)).sum(), x)
=> gradient is x, not 2*x, as the second x is treated as a constant.