beta)torch_npu.npu_group_norm_swish

接口原型

torch_npu.npu_group_norm_swish(Tensor input, int num_groups, Tensor weight, Tensor bias, float? eps=1e-5, float? swish_scale=1.0) -> (Tensor, Tensor, Tensor)

功能描述

对输入input进行组归一化计算,并计算Swish。

需要计算反向梯度场景时,若需要输出结果排除随机性,则需要设置确定性计算开关

参数说明

输出说明

out(Tensor) - 表示组归一化和swish计算的结果。

mean(Tensor) - 表示分组后的均值。

rstd(Tensor) - 表示分组后的标准差的倒数。

约束说明

需要计算反向梯度场景时,“input”的第1维除以“num_groups”的结果不能超过4000,“input”“weight”“bias”参数不支持含有-inf、inf或nan值。

支持的型号

调用示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import torch
import torch_npu
 
input = torch.randn(3, 4, 6, dtype=torch.float32).npu()
weight = torch.randn(input.size(1), dtype=torch.float32).npu()
bias = torch.randn(input.size(1), dtype=torch.float32).npu()
num_groups = input.size(1)
eps = 1e-5
swish_scale = 1.0
  out, mean, rstd = torch_npu.npu_group_norm_swish(input, num_groups, weight, bias, eps=eps, swish_scale=swish_scale)