Hello all, I’m still trying to wrap my head around these Ops, but looking at the example provided by Aesara, I have a few questions hopefully someone can answer:
link to example: Creating a new Op: Python implementation — Aesara 2.2.6+4.g7c32fc48c.dirty documentation
In the following example it seems like x is the only variable and so i thought grads() would return [a * output_grads[0]] and not [a * output_grads[0]+b]
also If i wanted a,x,b to be variables would grads() return
[ a * output_grads[0], x * output_grads[0], 1 * output_grads[0] ] ?
import aesara
from aesara.graph.op import Op
from aesara.graph.basic import Apply
class AXPBOp(Op):
"""
This creates an Op that takes x to a*x+b.
"""
__props__ = ("a", "b")
def __init__(self, a, b):
self.a = a
self.b = b
super().__init__()
def make_node(self, x):
x = aesara.tensor.as_tensor_variable(x)
return Apply(self, [x], [x.type()])
def perform(self, node, inputs, output_storage):
x = inputs[0]
z = output_storage[0]
z[0] = self.a * x + self.b
def infer_shape(self, fgraph, node, i0_shapes):
return i0_shapes
def grad(self, inputs, output_grads):
return [a * output_grads[0] + b]