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

[embed norm] switch to apex MixedFusedLayerNorm #262

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

stas00
Copy link
Contributor

@stas00 stas00 commented Mar 9, 2022

as noticed by @thomasw21 - switching embed layernorm to use MixedFusedLayerNorm for consistency with other layer norms.


Incidentally, this also fixes a bug with how torch.nn.LayerNorm was used until now.

the framework was putting LayerNorm into the wrong param group here:

weight_decay_params = {'params': []}
no_weight_decay_params = {'params': [], 'weight_decay': 0.0}
for module in modules:
for module_ in module.modules():
if isinstance(module_, LayerNorm):
no_weight_decay_params['params'].extend(
[p for p in list(module_._parameters.values())
if p is not None])
else:
weight_decay_params['params'].extend(
[p for n, p in list(module_._parameters.items())
if p is not None and n != 'bias'])
no_weight_decay_params['params'].extend(
[p for n, p in list(module_._parameters.items())
if p is not None and n == 'bias'])

it should have been in no_weight_decay_params but ended up in weight_decay_params because in this module LayerNorm is an alias for MixedFusedLayerNorm, so if isinstance(module_, LayerNorm) was False.

So if we want to use torch.nn.LayerNorm we have to change the code above to additionally check for or isinstance(module_, torch.nn.LayerNorm).

@stas00 stas00 merged commit b9883f4 into main Mar 9, 2022
@stas00 stas00 deleted the embed-fused_layer_norm branch March 9, 2022 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant