Coverage for  / home / jenkins / .local / lib / python3.10 / site-packages / hyper_parallel / components / functional / rms_norm.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-10-25 05:45 +0800

1# Copyright 2026 Huawei Technologies Co., Ltd 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14# ============================================================================ 

15"""Root mean square normalization function.""" 

16 

17import torch # pylint: disable=forbidden-backend-import 

18import torch_npu 

19 

20 

21def rms_norm(x: torch.Tensor, weight: torch.Tensor, eps: float = 1e-5) -> torch.Tensor: 

22 """Apply NPU-accelerated RMS normalization. 

23 

24 Args: 

25 x: Input tensor. 

26 weight: RMSNorm scale tensor. 

27 eps: Positive epsilon added to the variance. 

28 

29 Returns: 

30 The normalized tensor. 

31 """ 

32 return torch_npu.npu_rms_norm(x, weight, epsilon=eps)[0]