Skip to content

Commit ef5bd54

Browse files
committed
revert rms_norm.py
1 parent ca16a95 commit ef5bd54

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

examples/models/llama/TARGETS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ runtime.python_library(
113113
"source_transformation/prune_vocab.py",
114114
"source_transformation/quantize.py",
115115
"source_transformation/custom_kv_cache.py",
116+
"source_transformation/rms_norm.py",
116117
"source_transformation/rope.py",
117118
"source_transformation/sdpa.py",
118119
"source_transformation/spin_quant.py",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import torch
8+
from executorch.examples.models.llama.llama_transformer import RMSNorm
9+
10+
11+
def replace_rms_norm_with_native_rms_norm(module: torch.nn.Module):
12+
for name, child in module.named_children():
13+
if isinstance(child, RMSNorm):
14+
rms_norm = torch.nn.RMSNorm(child.dim, eps=child.eps)
15+
rms_norm.weight = child.weight
16+
setattr(
17+
module,
18+
name,
19+
rms_norm,
20+
)
21+
else:
22+
replace_rms_norm_with_native_rms_norm(child)
23+
return module

0 commit comments

Comments
 (0)