Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Optimize LayerNorm #161

Merged
merged 1 commit into from
Oct 6, 2023
Merged

Optimize LayerNorm #161

merged 1 commit into from
Oct 6, 2023

Conversation

daemyung
Copy link

@daemyung daemyung commented Oct 6, 2023

πŸ™ Describe the pull request

LayerNorm is optimized by performing only the necessary boundary checks.

βœ… Checklist

  • Code follows the project's coding conventions and style.
  • Tests have been added or updated to cover the changes.
  • Documentation has been updated, if necessary.

@daemyung daemyung added the enhancement New feature or request label Oct 6, 2023
@daemyung daemyung self-assigned this Oct 6, 2023
Copy link
Contributor

@mejai1206 mejai1206 left a comment

Choose a reason for hiding this comment

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

LGTM

grad_norm = weight * grad_output
else:
grad_norm = grad_output

grad_std = tl.sum(grad_norm * centered_mean, 1)
grad_var = grad_std * -(0.5 * rstd * rstd * rstd) / x_size
grad_distance = 2 * centered_mean * grad_var
grad_centered_mean = tl.where(condition, grad_norm * rstd + grad_distance, 0)
grad_centered_mean = grad_norm * rstd + grad_distance
Copy link
Contributor

Choose a reason for hiding this comment

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

μ—¬κΈ° 있던 where μ ˆμ€ 없어져도 결과에 영ν–₯을 μ•ˆ λ―ΈμΉ˜λ‚˜μš”?

Copy link
Author

Choose a reason for hiding this comment

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

λ„€ μœ„μ—μ„œ 데이터λ₯Ό λΆˆλŸ¬μ˜¬λ•Œ padding="zero"둜 ν•΄κ²°ν–ˆμ–΄μš”.

@daemyung daemyung merged commit 96b0328 into main Oct 6, 2023
1 check passed
@daemyung daemyung deleted the layer_norm branch October 6, 2023 15:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants