Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minor] Align layer norm eps value to PyTorch #221

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [0.0.x] - TBD
### Fixed
- Expose bias flag for feedforwards, same default as Timm [#220]
- Update eps value for layernormm, same default as torch [#221]

## [0.0.9] - 2022-02-09
### Added
Expand Down
4 changes: 2 additions & 2 deletions tests/test_triton_layernorm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def test_layernorm_parity(shape, amp):
eps = 1e-5

# Initialize the two layers, weights are 1 and 0 by default, no randomness
torch_layernorm = torch.nn.LayerNorm(X.shape[-1], eps).to("cuda")
triton_layernorm = FusedLayerNorm(X.shape[-1], eps).to("cuda")
torch_layernorm = torch.nn.LayerNorm(X.shape[-1], eps=eps).to("cuda")
triton_layernorm = FusedLayerNorm(X.shape[-1], affine=True, eps=eps).to("cuda")

with autocast(enabled=amp):
assert torch.allclose(X, X_) # sanity checking, else all hell breaks loose
Expand Down
4 changes: 2 additions & 2 deletions xformers/triton/layer_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FusedLayerNorm(nn.Module):

"""

def __init__(self, normalized_shape, affine=True, eps=1e-05):
def __init__(self, normalized_shape, affine=True, eps=1e-06):
super().__init__()
if affine:
self.weight = nn.Parameter(torch.ones(normalized_shape))
Expand All @@ -49,7 +49,7 @@ def layer_norm(
x: torch.Tensor,
weight: Optional[torch.Tensor] = None,
bias: Optional[torch.Tensor] = None,
eps: float = 1e-05,
eps: float = 1e-06,
) -> torch.Tensor:

global _triton_registered_warnings
Expand Down