GPUCodeForces/S1/uucoco_#42/PSMish_torch.py

27 lines
582 B
Python

import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self, alpha: float = 1.0, beta: float = 1.0):
super().__init__()
self.alpha = alpha
self.beta = beta
def forward(self, x: torch.Tensor) -> torch.Tensor:
gate = torch.tanh(torch.log(1.0 + torch.exp(self.beta * x)))
return self.alpha * x * gate
batch_size = 128
feature_dim = 512
def get_inputs():
x = torch.randn(batch_size, feature_dim, dtype=torch.float32)
return [x]
def get_init_inputs():
return [1.0, 1.0]