import torch
import torch.nn as nn

class Model(nn.Module):
    def __init__(self, scale: torch.Tensor, bias: torch.Tensor, group: int):
        super(Model, self).__init__()
        self.scale = nn.Parameter(scale)
        self.bias = nn.Parameter(bias)
        self.register_buffer("group", torch.tensor(int(group), dtype=torch.int32))

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        g = int(self.group.item())
        z = x * self.scale.view(1,-1,1,1) + self.bias.view(1,-1,1,1)
        C = z.size(1)
        G = (C + g - 1) // g
        y = torch.empty_like(x)
        for gi in range(G):
            s = gi * g
            e = min(s + g, C)
            m = torch.amax(z[:, s:e], dim=1, keepdim=True)
            ex = torch.exp(z[:, s:e] - m)
            den = torch.sum(ex, dim=1, keepdim=True)
            y[:, s:e] = (ex / den) * x[:, s:e]
        return y

N, C, H, W = 4, 96, 32, 32

def get_inputs():
    x = torch.randn(N, C, H, W)
    return [x]

def get_init_inputs():
    scale = torch.randn(C)
    bias = torch.randn(C)
    group = 16
    return [scale, bias, group]
