forked from ccf-ai-infra/GPUCodeForces
24 lines
491 B
Python
24 lines
491 B
Python
import torch
|
|
import torch.nn as nn
|
|
|
|
class Model(nn.Module):
|
|
"""
|
|
A model that applies LogSumExp over the last dimension.
|
|
"""
|
|
def __init__(self):
|
|
super(Model, self).__init__()
|
|
|
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
# PyTorch的logsumexp非常稳定且高效
|
|
return torch.logsumexp(x, dim=-1)
|
|
|
|
batch_size = 256
|
|
dim = 16384
|
|
|
|
def get_inputs():
|
|
x = torch.randn(batch_size, dim)
|
|
return [x]
|
|
|
|
def get_init_inputs():
|
|
return []
|