batched broadcasted autograd
This commit is contained in:
parent
3627e42469
commit
79de915bb2
2 changed files with 4 additions and 2 deletions
Binary file not shown.
|
|
@ -83,8 +83,10 @@ class MatmulBackward:
|
|||
def backward(self, gradient):
|
||||
x, y = self.input
|
||||
|
||||
if x.shape != y.shape: # broadcasted case
|
||||
return [gradient @ y.transpose(-1,-2), x.transpose(-1,-2) @ gradient]
|
||||
if x.ndim != y.ndim: # broadcasted case
|
||||
print("KKKKKKKKK", x.ndim, y.ndim)
|
||||
aux = (gradient @ y.transpose(-1,-2))
|
||||
return [aux.sum(axis=0), x.transpose(-1,-2) @ gradient]
|
||||
else:
|
||||
return [gradient @ y.transpose(-1,-2), x.transpose(-1,-2) @ gradient]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue