GPUCodeForces/S1/zizi05_#1/mish_torchcode.py

23 lines
555 B
Python

import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self, in_features):
super().__init__()
# 使用固定的随机种子确保可复现性
torch.manual_seed(42)
self.linear = nn.Linear(in_features, in_features)
def forward(self, x):
x = self.linear(x)
return x * torch.tanh(torch.nn.functional.softplus(x))
def get_inputs():
batch_size = 4096
in_features = 1024
x = torch.randn(batch_size, in_features)
return [x]
def get_init_inputs():
return [1024]