GPUCodeForces/S1 codes/geglu_sample/geglu_torch.py

26 lines
483 B
Python

import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x: torch.Tensor) -> torch.Tensor:
value, gate = x.chunk(2, dim=-1)
return value * F.gelu(gate, approximate="tanh")
batch_size = 2048
feature_dim = 4096
def get_inputs():
x = torch.randn(batch_size, feature_dim, dtype=torch.float32) * 3.0
return [x]
def get_init_inputs():
return []