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)
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) |