-
Notifications
You must be signed in to change notification settings - Fork 11
feat(PerfModel): add TE LayerNormFn perf model (Normalization) #548
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
acee57a
Add perf model coverage for TE _Linear and _LayerNormLinear fused ops
gphuang 1a11bc2
fix: use weight dtype for bpe_mat2 in te_linear and te_layer_norm_linear
gphuang 9666e8d
Fix te_layer_norm_fn docstring: clarify it reports FLOPS via Normaliz…
gphuang 52aab2a
Address Copilot Round 3: exact bytes test, docstring, and comment fix
gphuang df66164
Remove te_linear/te_layer_norm_linear from core — handled by Megatron…
gphuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| ############################################################################### | ||
| # Copyright (c) 2024 - 2025 Advanced Micro Devices, Inc. All rights reserved. | ||
| # | ||
| # See LICENSE for license information. | ||
| ############################################################################### | ||
|
|
||
| from TraceLens.PerfModel.perf_model import te_layer_norm_fn | ||
| from TraceLens.PerfModel.torch_op_mapping import ( | ||
| categorize_torch_op, | ||
| op_to_perf_model_class_map, | ||
| ) | ||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Mapping and categorization | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_te_layer_norm_fn_mapped(): | ||
| assert op_to_perf_model_class_map["LayerNormFn"] is te_layer_norm_fn | ||
|
|
||
|
|
||
| def test_layer_norm_fn_categorizes_as_norm_fwd(): | ||
| row = {"name": "LayerNormFn", "kernel_details": []} | ||
| assert categorize_torch_op(row) == "NORM_fwd" | ||
|
|
||
|
|
||
| def test_layer_norm_fn_backward_categorizes_as_norm_bwd(): | ||
| row = {"name": "LayerNormFnBackward", "kernel_details": []} | ||
| assert categorize_torch_op(row) == "NORM_bwd" | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Helpers — synthetic events matching real TE trace format | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _layer_norm_fn_event(X_shape, gamma_shape, dtype="c10::BFloat16"): | ||
| """LayerNormFn: Input[0]=X, Input[1]=gamma.""" | ||
| strides_X = [] | ||
| s = 1 | ||
| for d in reversed(X_shape): | ||
| strides_X.insert(0, s) | ||
| s *= d | ||
| return { | ||
| "name": "LayerNormFn", | ||
| "args": { | ||
| "Input Dims": [X_shape, gamma_shape, [], [], [], [], [], []], | ||
| "Input type": [ | ||
| dtype, | ||
| dtype, | ||
| "", | ||
| "", | ||
| "Scalar", | ||
| "Scalar", | ||
| "Scalar", | ||
| "Scalar", | ||
| ], | ||
| "Input Strides": [strides_X, [1], [], [], [], [], [], []], | ||
| "Concrete Inputs": ["", "", "", "", "1e-05", "256", "False", "True"], | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # te_layer_norm_fn — normalization model | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def test_te_layer_norm_fn_instantiates(): | ||
| event = _layer_norm_fn_event(X_shape=[2048, 4, 2048], gamma_shape=[2048]) | ||
| model = te_layer_norm_fn(event) | ||
| assert model.num_elems == 2048 * 4 * 2048 | ||
| assert model.num_channels == 2048 | ||
|
|
||
|
|
||
| def test_te_layer_norm_fn_bytes(): | ||
| event = _layer_norm_fn_event(X_shape=[2048, 4, 2048], gamma_shape=[2048]) | ||
| model = te_layer_norm_fn(event) | ||
| num_elems = 2048 * 4 * 2048 | ||
| num_channels = 2048 | ||
| bpe = 2 # bf16 | ||
| # is_affine=True, is_training=True, has_bias=False | ||
| # num_weight_tensors = 2 (mean+var) + 1 (gamma) + 2 (training) = 5 | ||
| activation_bytes = num_elems * bpe + num_elems * bpe | ||
| weight_bytes = 5 * num_channels * bpe | ||
| assert model.bytes() == activation_bytes + weight_bytes |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.