forked from ccf-ai-infra/GPUCodeForces
22 lines
479 B
Python
22 lines
479 B
Python
# softmax_torch.py
|
|
import torch
|
|
import torch.nn as nn
|
|
|
|
class Model(nn.Module):
|
|
"""使用 PyTorch 内置 nn.Softmax 的基准实现。"""
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.softmax = nn.Softmax(dim=-1)
|
|
|
|
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
return self.softmax(x)
|
|
|
|
batch_size = 256
|
|
feature_dim = 4096
|
|
|
|
def get_inputs():
|
|
x = torch.randn(batch_size, feature_dim) * 5
|
|
return [x]
|
|
|
|
def get_init_inputs():
|
|
return [] |