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.
图片

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
    Perform an exhaustive traversal of all possible parameter combinations for a specific hiddensize, compile and run each generated instance to collect timing data, and finally obtain the optimal parameter combination for the given shape.
  • Changed the computation method of normalization in the forward phase of the general branch.
    Changed from first calculating the mean then calculating the variance to obtaining both mean and variance in a single pass.
  • Mitigated register spilling in the backward pass of the general branch under certain conditions (e.g., when m is large).
    Accumulate dgamma and dbeta during dx computation/write-back rather than in hot loops; only cache y, not dy.
  • Optimized the dispatch strategy for the backward finalize kernel in the general branch.
    If n%32==0, launch the tuned kernel; otherwise, launch the general kernel.
  • The tuning tool is provided under the tuning_tools/ directory.

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

@charyang-ai charyang-ai self-assigned this Sep 5, 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.

2 participants