forked from ccf-ai-infra/GPUCodeForces
25 lines
672 B
Python
25 lines
672 B
Python
import torch
|
|
import torch.nn as nn
|
|
|
|
class Model(nn.Module):
|
|
def __init__(self, gamma: torch.Tensor, beta: torch.Tensor):
|
|
super(Model, self).__init__()
|
|
self.gamma = nn.Parameter(gamma)
|
|
self.beta = nn.Parameter(beta)
|
|
|
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
rms = torch.sqrt(torch.mean(x * x, dim=(2,3), keepdim=True))
|
|
g = torch.sigmoid(self.gamma.view(1,-1,1,1) * rms + self.beta.view(1,-1,1,1))
|
|
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():
|
|
gamma = torch.randn(C)
|
|
beta = torch.randn(C)
|
|
return [gamma, beta]
|