layernorm backward is indepedent of its mean (#4806)

This commit is contained in:
chenyu
2024-06-03 09:49:59 -04:00
committed by GitHub
parent 2dae657415
commit 3cc6ae0d85

View File

@@ -2590,7 +2590,7 @@ class Tensor:
print(t.mean().item(), t.std().item())
```
"""
y = (self - self.mean(axis, keepdim=True))
y = (self - self.detach().mean(axis, keepdim=True))
return y.mul((y*y).mean(axis, keepdim=True).add(eps).rsqrt())
def batchnorm(self, weight:Optional[Tensor], bias:Optional[Tensor], mean:Tensor, invstd:Tensor, axis:Union[int,Tuple[int,...]]=1) -> Tensor: