-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sheng Feng Wu
committed
Sep 6, 2024
1 parent
3614d3b
commit 8ab0e79
Showing
3 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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,23 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import torch | ||
from executorch.examples.models.llama2.llama_transformer import RMSNorm | ||
|
||
|
||
def replace_rms_norm_with_native_rms_norm(module: torch.nn.Module): | ||
for name, child in module.named_children(): | ||
if isinstance(child, RMSNorm): | ||
rms_norm = torch.nn.RMSNorm(child.dim, eps=child.eps) | ||
rms_norm.weight = child.weight | ||
setattr( | ||
module, | ||
name, | ||
rms_norm, | ||
) | ||
else: | ||
replace_rms_norm_with_native_rms_norm(child) | ||
return module |