forked from ccf-ai-infra/GPUCodeForces
23 lines
623 B
Python
23 lines
623 B
Python
import torch
|
|
import torch.nn as nn
|
|
import torch.nn.functional as F
|
|
|
|
class Model(nn.Module):
|
|
def __init__(self, min_val=-1.0, max_val=1.0, beta=1.0):
|
|
super().__init__()
|
|
self.min_val = min_val
|
|
self.max_val = max_val
|
|
self.beta = beta
|
|
|
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
return x + F.softplus(self.min_val - x, beta=self.beta) - F.softplus(x - self.max_val, beta=self.beta)
|
|
|
|
batch_size = 128
|
|
feature_dim = 1024
|
|
|
|
def get_inputs():
|
|
x = torch.randn(batch_size, feature_dim, dtype=torch.float32)
|
|
return [x]
|
|
|
|
def get_init_inputs():
|
|
return [-1.0, 1.0, 1.0] |