Repository navigation
Add RMSNorm module - #121364
Add RMSNorm module#121364mikaylagawarecki wants to merge 15 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/121364
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New FailuresAs of commit dce5f7c with merge base 148a8de ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
|
Yay love to see this! |
|
cc @stas00 finally your ask is here! |
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
|
thank you for the heads up, @wanchaol! Do you know if it is on par with |
albanD
left a comment
There was a problem hiding this comment.
Sounds pretty good!
Feel free to keep autograd and more optimized kernels for the next PR if you want to keep this one simple.
| return handle_torch_function( | ||
| rms_norm, (input, weight), input, normalized_shape, weight=weight, eps=eps | ||
| ) | ||
| if input.shape[-len(normalized_shape):] != normalized_shape: |
There was a problem hiding this comment.
If this error checking is here, does it mean that calling torch.rms_norm() without these will error out? Should we move these checks to c++ ?
|
|
||
| If a single integer is used, it is treated as a singleton list, and this module will | ||
| normalize over the last dimension which is expected to be of that specific size. | ||
| eps: a value added to the denominator for numerical stability. Default: 1e-6 |
There was a problem hiding this comment.
We should have eps be dtype-dependent. I think it's an oversight on our older modules where we assume they would always run in fp32.
I think we should start using torch.finfo(x.dtype).eps here WDYT?
cc @ngimel
@stas00 This seems to be the initial version adding the initial support of RMSNorm module that calls into basic aten op in C++, but looks like @mikaylagawarecki @albanD have plans to add more optimized kernels too! |
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) [ghstack-poisoned]
|
With the scaffolding in place, we'd accept a PR backing it with a fused implementation for perf when applicable. |
|
@pytorchmergebot revert -m "Broke internal tests" -c ghfirst |
|
@pytorchbot successfully started a revert job. Check the current status here. |
This reverts commit a7306de. Reverted #121364 on behalf of https://github.com/atalman due to Broke internal tests ([comment](#121364 (comment)))
|
@mikaylagawarecki your PR has been successfully reverted. |
|
@mikaylagawarecki has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@mikaylagawarecki has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@pytorchbot merge -f "Landed internally" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) Pull Request resolved: pytorch#121364 Approved by: https://github.com/albanD
This reverts commit a7306de. Reverted pytorch#121364 on behalf of https://github.com/atalman due to Broke internal tests ([comment](pytorch#121364 (comment)))
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51 **The implementation here is not optimized and we welcome pull requests to improve this** - Use `normalized_shape` instead of singular integer `dim` to be aligned with the `nn.LayerNorm` implementation - Remove the [upcast to float and downcast ](https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L73) Differential Revision: [](https://our.internmc.facebook.com/intern/diff/) Differential Revision: [D55485840](https://our.internmc.facebook.com/intern/diff/D55485840) Pull Request resolved: pytorch#121364 Approved by: https://github.com/albanD
Similar to https://github.com/facebookresearch/multimodal/blob/dbeed9724bc9099be173c86871df7d41f3b7e58c/torchmultimodal/modules/layers/normalizations.py#L51
The implementation here is not optimized and we welcome pull requests to improve this
normalized_shapeinstead of singular integerdimto be aligned with thenn.LayerNormimplementationStack from ghstack (oldest at bottom):
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler @amjames @desertfire @chauhang
Differential Revision:
Differential Revision: D55485840