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

add repr infomation for layer_norm and rms_norm #220

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions src/liger_kernel/transformers/layer_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def __init__(self, hidden_size, eps=1e-6, bias=False, init_fn="ones"):
"ones",
"zeros",
], f"init_fn must be either 'ones' or 'zeros', got {init_fn}"
self.hidden_size = hidden_size
self.eps = eps
self.weight = nn.Parameter(
torch.ones(hidden_size) if init_fn == "ones" else torch.zeros(hidden_size)
)
Expand All @@ -23,3 +25,6 @@ def forward(self, hidden_states):
return LigerLayerNormFunction.apply(
hidden_states, self.weight, self.bias, self.variance_epsilon
)

def extra_repr(self) -> str:
return f'{self.hidden_size}, eps={self.eps}'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no weight here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in line with nn.LayerNorm whose extra_repr is:

def extra_repr(self) -> str:
        return '{normalized_shape}, eps={eps}, ' \
            'elementwise_affine={elementwise_affine}'.format(**self.__dict__)

For rms_norm, it is in line with huggingface transformers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to keep them consistent here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sg

3 changes: 3 additions & 0 deletions src/liger_kernel/transformers/rms_norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ def forward(self, hidden_states):
self.offset,
self.casting_mode,
)

def extra_repr(self):
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}, offset={self.offset}"
Loading