Skip to content

Conversation

@eliotwang
Copy link
Contributor

Description

Optimized the LayerNorm kernel for specific shapes, with performance results shown in the figure. The optimizations also demonstrate good generalizability.
image

Fixes # (issue)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • Optimized performance when shapes match the tuned branch by offline tuning.
  • The performance improvement of the LayerNorm forward general kernel relies on algorithm optimization.
    Changed from first calculating the mean then calculating the variance to obtaining both mean and variance in a single pass based on Welford algorithm.
    1.Added a Stats_ge struct in utils.cu.
    2.Extended the kernel_traits class with an additional template parameter (defaulting to the Stats struct used by the tuned kernel).
    3.Modified kernel launches for the general case to explicitly specify the kernel_traits parameter.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@eliotwang eliotwang changed the title heyi's Ln_fwd optimization Layernorm forward optimization Nov 24, 2025
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