GPUCodeForces/S1/Ljy123_#38/torchcode.py

24 lines
672 B
Python

import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self, alpha: float, beta: float):
super(Model, self).__init__()
self.alpha = nn.Parameter(torch.tensor(float(alpha), dtype=torch.float32))
self.beta = nn.Parameter(torch.tensor(float(beta), dtype=torch.float32))
def forward(self, x: torch.Tensor) -> torch.Tensor:
d = torch.zeros_like(x)
d[..., :, 1:] = x[..., :, 1:] - x[..., :, :-1]
g = torch.sigmoid(self.alpha * d + self.beta)
return x * g
N, C, H, W = 8, 64, 64, 64
def get_inputs():
x = torch.randn(N, C, H, W)
return [x]
def get_init_inputs():
return [1.0, 0.0]