import torch
import torch.nn as nn

BATCH_SIZE = 4096
HIDDEN_DIM = 4096
SHAPE = (BATCH_SIZE, HIDDEN_DIM)

ALPHA_INIT = 3.0

class PSGU(nn.Module):
    '''
    PSGU: Parametric self-circulation gating unit for deep neural networks
    https://www.sciencedirect.com/science/article/pii/S1047320321001942
    Formula: f(x) = x * tanh(alpha * sigmoid(x))
    '''
    def __init__(self, alpha_init=3.0):
        super(PSGU, self).__init__()
        self.alpha = nn.Parameter(torch.tensor(alpha_init))

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        return x * torch.tanh(self.alpha * torch.sigmoid(x))

class Model(nn.Module):
    def __init__(self, alpha_init=3.0):
        super(Model, self).__init__()
        self.act = PSGU(alpha_init)
    
    def forward(self, x):
        return self.act(x)

def get_inputs():
    input_tensor = torch.randn(SHAPE, dtype=torch.float32) * 5.0
    return [input_tensor.contiguous()]

def get_init_inputs():
    return [ALPHA_INIT]