import torch
import torch.nn as nn
import torch.nn.functional as F

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

# NLReLU 超参数 beta ，论文中建议范围 0.7-1.1
BETA_VALUE = 1.0

class NLReLU(nn.Module):
    """
    "Natural-Logarithm-Rectified Activation Function in Convolutional Neural Networks"
    Formula:
      f(x) = log(beta * x + 1.0)   if x >= 0
      f(x) = 0                     if x < 0
    """
    def __init__(self, beta=1.0):
        super(NLReLU, self).__init__()
        self.beta = beta

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        x_relu = F.relu(x)
        inner = self.beta * x_relu + 1.0
        return torch.log(inner)

class Model(nn.Module):
    def __init__(self, beta=1.0):
        super(Model, self).__init__()
        self.act = NLReLU(beta=beta)
    
    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 [BETA_VALUE]