forked from ccf-ai-infra/GPUCodeForces
25 lines
628 B
Python
25 lines
628 B
Python
import torch
|
|
import torch.nn as nn
|
|
|
|
class Model(nn.Module):
|
|
def __init__(self, scale: torch.Tensor, bias: torch.Tensor):
|
|
super(Model, self).__init__()
|
|
self.scale = nn.Parameter(scale)
|
|
self.bias = nn.Parameter(bias)
|
|
|
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
z = x * self.scale.view(1, -1, 1, 1) + self.bias.view(1, -1, 1, 1)
|
|
g = torch.softmax(z, dim=1)
|
|
return g * x
|
|
|
|
N, C, H, W = 8, 64, 64, 64
|
|
|
|
def get_inputs():
|
|
x = torch.randn(N, C, H, W)
|
|
return [x]
|
|
|
|
def get_init_inputs():
|
|
scale = torch.randn(C)
|
|
bias = torch.randn(C)
|
|
return [scale, bias]
|