entry_point
stringlengths 1
65
| original_triton_python_code
stringlengths 208
619k
| optimised_triton_code
stringlengths 1.15k
275k
| repo_name
stringlengths 7
115
| module_name
stringlengths 1
65
| synthetic
bool 1
class | uuid
int64 0
18.5k
| licenses
listlengths 1
6
| stars
int64 0
19.8k
| sha
stringlengths 40
40
| repo_link
stringlengths 72
180
|
|---|---|---|---|---|---|---|---|---|---|---|
spatial_attn_layer
|
import torch
import torch.nn as nn
import torch.onnx
import torch.nn.parallel
class BasicConv(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride=1,
padding=0, dilation=1, groups=1, relu=True, bn=False, bias=False):
super(BasicConv, self).__init__()
self.out_channels = out_planes
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=
kernel_size, stride=stride, padding=padding, dilation=dilation,
groups=groups, bias=bias)
self.bn = nn.BatchNorm2d(out_planes, eps=1e-05, momentum=0.01,
affine=True) if bn else None
self.relu = nn.ReLU() if relu else None
def forward(self, x):
x = self.conv(x)
if self.bn is not None:
x = self.bn(x)
if self.relu is not None:
x = self.relu(x)
return x
class ChannelPool(nn.Module):
def forward(self, x):
return torch.cat((torch.max(x, 1)[0].unsqueeze(1), torch.mean(x, 1)
.unsqueeze(1)), dim=1)
class spatial_attn_layer(nn.Module):
def __init__(self, kernel_size=5):
super(spatial_attn_layer, self).__init__()
self.compress = ChannelPool()
self.spatial = BasicConv(2, 1, kernel_size, stride=1, padding=(
kernel_size - 1) // 2, relu=False)
def forward(self, x):
x_compress = self.compress(x)
x_out = self.spatial(x_compress)
scale = torch.sigmoid(x_out)
return x * scale
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.onnx
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 2
x0 = xindex % 16
x2 = xindex // 32
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp9 = triton_helpers.maximum(tmp7, tmp8)
tmp10 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp11 = triton_helpers.maximum(tmp9, tmp10)
tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
tmp13 = tl.where(tmp4, tmp11, tmp12)
tmp14 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp17 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp14 & xmask,
eviction_policy='evict_last', other=0.0)
tmp18 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp14 & xmask,
eviction_policy='evict_last', other=0.0)
tmp19 = tmp17 + tmp18
tmp20 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp14 & xmask,
eviction_policy='evict_last', other=0.0)
tmp21 = tmp19 + tmp20
tmp22 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp14 & xmask,
eviction_policy='evict_last', other=0.0)
tmp23 = tmp21 + tmp22
tmp24 = 4.0
tmp25 = tmp23 / tmp24
tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype)
tmp27 = tl.where(tmp14, tmp25, tmp26)
tmp28 = tl.where(tmp4, tmp13, tmp27)
tl.store(out_ptr0 + x3, tmp28, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_1(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x3, tmp3, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (1, 2, 5, 5), (50, 25, 5, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(128)](primals_1, buf0, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(2, 2), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 1, 4, 4), (16, 16, 4, 1))
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_1[grid(256)](primals_1, buf1, buf2,
256, XBLOCK=256, num_warps=4, num_stages=1)
return buf2, primals_1, primals_2, buf0, buf1
class BasicConv(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride=1,
padding=0, dilation=1, groups=1, relu=True, bn=False, bias=False):
super(BasicConv, self).__init__()
self.out_channels = out_planes
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size=
kernel_size, stride=stride, padding=padding, dilation=dilation,
groups=groups, bias=bias)
self.bn = nn.BatchNorm2d(out_planes, eps=1e-05, momentum=0.01,
affine=True) if bn else None
self.relu = nn.ReLU() if relu else None
def forward(self, x):
x = self.conv(x)
if self.bn is not None:
x = self.bn(x)
if self.relu is not None:
x = self.relu(x)
return x
class ChannelPool(nn.Module):
def forward(self, x):
return torch.cat((torch.max(x, 1)[0].unsqueeze(1), torch.mean(x, 1)
.unsqueeze(1)), dim=1)
class spatial_attn_layerNew(nn.Module):
def __init__(self, kernel_size=5):
super(spatial_attn_layerNew, self).__init__()
self.compress = ChannelPool()
self.spatial = BasicConv(2, 1, kernel_size, stride=1, padding=(
kernel_size - 1) // 2, relu=False)
def forward(self, input_0):
primals_2 = self.spatial.conv.weight
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
Ganzooo/soil_segmentation
|
spatial_attn_layer
| false
| 2,296
|
[
"MIT"
] | 0
|
56f410e3e184f24e52dd4b542ea309f0d203ca00
|
https://github.com/Ganzooo/soil_segmentation/tree/56f410e3e184f24e52dd4b542ea309f0d203ca00
|
AvgPoolPad
|
import torch
import torch.utils.data
import torch.nn as nn
from torch import optim as optim
import torch.nn.parallel
class AvgPoolPad(nn.Module):
def __init__(self, stride=2, padding=1):
super(AvgPoolPad, self).__init__()
self.pad = nn.ZeroPad2d((1, 0, 1, 0))
self.pool = nn.AvgPool2d(3, stride=stride, padding=padding,
count_include_pad=False)
def forward(self, x):
x = self.pad(x)
x = self.pool(x)
x = x[:, :, 1:, 1:]
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.utils.data
import torch.nn as nn
from torch import optim as optim
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_avg_pool2d_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 144
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 3 % 3
x0 = xindex % 3
x2 = xindex // 9
x4 = xindex
tmp0 = -1 + 2 * x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 5, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + 2 * x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = -2 + 2 * x1
tmp12 = tmp11 >= tmp1
tmp13 = -2 + 2 * x0
tmp14 = tmp13 >= tmp1
tmp15 = tmp12 & tmp14
tmp16 = tmp15 & tmp10
tmp17 = tl.load(in_ptr0 + (-10 + 2 * x0 + 8 * x1 + 16 * x2), tmp16 &
xmask, eviction_policy='evict_last', other=0.0)
tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
tmp19 = tl.where(tmp10, tmp17, tmp18)
tmp20 = 2 * x0
tmp21 = tmp20 >= tmp1
tmp22 = tmp20 < tmp3
tmp23 = tmp21 & tmp22
tmp24 = tmp5 & tmp23
tmp25 = tmp12 & tmp7
tmp26 = tmp25 & tmp24
tmp27 = tl.load(in_ptr0 + (-9 + 2 * x0 + 8 * x1 + 16 * x2), tmp26 &
xmask, eviction_policy='evict_last', other=0.0)
tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
tmp29 = tl.where(tmp24, tmp27, tmp28)
tmp30 = tmp29 + tmp19
tmp31 = 1 + 2 * x0
tmp32 = tmp31 >= tmp1
tmp33 = tmp31 < tmp3
tmp34 = tmp32 & tmp33
tmp35 = tmp5 & tmp34
tmp36 = tmp12 & tmp21
tmp37 = tmp36 & tmp35
tmp38 = tl.load(in_ptr0 + (-8 + 2 * x0 + 8 * x1 + 16 * x2), tmp37 &
xmask, eviction_policy='evict_last', other=0.0)
tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype)
tmp40 = tl.where(tmp35, tmp38, tmp39)
tmp41 = tmp40 + tmp30
tmp42 = 2 * x1
tmp43 = tmp42 >= tmp1
tmp44 = tmp42 < tmp3
tmp45 = tmp43 & tmp44
tmp46 = tmp45 & tmp9
tmp47 = tmp2 & tmp14
tmp48 = tmp47 & tmp46
tmp49 = tl.load(in_ptr0 + (-6 + 2 * x0 + 8 * x1 + 16 * x2), tmp48 &
xmask, eviction_policy='evict_last', other=0.0)
tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype)
tmp51 = tl.where(tmp46, tmp49, tmp50)
tmp52 = tmp51 + tmp41
tmp53 = tmp45 & tmp23
tmp54 = tmp2 & tmp7
tmp55 = tmp54 & tmp53
tmp56 = tl.load(in_ptr0 + (-5 + 2 * x0 + 8 * x1 + 16 * x2), tmp55 &
xmask, eviction_policy='evict_last', other=0.0)
tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype)
tmp58 = tl.where(tmp53, tmp56, tmp57)
tmp59 = tmp58 + tmp52
tmp60 = tmp45 & tmp34
tmp61 = tmp2 & tmp21
tmp62 = tmp61 & tmp60
tmp63 = tl.load(in_ptr0 + (-4 + 2 * x0 + 8 * x1 + 16 * x2), tmp62 &
xmask, eviction_policy='evict_last', other=0.0)
tmp64 = tl.full(tmp63.shape, 0.0, tmp63.dtype)
tmp65 = tl.where(tmp60, tmp63, tmp64)
tmp66 = tmp65 + tmp59
tmp67 = 1 + 2 * x1
tmp68 = tmp67 >= tmp1
tmp69 = tmp67 < tmp3
tmp70 = tmp68 & tmp69
tmp71 = tmp70 & tmp9
tmp72 = tmp43 & tmp14
tmp73 = tmp72 & tmp71
tmp74 = tl.load(in_ptr0 + (-2 + 2 * x0 + 8 * x1 + 16 * x2), tmp73 &
xmask, eviction_policy='evict_last', other=0.0)
tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype)
tmp76 = tl.where(tmp71, tmp74, tmp75)
tmp77 = tmp76 + tmp66
tmp78 = tmp70 & tmp23
tmp79 = tmp43 & tmp7
tmp80 = tmp79 & tmp78
tmp81 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x1 + 16 * x2), tmp80 &
xmask, eviction_policy='evict_last', other=0.0)
tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype)
tmp83 = tl.where(tmp78, tmp81, tmp82)
tmp84 = tmp83 + tmp77
tmp85 = tmp70 & tmp34
tmp86 = tmp43 & tmp21
tmp87 = tmp86 & tmp85
tmp88 = tl.load(in_ptr0 + (2 * x0 + 8 * x1 + 16 * x2), tmp87 & xmask,
eviction_policy='evict_last', other=0.0)
tmp89 = tl.full(tmp88.shape, 0.0, tmp88.dtype)
tmp90 = tl.where(tmp85, tmp88, tmp89)
tmp91 = tmp90 + tmp84
tmp92 = (0 * (0 >= -1 + 2 * x0) + (-1 + 2 * x0) * (-1 + 2 * x0 > 0)) * (
0 * (0 >= -1 + 2 * x1) + (-1 + 2 * x1) * (-1 + 2 * x1 > 0)) + (5 *
(5 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 5)) * (5 * (5 <= 2 +
2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 5)) + -1 * (0 * (0 >= -1 + 2 *
x0) + (-1 + 2 * x0) * (-1 + 2 * x0 > 0)) * (5 * (5 <= 2 + 2 * x1) +
(2 + 2 * x1) * (2 + 2 * x1 < 5)) + -1 * (0 * (0 >= -1 + 2 * x1) + (
-1 + 2 * x1) * (-1 + 2 * x1 > 0)) * (5 * (5 <= 2 + 2 * x0) + (2 + 2 *
x0) * (2 + 2 * x0 < 5))
tmp93 = tmp91 / tmp92
tl.store(out_ptr0 + x4, tmp93, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_avg_pool2d_constant_pad_nd_0[grid(144)](arg0_1,
buf0, 144, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 4, 2, 2), (36, 9, 3, 1), 4),
class AvgPoolPadNew(nn.Module):
def __init__(self, stride=2, padding=1):
super(AvgPoolPadNew, self).__init__()
self.pad = nn.ZeroPad2d((1, 0, 1, 0))
self.pool = nn.AvgPool2d(3, stride=stride, padding=padding,
count_include_pad=False)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Exir-lxr/crldr-prune-pytorch
|
AvgPoolPad
| false
| 2,297
|
[
"Apache-2.0"
] | 0
|
adeb5e0b24ce66ff9531d4d947f72412c1b5c033
|
https://github.com/Exir-lxr/crldr-prune-pytorch/tree/adeb5e0b24ce66ff9531d4d947f72412c1b5c033
|
Contract
|
import torch
import torch.nn as nn
class Contract(nn.Module):
def __init__(self, gain=2):
super().__init__()
self.gain = gain
def forward(self, x):
b, c, h, w = x.size()
s = self.gain
x = x.view(b, c, h // s, s, w // s, s)
x = x.permute(0, 3, 5, 1, 2, 4).contiguous()
return x.view(b, c * s * s, h // s, w // s)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x3 = xindex % 2
x4 = xindex // 2
y0 = yindex % 2
y1 = yindex // 2 % 2
y2 = yindex // 4
x6 = xindex
y5 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 2 * x3 + 4 * y1 + 8 * x4 + 64 * y2),
xmask & ymask)
tl.store(out_ptr0 + (x6 + 16 * y5), tmp0, xmask & ymask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 2, 2, 4, 2, 2), (64, 32, 16, 4, 2, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 16)](arg0_1, buf0, 16, 16, XBLOCK
=16, YBLOCK=16, num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 16, 2, 2), (64, 4, 2, 1), 0),
class ContractNew(nn.Module):
def __init__(self, gain=2):
super().__init__()
self.gain = gain
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
GoalballAnalysis/GUI
|
Contract
| false
| 2,298
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
Quantizing_cossim
|
import torch
import torch.nn as nn
from typing import Tuple
class Quantizing_cossim(nn.Module):
"""
This is quantizing layer.
"""
__initialized: 'bool' = True
def __init__(self, num_quantizing: 'int', quantizing_dim: 'int',
_weight: 'torch.Tensor'=None, initialize_by_dataset: 'bool'=True,
mean: 'float'=0.0, std: 'float'=1.0, eps: 'float'=1e-08, dtype:
'torch.dtype'=None, device: 'torch.device'=None):
super().__init__()
assert num_quantizing > 0
assert quantizing_dim > 0
self.num_quantizing = num_quantizing
self.quantizing_dim = quantizing_dim
self.initialize_by_dataset = initialize_by_dataset
self.mean, self.std = mean, std
self.eps = eps
if _weight is None:
self.weight = nn.Parameter(torch.empty(num_quantizing,
quantizing_dim, dtype=dtype, device=device))
nn.init.normal_(self.weight, mean=mean, std=std)
if initialize_by_dataset:
self.__initialized = False
self.__initialized_length = 0
else:
assert _weight.dim() == 2
assert _weight.size(0) == num_quantizing
assert _weight.size(1) == quantizing_dim
self.weight = nn.Parameter(_weight.to(device))
def forward(self, x: 'torch.Tensor') ->Tuple[torch.Tensor]:
"""
x : shape is (*, E), and weight shape is (Q, E).
return -> ( quantized : shape is (*, E), quantized_idx : shape is (*,) )
"""
input_size = x.shape
h = x.view(-1, self.quantizing_dim)
if not self.__initialized and self.initialize_by_dataset:
getting_len = self.num_quantizing - self.__initialized_length
init_weight = h[torch.randperm(len(h))[:getting_len]]
_until = self.__initialized_length + init_weight.size(0)
self.weight.data[self.__initialized_length:_until] = init_weight
self.__initialized_length = _until
None
if _until >= self.num_quantizing:
self.__initialized = True
None
dist = self.calculate_distance(h)
q_idx = torch.argmin(dist, dim=-1)
q_data = self.weight[q_idx]
return q_data.view(input_size), q_idx.view(input_size[:1])
def from_idx(self, idx: 'torch.Tensor') ->torch.Tensor:
"""
idx: shape is (*, ). int tensor.
return -> (*, E) float tensor
"""
input_size = idx.shape
i = idx.view(-1)
q_data = self.weight[i].view(*input_size, self.quantizing_dim)
return q_data
def load_state_dict(self, state_dict, strict: 'bool'):
self.__initialized = True
return super().load_state_dict(state_dict, strict=strict)
def __repr__(self):
s = f'Quantizing({self.num_quantizing}, {self.quantizing_dim})'
return s
def calculate_distance(self, x: 'torch.Tensor') ->torch.Tensor:
"""
x: shape is (B, *), float tensor
"""
assert x.dim() == 2
dot = torch.matmul(x, self.weight.T)
x_l2n = torch.linalg.norm(x, dim=-1)[:, None]
w_l2n = torch.linalg.norm(self.weight, dim=-1)[None, :]
norm = torch.matmul(x_l2n, w_l2n)
norm[norm < self.eps] = self.eps
cos_sim = dot / norm
return -cos_sim + 1
def isInitialized(self) ->bool:
return self.__initialized
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'num_quantizing': 4, 'quantizing_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_linalg_vector_norm_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp1 = tmp0 * tmp0
tmp3 = tmp2 * tmp2
tmp4 = tmp1 + tmp3
tmp6 = tmp5 * tmp5
tmp7 = tmp4 + tmp6
tmp9 = tmp8 * tmp8
tmp10 = tmp7 + tmp9
tmp11 = libdevice.sqrt(tmp10)
tl.store(out_ptr0 + x0, tmp11, xmask)
@triton.jit
def triton_poi_fused_index_put_lift_fresh_1(in_out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = 1e-08
tmp2 = tmp0 < tmp1
tmp3 = 9.99999993922529e-09
tmp4 = tl.where(tmp2, tmp3, tmp0)
tl.store(in_out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused_add_argmin_div_neg_2(in_ptr0, in_ptr1, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp27 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp45 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp46 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 / tmp1
tmp3 = -tmp2
tmp4 = 1.0
tmp5 = tmp3 + tmp4
tmp8 = tmp6 / tmp7
tmp9 = -tmp8
tmp10 = tmp9 + tmp4
tmp11 = tmp5 < tmp10
tmp12 = tmp5 == tmp10
tmp13 = tmp5 != tmp5
tmp14 = tmp10 != tmp10
tmp15 = tmp13 > tmp14
tmp16 = tmp11 | tmp15
tmp17 = tmp13 & tmp14
tmp18 = tmp12 | tmp17
tmp19 = tl.full([1], 0, tl.int64)
tmp20 = tl.full([1], 1, tl.int64)
tmp21 = tmp19 < tmp20
tmp22 = tmp18 & tmp21
tmp23 = tmp16 | tmp22
tmp24 = tl.where(tmp23, tmp5, tmp10)
tmp25 = tl.where(tmp23, tmp19, tmp20)
tmp28 = tmp26 / tmp27
tmp29 = -tmp28
tmp30 = tmp29 + tmp4
tmp31 = tmp24 < tmp30
tmp32 = tmp24 == tmp30
tmp33 = tmp24 != tmp24
tmp34 = tmp30 != tmp30
tmp35 = tmp33 > tmp34
tmp36 = tmp31 | tmp35
tmp37 = tmp33 & tmp34
tmp38 = tmp32 | tmp37
tmp39 = tl.full([1], 2, tl.int64)
tmp40 = tmp25 < tmp39
tmp41 = tmp38 & tmp40
tmp42 = tmp36 | tmp41
tmp43 = tl.where(tmp42, tmp24, tmp30)
tmp44 = tl.where(tmp42, tmp25, tmp39)
tmp47 = tmp45 / tmp46
tmp48 = -tmp47
tmp49 = tmp48 + tmp4
tmp50 = tmp43 < tmp49
tmp51 = tmp43 == tmp49
tmp52 = tmp43 != tmp43
tmp53 = tmp49 != tmp49
tmp54 = tmp52 > tmp53
tmp55 = tmp50 | tmp54
tmp56 = tmp52 & tmp53
tmp57 = tmp51 | tmp56
tmp58 = tl.full([1], 3, tl.int64)
tmp59 = tmp44 < tmp58
tmp60 = tmp57 & tmp59
tmp61 = tmp55 | tmp60
tl.where(tmp61, tmp43, tmp49)
tmp63 = tl.where(tmp61, tmp44, tmp58)
tl.store(out_ptr0 + x0, tmp63, xmask)
@triton.jit
def triton_poi_fused_index_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4
x0 = xindex % 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 4, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tl.device_assert((0 <= tmp4) & (tmp4 < 4) | ~xmask,
'index out of bounds: 0 <= tmp4 < 4')
tmp6 = tl.load(in_ptr1 + (x0 + 4 * tmp4), xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4),
(1, 4), 0), out=buf0)
buf1 = empty_strided_cuda((4,), (1,), torch.float32)
get_raw_stream(0)
triton_poi_fused_linalg_vector_norm_0[grid(4)](primals_1, buf1, 4,
XBLOCK=4, num_warps=1, num_stages=1)
del primals_1
buf2 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_linalg_vector_norm_0[grid(4)](primals_2, buf2, 4,
XBLOCK=4, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (4, 1), (1, 0), 0),
reinterpret_tensor(buf2, (1, 4), (0, 1), 0), out=buf3)
del buf1
del buf2
buf4 = buf3
del buf3
triton_poi_fused_index_put_lift_fresh_1[grid(16)](buf4, 16, XBLOCK=
16, num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((4,), (1,), torch.int64)
triton_poi_fused_add_argmin_div_neg_2[grid(4)](buf0, buf4, buf5, 4,
XBLOCK=4, num_warps=1, num_stages=1)
del buf0
buf6 = buf4
del buf4
triton_poi_fused_index_3[grid(16)](buf5, primals_2, buf6, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_2
return buf6, buf5, buf5
class Quantizing_cossimNew(nn.Module):
"""
This is quantizing layer.
"""
__initialized: 'bool' = True
def __init__(self, num_quantizing: 'int', quantizing_dim: 'int',
_weight: 'torch.Tensor'=None, initialize_by_dataset: 'bool'=True,
mean: 'float'=0.0, std: 'float'=1.0, eps: 'float'=1e-08, dtype:
'torch.dtype'=None, device: 'torch.device'=None):
super().__init__()
assert num_quantizing > 0
assert quantizing_dim > 0
self.num_quantizing = num_quantizing
self.quantizing_dim = quantizing_dim
self.initialize_by_dataset = initialize_by_dataset
self.mean, self.std = mean, std
self.eps = eps
if _weight is None:
self.weight = nn.Parameter(torch.empty(num_quantizing,
quantizing_dim, dtype=dtype, device=device))
nn.init.normal_(self.weight, mean=mean, std=std)
if initialize_by_dataset:
self.__initialized = False
self.__initialized_length = 0
else:
assert _weight.dim() == 2
assert _weight.size(0) == num_quantizing
assert _weight.size(1) == quantizing_dim
self.weight = nn.Parameter(_weight.to(device))
def from_idx(self, idx: 'torch.Tensor') ->torch.Tensor:
"""
idx: shape is (*, ). int tensor.
return -> (*, E) float tensor
"""
input_size = idx.shape
i = idx.view(-1)
q_data = self.weight[i].view(*input_size, self.quantizing_dim)
return q_data
def load_state_dict(self, state_dict, strict: 'bool'):
self.__initialized = True
return super().load_state_dict(state_dict, strict=strict)
def __repr__(self):
s = f'Quantizing({self.num_quantizing}, {self.quantizing_dim})'
return s
def calculate_distance(self, x: 'torch.Tensor') ->torch.Tensor:
"""
x: shape is (B, *), float tensor
"""
assert x.dim() == 2
dot = torch.matmul(x, self.weight.T)
x_l2n = torch.linalg.norm(x, dim=-1)[:, None]
w_l2n = torch.linalg.norm(self.weight, dim=-1)[None, :]
norm = torch.matmul(x_l2n, w_l2n)
norm[norm < self.eps] = self.eps
cos_sim = dot / norm
return -cos_sim + 1
def isInitialized(self) ->bool:
return self.__initialized
def forward(self, input_0):
primals_1 = self.weight
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0], output[1]
|
Geson-anko/VQ_AutoEncoder
|
Quantizing_cossim
| false
| 2,299
|
[
"MIT"
] | 0
|
62e1694de38ea6f152891e19abc190ad4048e587
|
https://github.com/Geson-anko/VQ_AutoEncoder/tree/62e1694de38ea6f152891e19abc190ad4048e587
|
MultiHeadAttentionLayer
|
import math
import torch
import torch.nn as nn
class MultiHeadAttentionLayer(nn.Module):
def __init__(self, hidden_dim, n_heads, dropout=0.1):
super().__init__()
assert hidden_dim % n_heads == 0
self.hidden_dim = hidden_dim
self.n_heads = n_heads
self.head_dim = hidden_dim // n_heads
self.fc_q = nn.Linear(hidden_dim, hidden_dim)
self.fc_k = nn.Linear(hidden_dim, hidden_dim)
self.fc_v = nn.Linear(hidden_dim, hidden_dim)
self.fc_o = nn.Linear(hidden_dim, hidden_dim)
self.dropout = nn.Dropout(dropout)
self.layer_norm = nn.LayerNorm(hidden_dim, eps=1e-06)
self.scale = math.sqrt(self.head_dim)
def forward(self, q, k, v, mask=None):
batch_size = q.size(0)
q = self.layer_norm(q)
q = self.fc_q(q)
k = self.fc_k(k)
v = self.fc_v(v)
q = q.view(batch_size, -1, self.n_heads, self.head_dim).permute(0,
2, 1, 3)
k = k.view(batch_size, -1, self.n_heads, self.head_dim).permute(0,
2, 1, 3)
v = v.view(batch_size, -1, self.n_heads, self.head_dim).permute(0,
2, 1, 3)
att = torch.matmul(q / self.scale, k.permute(0, 1, 3, 2))
if mask is not None:
att = att.masked_fill(mask == 0, -10000000000.0)
att = torch.softmax(att, dim=-1)
out = torch.matmul(self.dropout(att), v)
out = out.permute(0, 2, 1, 3).contiguous()
out = out.view(batch_size, self.hidden_dim)
out = self.dropout(self.fc_o(out))
return out, att
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4, 4, 4]), torch.rand([4, 4,
4, 4])]
def get_init_inputs():
return [[], {'hidden_dim': 4, 'n_heads': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-06
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_div_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_per_fused__softmax_4(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tmp6 / tmp10
tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (4,), (1,))
assert_size_stride(primals_11, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_12, (4, 4), (4, 1))
assert_size_stride(primals_13, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
buf1 = empty_strided_cuda((4, 1), (1, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_native_layer_norm_0[grid(4)](primals_1, buf0, buf1,
4, XBLOCK=4, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(16)](primals_1, buf0,
buf1, primals_2, primals_3, buf2, 16, XBLOCK=16, num_warps=1,
num_stages=1)
del buf0
del buf1
del primals_2
del primals_3
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf2, reinterpret_tensor(primals_4, (4, 4), (1, 4
), 0), out=buf3)
buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_8, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf4)
del primals_6
buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_11, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (4, 4), (1, 4), 0), out=buf5)
del primals_9
buf6 = reinterpret_tensor(buf3, (4, 4, 1, 1), (4, 1, 16, 16), 0)
del buf3
triton_poi_fused_div_2[grid(16)](buf6, primals_5, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_5
buf7 = empty_strided_cuda((4, 4, 1, 16), (64, 16, 16, 1), torch.float32
)
triton_poi_fused_clone_3[grid(16, 16)](buf4, primals_7, buf7, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_7
buf8 = reinterpret_tensor(buf4, (16, 1, 16), (16, 16, 1), 0)
del buf4
extern_kernels.bmm(reinterpret_tensor(buf6, (16, 1, 1), (1, 0, 0),
0), reinterpret_tensor(buf7, (16, 1, 16), (16, 0, 1), 0), out=buf8)
buf11 = empty_strided_cuda((4, 4, 1, 16), (64, 16, 16, 1), torch.
float32)
triton_per_fused__softmax_4[grid(16)](buf8, buf11, 16, 16, XBLOCK=8,
num_warps=2, num_stages=1)
buf12 = reinterpret_tensor(buf8, (4, 4, 16, 1), (64, 16, 1, 1), 0)
del buf8
triton_poi_fused_clone_3[grid(16, 16)](buf5, primals_10, buf12, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del buf5
del primals_10
buf13 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf11, (16, 1, 16), (16, 16,
1), 0), reinterpret_tensor(buf12, (16, 16, 1), (16, 1, 0), 0),
out=buf13)
buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_13, reinterpret_tensor(buf13, (4, 4),
(4, 1), 0), reinterpret_tensor(primals_12, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf14)
del primals_13
return buf14, buf11, primals_1, buf2, reinterpret_tensor(primals_8, (64,
4), (4, 1), 0), reinterpret_tensor(primals_11, (64, 4), (4, 1), 0
), buf11, reinterpret_tensor(buf13, (4, 4), (4, 1), 0
), primals_12, reinterpret_tensor(buf12, (16, 1, 16), (16, 1, 1), 0
), reinterpret_tensor(buf6, (16, 1, 1), (1, 1, 4), 0
), reinterpret_tensor(buf7, (16, 16, 1), (16, 1, 16), 0), primals_4
class MultiHeadAttentionLayerNew(nn.Module):
def __init__(self, hidden_dim, n_heads, dropout=0.1):
super().__init__()
assert hidden_dim % n_heads == 0
self.hidden_dim = hidden_dim
self.n_heads = n_heads
self.head_dim = hidden_dim // n_heads
self.fc_q = nn.Linear(hidden_dim, hidden_dim)
self.fc_k = nn.Linear(hidden_dim, hidden_dim)
self.fc_v = nn.Linear(hidden_dim, hidden_dim)
self.fc_o = nn.Linear(hidden_dim, hidden_dim)
self.dropout = nn.Dropout(dropout)
self.layer_norm = nn.LayerNorm(hidden_dim, eps=1e-06)
self.scale = math.sqrt(self.head_dim)
def forward(self, input_0, input_1, input_2):
primals_1 = self.fc_q.weight
primals_2 = self.fc_q.bias
primals_4 = self.fc_k.weight
primals_3 = self.fc_k.bias
primals_6 = self.fc_v.weight
primals_5 = self.fc_v.bias
primals_9 = self.fc_o.weight
primals_7 = self.fc_o.bias
primals_10 = self.layer_norm.weight
primals_13 = self.layer_norm.bias
primals_12 = input_0
primals_8 = input_1
primals_11 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13])
return output[0], output[1]
|
GaroneHuang/pan_pp.pytorch
|
MultiHeadAttentionLayer
| false
| 2,300
|
[
"Apache-2.0"
] | 0
|
dde41ad652179433ad8a9650f671dc6742b783f9
|
https://github.com/GaroneHuang/pan_pp.pytorch/tree/dde41ad652179433ad8a9650f671dc6742b783f9
|
MaxPoolPad
|
import torch
import torch.nn as nn
class MaxPoolPad(nn.Module):
def __init__(self):
super(MaxPoolPad, self).__init__()
self.pad = nn.ZeroPad2d((1, 0, 1, 0))
self.pool = nn.MaxPool2d(3, stride=2, padding=1)
def forward(self, x):
x = self.pad(x)
x = self.pool(x)
x = x[:, :, 1:, 1:].contiguous()
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_constant_pad_nd_max_pool2d_with_indices_0(in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 144
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 3 % 3
x0 = xindex % 3
x2 = xindex // 9
x4 = xindex
tmp0 = -1 + 2 * x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 5, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + 2 * x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = -2 + 2 * x1
tmp12 = tmp11 >= tmp1
tmp13 = -2 + 2 * x0
tmp14 = tmp13 >= tmp1
tmp15 = tmp12 & tmp14
tmp16 = tmp15 & tmp10
tmp17 = tl.load(in_ptr0 + (-10 + 2 * x0 + 8 * x1 + 16 * x2), tmp16 &
xmask, eviction_policy='evict_last', other=0.0)
tmp18 = tl.full(tmp17.shape, float('-inf'), tmp17.dtype)
tmp19 = tl.where(tmp10, tmp17, tmp18)
tmp20 = 2 * x0
tmp21 = tmp20 >= tmp1
tmp22 = tmp20 < tmp3
tmp23 = tmp21 & tmp22
tmp24 = tmp5 & tmp23
tmp25 = tmp12 & tmp7
tmp26 = tmp25 & tmp24
tmp27 = tl.load(in_ptr0 + (-9 + 2 * x0 + 8 * x1 + 16 * x2), tmp26 &
xmask, eviction_policy='evict_last', other=0.0)
tmp28 = tl.full(tmp27.shape, float('-inf'), tmp27.dtype)
tmp29 = tl.where(tmp24, tmp27, tmp28)
tmp30 = triton_helpers.maximum(tmp29, tmp19)
tmp31 = 1 + 2 * x0
tmp32 = tmp31 >= tmp1
tmp33 = tmp31 < tmp3
tmp34 = tmp32 & tmp33
tmp35 = tmp5 & tmp34
tmp36 = tmp12 & tmp21
tmp37 = tmp36 & tmp35
tmp38 = tl.load(in_ptr0 + (-8 + 2 * x0 + 8 * x1 + 16 * x2), tmp37 &
xmask, eviction_policy='evict_last', other=0.0)
tmp39 = tl.full(tmp38.shape, float('-inf'), tmp38.dtype)
tmp40 = tl.where(tmp35, tmp38, tmp39)
tmp41 = triton_helpers.maximum(tmp40, tmp30)
tmp42 = 2 * x1
tmp43 = tmp42 >= tmp1
tmp44 = tmp42 < tmp3
tmp45 = tmp43 & tmp44
tmp46 = tmp45 & tmp9
tmp47 = tmp2 & tmp14
tmp48 = tmp47 & tmp46
tmp49 = tl.load(in_ptr0 + (-6 + 2 * x0 + 8 * x1 + 16 * x2), tmp48 &
xmask, eviction_policy='evict_last', other=0.0)
tmp50 = tl.full(tmp49.shape, float('-inf'), tmp49.dtype)
tmp51 = tl.where(tmp46, tmp49, tmp50)
tmp52 = triton_helpers.maximum(tmp51, tmp41)
tmp53 = tmp45 & tmp23
tmp54 = tmp2 & tmp7
tmp55 = tmp54 & tmp53
tmp56 = tl.load(in_ptr0 + (-5 + 2 * x0 + 8 * x1 + 16 * x2), tmp55 &
xmask, eviction_policy='evict_last', other=0.0)
tmp57 = tl.full(tmp56.shape, float('-inf'), tmp56.dtype)
tmp58 = tl.where(tmp53, tmp56, tmp57)
tmp59 = triton_helpers.maximum(tmp58, tmp52)
tmp60 = tmp45 & tmp34
tmp61 = tmp2 & tmp21
tmp62 = tmp61 & tmp60
tmp63 = tl.load(in_ptr0 + (-4 + 2 * x0 + 8 * x1 + 16 * x2), tmp62 &
xmask, eviction_policy='evict_last', other=0.0)
tmp64 = tl.full(tmp63.shape, float('-inf'), tmp63.dtype)
tmp65 = tl.where(tmp60, tmp63, tmp64)
tmp66 = triton_helpers.maximum(tmp65, tmp59)
tmp67 = 1 + 2 * x1
tmp68 = tmp67 >= tmp1
tmp69 = tmp67 < tmp3
tmp70 = tmp68 & tmp69
tmp71 = tmp70 & tmp9
tmp72 = tmp43 & tmp14
tmp73 = tmp72 & tmp71
tmp74 = tl.load(in_ptr0 + (-2 + 2 * x0 + 8 * x1 + 16 * x2), tmp73 &
xmask, eviction_policy='evict_last', other=0.0)
tmp75 = tl.full(tmp74.shape, float('-inf'), tmp74.dtype)
tmp76 = tl.where(tmp71, tmp74, tmp75)
tmp77 = triton_helpers.maximum(tmp76, tmp66)
tmp78 = tmp70 & tmp23
tmp79 = tmp43 & tmp7
tmp80 = tmp79 & tmp78
tmp81 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x1 + 16 * x2), tmp80 &
xmask, eviction_policy='evict_last', other=0.0)
tmp82 = tl.full(tmp81.shape, float('-inf'), tmp81.dtype)
tmp83 = tl.where(tmp78, tmp81, tmp82)
tmp84 = triton_helpers.maximum(tmp83, tmp77)
tmp85 = tmp70 & tmp34
tmp86 = tmp43 & tmp21
tmp87 = tmp86 & tmp85
tmp88 = tl.load(in_ptr0 + (2 * x0 + 8 * x1 + 16 * x2), tmp87 & xmask,
eviction_policy='evict_last', other=0.0)
tmp89 = tl.full(tmp88.shape, float('-inf'), tmp88.dtype)
tmp90 = tl.where(tmp85, tmp88, tmp89)
tmp91 = triton_helpers.maximum(tmp90, tmp84)
tl.store(out_ptr0 + x4, tmp91, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2 % 2
x2 = xindex // 4
x3 = xindex
tmp0 = tl.load(in_ptr0 + (4 + x0 + 3 * x1 + 9 * x2), xmask)
tl.store(out_ptr0 + x3, tmp0, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_constant_pad_nd_max_pool2d_with_indices_0[grid(144)](
arg0_1, buf0, 144, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
triton_poi_fused_clone_1[grid(64)](buf0, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf0
return buf1,
class MaxPoolPadNew(nn.Module):
def __init__(self):
super(MaxPoolPadNew, self).__init__()
self.pad = nn.ZeroPad2d((1, 0, 1, 0))
self.pool = nn.MaxPool2d(3, stride=2, padding=1)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
GoalballAnalysis/GUI
|
MaxPoolPad
| false
| 2,301
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
AconC
|
import torch
import torch.nn as nn
class AconC(nn.Module):
""" ACON activation (activate or not).
AconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is a learnable parameter
according to "Activate or Not: Learning Customized Activation" <https://arxiv.org/pdf/2009.04759.pdf>.
"""
def __init__(self, c1):
super().__init__()
self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.beta = nn.Parameter(torch.ones(1, c1, 1, 1))
def forward(self, x):
dpx = (self.p1 - self.p2) * x
return dpx * torch.sigmoid(self.beta * dpx) + self.p2 * x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'c1': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_sub_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 - tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_mul_sigmoid_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 4
x3 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x3, xmask)
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp2
tmp5 = tl.sigmoid(tmp4)
tmp6 = tmp2 * tmp5
tmp8 = tmp7 * tmp1
tmp9 = tmp6 + tmp8
tl.store(out_ptr0 + x3, tmp9, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (1, 4, 1, 1), (4, 1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_sub_0[grid(4)](primals_1, primals_2, buf0, 4,
XBLOCK=4, num_warps=1, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_sigmoid_1[grid(256)](buf0, primals_3,
primals_4, primals_2, buf1, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_2
return buf1, primals_3, primals_4, buf0
class AconCNew(nn.Module):
""" ACON activation (activate or not).
AconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is a learnable parameter
according to "Activate or Not: Learning Customized Activation" <https://arxiv.org/pdf/2009.04759.pdf>.
"""
def __init__(self, c1):
super().__init__()
self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.beta = nn.Parameter(torch.ones(1, c1, 1, 1))
def forward(self, input_0):
primals_1 = self.p1
primals_2 = self.p2
primals_4 = self.beta
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
GoalballAnalysis/GUI
|
AconC
| false
| 2,302
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
Encoder
|
import torch
import torch.nn.functional as F
from torch import nn
class Encoder(nn.Module):
def __init__(self, input_size: 'int', output_size: 'int', max_temp:
'float'=10.0, min_temp: 'float'=0.1, reg_threshold: 'float'=3.0,
reg_eps: 'float'=1e-10) ->None:
"""Feature selection encoder
Implemented according to "`Concrete Autoencoders for Differentiable Feature Selection and Reconstruction.`"
:cite:p:`DBLP:journals/corr/abs-1901-09346`.
Args:
input_size: size of the input layer. Should be the same as the `output_size` of the decoder.
output_size: size of the latent layer. Should be the same as the `input_size` of the decoder.
max_temp: maximum temperature for Gumble Softmax. Defaults to 10.0.
min_temp: minimum temperature for Gumble Softmax. Defaults to 0.1.
reg_threshold: regularization threshold. The encoder will be penalized when the sum of
probabilities for a selection neuron exceed this threshold. Defaults to 0.3.
reg_eps: regularization epsilon. Minimum value for the clamped softmax function in
regularization term. Defaults to 1e-10.
"""
super(Encoder, self).__init__()
self.register_buffer('temp', torch.tensor(max_temp))
self.register_buffer('max_temp', torch.tensor(max_temp))
self.register_buffer('min_temp', torch.tensor(min_temp))
self.register_buffer('reg_threshold', torch.tensor(reg_threshold))
self.register_buffer('reg_eps', torch.tensor(reg_eps))
logits = nn.init.xavier_normal_(torch.empty(output_size, input_size))
self.logits = nn.Parameter(logits, requires_grad=True)
@property
def latent_features(self):
return torch.argmax(self.logits, 1)
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
"""Uses the trained encoder to make inferences.
Args:
x (torch.Tensor): input data. Should be the same size as the encoder input.
Returns:
torch.Tensor: encoder output of size `output_size`.
"""
logits_size = self.logits.size()
if self.training:
uniform = torch.rand(logits_size, device=x.device)
gumbel = -torch.log(-torch.log(uniform))
noisy_logits = (self.logits + gumbel) / self.temp
samples = F.softmax(noisy_logits, dim=1)
selections = samples
else:
dim_argmax = len(logits_size) - 1
logits_argmax = torch.argmax(self.logits, dim_argmax)
discrete_logits = F.one_hot(logits_argmax, num_classes=
logits_size[1])
selections = discrete_logits
encoded = torch.matmul(x, torch.transpose(selections.float(), 0, 1))
return encoded
def update_temp(self, current_epoch, max_epochs) ->torch.Tensor:
self.temp = self.max_temp * torch.pow(self.min_temp / self.max_temp,
current_epoch / max_epochs)
return self.temp
def calc_mean_max(self) ->torch.Tensor:
logits_softmax = F.softmax(self.logits, dim=1)
logits_max = torch.max(logits_softmax, 1).values
mean_max = torch.mean(logits_max)
return mean_max
def regularization(self) ->float:
"""Regularization term according to https://homes.esat.kuleuven.be/~abertran/reports/TS_JNE_2021.pdf. The sum of
probabilities for a selection neuron is penalized if its larger than the threshold value. The returned value is
summed with the loss function."""
selection = torch.clamp(F.softmax(self.logits, dim=1), self.reg_eps, 1)
return torch.sum(F.relu(torch.norm(selection, 1, dim=0) - self.
reg_threshold))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4, 'output_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn.functional as F
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_argmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp17 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp32 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 > tmp1
tmp3 = tmp0 == tmp1
tmp4 = tmp0 != tmp0
tmp5 = tmp1 != tmp1
tmp6 = tmp4 > tmp5
tmp7 = tmp2 | tmp6
tmp8 = tmp4 & tmp5
tmp9 = tmp3 | tmp8
tmp10 = tl.full([1], 0, tl.int64)
tmp11 = tl.full([1], 1, tl.int64)
tmp12 = tmp10 < tmp11
tmp13 = tmp9 & tmp12
tmp14 = tmp7 | tmp13
tmp15 = tl.where(tmp14, tmp0, tmp1)
tmp16 = tl.where(tmp14, tmp10, tmp11)
tmp18 = tmp15 > tmp17
tmp19 = tmp15 == tmp17
tmp20 = tmp15 != tmp15
tmp21 = tmp17 != tmp17
tmp22 = tmp20 > tmp21
tmp23 = tmp18 | tmp22
tmp24 = tmp20 & tmp21
tmp25 = tmp19 | tmp24
tmp26 = tl.full([1], 2, tl.int64)
tmp27 = tmp16 < tmp26
tmp28 = tmp25 & tmp27
tmp29 = tmp23 | tmp28
tmp30 = tl.where(tmp29, tmp15, tmp17)
tmp31 = tl.where(tmp29, tmp16, tmp26)
tmp33 = tmp30 > tmp32
tmp34 = tmp30 == tmp32
tmp35 = tmp30 != tmp30
tmp36 = tmp32 != tmp32
tmp37 = tmp35 > tmp36
tmp38 = tmp33 | tmp37
tmp39 = tmp35 & tmp36
tmp40 = tmp34 | tmp39
tmp41 = tl.full([1], 3, tl.int64)
tmp42 = tmp31 < tmp41
tmp43 = tmp40 & tmp42
tmp44 = tmp38 | tmp43
tl.where(tmp44, tmp30, tmp32)
tmp46 = tl.where(tmp44, tmp31, tmp41)
tl.store(out_ptr0 + x0, tmp46, xmask)
@triton.jit
def triton_poi_fused__to_copy_arange_eq_1(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4
x0 = xindex % 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = x0
tmp2 = tmp0 == tmp1
tmp3 = tmp2.to(tl.int64)
tmp4 = tmp3.to(tl.float32)
tl.store(out_ptr0 + x2, tmp4, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4,), (1,), torch.int64)
get_raw_stream(0)
triton_poi_fused_argmax_0[grid(4)](arg0_1, buf0, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__to_copy_arange_eq_1[grid(16)](buf0, buf1, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del buf0
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(arg1_1, (64, 4), (4, 1), 0),
reinterpret_tensor(buf1, (4, 4), (1, 4), 0), out=buf2)
del arg1_1
del buf1
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0),
class EncoderNew(nn.Module):
def __init__(self, input_size: 'int', output_size: 'int', max_temp:
'float'=10.0, min_temp: 'float'=0.1, reg_threshold: 'float'=3.0,
reg_eps: 'float'=1e-10) ->None:
"""Feature selection encoder
Implemented according to "`Concrete Autoencoders for Differentiable Feature Selection and Reconstruction.`"
:cite:p:`DBLP:journals/corr/abs-1901-09346`.
Args:
input_size: size of the input layer. Should be the same as the `output_size` of the decoder.
output_size: size of the latent layer. Should be the same as the `input_size` of the decoder.
max_temp: maximum temperature for Gumble Softmax. Defaults to 10.0.
min_temp: minimum temperature for Gumble Softmax. Defaults to 0.1.
reg_threshold: regularization threshold. The encoder will be penalized when the sum of
probabilities for a selection neuron exceed this threshold. Defaults to 0.3.
reg_eps: regularization epsilon. Minimum value for the clamped softmax function in
regularization term. Defaults to 1e-10.
"""
super(EncoderNew, self).__init__()
self.register_buffer('temp', torch.tensor(max_temp))
self.register_buffer('max_temp', torch.tensor(max_temp))
self.register_buffer('min_temp', torch.tensor(min_temp))
self.register_buffer('reg_threshold', torch.tensor(reg_threshold))
self.register_buffer('reg_eps', torch.tensor(reg_eps))
logits = nn.init.xavier_normal_(torch.empty(output_size, input_size))
self.logits = nn.Parameter(logits, requires_grad=True)
@property
def latent_features(self):
return torch.argmax(self.logits, 1)
def update_temp(self, current_epoch, max_epochs) ->torch.Tensor:
self.temp = self.max_temp * torch.pow(self.min_temp / self.max_temp,
current_epoch / max_epochs)
return self.temp
def calc_mean_max(self) ->torch.Tensor:
logits_softmax = F.softmax(self.logits, dim=1)
logits_max = torch.max(logits_softmax, 1).values
mean_max = torch.mean(logits_max)
return mean_max
def regularization(self) ->float:
"""Regularization term according to https://homes.esat.kuleuven.be/~abertran/reports/TS_JNE_2021.pdf. The sum of
probabilities for a selection neuron is penalized if its larger than the threshold value. The returned value is
summed with the loss function."""
selection = torch.clamp(F.softmax(self.logits, dim=1), self.reg_eps, 1)
return torch.sum(F.relu(torch.norm(selection, 1, dim=0) - self.
reg_threshold))
def forward(self, input_0):
arg0_1 = self.logits
arg1_1 = input_0
output = call([arg0_1, arg1_1])
return output[0]
|
GewoonMaarten/spherical-dmri-conv
|
Encoder
| false
| 2,303
|
[
"MIT"
] | 0
|
6a5bbb31cf70a5f8b839f92e534f49664001ea09
|
https://github.com/GewoonMaarten/spherical-dmri-conv/tree/6a5bbb31cf70a5f8b839f92e534f49664001ea09
|
Expand
|
import torch
import torch.nn as nn
class Expand(nn.Module):
def __init__(self, gain=2):
super().__init__()
self.gain = gain
def forward(self, x):
b, c, h, w = x.size()
s = self.gain
x = x.view(b, s, s, c // s ** 2, h, w)
x = x.permute(0, 3, 4, 1, 5, 2).contiguous()
return x.view(b, c // s ** 2, h * s, w * s)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 128
xnumel = 2
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x4 = xindex
y0 = yindex % 4
y1 = yindex // 4 % 2
y2 = yindex // 8 % 4
y3 = yindex // 32
y5 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * y2 + 16 * x4 + 32 * y1 + 64 * y3),
xmask & ymask, eviction_policy='evict_last')
tl.store(out_ptr0 + (x4 + 2 * y5), tmp0, xmask & ymask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4, 2, 4, 2), (64, 64, 16, 8, 2, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(128, 2)](arg0_1, buf0, 128, 2, XBLOCK
=2, YBLOCK=64, num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 1, 8, 8), (64, 64, 8, 1), 0),
class ExpandNew(nn.Module):
def __init__(self, gain=2):
super().__init__()
self.gain = gain
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
GoalballAnalysis/GUI
|
Expand
| false
| 2,304
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
SEModule
|
import torch
import torch.utils.data
import torch.nn as nn
from torch import optim as optim
import torch.nn.parallel
class SEModule(nn.Module):
def __init__(self, channels, reduction):
super(SEModule, self).__init__()
self.fc1 = nn.Conv2d(channels, channels // reduction, kernel_size=1,
padding=0)
self.relu = nn.ReLU(inplace=True)
self.fc2 = nn.Conv2d(channels // reduction, channels, kernel_size=1,
padding=0)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
module_input = x
x = x.view(x.size(0), x.size(1), -1).mean(-1).view(x.size(0), x.
size(1), 1, 1)
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
x = self.sigmoid(x)
return module_input * x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channels': 4, 'reduction': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.utils.data
import torch.nn as nn
from torch import optim as optim
import torch.nn.parallel
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = triton_helpers.maximum(tmp4, tmp3)
tl.store(in_out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (1,), (1,))
assert_size_stride(primals_4, (4, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = extern_kernels.convolution(reinterpret_tensor(buf1, (4, 4, 1,
1), (4, 1, 0, 0), 0), primals_2, stride=(1, 1), padding=(0, 0),
dilation=(1, 1), transposed=False, output_padding=(0, 0),
groups=1, bias=None)
assert_size_stride(buf2, (4, 1, 1, 1), (1, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_relu_1[grid(4)](buf3, primals_3, 4,
XBLOCK=4, num_warps=1, num_stages=1)
del primals_3
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1))
buf5 = buf4
del buf4
triton_poi_fused_convolution_2[grid(16)](buf5, primals_5, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_5
buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_3[grid(256)](primals_1, buf5, buf6,
256, XBLOCK=128, num_warps=4, num_stages=1)
return buf6, primals_1, primals_2, primals_4, reinterpret_tensor(buf1,
(4, 4, 1, 1), (4, 1, 1, 1), 0), buf3, buf5
class SEModuleNew(nn.Module):
def __init__(self, channels, reduction):
super(SEModuleNew, self).__init__()
self.fc1 = nn.Conv2d(channels, channels // reduction, kernel_size=1,
padding=0)
self.relu = nn.ReLU(inplace=True)
self.fc2 = nn.Conv2d(channels // reduction, channels, kernel_size=1,
padding=0)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.fc1.weight
primals_3 = self.fc1.bias
primals_4 = self.fc2.weight
primals_5 = self.fc2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Exir-lxr/crldr-prune-pytorch
|
SEModule
| false
| 2,305
|
[
"Apache-2.0"
] | 0
|
adeb5e0b24ce66ff9531d4d947f72412c1b5c033
|
https://github.com/Exir-lxr/crldr-prune-pytorch/tree/adeb5e0b24ce66ff9531d4d947f72412c1b5c033
|
PANNsLoss
|
import torch
import torch.nn as nn
class PANNsLoss(nn.Module):
def __init__(self):
super().__init__()
self.bce = nn.BCEWithLogitsLoss()
self.cel = nn.CrossEntropyLoss()
def forward(self, input, target):
"""
input_ = input
input_ = torch.where(
torch.isnan(input_),
torch.zeros_like(input_),
input_
)
input_ = torch.where(
torch.isinf(input_),
torch.zeros_like(input_),
input_
)
target = target.float()
"""
return self.bce(input, target)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_binary_cross_entropy_with_logits_0(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp3 = tl.load(in_ptr1 + r0, None)
tmp1 = 1.0
tmp2 = tmp1 - tmp0
tmp4 = tmp2 * tmp3
tmp5 = 0.0
tmp6 = triton_helpers.minimum(tmp5, tmp3)
tmp7 = tl_math.abs(tmp3)
tmp8 = -tmp7
tmp9 = tl_math.exp(tmp8)
tmp10 = libdevice.log1p(tmp9)
tmp11 = tmp6 - tmp10
tmp12 = tmp4 - tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
tmp16 = 256.0
tmp17 = tmp15 / tmp16
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp17, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_binary_cross_entropy_with_logits_0[grid(1)](buf1,
arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf1,
class PANNsLossNew(nn.Module):
def __init__(self):
super().__init__()
self.bce = nn.BCEWithLogitsLoss()
self.cel = nn.CrossEntropyLoss()
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Gopi-Durgaprasad/Kaggle-Cornell-Birdcall-Identification
|
PANNsLoss
| false
| 2,306
|
[
"Apache-2.0"
] | 0
|
9eafbcba3323c29b0f9271911debc2f18af78f23
|
https://github.com/Gopi-Durgaprasad/Kaggle-Cornell-Birdcall-Identification/tree/9eafbcba3323c29b0f9271911debc2f18af78f23
|
AvgPoolPad
|
import torch
import torch.nn as nn
class AvgPoolPad(nn.Module):
def __init__(self, stride=2, padding=1):
super(AvgPoolPad, self).__init__()
self.pad = nn.ZeroPad2d((1, 0, 1, 0))
self.pool = nn.AvgPool2d(3, stride=stride, padding=padding,
count_include_pad=False)
def forward(self, x):
x = self.pad(x)
x = self.pool(x)
x = x[:, :, 1:, 1:].contiguous()
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_avg_pool2d_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 144
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 3 % 3
x0 = xindex % 3
x2 = xindex // 9
x4 = xindex
tmp0 = -1 + 2 * x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 5, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + 2 * x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = -2 + 2 * x1
tmp12 = tmp11 >= tmp1
tmp13 = -2 + 2 * x0
tmp14 = tmp13 >= tmp1
tmp15 = tmp12 & tmp14
tmp16 = tmp15 & tmp10
tmp17 = tl.load(in_ptr0 + (-10 + 2 * x0 + 8 * x1 + 16 * x2), tmp16 &
xmask, eviction_policy='evict_last', other=0.0)
tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
tmp19 = tl.where(tmp10, tmp17, tmp18)
tmp20 = 2 * x0
tmp21 = tmp20 >= tmp1
tmp22 = tmp20 < tmp3
tmp23 = tmp21 & tmp22
tmp24 = tmp5 & tmp23
tmp25 = tmp12 & tmp7
tmp26 = tmp25 & tmp24
tmp27 = tl.load(in_ptr0 + (-9 + 2 * x0 + 8 * x1 + 16 * x2), tmp26 &
xmask, eviction_policy='evict_last', other=0.0)
tmp28 = tl.full(tmp27.shape, 0.0, tmp27.dtype)
tmp29 = tl.where(tmp24, tmp27, tmp28)
tmp30 = tmp29 + tmp19
tmp31 = 1 + 2 * x0
tmp32 = tmp31 >= tmp1
tmp33 = tmp31 < tmp3
tmp34 = tmp32 & tmp33
tmp35 = tmp5 & tmp34
tmp36 = tmp12 & tmp21
tmp37 = tmp36 & tmp35
tmp38 = tl.load(in_ptr0 + (-8 + 2 * x0 + 8 * x1 + 16 * x2), tmp37 &
xmask, eviction_policy='evict_last', other=0.0)
tmp39 = tl.full(tmp38.shape, 0.0, tmp38.dtype)
tmp40 = tl.where(tmp35, tmp38, tmp39)
tmp41 = tmp40 + tmp30
tmp42 = 2 * x1
tmp43 = tmp42 >= tmp1
tmp44 = tmp42 < tmp3
tmp45 = tmp43 & tmp44
tmp46 = tmp45 & tmp9
tmp47 = tmp2 & tmp14
tmp48 = tmp47 & tmp46
tmp49 = tl.load(in_ptr0 + (-6 + 2 * x0 + 8 * x1 + 16 * x2), tmp48 &
xmask, eviction_policy='evict_last', other=0.0)
tmp50 = tl.full(tmp49.shape, 0.0, tmp49.dtype)
tmp51 = tl.where(tmp46, tmp49, tmp50)
tmp52 = tmp51 + tmp41
tmp53 = tmp45 & tmp23
tmp54 = tmp2 & tmp7
tmp55 = tmp54 & tmp53
tmp56 = tl.load(in_ptr0 + (-5 + 2 * x0 + 8 * x1 + 16 * x2), tmp55 &
xmask, eviction_policy='evict_last', other=0.0)
tmp57 = tl.full(tmp56.shape, 0.0, tmp56.dtype)
tmp58 = tl.where(tmp53, tmp56, tmp57)
tmp59 = tmp58 + tmp52
tmp60 = tmp45 & tmp34
tmp61 = tmp2 & tmp21
tmp62 = tmp61 & tmp60
tmp63 = tl.load(in_ptr0 + (-4 + 2 * x0 + 8 * x1 + 16 * x2), tmp62 &
xmask, eviction_policy='evict_last', other=0.0)
tmp64 = tl.full(tmp63.shape, 0.0, tmp63.dtype)
tmp65 = tl.where(tmp60, tmp63, tmp64)
tmp66 = tmp65 + tmp59
tmp67 = 1 + 2 * x1
tmp68 = tmp67 >= tmp1
tmp69 = tmp67 < tmp3
tmp70 = tmp68 & tmp69
tmp71 = tmp70 & tmp9
tmp72 = tmp43 & tmp14
tmp73 = tmp72 & tmp71
tmp74 = tl.load(in_ptr0 + (-2 + 2 * x0 + 8 * x1 + 16 * x2), tmp73 &
xmask, eviction_policy='evict_last', other=0.0)
tmp75 = tl.full(tmp74.shape, 0.0, tmp74.dtype)
tmp76 = tl.where(tmp71, tmp74, tmp75)
tmp77 = tmp76 + tmp66
tmp78 = tmp70 & tmp23
tmp79 = tmp43 & tmp7
tmp80 = tmp79 & tmp78
tmp81 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x1 + 16 * x2), tmp80 &
xmask, eviction_policy='evict_last', other=0.0)
tmp82 = tl.full(tmp81.shape, 0.0, tmp81.dtype)
tmp83 = tl.where(tmp78, tmp81, tmp82)
tmp84 = tmp83 + tmp77
tmp85 = tmp70 & tmp34
tmp86 = tmp43 & tmp21
tmp87 = tmp86 & tmp85
tmp88 = tl.load(in_ptr0 + (2 * x0 + 8 * x1 + 16 * x2), tmp87 & xmask,
eviction_policy='evict_last', other=0.0)
tmp89 = tl.full(tmp88.shape, 0.0, tmp88.dtype)
tmp90 = tl.where(tmp85, tmp88, tmp89)
tmp91 = tmp90 + tmp84
tmp92 = (0 * (0 >= -1 + 2 * x0) + (-1 + 2 * x0) * (-1 + 2 * x0 > 0)) * (
0 * (0 >= -1 + 2 * x1) + (-1 + 2 * x1) * (-1 + 2 * x1 > 0)) + (5 *
(5 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 * x0 < 5)) * (5 * (5 <= 2 +
2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 5)) + -1 * (0 * (0 >= -1 + 2 *
x0) + (-1 + 2 * x0) * (-1 + 2 * x0 > 0)) * (5 * (5 <= 2 + 2 * x1) +
(2 + 2 * x1) * (2 + 2 * x1 < 5)) + -1 * (0 * (0 >= -1 + 2 * x1) + (
-1 + 2 * x1) * (-1 + 2 * x1 > 0)) * (5 * (5 <= 2 + 2 * x0) + (2 + 2 *
x0) * (2 + 2 * x0 < 5))
tmp93 = tmp91 / tmp92
tl.store(out_ptr0 + x4, tmp93, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2 % 2
x2 = xindex // 4
x3 = xindex
tmp0 = tl.load(in_ptr0 + (4 + x0 + 3 * x1 + 9 * x2), xmask)
tl.store(out_ptr0 + x3, tmp0, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_avg_pool2d_constant_pad_nd_0[grid(144)](arg0_1,
buf0, 144, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
triton_poi_fused_clone_1[grid(64)](buf0, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf0
return buf1,
class AvgPoolPadNew(nn.Module):
def __init__(self, stride=2, padding=1):
super(AvgPoolPadNew, self).__init__()
self.pad = nn.ZeroPad2d((1, 0, 1, 0))
self.pool = nn.AvgPool2d(3, stride=stride, padding=padding,
count_include_pad=False)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
GoalballAnalysis/GUI
|
AvgPoolPad
| false
| 2,307
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
Classifier
|
import torch
import torch.distributed
import torch.nn as nn
class Classifier(nn.Module):
def __init__(self, hidden_size):
super(Classifier, self).__init__()
self.linear1 = nn.Linear(hidden_size, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x, mask_cls):
h = self.linear1(x).squeeze(-1)
sent_scores = self.sigmoid(h) * mask_cls.float()
return sent_scores
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'hidden_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.distributed
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 64
x2 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr1 + x2, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp3 = tmp1 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (1, 4), (4, 1))
assert_size_stride(primals_2, (1,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf1 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 1), (1, 4), 0
), alpha=1, beta=1, out=buf1)
del primals_1
del primals_2
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_sigmoid_0[grid(256)](buf1, primals_4, buf2,
256, XBLOCK=128, num_warps=4, num_stages=1)
return buf2, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf1
class ClassifierNew(nn.Module):
def __init__(self, hidden_size):
super(ClassifierNew, self).__init__()
self.linear1 = nn.Linear(hidden_size, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0, input_1):
primals_1 = self.linear1.weight
primals_2 = self.linear1.bias
primals_3 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
GraphGrailAi/summ-abs-dev
|
Classifier
| false
| 2,308
|
[
"MIT"
] | 0
|
512f253bf72b6529589b29d06959b560b79f1cde
|
https://github.com/GraphGrailAi/summ-abs-dev/tree/512f253bf72b6529589b29d06959b560b79f1cde
|
BCEBlurWithLogitsLoss
|
import torch
import torch.nn as nn
class BCEBlurWithLogitsLoss(nn.Module):
def __init__(self, alpha=0.05):
super().__init__()
self.loss_fcn = nn.BCEWithLogitsLoss(reduction='none')
self.alpha = alpha
def forward(self, pred, true):
loss = self.loss_fcn(pred, true)
pred = torch.sigmoid(pred)
dx = pred - true
alpha_factor = 1 - torch.exp((dx - 1) / (self.alpha + 0.0001))
loss *= alpha_factor
return loss.mean()
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_binary_cross_entropy_with_logits_div_exp_mean_mul_rsub_sigmoid_sub_0(
in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp3 = tl.load(in_ptr1 + r0, None)
tmp1 = 1.0
tmp2 = tmp1 - tmp0
tmp4 = tmp2 * tmp3
tmp5 = 0.0
tmp6 = triton_helpers.minimum(tmp5, tmp3)
tmp7 = tl_math.abs(tmp3)
tmp8 = -tmp7
tmp9 = tl_math.exp(tmp8)
tmp10 = libdevice.log1p(tmp9)
tmp11 = tmp6 - tmp10
tmp12 = tmp4 - tmp11
tmp13 = tl.sigmoid(tmp3)
tmp14 = tmp13 - tmp0
tmp15 = tmp14 - tmp1
tmp16 = 19.96007984031936
tmp17 = tmp15 * tmp16
tmp18 = tl_math.exp(tmp17)
tmp19 = tmp1 - tmp18
tmp20 = tmp12 * tmp19
tmp21 = tl.broadcast_to(tmp20, [RBLOCK])
tmp23 = triton_helpers.promote_to_tensor(tl.sum(tmp21, 0))
tmp24 = 256.0
tmp25 = tmp23 / tmp24
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp25, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_binary_cross_entropy_with_logits_div_exp_mean_mul_rsub_sigmoid_sub_0[
grid(1)](buf1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf1,
class BCEBlurWithLogitsLossNew(nn.Module):
def __init__(self, alpha=0.05):
super().__init__()
self.loss_fcn = nn.BCEWithLogitsLoss(reduction='none')
self.alpha = alpha
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
GoalballAnalysis/GUI
|
BCEBlurWithLogitsLoss
| false
| 2,309
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
BAP
|
import torch
import torch.nn as nn
class BAP(nn.Module):
def __init__(self, **kwargs):
super(BAP, self).__init__()
def forward(self, feature_maps, attention_maps):
feature_shape = feature_maps.size()
attention_shape = attention_maps.size()
phi_I = torch.einsum('imjk,injk->imn', (attention_maps, feature_maps))
phi_I = torch.div(phi_I, attention_shape[1] * attention_shape[2])
phi_I = torch.mul(torch.sign(phi_I), torch.sqrt(torch.abs(phi_I) +
1e-12))
phi_I = phi_I.view(feature_shape[0], -1, 1, 1)
raw_features = torch.nn.functional.normalize(phi_I, dim=-1)
pooling_features = raw_features * 100.0
return pooling_features
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_0(in_out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = 0.0625
tmp2 = tmp0 * tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = tmp3 < tmp2
tmp5 = tmp4.to(tl.int8)
tmp6 = tmp2 < tmp3
tmp7 = tmp6.to(tl.int8)
tmp8 = tmp5 - tmp7
tmp9 = tmp8.to(tmp2.dtype)
tmp10 = tl_math.abs(tmp2)
tmp11 = 1e-12
tmp12 = tmp10 + tmp11
tmp13 = libdevice.sqrt(tmp12)
tmp14 = tmp9 * tmp13
tmp15 = tmp14 * tmp14
tmp16 = libdevice.sqrt(tmp15)
tmp17 = triton_helpers.maximum(tmp16, tmp11)
tmp18 = tmp14 / tmp17
tmp19 = 100.0
tmp20 = tmp18 * tmp19
tl.store(in_out_ptr0 + x0, tmp20, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg1_1, (4, 4, 16), (64, 16,
1), 0), reinterpret_tensor(arg0_1, (4, 16, 4), (64, 1, 16), 0),
out=buf0)
del arg0_1
del arg1_1
buf1 = reinterpret_tensor(buf0, (4, 16, 1, 1), (16, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_0[grid(64)](buf1,
64, XBLOCK=64, num_warps=1, num_stages=1)
return buf1,
class BAPNew(nn.Module):
def __init__(self, **kwargs):
super(BAPNew, self).__init__()
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
GunjanChourasia/WS_DAN_PyTorch
|
BAP
| false
| 2,310
|
[
"MIT"
] | 0
|
6c12a1b5b0b8980e3b69d44474e0b5edb455570c
|
https://github.com/GunjanChourasia/WS_DAN_PyTorch/tree/6c12a1b5b0b8980e3b69d44474e0b5edb455570c
|
SpatialAttention
|
import torch
from torch import nn
class SpatialAttention(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttention, self).__init__()
assert kernel_size in (3, 7), 'kernel size must be 3 or 7'
padding = 3 if kernel_size == 7 else 1
self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
x = torch.cat([avg_out, max_out], dim=1)
x = self.conv1(x)
return self.sigmoid(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 2
x0 = xindex % 16
x2 = xindex // 32
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp9 = tmp7 + tmp8
tmp10 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = 4.0
tmp13 = tmp11 / tmp12
tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
tmp15 = tl.where(tmp4, tmp13, tmp14)
tmp16 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp19 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp16 & xmask,
eviction_policy='evict_last', other=0.0)
tmp20 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp16 & xmask,
eviction_policy='evict_last', other=0.0)
tmp21 = triton_helpers.maximum(tmp19, tmp20)
tmp22 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp16 & xmask,
eviction_policy='evict_last', other=0.0)
tmp23 = triton_helpers.maximum(tmp21, tmp22)
tmp24 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp16 & xmask,
eviction_policy='evict_last', other=0.0)
tmp25 = triton_helpers.maximum(tmp23, tmp24)
tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype)
tmp27 = tl.where(tmp16, tmp25, tmp26)
tmp28 = tl.where(tmp4, tmp15, tmp27)
tl.store(out_ptr0 + x3, tmp28, xmask)
@triton.jit
def triton_poi_fused_sigmoid_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.sigmoid(tmp0)
tl.store(in_out_ptr0 + x0, tmp1, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (1, 2, 7, 7), (98, 49, 7, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(128)](primals_1, buf0, 128, XBLOCK=128,
num_warps=4, num_stages=1)
del primals_1
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 1, 4, 4), (16, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_sigmoid_1[grid(64)](buf2, 64, XBLOCK=64, num_warps
=1, num_stages=1)
return buf2, primals_2, buf0, buf2
class SpatialAttentionNew(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttentionNew, self).__init__()
assert kernel_size in (3, 7), 'kernel size must be 3 or 7'
padding = 3 if kernel_size == 7 else 1
self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.conv1.weight
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
SpatialAttention
| false
| 2,311
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
MeanVoxelFeatureExtractor
|
import torch
import torch.nn as nn
class VoxelFeatureExtractor(nn.Module):
def __init__(self, **kwargs):
super().__init__()
def get_output_feature_dim(self):
raise NotImplementedError
def forward(self, **kwargs):
raise NotImplementedError
class MeanVoxelFeatureExtractor(VoxelFeatureExtractor):
def __init__(self, **kwargs):
super().__init__()
def get_output_feature_dim(self):
return cfg.DATA_CONFIG.NUM_POINT_FEATURES['use']
def forward(self, features, num_voxels, **kwargs):
"""
:param features: (N, max_points_of_each_voxel, 3 + C)
:param num_voxels: (N)
:param kwargs:
:return:
"""
points_mean = features[:, :, :].sum(dim=1, keepdim=False
) / num_voxels.type_as(features).view(-1, 1)
return points_mean.contiguous()
def get_inputs():
return [torch.rand([64, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_div_sum_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (4 + x0 + 16 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (8 + x0 + 16 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (12 + x0 + 16 * x1), xmask)
tmp7 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp8 = tmp6 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (64, 4, 4), (16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_sum_0[grid(256)](arg0_1, arg1_1, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
return buf0,
class VoxelFeatureExtractor(nn.Module):
def __init__(self, **kwargs):
super().__init__()
def get_output_feature_dim(self):
raise NotImplementedError
def forward(self, **kwargs):
raise NotImplementedError
class MeanVoxelFeatureExtractorNew(VoxelFeatureExtractor):
def __init__(self, **kwargs):
super().__init__()
def get_output_feature_dim(self):
return cfg.DATA_CONFIG.NUM_POINT_FEATURES['use']
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
GuilinZ/PCDet
|
MeanVoxelFeatureExtractor
| false
| 2,312
|
[
"Apache-2.0"
] | 0
|
f39769160854871bec9954630b9a4369b603391d
|
https://github.com/GuilinZ/PCDet/tree/f39769160854871bec9954630b9a4369b603391d
|
HardAttn
|
import torch
from torch.nn import functional as F
import torch.nn as nn
class HardAttn(nn.Module):
"""Hard Attention (Sec. 3.1.II)"""
def __init__(self, in_channels):
super(HardAttn, self).__init__()
self.fc = nn.Linear(in_channels, 4 * 2)
self.init_params()
def init_params(self):
self.fc.weight.data.zero_()
self.fc.bias.data.copy_(torch.tensor([0, -0.75, 0, -0.25, 0, 0.25,
0, 0.75], dtype=torch.float))
def forward(self, x):
x = F.avg_pool2d(x, x.size()[2:]).view(x.size(0), x.size(1))
theta = torch.tanh(self.fc(x))
theta = theta.view(-1, 4, 2)
return theta
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 + tmp0
tmp4 = tmp3 + tmp2
tmp6 = tmp5 + tmp4
tmp8 = tmp7 + tmp6
tmp10 = tmp9 + tmp8
tmp12 = tmp11 + tmp10
tmp14 = tmp13 + tmp12
tmp16 = tmp15 + tmp14
tmp18 = tmp17 + tmp16
tmp20 = tmp19 + tmp18
tmp22 = tmp21 + tmp20
tmp24 = tmp23 + tmp22
tmp26 = tmp25 + tmp24
tmp28 = tmp27 + tmp26
tmp30 = tmp29 + tmp28
tmp31 = 0.0625
tmp32 = tmp30 * tmp31
tl.store(out_ptr0 + x0, tmp32, xmask)
@triton.jit
def triton_poi_fused_tanh_tanh_backward_1(in_out_ptr0, in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 8
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = libdevice.tanh(tmp2)
tmp4 = tmp3 * tmp3
tmp5 = 1.0
tmp6 = tmp5 - tmp4
tl.store(in_out_ptr0 + x2, tmp3, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (8, 4), (4, 1))
assert_size_stride(primals_3, (8,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_avg_pool2d_0[grid(16)](primals_1, buf0, 16, XBLOCK
=16, num_warps=1, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 8), (1, 4), 0), out=buf1)
del primals_2
buf2 = buf1
del buf1
buf3 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
triton_poi_fused_tanh_tanh_backward_1[grid(32)](buf2, primals_3,
buf3, 32, XBLOCK=32, num_warps=1, num_stages=1)
del primals_3
return reinterpret_tensor(buf2, (4, 4, 2), (8, 2, 1), 0
), reinterpret_tensor(buf0, (4, 4), (4, 1), 0), buf3
class HardAttnNew(nn.Module):
"""Hard Attention (Sec. 3.1.II)"""
def __init__(self, in_channels):
super(HardAttnNew, self).__init__()
self.fc = nn.Linear(in_channels, 4 * 2)
self.init_params()
def init_params(self):
self.fc.weight.data.zero_()
self.fc.bias.data.copy_(torch.tensor([0, -0.75, 0, -0.25, 0, 0.25,
0, 0.75], dtype=torch.float))
def forward(self, input_0):
primals_2 = self.fc.weight
primals_3 = self.fc.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
GoalballAnalysis/GUI
|
HardAttn
| false
| 2,313
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
MetaAconC
|
import torch
import torch.nn as nn
class MetaAconC(nn.Module):
""" ACON activation (activate or not).
MetaAconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is generated by a small network
according to "Activate or Not: Learning Customized Activation" <https://arxiv.org/pdf/2009.04759.pdf>.
"""
def __init__(self, c1, k=1, s=1, r=16):
super().__init__()
c2 = max(r, c1 // r)
self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.fc1 = nn.Conv2d(c1, c2, k, s, bias=True)
self.fc2 = nn.Conv2d(c2, c1, k, s, bias=True)
def forward(self, x):
y = x.mean(dim=2, keepdims=True).mean(dim=3, keepdims=True)
beta = torch.sigmoid(self.fc2(self.fc1(y)))
dpx = (self.p1 - self.p2) * x
return dpx * torch.sigmoid(beta * dpx) + self.p2 * x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'c1': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mean_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp10 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp14 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp18 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp28 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp30 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp32 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp15 = tmp13 + tmp14
tmp16 = tmp15 / tmp7
tmp17 = tmp8 + tmp16
tmp20 = tmp18 + tmp19
tmp22 = tmp20 + tmp21
tmp24 = tmp22 + tmp23
tmp25 = tmp24 / tmp7
tmp26 = tmp17 + tmp25
tmp29 = tmp27 + tmp28
tmp31 = tmp29 + tmp30
tmp33 = tmp31 + tmp32
tmp34 = tmp33 / tmp7
tmp35 = tmp26 + tmp34
tmp36 = tmp35 / tmp7
tl.store(out_ptr0 + x0, tmp36, xmask)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_sub_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 - tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_mul_sigmoid_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 4
x3 = xindex
x4 = xindex // 16
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x3, xmask)
tmp3 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp4 = tl.sigmoid(tmp3)
tmp5 = tmp4 * tmp2
tmp6 = tl.sigmoid(tmp5)
tmp7 = tmp2 * tmp6
tmp9 = tmp8 * tmp1
tmp10 = tmp7 + tmp9
tl.store(out_ptr0 + x3, tmp10, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (16, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (16,), (1,))
assert_size_stride(primals_4, (4, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_7, (1, 4, 1, 1), (4, 1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mean_0[grid(16)](primals_1, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 16, 1, 1), (16, 1, 1, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(64)](buf2, primals_3, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_3
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 1, 1), (4, 1, 1, 1))
buf4 = buf3
del buf3
triton_poi_fused_convolution_2[grid(16)](buf4, primals_5, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused_sub_3[grid(4)](primals_6, primals_7, buf5, 4,
XBLOCK=4, num_warps=1, num_stages=1)
del primals_6
buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_sigmoid_4[grid(256)](buf5, primals_1, buf4,
primals_7, buf6, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_7
return buf6, primals_1, primals_2, primals_4, buf0, buf2, buf4, buf5
class MetaAconCNew(nn.Module):
""" ACON activation (activate or not).
MetaAconC: (p1*x-p2*x) * sigmoid(beta*(p1*x-p2*x)) + p2*x, beta is generated by a small network
according to "Activate or Not: Learning Customized Activation" <https://arxiv.org/pdf/2009.04759.pdf>.
"""
def __init__(self, c1, k=1, s=1, r=16):
super().__init__()
c2 = max(r, c1 // r)
self.p1 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.p2 = nn.Parameter(torch.randn(1, c1, 1, 1))
self.fc1 = nn.Conv2d(c1, c2, k, s, bias=True)
self.fc2 = nn.Conv2d(c2, c1, k, s, bias=True)
def forward(self, input_0):
primals_6 = self.p1
primals_7 = self.p2
primals_2 = self.fc1.weight
primals_3 = self.fc1.bias
primals_4 = self.fc2.weight
primals_5 = self.fc2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
GoalballAnalysis/GUI
|
MetaAconC
| false
| 2,314
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
TransformerLayer
|
import torch
import torch.nn as nn
class TransformerLayer(nn.Module):
def __init__(self, c, num_heads):
super().__init__()
self.q = nn.Linear(c, c, bias=False)
self.k = nn.Linear(c, c, bias=False)
self.v = nn.Linear(c, c, bias=False)
self.ma = nn.MultiheadAttention(embed_dim=c, num_heads=num_heads)
self.fc1 = nn.Linear(c, c, bias=False)
self.fc2 = nn.Linear(c, c, bias=False)
def forward(self, x):
x = self.ma(self.q(x), self.k(x), self.v(x))[0] + x
x = self.fc2(self.fc1(x)) + x
return x
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'c': 4, 'num_heads': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mul_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 4
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x1), xmask & ymask)
tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_4(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10) = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (12, 4), (4, 1))
assert_size_stride(primals_6, (12,), (1,))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4), (4, 1))
assert_size_stride(primals_10, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_2, reinterpret_tensor(primals_1, (4, 4),
(1, 4), 0), out=buf0)
del primals_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_2, reinterpret_tensor(primals_3, (4, 4),
(1, 4), 0), out=buf1)
del primals_3
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_2, reinterpret_tensor(primals_4, (4, 4),
(1, 4), 0), out=buf2)
del primals_4
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf0, reinterpret_tensor(primals_5, (4, 4), (1, 4
), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_6, (4,), (1,), 4),
buf1, reinterpret_tensor(primals_5, (4, 4), (1, 4), 16), alpha=
1, beta=1, out=buf4)
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(reinterpret_tensor(primals_6, (4,), (1,), 8),
buf2, reinterpret_tensor(primals_5, (4, 4), (1, 4), 32), alpha=
1, beta=1, out=buf5)
buf6 = reinterpret_tensor(buf3, (4, 4, 1), (1, 4, 16), 0)
del buf3
get_raw_stream(0)
triton_poi_fused_mul_0[grid(16)](buf6, primals_6, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_6
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf6, reinterpret_tensor(buf4, (4, 1, 4), (1, 1,
4), 0), out=buf7)
buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(64)](buf7, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf9 = buf7
del buf7
triton_poi_fused__softmax_2[grid(64)](buf8, buf9, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf8
buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(buf9, reinterpret_tensor(buf5, (4, 4, 1), (1, 4,
1), 0), out=buf10)
buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 1), torch.float32)
triton_poi_fused_clone_3[grid(4, 4)](buf10, buf11, 4, 4, XBLOCK=4,
YBLOCK=4, num_warps=1, num_stages=1)
buf12 = reinterpret_tensor(buf10, (4, 4), (4, 1), 0)
del buf10
extern_kernels.mm(reinterpret_tensor(buf11, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf12)
buf13 = buf12
del buf12
triton_poi_fused_add_4[grid(16)](buf13, primals_8, primals_2, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_8
buf14 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf13, reinterpret_tensor(primals_9, (4, 4), (1,
4), 0), out=buf14)
buf15 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(buf13, buf14, reinterpret_tensor(primals_10, (
4, 4), (1, 4), 0), alpha=1, beta=1, out=buf15)
return buf15, primals_2, buf0, buf1, buf2, buf9, reinterpret_tensor(buf11,
(4, 4), (4, 1), 0
), buf13, buf14, primals_10, primals_9, primals_7, reinterpret_tensor(
buf5, (4, 1, 4), (1, 1, 4), 0), reinterpret_tensor(buf6, (4, 1, 4),
(1, 1, 4), 0), reinterpret_tensor(buf4, (4, 4, 1), (1, 4, 1), 0
), reinterpret_tensor(primals_5, (4, 4), (4, 1), 32
), reinterpret_tensor(primals_5, (4, 4), (4, 1), 16
), reinterpret_tensor(primals_5, (4, 4), (4, 1), 0)
class TransformerLayerNew(nn.Module):
def __init__(self, c, num_heads):
super().__init__()
self.q = nn.Linear(c, c, bias=False)
self.k = nn.Linear(c, c, bias=False)
self.v = nn.Linear(c, c, bias=False)
self.ma = nn.MultiheadAttention(embed_dim=c, num_heads=num_heads)
self.fc1 = nn.Linear(c, c, bias=False)
self.fc2 = nn.Linear(c, c, bias=False)
def forward(self, input_0):
primals_1 = self.q.weight
primals_2 = self.k.weight
primals_3 = self.v.weight
primals_5 = self.ma.in_proj_weight
primals_6 = self.ma.in_proj_bias
primals_4 = self.ma.out_proj.weight
primals_8 = self.ma.out_proj.bias
primals_7 = self.fc1.weight
primals_9 = self.fc2.weight
primals_10 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9, primals_10])
return output[0]
|
GoalballAnalysis/GUI
|
TransformerLayer
| false
| 2,315
|
[
"MIT"
] | 0
|
c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
https://github.com/GoalballAnalysis/GUI/tree/c7f1cc27f4fd7f861c3ca09f5ca25d1a3f19a8a7
|
ResizeCat
|
import torch
import torch.nn as nn
class ResizeCat(nn.Module):
def __init__(self, **kwargs):
super(ResizeCat, self).__init__()
def forward(self, at1, at3, at5):
_N, _C, H, W = at1.size()
resized_at3 = nn.functional.interpolate(at3, (H, W))
resized_at5 = nn.functional.interpolate(at5, (H, W))
cat_at = torch.cat((at1, resized_at3, resized_at5), dim=1)
return cat_at
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 768
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex // 16 % 12
x3 = xindex // 192
x4 = xindex % 16
x1 = xindex // 4 % 4
x0 = xindex % 4
x5 = xindex
tmp0 = x2
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x4 + 16 * x2 + 64 * x3), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 8, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = x1
tmp11 = tmp10.to(tl.float32)
tmp12 = 1.0
tmp13 = tmp11 * tmp12
tmp14 = tmp13.to(tl.int32)
tmp15 = x0
tmp16 = tmp15.to(tl.float32)
tmp17 = tmp16 * tmp12
tmp18 = tmp17.to(tl.int32)
tmp19 = tl.load(in_ptr1 + (tmp18 + 4 * tmp14 + 16 * (-4 + x2) + 64 * x3
), tmp9 & xmask, eviction_policy='evict_last', other=0.0)
tmp20 = tmp0 >= tmp7
tl.full([1], 12, tl.int64)
tmp23 = tl.load(in_ptr2 + (tmp18 + 4 * tmp14 + 16 * (-8 + x2) + 64 * x3
), tmp20 & tmp9 & xmask, eviction_policy='evict_last', other=0.0)
tmp24 = tl.where(tmp9, tmp19, tmp23)
tmp25 = tl.where(tmp4, tmp5, tmp24)
tl.store(out_ptr0 + x5, tmp25, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.float32
)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(768)](arg0_1, arg1_1, arg2_1, buf0, 768,
XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf0,
class ResizeCatNew(nn.Module):
def __init__(self, **kwargs):
super(ResizeCatNew, self).__init__()
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
GunjanChourasia/WS_DAN_PyTorch
|
ResizeCat
| false
| 2,316
|
[
"MIT"
] | 0
|
6c12a1b5b0b8980e3b69d44474e0b5edb455570c
|
https://github.com/GunjanChourasia/WS_DAN_PyTorch/tree/6c12a1b5b0b8980e3b69d44474e0b5edb455570c
|
MMD_loss
|
import torch
import torch.utils.data
import torch
import torch.nn as nn
class MMD_loss(nn.Module):
def __init__(self, kernel_mul=2.0, kernel_num=5):
super(MMD_loss, self).__init__()
self.kernel_num = kernel_num
self.kernel_mul = kernel_mul
self.fix_sigma = None
def guassian_kernel(self, source, target, kernel_mul=2.0, kernel_num=5,
fix_sigma=None):
n_samples = int(source.size()[0]) + int(target.size()[0])
total = torch.cat([source, target], dim=0)
total0 = total.unsqueeze(0).expand(int(total.size(0)), int(total.
size(0)), int(total.size(1)))
total1 = total.unsqueeze(1).expand(int(total.size(0)), int(total.
size(0)), int(total.size(1)))
L2_distance = ((total0 - total1) ** 2).sum(2)
if fix_sigma:
bandwidth = fix_sigma
else:
bandwidth = torch.sum(L2_distance.data) / (n_samples ** 2 -
n_samples)
bandwidth /= kernel_mul ** (kernel_num // 2)
bandwidth_list = [(bandwidth * kernel_mul ** i) for i in range(
kernel_num)]
kernel_val = [torch.exp(-L2_distance / bandwidth_temp) for
bandwidth_temp in bandwidth_list]
return sum(kernel_val)
def forward(self, source, target):
batch_size = int(source.size()[0])
kernels = self.guassian_kernel(source, target, kernel_mul=self.
kernel_mul, kernel_num=self.kernel_num, fix_sigma=self.fix_sigma)
XX = kernels[:batch_size, :batch_size]
YY = kernels[batch_size:, batch_size:]
XY = kernels[:batch_size, batch_size:]
YX = kernels[batch_size:, :batch_size]
loss = torch.mean(XX + YY - XY - YX)
return loss
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.utils.data
import torch
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_div_exp_mul_neg_pow_sub_sum_0(in_ptr0, in_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 64
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex % 8
r1 = rindex // 8
r2 = rindex
tmp0 = r0
tl.full([1, 1], 0, tl.int64)
tmp3 = tl.full([1, 1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + tl.broadcast_to(4 * r0, [XBLOCK, RBLOCK]),
tmp4, eviction_policy='evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1, 1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + tl.broadcast_to(4 * (-4 + r0), [XBLOCK, RBLOCK
]), tmp6, eviction_policy='evict_last', other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tmp11 = r1
tmp13 = tmp11 < tmp3
tmp14 = tl.load(in_ptr0 + tl.broadcast_to(4 * r1, [XBLOCK, RBLOCK]),
tmp13, eviction_policy='evict_last', other=0.0)
tmp15 = tmp11 >= tmp3
tmp17 = tl.load(in_ptr1 + tl.broadcast_to(4 * (-4 + r1), [XBLOCK,
RBLOCK]), tmp15, eviction_policy='evict_last', other=0.0)
tmp18 = tl.where(tmp13, tmp14, tmp17)
tmp19 = tmp10 - tmp18
tmp20 = tmp19 * tmp19
tmp21 = tl.load(in_ptr0 + tl.broadcast_to(1 + 4 * r0, [XBLOCK, RBLOCK]),
tmp4, eviction_policy='evict_last', other=0.0)
tmp22 = tl.load(in_ptr1 + tl.broadcast_to(1 + 4 * (-4 + r0), [XBLOCK,
RBLOCK]), tmp6, eviction_policy='evict_last', other=0.0)
tmp23 = tl.where(tmp4, tmp21, tmp22)
tmp24 = tl.load(in_ptr0 + tl.broadcast_to(1 + 4 * r1, [XBLOCK, RBLOCK]),
tmp13, eviction_policy='evict_last', other=0.0)
tmp25 = tl.load(in_ptr1 + tl.broadcast_to(1 + 4 * (-4 + r1), [XBLOCK,
RBLOCK]), tmp15, eviction_policy='evict_last', other=0.0)
tmp26 = tl.where(tmp13, tmp24, tmp25)
tmp27 = tmp23 - tmp26
tmp28 = tmp27 * tmp27
tmp29 = tmp20 + tmp28
tmp30 = tl.load(in_ptr0 + tl.broadcast_to(2 + 4 * r0, [XBLOCK, RBLOCK]),
tmp4, eviction_policy='evict_last', other=0.0)
tmp31 = tl.load(in_ptr1 + tl.broadcast_to(2 + 4 * (-4 + r0), [XBLOCK,
RBLOCK]), tmp6, eviction_policy='evict_last', other=0.0)
tmp32 = tl.where(tmp4, tmp30, tmp31)
tmp33 = tl.load(in_ptr0 + tl.broadcast_to(2 + 4 * r1, [XBLOCK, RBLOCK]),
tmp13, eviction_policy='evict_last', other=0.0)
tmp34 = tl.load(in_ptr1 + tl.broadcast_to(2 + 4 * (-4 + r1), [XBLOCK,
RBLOCK]), tmp15, eviction_policy='evict_last', other=0.0)
tmp35 = tl.where(tmp13, tmp33, tmp34)
tmp36 = tmp32 - tmp35
tmp37 = tmp36 * tmp36
tmp38 = tmp29 + tmp37
tmp39 = tl.load(in_ptr0 + tl.broadcast_to(3 + 4 * r0, [XBLOCK, RBLOCK]),
tmp4, eviction_policy='evict_last', other=0.0)
tmp40 = tl.load(in_ptr1 + tl.broadcast_to(3 + 4 * (-4 + r0), [XBLOCK,
RBLOCK]), tmp6, eviction_policy='evict_last', other=0.0)
tmp41 = tl.where(tmp4, tmp39, tmp40)
tmp42 = tl.load(in_ptr0 + tl.broadcast_to(3 + 4 * r1, [XBLOCK, RBLOCK]),
tmp13, eviction_policy='evict_last', other=0.0)
tmp43 = tl.load(in_ptr1 + tl.broadcast_to(3 + 4 * (-4 + r1), [XBLOCK,
RBLOCK]), tmp15, eviction_policy='evict_last', other=0.0)
tmp44 = tl.where(tmp13, tmp42, tmp43)
tmp45 = tmp41 - tmp44
tmp46 = tmp45 * tmp45
tmp47 = tmp38 + tmp46
tmp48 = tl.broadcast_to(tmp47, [XBLOCK, RBLOCK])
tmp50 = tl.sum(tmp48, 1)[:, None]
tmp51 = -tmp47
tmp52 = 0.017857142857142856
tmp53 = tmp50 * tmp52
tmp54 = 0.25
tmp55 = tmp53 * tmp54
tmp56 = 1.0
tmp57 = tmp55 * tmp56
tmp58 = tmp51 / tmp57
tmp59 = tl_math.exp(tmp58)
tmp60 = 0.0
tmp61 = tmp59 + tmp60
tmp62 = 2.0
tmp63 = tmp55 * tmp62
tmp64 = tmp51 / tmp63
tmp65 = tl_math.exp(tmp64)
tmp66 = tmp61 + tmp65
tmp67 = 4.0
tmp68 = tmp55 * tmp67
tmp69 = tmp51 / tmp68
tmp70 = tl_math.exp(tmp69)
tmp71 = tmp66 + tmp70
tmp72 = 8.0
tmp73 = tmp55 * tmp72
tmp74 = tmp51 / tmp73
tmp75 = tl_math.exp(tmp74)
tmp76 = tmp71 + tmp75
tmp77 = 16.0
tmp78 = tmp55 * tmp77
tmp79 = tmp51 / tmp78
tmp80 = tl_math.exp(tmp79)
tmp81 = tmp76 + tmp80
tl.store(out_ptr2 + tl.broadcast_to(r2, [XBLOCK, RBLOCK]), tmp81, None)
@triton.jit
def triton_per_fused_add_mean_sub_1(in_out_ptr0, in_ptr0, xnumel, rnumel,
XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex % 4
r1 = rindex // 4
tmp0 = tl.load(in_ptr0 + (r0 + 8 * r1), None)
tmp1 = tl.load(in_ptr0 + (36 + r0 + 8 * r1), None)
tmp3 = tl.load(in_ptr0 + (4 + r0 + 8 * r1), None)
tmp5 = tl.load(in_ptr0 + (32 + r0 + 8 * r1), None)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 - tmp3
tmp6 = tmp4 - tmp5
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.sum(tmp7, 1)[:, None]
tmp10 = 16.0
tmp11 = tmp9 / tmp10
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp11, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf2 = empty_strided_cuda((8, 8), (8, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_add_div_exp_mul_neg_pow_sub_sum_0[grid(1)](arg0_1,
arg1_1, buf2, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
buf3 = empty_strided_cuda((), (), torch.float32)
buf4 = buf3
del buf3
triton_per_fused_add_mean_sub_1[grid(1)](buf4, buf2, 1, 16, XBLOCK=
1, num_warps=2, num_stages=1)
del buf2
return buf4,
class MMD_lossNew(nn.Module):
def __init__(self, kernel_mul=2.0, kernel_num=5):
super(MMD_lossNew, self).__init__()
self.kernel_num = kernel_num
self.kernel_mul = kernel_mul
self.fix_sigma = None
def guassian_kernel(self, source, target, kernel_mul=2.0, kernel_num=5,
fix_sigma=None):
n_samples = int(source.size()[0]) + int(target.size()[0])
total = torch.cat([source, target], dim=0)
total0 = total.unsqueeze(0).expand(int(total.size(0)), int(total.
size(0)), int(total.size(1)))
total1 = total.unsqueeze(1).expand(int(total.size(0)), int(total.
size(0)), int(total.size(1)))
L2_distance = ((total0 - total1) ** 2).sum(2)
if fix_sigma:
bandwidth = fix_sigma
else:
bandwidth = torch.sum(L2_distance.data) / (n_samples ** 2 -
n_samples)
bandwidth /= kernel_mul ** (kernel_num // 2)
bandwidth_list = [(bandwidth * kernel_mul ** i) for i in range(
kernel_num)]
kernel_val = [torch.exp(-L2_distance / bandwidth_temp) for
bandwidth_temp in bandwidth_list]
return sum(kernel_val)
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
HC-Feynman/10708-proj
|
MMD_loss
| false
| 2,317
|
[
"BSD-3-Clause"
] | 0
|
592ed86671539b6e910dac72391ef0d3ae8e79ef
|
https://github.com/HC-Feynman/10708-proj/tree/592ed86671539b6e910dac72391ef0d3ae8e79ef
|
ChannelAttention_avg
|
import torch
from torch import nn
class ChannelAttention_avg(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention_avg, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, 2, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
b, _, _, _ = x.size()
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
out = self.sigmoid(avg_out)
y1 = out[:, 0:1, :, :]
y1 = y1.expand(b, 32, 1, 1)
y2 = out[:, 1:, :, :]
y2 = y2.expand(b, 32, 1, 1)
y_sum = torch.cat((y1, y2), 1)
return y_sum
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_planes': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_cat_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 64
x1 = xindex // 64
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 32, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + 2 * x1, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.sigmoid(tmp5)
tmp7 = tl.full(tmp6.shape, 0.0, tmp6.dtype)
tmp8 = tl.where(tmp4, tmp6, tmp7)
tmp9 = tmp0 >= tmp3
tl.full([1], 64, tl.int64)
tmp12 = tl.load(in_ptr0 + (1 + 2 * x1), tmp9 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp13 = tl.sigmoid(tmp12)
tmp14 = tl.full(tmp13.shape, 0.0, tmp13.dtype)
tmp15 = tl.where(tmp9, tmp13, tmp14)
tmp16 = tl.where(tmp4, tmp8, tmp15)
tl.store(out_ptr0 + x2, tmp16, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (8, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (2, 8, 1, 1), (8, 1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
del primals_1
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 8, 1, 1), (8, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_relu_1[grid(32)](buf3, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf4 = extern_kernels.convolution(buf3, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 2, 1, 1), (2, 1, 1, 1))
buf5 = empty_strided_cuda((4, 64, 1, 1), (64, 1, 1, 1), torch.float32)
triton_poi_fused_cat_2[grid(256)](buf4, buf5, 256, XBLOCK=128,
num_warps=4, num_stages=1)
return buf5, primals_2, primals_3, buf1, buf3, buf4
class ChannelAttention_avgNew(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention_avgNew, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, 2, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.fc1.weight
primals_3 = self.fc2.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
ChannelAttention_avg
| false
| 2,318
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
NormedConv2d
|
import torch
from torch import nn
class NormedConv2d(nn.Conv2d):
"""Normalized Conv2d Layer.
Args:
tempeature (float, optional): Tempeature term. Default to 20.
power (int, optional): Power term. Default to 1.0.
eps (float, optional): The minimal value of divisor to
keep numerical stability. Default to 1e-6.
norm_over_kernel (bool, optional): Normalize over kernel.
Default to False.
"""
def __init__(self, *args, tempearture=20, power=1.0, eps=1e-06,
norm_over_kernel=False, **kwargs):
super(NormedConv2d, self).__init__(*args, **kwargs)
self.tempearture = tempearture
self.power = power
self.norm_over_kernel = norm_over_kernel
self.eps = eps
def forward(self, x):
if not self.norm_over_kernel:
weight_ = self.weight / (self.weight.norm(dim=1, keepdim=True).
pow(self.power) + self.eps)
else:
weight_ = self.weight / (self.weight.view(self.weight.size(0),
-1).norm(dim=1, keepdim=True).pow(self.power)[..., None,
None] + self.eps)
x_ = x / (x.norm(dim=1, keepdim=True).pow(self.power) + self.eps)
x_ = x_ * self.tempearture
if hasattr(self, 'conv2d_forward'):
x_ = self.conv2d_forward(x_, weight_)
elif torch.__version__ >= '1.8':
x_ = self._conv_forward(x_, weight_, self.bias)
else:
x_ = self._conv_forward(x_, weight_)
return x_
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_div_linalg_vector_norm_pow_0(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-06
tmp14 = tmp12 + tmp13
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x3, tmp15, xmask)
@triton.jit
def triton_poi_fused_add_div_linalg_vector_norm_mul_pow_1(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-06
tmp14 = tmp12 + tmp13
tmp15 = tmp0 / tmp14
tmp16 = 20.0
tmp17 = tmp15 * tmp16
tl.store(out_ptr0 + x3, tmp17, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_linalg_vector_norm_pow_0[grid(256)](primals_1,
buf0, 256, XBLOCK=256, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_div_linalg_vector_norm_mul_pow_1[grid(256)](
primals_2, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, buf0, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_2[grid(16)](buf3, primals_3, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
return buf3, primals_1, buf0, buf1
class NormedConv2dNew(nn.Conv2d):
"""Normalized Conv2d Layer.
Args:
tempeature (float, optional): Tempeature term. Default to 20.
power (int, optional): Power term. Default to 1.0.
eps (float, optional): The minimal value of divisor to
keep numerical stability. Default to 1e-6.
norm_over_kernel (bool, optional): Normalize over kernel.
Default to False.
"""
def __init__(self, *args, tempearture=20, power=1.0, eps=1e-06,
norm_over_kernel=False, **kwargs):
super(NormedConv2dNew, self).__init__(*args, **kwargs)
self.tempearture = tempearture
self.power = power
self.norm_over_kernel = norm_over_kernel
self.eps = eps
def forward(self, input_0):
primals_1 = self.weight
primals_3 = self.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
NormedConv2d
| false
| 2,319
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
MultiHeadAttention
|
import torch
import numpy as np
import torch.nn as nn
class MultiHeadAttention(nn.Module):
"""Multi-Head Attention Layer"""
def __init__(self, hidden_size, num_attention_heads, attention_dropout_prob
):
super(MultiHeadAttention, self).__init__()
self.h = num_attention_heads
self.d_k = hidden_size // num_attention_heads
self.w_q = nn.Linear(hidden_size, hidden_size)
self.w_k = nn.Linear(hidden_size, hidden_size)
self.w_v = nn.Linear(hidden_size, hidden_size)
self.w_o = nn.Linear(hidden_size, hidden_size)
self.dropout = nn.Dropout(attention_dropout_prob)
def forward(self, query, key, value, mask=None):
batch_size, hidden_size = query.shape[0], query.shape[2]
q = self.w_q(query)
k = self.w_k(key)
v = self.w_v(value)
q = q.view(batch_size, -1, self.h, self.d_k).permute(0, 2, 1, 3)
k = k.view(batch_size, -1, self.h, self.d_k).permute(0, 2, 3, 1)
v = v.view(batch_size, -1, self.h, self.d_k).permute(0, 2, 1, 3)
attention_scores = torch.matmul(q, k) / np.sqrt(self.d_k)
if mask is not None:
attention_scores = attention_scores.masked_fill(mask == 0, -10000.0
)
attention_probs = torch.softmax(attention_scores, dim=-1)
attention_probs = self.dropout(attention_probs)
y = torch.matmul(attention_probs, v)
y = y.permute(0, 2, 1, 3).contiguous().view(batch_size, -1, hidden_size
)
return self.w_o(y)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {'hidden_size': 4, 'num_attention_heads': 4,
'attention_dropout_prob': 0.5}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_per_fused__softmax_1(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 256
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, float('-inf'))
tmp4 = triton_helpers.max2(tmp3, 1)[:, None]
tmp5 = tmp0 - tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.where(xmask, tmp7, 0)
tmp10 = tl.sum(tmp9, 1)[:, None]
tmp11 = tmp6 / tmp10
tl.store(out_ptr2 + (r1 + 16 * x0), tmp11, xmask)
@triton.jit
def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 16
y1 = yindex // 16
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_10, (4, 4), (4, 1))
assert_size_stride(primals_11, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_9, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
del primals_7
buf3 = empty_strided_cuda((4, 4, 16, 1), (64, 16, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 16)](buf0, primals_3, buf3, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_3
buf4 = reinterpret_tensor(buf0, (4, 4, 1, 16), (64, 16, 16, 1), 0)
del buf0
triton_poi_fused_clone_0[grid(16, 16)](buf1, primals_5, buf4, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((16, 16, 16), (256, 16, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 16, 1), (16, 1, 0),
0), reinterpret_tensor(buf4, (16, 1, 16), (16, 0, 1), 0), out=buf5)
buf8 = empty_strided_cuda((4, 4, 16, 16), (1024, 256, 16, 1), torch
.float32)
triton_per_fused__softmax_1[grid(256)](buf5, buf8, 256, 16, XBLOCK=
8, num_warps=2, num_stages=1)
del buf5
buf9 = reinterpret_tensor(buf1, (4, 4, 16, 1), (64, 16, 1, 1), 0)
del buf1
triton_poi_fused_clone_0[grid(16, 16)](buf2, primals_8, buf9, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_8
buf10 = reinterpret_tensor(buf2, (16, 16, 1), (16, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf8, (16, 16, 16), (256, 16,
1), 0), reinterpret_tensor(buf9, (16, 16, 1), (16, 1, 0), 0),
out=buf10)
buf11 = empty_strided_cuda((4, 16, 4, 1), (64, 4, 1, 1), torch.float32)
triton_poi_fused_clone_2[grid(64, 4)](buf10, buf11, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
buf12 = reinterpret_tensor(buf10, (64, 4), (4, 1), 0)
del buf10
extern_kernels.addmm(primals_11, reinterpret_tensor(buf11, (64, 4),
(4, 1), 0), reinterpret_tensor(primals_10, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf12)
del primals_11
return reinterpret_tensor(buf12, (4, 16, 4), (64, 4, 1), 0
), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_6, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0
), buf8, reinterpret_tensor(buf11, (64, 4), (4, 1), 0
), primals_10, reinterpret_tensor(buf9, (16, 1, 16), (16, 1, 1), 0
), reinterpret_tensor(buf3, (16, 1, 16), (16, 1, 1), 0
), reinterpret_tensor(buf4, (16, 16, 1), (16, 1, 16), 0)
class MultiHeadAttentionNew(nn.Module):
"""Multi-Head Attention Layer"""
def __init__(self, hidden_size, num_attention_heads, attention_dropout_prob
):
super(MultiHeadAttentionNew, self).__init__()
self.h = num_attention_heads
self.d_k = hidden_size // num_attention_heads
self.w_q = nn.Linear(hidden_size, hidden_size)
self.w_k = nn.Linear(hidden_size, hidden_size)
self.w_v = nn.Linear(hidden_size, hidden_size)
self.w_o = nn.Linear(hidden_size, hidden_size)
self.dropout = nn.Dropout(attention_dropout_prob)
def forward(self, input_0, input_1, input_2):
primals_2 = self.w_q.weight
primals_3 = self.w_q.bias
primals_4 = self.w_k.weight
primals_5 = self.w_k.bias
primals_7 = self.w_v.weight
primals_8 = self.w_v.bias
primals_10 = self.w_o.weight
primals_11 = self.w_o.bias
primals_1 = input_0
primals_6 = input_1
primals_9 = input_2
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11])
return output[0]
|
Ginga1892/bert-x
|
MultiHeadAttention
| false
| 2,320
|
[
"MIT"
] | 0
|
903970ef0a6967aa20a82bcf56b874602e37a04d
|
https://github.com/Ginga1892/bert-x/tree/903970ef0a6967aa20a82bcf56b874602e37a04d
|
GlobalAttention
|
import torch
import torch.distributed
import torch.nn as nn
import torch.nn.functional as F
def sequence_mask(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max()
return torch.arange(0, max_len).type_as(lengths).repeat(batch_size, 1).lt(
lengths.unsqueeze(1))
class GlobalAttention(nn.Module):
"""
Global attention takes a matrix and a query vector. It
then computes a parameterized convex combination of the matrix
based on the input query.
Constructs a unit mapping a query `q` of size `dim`
and a source matrix `H` of size `n x dim`, to an output
of size `dim`.
.. mermaid::
graph BT
A[Query]
subgraph RNN
C[H 1]
D[H 2]
E[H N]
end
F[Attn]
G[Output]
A --> F
C --> F
D --> F
E --> F
C -.-> G
D -.-> G
E -.-> G
F --> G
All models compute the output as
:math:`c = sum_{j=1}^{SeqLength} a_j H_j` where
:math:`a_j` is the softmax of a score function.
Then then apply a projection layer to [q, c].
However they
differ on how they compute the attention score.
* Luong Attention (dot, general):
* dot: :math:`score(H_j,q) = H_j^T q`
* general: :math:`score(H_j, q) = H_j^T W_a q`
* Bahdanau Attention (mlp):
* :math:`score(H_j, q) = v_a^T tanh(W_a q + U_a h_j)`
Args:
dim (int): dimensionality of query and key
coverage (bool): use coverage term
attn_type (str): type of attention to use, options [dot,general,mlp]
"""
def __init__(self, dim, attn_type='dot'):
super(GlobalAttention, self).__init__()
self.dim = dim
assert attn_type in ['dot', 'general', 'mlp'
], 'Please select a valid attention type.'
self.attn_type = attn_type
if self.attn_type == 'general':
self.linear_in = nn.Linear(dim, dim, bias=False)
elif self.attn_type == 'mlp':
self.linear_context = nn.Linear(dim, dim, bias=False)
self.linear_query = nn.Linear(dim, dim, bias=True)
self.v = nn.Linear(dim, 1, bias=False)
out_bias = self.attn_type == 'mlp'
self.linear_out = nn.Linear(dim * 2, dim, bias=out_bias)
def score(self, h_t, h_s):
"""
Args:
h_t (`FloatTensor`): sequence of queries `[batch x tgt_len x dim]`
h_s (`FloatTensor`): sequence of sources `[batch x src_len x dim]`
Returns:
:obj:`FloatTensor`:
raw attention scores (unnormalized) for each src index
`[batch x tgt_len x src_len]`
"""
src_batch, src_len, _src_dim = h_s.size()
tgt_batch, tgt_len, tgt_dim = h_t.size()
if self.attn_type in ['general', 'dot']:
if self.attn_type == 'general':
h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim)
h_t_ = self.linear_in(h_t_)
h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim)
h_s_ = h_s.transpose(1, 2)
return torch.bmm(h_t, h_s_)
else:
dim = self.dim
wq = self.linear_query(h_t.view(-1, dim))
wq = wq.view(tgt_batch, tgt_len, 1, dim)
wq = wq.expand(tgt_batch, tgt_len, src_len, dim)
uh = self.linear_context(h_s.contiguous().view(-1, dim))
uh = uh.view(src_batch, 1, src_len, dim)
uh = uh.expand(src_batch, tgt_len, src_len, dim)
wquh = torch.tanh(wq + uh)
return self.v(wquh.view(-1, dim)).view(tgt_batch, tgt_len, src_len)
def forward(self, source, memory_bank, memory_lengths=None,
memory_masks=None):
"""
Args:
source (`FloatTensor`): query vectors `[batch x tgt_len x dim]`
memory_bank (`FloatTensor`): source vectors `[batch x src_len x dim]`
memory_lengths (`LongTensor`): the source context lengths `[batch]`
coverage (`FloatTensor`): None (not supported yet)
Returns:
(`FloatTensor`, `FloatTensor`):
* Computed vector `[tgt_len x batch x dim]`
* Attention distribtutions for each query
`[tgt_len x batch x src_len]`
"""
if source.dim() == 2:
one_step = True
source = source.unsqueeze(1)
else:
one_step = False
batch, source_l, dim = memory_bank.size()
batch_, target_l, dim_ = source.size()
align = self.score(source, memory_bank)
if memory_masks is not None:
memory_masks = memory_masks.transpose(0, 1)
memory_masks = memory_masks.transpose(1, 2)
align.masked_fill_(1 - memory_masks.byte(), -float('inf'))
if memory_lengths is not None:
mask = sequence_mask(memory_lengths, max_len=align.size(-1))
mask = mask.unsqueeze(1)
align.masked_fill_(1 - mask, -float('inf'))
align_vectors = F.softmax(align.view(batch * target_l, source_l), -1)
align_vectors = align_vectors.view(batch, target_l, source_l)
c = torch.bmm(align_vectors, memory_bank)
concat_c = torch.cat([c, source], 2).view(batch * target_l, dim * 2)
attn_h = self.linear_out(concat_c).view(batch, target_l, dim)
if self.attn_type in ['general', 'dot']:
attn_h = torch.tanh(attn_h)
if one_step:
attn_h = attn_h.squeeze(1)
align_vectors = align_vectors.squeeze(1)
else:
attn_h = attn_h.transpose(0, 1).contiguous()
align_vectors = align_vectors.transpose(0, 1).contiguous()
return attn_h, align_vectors
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.distributed
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 8
x1 = xindex // 8
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + (4 * x1 + (-4 + x0)), tmp6 & xmask,
eviction_policy='evict_last', other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x2, tmp10, xmask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1), xmask)
tmp1 = libdevice.tanh(tmp0)
tl.store(out_ptr0 + x3, tmp1, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1), xmask)
tl.store(out_ptr0 + x3, tmp0, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_3, (4, 8), (8, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(primals_1, reinterpret_tensor(primals_2, (4, 4,
4), (16, 1, 4), 0), out=buf0)
buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf2 = reinterpret_tensor(buf0, (16, 4), (4, 1), 0)
del buf0
triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1), 0)
del buf1
extern_kernels.bmm(reinterpret_tensor(buf2, (4, 4, 4), (16, 4, 1),
0), primals_2, out=buf3)
del primals_2
buf4 = empty_strided_cuda((4, 4, 8), (32, 8, 1), torch.float32)
triton_poi_fused_cat_2[grid(128)](buf3, primals_1, buf4, 128,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0)
del buf3
extern_kernels.mm(reinterpret_tensor(buf4, (16, 8), (8, 1), 0),
reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf5)
del primals_3
buf6 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_clone_3[grid(64)](buf5, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_clone_4[grid(64)](buf2, buf7, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf2
return buf6, buf7, reinterpret_tensor(buf4, (16, 8), (8, 1), 0), buf5
def sequence_mask(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max()
return torch.arange(0, max_len).type_as(lengths).repeat(batch_size, 1).lt(
lengths.unsqueeze(1))
class GlobalAttentionNew(nn.Module):
"""
Global attention takes a matrix and a query vector. It
then computes a parameterized convex combination of the matrix
based on the input query.
Constructs a unit mapping a query `q` of size `dim`
and a source matrix `H` of size `n x dim`, to an output
of size `dim`.
.. mermaid::
graph BT
A[Query]
subgraph RNN
C[H 1]
D[H 2]
E[H N]
end
F[Attn]
G[Output]
A --> F
C --> F
D --> F
E --> F
C -.-> G
D -.-> G
E -.-> G
F --> G
All models compute the output as
:math:`c = sum_{j=1}^{SeqLength} a_j H_j` where
:math:`a_j` is the softmax of a score function.
Then then apply a projection layer to [q, c].
However they
differ on how they compute the attention score.
* Luong Attention (dot, general):
* dot: :math:`score(H_j,q) = H_j^T q`
* general: :math:`score(H_j, q) = H_j^T W_a q`
* Bahdanau Attention (mlp):
* :math:`score(H_j, q) = v_a^T tanh(W_a q + U_a h_j)`
Args:
dim (int): dimensionality of query and key
coverage (bool): use coverage term
attn_type (str): type of attention to use, options [dot,general,mlp]
"""
def __init__(self, dim, attn_type='dot'):
super(GlobalAttentionNew, self).__init__()
self.dim = dim
assert attn_type in ['dot', 'general', 'mlp'
], 'Please select a valid attention type.'
self.attn_type = attn_type
if self.attn_type == 'general':
self.linear_in = nn.Linear(dim, dim, bias=False)
elif self.attn_type == 'mlp':
self.linear_context = nn.Linear(dim, dim, bias=False)
self.linear_query = nn.Linear(dim, dim, bias=True)
self.v = nn.Linear(dim, 1, bias=False)
out_bias = self.attn_type == 'mlp'
self.linear_out = nn.Linear(dim * 2, dim, bias=out_bias)
def score(self, h_t, h_s):
"""
Args:
h_t (`FloatTensor`): sequence of queries `[batch x tgt_len x dim]`
h_s (`FloatTensor`): sequence of sources `[batch x src_len x dim]`
Returns:
:obj:`FloatTensor`:
raw attention scores (unnormalized) for each src index
`[batch x tgt_len x src_len]`
"""
src_batch, src_len, _src_dim = h_s.size()
tgt_batch, tgt_len, tgt_dim = h_t.size()
if self.attn_type in ['general', 'dot']:
if self.attn_type == 'general':
h_t_ = h_t.view(tgt_batch * tgt_len, tgt_dim)
h_t_ = self.linear_in(h_t_)
h_t = h_t_.view(tgt_batch, tgt_len, tgt_dim)
h_s_ = h_s.transpose(1, 2)
return torch.bmm(h_t, h_s_)
else:
dim = self.dim
wq = self.linear_query(h_t.view(-1, dim))
wq = wq.view(tgt_batch, tgt_len, 1, dim)
wq = wq.expand(tgt_batch, tgt_len, src_len, dim)
uh = self.linear_context(h_s.contiguous().view(-1, dim))
uh = uh.view(src_batch, 1, src_len, dim)
uh = uh.expand(src_batch, tgt_len, src_len, dim)
wquh = torch.tanh(wq + uh)
return self.v(wquh.view(-1, dim)).view(tgt_batch, tgt_len, src_len)
def forward(self, input_0, input_1):
primals_3 = self.linear_out.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3])
return output[0], output[1]
|
GraphGrailAi/summ-abs-dev
|
GlobalAttention
| false
| 2,321
|
[
"MIT"
] | 0
|
512f253bf72b6529589b29d06959b560b79f1cde
|
https://github.com/GraphGrailAi/summ-abs-dev/tree/512f253bf72b6529589b29d06959b560b79f1cde
|
ChannelAttention
|
import torch
from torch import nn
class ChannelAttention(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = avg_out + max_out
return self.sigmoid(out)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_planes': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_adaptive_max_pool2d_2(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = triton_helpers.maximum(tmp11, tmp10)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp16 = triton_helpers.maximum(tmp15, tmp14)
tmp18 = triton_helpers.maximum(tmp17, tmp16)
tmp20 = triton_helpers.maximum(tmp19, tmp18)
tmp22 = triton_helpers.maximum(tmp21, tmp20)
tmp24 = triton_helpers.maximum(tmp23, tmp22)
tmp26 = triton_helpers.maximum(tmp25, tmp24)
tmp28 = triton_helpers.maximum(tmp27, tmp26)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(out_ptr0 + x0, tmp30, xmask)
@triton.jit
def triton_poi_fused_add_sigmoid_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x0, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (8, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (4, 8, 1, 1), (8, 1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 8, 1, 1), (8, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_relu_1[grid(32)](buf3, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf4 = extern_kernels.convolution(buf3, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1))
buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused_adaptive_max_pool2d_2[grid(16)](primals_1, buf5,
16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_1
buf6 = extern_kernels.convolution(buf5, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 8, 1, 1), (8, 1, 1, 1))
buf7 = buf6
del buf6
triton_poi_fused_relu_1[grid(32)](buf7, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf8 = extern_kernels.convolution(buf7, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 4, 1, 1), (4, 1, 1, 1))
buf9 = buf4
del buf4
triton_poi_fused_add_sigmoid_3[grid(16)](buf9, buf8, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf8
return buf9, primals_2, primals_3, buf1, buf3, buf5, buf7, buf9
class ChannelAttentionNew(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttentionNew, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.fc1.weight
primals_3 = self.fc2.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
ChannelAttention
| false
| 2,322
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
NormedLinear
|
import torch
import torch.nn.functional as F
from torch import nn
class NormedLinear(nn.Linear):
"""Normalized Linear Layer.
Args:
tempeature (float, optional): Tempeature term. Default to 20.
power (int, optional): Power term. Default to 1.0.
eps (float, optional): The minimal value of divisor to
keep numerical stability. Default to 1e-6.
"""
def __init__(self, *args, tempearture=20, power=1.0, eps=1e-06, **kwargs):
super(NormedLinear, self).__init__(*args, **kwargs)
self.tempearture = tempearture
self.power = power
self.eps = eps
self.init_weights()
def init_weights(self):
nn.init.normal_(self.weight, mean=0, std=0.01)
if self.bias is not None:
nn.init.constant_(self.bias, 0)
def forward(self, x):
weight_ = self.weight / (self.weight.norm(dim=1, keepdim=True).pow(
self.power) + self.eps)
x_ = x / (x.norm(dim=1, keepdim=True).pow(self.power) + self.eps)
x_ = x_ * self.tempearture
return F.linear(x_, weight_, self.bias)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_features': 4, 'out_features': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_div_linalg_vector_norm_mul_pow_0(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-06
tmp14 = tmp12 + tmp13
tmp15 = tmp0 / tmp14
tmp16 = 20.0
tmp17 = tmp15 * tmp16
tl.store(out_ptr0 + x3, tmp17, xmask)
@triton.jit
def triton_poi_fused_add_div_linalg_vector_norm_pow_1(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = 1e-06
tmp14 = tmp12 + tmp13
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + x2, tmp15, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_linalg_vector_norm_mul_pow_0[grid(256)](
primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused_add_div_linalg_vector_norm_pow_1[grid(16)](primals_1,
buf1, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_3, reinterpret_tensor(buf0, (64, 4), (
4, 1), 0), reinterpret_tensor(buf1, (4, 4), (1, 4), 0), alpha=1,
beta=1, out=buf2)
del buf1
del primals_3
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_1, reinterpret_tensor(buf0, (64, 4), (4, 1), 0)
class NormedLinearNew(nn.Linear):
"""Normalized Linear Layer.
Args:
tempeature (float, optional): Tempeature term. Default to 20.
power (int, optional): Power term. Default to 1.0.
eps (float, optional): The minimal value of divisor to
keep numerical stability. Default to 1e-6.
"""
def __init__(self, *args, tempearture=20, power=1.0, eps=1e-06, **kwargs):
super(NormedLinearNew, self).__init__(*args, **kwargs)
self.tempearture = tempearture
self.power = power
self.eps = eps
self.init_weights()
def init_weights(self):
nn.init.normal_(self.weight, mean=0, std=0.01)
if self.bias is not None:
nn.init.constant_(self.bias, 0)
def forward(self, input_0):
primals_1 = self.weight
primals_3 = self.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
NormedLinear
| false
| 2,323
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
ChannelAttention_a
|
import torch
from torch import nn
class ChannelAttention_a(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention_a, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, 2, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
b, _, _, _ = x.size()
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = self.sigmoid(avg_out + max_out)
y1 = out[:, 0:1, :, :]
y1 = y1.expand(b, 32, 1, 1)
y2 = out[:, 1:, :, :]
y2 = y2.expand(b, 32, 1, 1)
y_sum = torch.cat((y1, y2), 1)
return y_sum
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_planes': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_adaptive_max_pool2d_2(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = triton_helpers.maximum(tmp11, tmp10)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp16 = triton_helpers.maximum(tmp15, tmp14)
tmp18 = triton_helpers.maximum(tmp17, tmp16)
tmp20 = triton_helpers.maximum(tmp19, tmp18)
tmp22 = triton_helpers.maximum(tmp21, tmp20)
tmp24 = triton_helpers.maximum(tmp23, tmp22)
tmp26 = triton_helpers.maximum(tmp25, tmp24)
tmp28 = triton_helpers.maximum(tmp27, tmp26)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(out_ptr0 + x0, tmp30, xmask)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 64
x1 = xindex // 64
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 32, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + 2 * x1, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr1 + 2 * x1, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.sigmoid(tmp7)
tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
tmp10 = tl.where(tmp4, tmp8, tmp9)
tmp11 = tmp0 >= tmp3
tl.full([1], 64, tl.int64)
tmp14 = tl.load(in_ptr0 + (1 + 2 * x1), tmp11 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp15 = tl.load(in_ptr1 + (1 + 2 * x1), tmp11 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp16 = tmp14 + tmp15
tmp17 = tl.sigmoid(tmp16)
tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
tmp19 = tl.where(tmp11, tmp17, tmp18)
tmp20 = tl.where(tmp4, tmp10, tmp19)
tl.store(out_ptr0 + x2, tmp20, xmask)
@triton.jit
def triton_poi_fused_add_sigmoid_sigmoid_backward_4(in_out_ptr0, in_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 8
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tmp4 = 1.0
tmp5 = tmp4 - tmp3
tmp6 = tmp3 * tmp5
tl.store(in_out_ptr0 + x0, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (8, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (2, 8, 1, 1), (8, 1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 8, 1, 1), (8, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_relu_1[grid(32)](buf3, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf4 = extern_kernels.convolution(buf3, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 2, 1, 1), (2, 1, 1, 1))
buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused_adaptive_max_pool2d_2[grid(16)](primals_1, buf5,
16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_1
buf6 = extern_kernels.convolution(buf5, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 8, 1, 1), (8, 1, 1, 1))
buf7 = buf6
del buf6
triton_poi_fused_relu_1[grid(32)](buf7, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf8 = extern_kernels.convolution(buf7, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 2, 1, 1), (2, 1, 1, 1))
buf9 = empty_strided_cuda((4, 64, 1, 1), (64, 1, 1, 1), torch.float32)
triton_poi_fused_cat_3[grid(256)](buf4, buf8, buf9, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf10 = buf4
del buf4
triton_poi_fused_add_sigmoid_sigmoid_backward_4[grid(8)](buf10,
buf8, 8, XBLOCK=8, num_warps=1, num_stages=1)
del buf8
return buf9, primals_2, primals_3, buf1, buf3, buf5, buf7, buf10
class ChannelAttention_aNew(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention_aNew, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, 2, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.fc1.weight
primals_3 = self.fc2.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
ChannelAttention_a
| false
| 2,324
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
UpConv
|
import torch
import torch.nn as nn
from enum import Enum
from enum import auto
class UpsampleType(Enum):
CONV_TRANSPOSE = auto()
NEAREST_NEIGHBOUR = auto()
BILINEAR = auto()
class UpConv(nn.Module):
"""
Custom module to handle a single Upsample + Convolution block used in the decoder layer.
Takes an optional argument stating which type of upsampling to use. This argument should be provided from the
UpsanmpleType enum above.
"""
def __init__(self, in_channels: 'int', out_channels: 'int',
upsample_type: 'UpsampleType'=UpsampleType.CONV_TRANSPOSE, name=''):
super().__init__()
self.upsample = self._upsample(upsample_type, in_channels)
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=3,
padding='same')
self.name = name
def _upsample(self, upsample_type: 'UpsampleType', num_channels: 'int'):
if upsample_type == UpsampleType.CONV_TRANSPOSE:
return nn.ConvTranspose2d(num_channels, num_channels,
kernel_size=2, stride=2)
if upsample_type == UpsampleType.NEAREST_NEIGHBOUR:
return nn.UpsamplingNearest2d(scale_factor=2)
if upsample_type == UpsampleType.BILINEAR:
return nn.UpsamplingBilinear2d(scale_factor=2)
raise NotImplementedError(
f'Upsampling mode of {str(upsample_type)} is not supported.')
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
x = self.upsample(x)
return self.conv(x)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
from enum import Enum
from enum import auto
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
@triton.jit
def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 64 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 2, 2), (16, 4, 2, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(2,
2), padding=(0, 0), dilation=(1, 1), transposed=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 8, 8), (256, 64, 8, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(1024)](buf1, primals_2, 1024,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 8, 8), (256, 64, 8, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_0[grid(1024)](buf3, primals_5, 1024,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
return buf3, primals_1, primals_3, primals_4, buf1
class UpsampleType(Enum):
CONV_TRANSPOSE = auto()
NEAREST_NEIGHBOUR = auto()
BILINEAR = auto()
class UpConvNew(nn.Module):
"""
Custom module to handle a single Upsample + Convolution block used in the decoder layer.
Takes an optional argument stating which type of upsampling to use. This argument should be provided from the
UpsanmpleType enum above.
"""
def __init__(self, in_channels: 'int', out_channels: 'int',
upsample_type: 'UpsampleType'=UpsampleType.CONV_TRANSPOSE, name=''):
super().__init__()
self.upsample = self._upsample(upsample_type, in_channels)
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size=3,
padding='same')
self.name = name
def _upsample(self, upsample_type: 'UpsampleType', num_channels: 'int'):
if upsample_type == UpsampleType.CONV_TRANSPOSE:
return nn.ConvTranspose2d(num_channels, num_channels,
kernel_size=2, stride=2)
if upsample_type == UpsampleType.NEAREST_NEIGHBOUR:
return nn.UpsamplingNearest2d(scale_factor=2)
if upsample_type == UpsampleType.BILINEAR:
return nn.UpsamplingBilinear2d(scale_factor=2)
raise NotImplementedError(
f'Upsampling mode of {str(upsample_type)} is not supported.')
def forward(self, input_0):
primals_1 = self.upsample.weight
primals_2 = self.upsample.bias
primals_4 = self.conv.weight
primals_5 = self.conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
HalestormAI/efficientnet-unet
|
UpConv
| false
| 2,325
|
[
"MIT"
] | 0
|
b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
https://github.com/HalestormAI/efficientnet-unet/tree/b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
InstockMask
|
import torch
import torch.nn as nn
class InstockMask(nn.Module):
def __init__(self, time_step, ltsp, min_instock_ratio=0.5,
eps_instock_dph=0.001, eps_total_dph=0.001, **kwargs):
super(InstockMask, self).__init__(**kwargs)
if not eps_total_dph > 0:
raise ValueError(
f'epsilon_total_dph of {eps_total_dph} is invalid! This parameter must be > 0 to avoid division by 0.'
)
self.min_instock_ratio = min_instock_ratio
self.eps_instock_dph = eps_instock_dph
self.eps_total_dph = eps_total_dph
def forward(self, demand, total_dph, instock_dph):
if total_dph is not None and instock_dph is not None:
total_dph = total_dph + self.eps_total_dph
instock_dph = instock_dph + self.eps_instock_dph
instock_rate = torch.round(instock_dph / total_dph)
demand = torch.where(instock_rate >= self.min_instock_ratio,
demand, -torch.ones_like(demand))
return demand
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {'time_step': 4, 'ltsp': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_div_ge_neg_round_where_0(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp3 = tl.load(in_ptr1 + x0, xmask)
tmp9 = tl.load(in_ptr2 + x0, xmask)
tmp1 = 0.001
tmp2 = tmp0 + tmp1
tmp4 = tmp3 + tmp1
tmp5 = tmp2 / tmp4
tmp6 = libdevice.nearbyint(tmp5)
tmp7 = 0.5
tmp8 = tmp6 >= tmp7
tmp10 = -1.0
tmp11 = tl.where(tmp8, tmp9, tmp10)
tl.store(out_ptr0 + x0, tmp11, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_ge_neg_round_where_0[grid(256)](arg1_1,
arg0_1, arg2_1, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf0,
class InstockMaskNew(nn.Module):
def __init__(self, time_step, ltsp, min_instock_ratio=0.5,
eps_instock_dph=0.001, eps_total_dph=0.001, **kwargs):
super(InstockMaskNew, self).__init__(**kwargs)
if not eps_total_dph > 0:
raise ValueError(
f'epsilon_total_dph of {eps_total_dph} is invalid! This parameter must be > 0 to avoid division by 0.'
)
self.min_instock_ratio = min_instock_ratio
self.eps_instock_dph = eps_instock_dph
self.eps_total_dph = eps_total_dph
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
GoldbergData/pytorch-forecasting
|
InstockMask
| false
| 2,326
|
[
"MIT"
] | 0
|
e2ef3794da5d996c9740d932a4f55269bb4003f2
|
https://github.com/GoldbergData/pytorch-forecasting/tree/e2ef3794da5d996c9740d932a4f55269bb4003f2
|
EncoderImagePrecomp
|
import torch
import numpy as np
import torch.nn as nn
import torch.nn.init
from collections import OrderedDict
def l2norm(X):
"""L2-normalize columns of X
"""
norm = torch.pow(X, 2).sum(dim=1, keepdim=True).sqrt()
X = torch.div(X, norm)
return X
class EncoderImagePrecomp(nn.Module):
def __init__(self, img_dim, embed_size, use_abs=False, no_imgnorm=False):
super(EncoderImagePrecomp, self).__init__()
self.embed_size = embed_size
self.no_imgnorm = no_imgnorm
self.use_abs = use_abs
self.fc = nn.Linear(img_dim, embed_size)
self.init_weights()
def init_weights(self):
"""Xavier initialization for the fully connected layer
"""
r = np.sqrt(6.0) / np.sqrt(self.fc.in_features + self.fc.out_features)
self.fc.weight.data.uniform_(-r, r)
self.fc.bias.data.fill_(0)
def forward(self, images):
"""Extract image feature vectors."""
features = self.fc(images)
if not self.no_imgnorm:
features = l2norm(features)
if self.use_abs:
features = torch.abs(features)
return features
def load_state_dict(self, state_dict):
"""Copies parameters. overwritting the default one to
accept state_dict from Full model
"""
own_state = self.state_dict()
new_state = OrderedDict()
for name, param in state_dict.items():
if name in own_state:
new_state[name] = param
super(EncoderImagePrecomp, self).load_state_dict(new_state)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'img_dim': 4, 'embed_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import numpy as np
import torch.nn as nn
import torch.nn.init
from collections import OrderedDict
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_pow_sqrt_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 * tmp1
tmp4 = tmp3 * tmp3
tmp5 = tmp2 + tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp12 = libdevice.sqrt(tmp11)
tmp13 = tmp0 / tmp12
tl.store(out_ptr0 + x3, tmp13, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_pow_sqrt_sum_0[grid(256)](buf0, buf1, 256,
XBLOCK=256, num_warps=4, num_stages=1)
return buf1, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf0
def l2norm(X):
"""L2-normalize columns of X
"""
norm = torch.pow(X, 2).sum(dim=1, keepdim=True).sqrt()
X = torch.div(X, norm)
return X
class EncoderImagePrecompNew(nn.Module):
def __init__(self, img_dim, embed_size, use_abs=False, no_imgnorm=False):
super(EncoderImagePrecompNew, self).__init__()
self.embed_size = embed_size
self.no_imgnorm = no_imgnorm
self.use_abs = use_abs
self.fc = nn.Linear(img_dim, embed_size)
self.init_weights()
def init_weights(self):
"""Xavier initialization for the fully connected layer
"""
r = np.sqrt(6.0) / np.sqrt(self.fc.in_features + self.fc.out_features)
self.fc.weight.data.uniform_(-r, r)
self.fc.bias.data.fill_(0)
def load_state_dict(self, state_dict):
"""Copies parameters. overwritting the default one to
accept state_dict from Full model
"""
own_state = self.state_dict()
new_state = OrderedDict()
for name, param in state_dict.items():
if name in own_state:
new_state[name] = param
super(EncoderImagePrecompNew, self).load_state_dict(new_state)
def forward(self, input_0):
primals_1 = self.fc.weight
primals_2 = self.fc.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Harshdeep1996/jina-hub
|
EncoderImagePrecomp
| false
| 2,327
|
[
"Apache-2.0"
] | 0
|
880ff719715b89969860c70219d26a931a031d10
|
https://github.com/Harshdeep1996/jina-hub/tree/880ff719715b89969860c70219d26a931a031d10
|
Attention
|
import math
import torch
from torch import nn
class Attention(nn.Module):
"""A generic attention module for a decoder in seq2seq"""
def __init__(self, dim, use_tanh=False, C=10):
super(Attention, self).__init__()
self.use_tanh = use_tanh
self.project_query = nn.Linear(dim, dim)
self.project_ref = nn.Conv1d(dim, dim, 1, 1)
self.C = C
self.tanh = nn.Tanh()
self.v = nn.Parameter(torch.FloatTensor(dim))
self.v.data.uniform_(-(1.0 / math.sqrt(dim)), 1.0 / math.sqrt(dim))
def forward(self, query, ref):
"""
Args:
query: is the hidden state of the decoder at the current
time step. batch x dim
ref: the set of hidden states from the encoder.
sourceL x batch x hidden_dim
"""
ref = ref.permute(1, 2, 0)
q = self.project_query(query).unsqueeze(2)
e = self.project_ref(ref)
expanded_q = q.repeat(1, 1, e.size(2))
v_view = self.v.unsqueeze(0).expand(expanded_q.size(0), len(self.v)
).unsqueeze(1)
u = torch.bmm(v_view, self.tanh(expanded_q + e)).squeeze(1)
if self.use_tanh:
logits = self.C * self.tanh(u)
else:
logits = u
return e, logits
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import math
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x1), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (x1 + 4 * y0), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_convolution_repeat_tanh_1(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x1 = xindex // 4 % 4
x3 = xindex // 4
tmp0 = tl.load(in_out_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp3 + tmp2
tmp5 = libdevice.tanh(tmp4)
tl.store(in_out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr0 + x4, tmp5, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4, 4, 1), (4, 1, 1))
assert_size_stride(primals_6, (4,), (1,))
assert_size_stride(primals_7, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_3, primals_4, reinterpret_tensor(
primals_2, (4, 4), (1, 4), 0), alpha=1, beta=1, out=buf0)
del primals_2
del primals_3
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(16, 4)](primals_1, buf1, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_5, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 4), (16, 4, 1))
buf3 = buf2
del buf2
buf4 = buf1
del buf1
triton_poi_fused_add_convolution_repeat_tanh_1[grid(64)](buf3,
primals_6, buf0, buf4, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_6
buf5 = reinterpret_tensor(buf0, (4, 1, 4), (4, 4, 1), 0)
del buf0
extern_kernels.bmm(reinterpret_tensor(primals_7, (4, 1, 4), (0, 0,
1), 0), buf4, out=buf5)
return buf3, reinterpret_tensor(buf5, (4, 4), (4, 1), 0
), primals_4, primals_5, primals_7, reinterpret_tensor(primals_1, (
4, 4, 4), (4, 1, 16), 0), buf4
class AttentionNew(nn.Module):
"""A generic attention module for a decoder in seq2seq"""
def __init__(self, dim, use_tanh=False, C=10):
super(AttentionNew, self).__init__()
self.use_tanh = use_tanh
self.project_query = nn.Linear(dim, dim)
self.project_ref = nn.Conv1d(dim, dim, 1, 1)
self.C = C
self.tanh = nn.Tanh()
self.v = nn.Parameter(torch.FloatTensor(dim))
self.v.data.uniform_(-(1.0 / math.sqrt(dim)), 1.0 / math.sqrt(dim))
def forward(self, input_0, input_1):
primals_3 = self.v
primals_2 = self.project_query.weight
primals_6 = self.project_query.bias
primals_5 = self.project_ref.weight
primals_7 = self.project_ref.bias
primals_4 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0], output[1]
|
GuyLor/attention-learn-to-route
|
Attention
| false
| 2,328
|
[
"MIT"
] | 0
|
d07d5c1465f7ee5d18651e23cfae9aa1f52a9c6c
|
https://github.com/GuyLor/attention-learn-to-route/tree/d07d5c1465f7ee5d18651e23cfae9aa1f52a9c6c
|
DiceCoefficientLoss
|
import torch
import torch.nn as nn
class DiceCoefficientLoss(nn.Module):
def __init__(self, apply_softmax: 'bool'=False, eps: 'float'=1e-06):
super().__init__()
self.apply_softmax = apply_softmax
self.eps = eps
def forward(self, x: 'torch.Tensor', y: 'torch.Tensor', multiclass=True
) ->torch.Tensor:
"""
If we're doing multiclass segmentation, we want to calculate dice for each channel independently and then mean-
reduce afterwards.
:param x: The estimated segmentation logits
:param y: The labels
:param multiclass: Whether the logits should be calculated multiclass-wise.
:return: The Dice score, averaged over channels if multiclass.
"""
if x.size() != y.size():
raise RuntimeError(
f'Cannot calculate DICE score - input and label size do not match ({x.shape} vs. {y.shape})'
)
dice = 0
if multiclass:
for cls_idx in range(x.shape[1]):
dice += self._dice(x[:, cls_idx, ...], y[:, cls_idx, ...])
dice = dice / x.shape[1]
else:
dice = self._dice(x, y)
return 1 - dice
def _dice(self, x: 'torch.Tensor', y: 'torch.Tensor') ->torch.Tensor:
"""
Calculate the DICE score for input logits, x, against labels, y.
:param x: The estimated segmentation logits
:param y: The labels
:return: The dice score for this pair
"""
if self.apply_softmax:
x = torch.softmax(x, dim=1)
x = x.view(-1)
y = y.view(-1)
intersection = torch.dot(x, y)
return (2.0 * intersection + self.eps) / (x.sum() + y.sum() + self.eps)
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_div_dot_mul_rsub_sum_0(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp24 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
tmp25 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last')
tmp36 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
tmp37 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.sum(tmp3, 1)[:, None]
tmp6 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp8 = tl.sum(tmp6, 1)[:, None]
tmp9 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp11 = tl.sum(tmp9, 1)[:, None]
tmp14 = tmp12 * tmp13
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp17 = tl.sum(tmp15, 1)[:, None]
tmp18 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp20 = tl.sum(tmp18, 1)[:, None]
tmp21 = tl.broadcast_to(tmp13, [XBLOCK, RBLOCK])
tmp23 = tl.sum(tmp21, 1)[:, None]
tmp26 = tmp24 * tmp25
tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK])
tmp29 = tl.sum(tmp27, 1)[:, None]
tmp30 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp32 = tl.sum(tmp30, 1)[:, None]
tmp33 = tl.broadcast_to(tmp25, [XBLOCK, RBLOCK])
tmp35 = tl.sum(tmp33, 1)[:, None]
tmp38 = tmp36 * tmp37
tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK])
tmp41 = tl.sum(tmp39, 1)[:, None]
tmp42 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
tmp44 = tl.sum(tmp42, 1)[:, None]
tmp45 = tl.broadcast_to(tmp37, [XBLOCK, RBLOCK])
tmp47 = tl.sum(tmp45, 1)[:, None]
tmp48 = 2.0
tmp49 = tmp5 * tmp48
tmp50 = 1e-06
tmp51 = tmp49 + tmp50
tmp52 = tmp8 + tmp11
tmp53 = tmp52 + tmp50
tmp54 = tmp51 / tmp53
tmp55 = 0.0
tmp56 = tmp54 + tmp55
tmp57 = tmp17 * tmp48
tmp58 = tmp57 + tmp50
tmp59 = tmp20 + tmp23
tmp60 = tmp59 + tmp50
tmp61 = tmp58 / tmp60
tmp62 = tmp56 + tmp61
tmp63 = tmp29 * tmp48
tmp64 = tmp63 + tmp50
tmp65 = tmp32 + tmp35
tmp66 = tmp65 + tmp50
tmp67 = tmp64 / tmp66
tmp68 = tmp62 + tmp67
tmp69 = tmp41 * tmp48
tmp70 = tmp69 + tmp50
tmp71 = tmp44 + tmp47
tmp72 = tmp71 + tmp50
tmp73 = tmp70 / tmp72
tmp74 = tmp68 + tmp73
tmp75 = 0.25
tmp76 = tmp74 * tmp75
tmp77 = 1.0
tmp78 = tmp77 - tmp76
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp78, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf12 = buf0
del buf0
buf13 = buf12
del buf12
get_raw_stream(0)
triton_per_fused_add_div_dot_mul_rsub_sum_0[grid(1)](buf13, arg0_1,
arg1_1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf13,
class DiceCoefficientLossNew(nn.Module):
def __init__(self, apply_softmax: 'bool'=False, eps: 'float'=1e-06):
super().__init__()
self.apply_softmax = apply_softmax
self.eps = eps
def _dice(self, x: 'torch.Tensor', y: 'torch.Tensor') ->torch.Tensor:
"""
Calculate the DICE score for input logits, x, against labels, y.
:param x: The estimated segmentation logits
:param y: The labels
:return: The dice score for this pair
"""
if self.apply_softmax:
x = torch.softmax(x, dim=1)
x = x.view(-1)
y = y.view(-1)
intersection = torch.dot(x, y)
return (2.0 * intersection + self.eps) / (x.sum() + y.sum() + self.eps)
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
HalestormAI/efficientnet-unet
|
DiceCoefficientLoss
| false
| 2,329
|
[
"MIT"
] | 0
|
b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
https://github.com/HalestormAI/efficientnet-unet/tree/b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
NormalizationLayer
|
import torch
import torch.nn.init
class NormalizationLayer(torch.nn.Module):
"""Class for normalization layer."""
def __init__(self, normalize_scale=1.0, learn_scale=True):
super(NormalizationLayer, self).__init__()
self.norm_s = float(normalize_scale)
if learn_scale:
self.norm_s = torch.nn.Parameter(torch.FloatTensor((self.norm_s,)))
def forward(self, x):
features = self.norm_s * x / torch.norm(x, dim=1, keepdim=True
).expand_as(x)
return features
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn.init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_div_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tmp2 = tl.load(in_ptr1 + x3, xmask)
tmp4 = tl.load(in_ptr1 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr1 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr1 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr1 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 * tmp2
tmp5 = tmp4 * tmp4
tmp7 = tmp6 * tmp6
tmp8 = tmp5 + tmp7
tmp10 = tmp9 * tmp9
tmp11 = tmp8 + tmp10
tmp13 = tmp12 * tmp12
tmp14 = tmp11 + tmp13
tmp15 = libdevice.sqrt(tmp14)
tmp16 = tmp3 / tmp15
tl.store(out_ptr0 + x3, tmp16, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (1,), (1,))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_mul_0[grid(256)](primals_1, primals_2, buf0,
256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_1
return buf0, primals_2
class NormalizationLayerNew(torch.nn.Module):
"""Class for normalization layer."""
def __init__(self, normalize_scale=1.0, learn_scale=True):
super(NormalizationLayerNew, self).__init__()
self.norm_s = float(normalize_scale)
if learn_scale:
self.norm_s = torch.nn.Parameter(torch.FloatTensor((self.norm_s,)))
def forward(self, input_0):
primals_1 = self.norm_s
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
Harshdeep1996/jina-hub
|
NormalizationLayer
| false
| 2,330
|
[
"Apache-2.0"
] | 0
|
880ff719715b89969860c70219d26a931a031d10
|
https://github.com/Harshdeep1996/jina-hub/tree/880ff719715b89969860c70219d26a931a031d10
|
LinearZeros
|
import torch
import torch.nn as nn
class LinearZeros(nn.Linear):
def __init__(self, in_channels, out_channels, logscale_factor=3):
super().__init__(in_channels, out_channels)
self.logscale_factor = logscale_factor
self.register_parameter('logs', nn.Parameter(torch.zeros(out_channels))
)
self.weight.data.zero_()
self.bias.data.zero_()
def forward(self, input):
output = super().forward(input)
return output * torch.exp(self.logs * self.logscale_factor)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_exp_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = 3.0
tmp3 = tmp1 * tmp2
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp0 * tmp4
tl.store(out_ptr0 + x2, tmp5, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_exp_mul_0[grid(256)](buf0, primals_4, buf1, 256,
XBLOCK=128, num_warps=4, num_stages=1)
return buf1, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0
class LinearZerosNew(nn.Linear):
def __init__(self, in_channels, out_channels, logscale_factor=3):
super().__init__(in_channels, out_channels)
self.logscale_factor = logscale_factor
self.register_parameter('logs', nn.Parameter(torch.zeros(out_channels))
)
self.weight.data.zero_()
self.bias.data.zero_()
def forward(self, input_0):
primals_1 = self.weight
primals_2 = self.bias
primals_4 = self.logs
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
GauriJagatap/glow-pytorch
|
LinearZeros
| false
| 2,331
|
[
"MIT"
] | 0
|
e379f524b7cc0b57a9bc2849f4115f97bda5a1de
|
https://github.com/GauriJagatap/glow-pytorch/tree/e379f524b7cc0b57a9bc2849f4115f97bda5a1de
|
LayerNorm
|
import torch
from torch import nn
from torch.nn import functional as F
class LayerNorm(nn.Module):
def __init__(self, channels, eps=1e-05):
super().__init__()
self.channels = channels
self.eps = eps
self.gamma = nn.Parameter(torch.ones(channels))
self.beta = nn.Parameter(torch.zeros(channels))
def forward(self, x):
x = x.transpose(1, -1)
x = F.layer_norm(x, (self.channels,), self.gamma, self.beta, self.eps)
return x.transpose(1, -1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channels': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x2, tmp8, xmask)
tl.store(out_ptr1 + x2, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.
constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x3 = xindex
y2 = yindex // 16
y4 = yindex % 16
y5 = yindex
y0 = yindex % 4
y1 = yindex // 4 % 4
tmp0 = tl.load(in_ptr0 + (y4 + 16 * x3 + 64 * y2), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y5, ymask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + y5, ymask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x3, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x3, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + (x3 + 4 * y1 + 16 * y0 + 64 * y2), tmp8, xmask & ymask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 1, 4, 64), torch.float32)
get_raw_stream(0)
triton_poi_fused_native_layer_norm_0[grid(64)](primals_1, buf0,
buf1, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(64, 4)](primals_1, buf0,
buf1, primals_2, primals_3, buf2, 64, 4, XBLOCK=4, YBLOCK=32,
num_warps=4, num_stages=1)
del buf0
del buf1
del primals_2
del primals_3
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 1, 4, 16), 0), primals_1
class LayerNormNew(nn.Module):
def __init__(self, channels, eps=1e-05):
super().__init__()
self.channels = channels
self.eps = eps
self.gamma = nn.Parameter(torch.ones(channels))
self.beta = nn.Parameter(torch.zeros(channels))
def forward(self, input_0):
primals_2 = self.gamma
primals_3 = self.beta
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HalimSD/A-eye
|
LayerNorm
| false
| 2,332
|
[
"MIT"
] | 0
|
502dcdf47d54d93e8745be7c49897064550db8c7
|
https://github.com/HalimSD/A-eye/tree/502dcdf47d54d93e8745be7c49897064550db8c7
|
ResampleNorm
|
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.functional as F
class TimeDistributedInterpolation(nn.Module):
def __init__(self, output_size: 'int', batch_first: 'bool'=False,
trainable: 'bool'=False):
super().__init__()
self.output_size = output_size
self.batch_first = batch_first
self.trainable = trainable
if self.trainable:
self.mask = nn.Parameter(torch.zeros(self.output_size, dtype=
torch.float32))
self.gate = nn.Sigmoid()
def interpolate(self, x):
upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode=
'linear', align_corners=True).squeeze(1)
if self.trainable:
upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0
return upsampled
def forward(self, x):
if len(x.size()) <= 2:
return self.interpolate(x)
x_reshape = x.contiguous().view(-1, x.size(-1))
y = self.interpolate(x_reshape)
if self.batch_first:
y = y.contiguous().view(x.size(0), -1, y.size(-1))
else:
y = y.view(-1, x.size(1), y.size(-1))
return y
class ResampleNorm(nn.Module):
def __init__(self, input_size: 'int', output_size: 'int'=None,
trainable_add: 'bool'=True):
super().__init__()
self.input_size = input_size
self.trainable_add = trainable_add
self.output_size = output_size or input_size
if self.input_size != self.output_size:
self.resample = TimeDistributedInterpolation(self.output_size,
batch_first=True, trainable=False)
if self.trainable_add:
self.mask = nn.Parameter(torch.zeros(self.output_size, dtype=
torch.float))
self.gate = nn.Sigmoid()
self.norm = nn.LayerNorm(self.output_size)
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
if self.input_size != self.output_size:
x = self.resample(x)
if self.trainable_add:
x = x * self.gate(self.mask) * 2.0
output = self.norm(x)
return output
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn.functional as F
import torch.nn as nn
import torch.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_native_layer_norm_sigmoid_0(in_ptr0, in_ptr1,
out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp7 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr1 + 1)
tmp9 = tl.broadcast_to(tmp8, [XBLOCK])
tmp14 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp15 = tl.load(in_ptr1 + 2)
tmp16 = tl.broadcast_to(tmp15, [XBLOCK])
tmp21 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp22 = tl.load(in_ptr1 + 3)
tmp23 = tl.broadcast_to(tmp22, [XBLOCK])
tmp3 = tl.sigmoid(tmp2)
tmp4 = tmp0 * tmp3
tmp5 = 2.0
tmp6 = tmp4 * tmp5
tmp10 = tl.sigmoid(tmp9)
tmp11 = tmp7 * tmp10
tmp12 = tmp11 * tmp5
tmp13 = tmp6 + tmp12
tmp17 = tl.sigmoid(tmp16)
tmp18 = tmp14 * tmp17
tmp19 = tmp18 * tmp5
tmp20 = tmp13 + tmp19
tmp24 = tl.sigmoid(tmp23)
tmp25 = tmp21 * tmp24
tmp26 = tmp25 * tmp5
tmp27 = tmp20 + tmp26
tmp28 = 4.0
tmp29 = tmp27 / tmp28
tmp30 = tmp6 - tmp29
tmp31 = tmp30 * tmp30
tmp32 = tmp12 - tmp29
tmp33 = tmp32 * tmp32
tmp34 = tmp31 + tmp33
tmp35 = tmp19 - tmp29
tmp36 = tmp35 * tmp35
tmp37 = tmp34 + tmp36
tmp38 = tmp26 - tmp29
tmp39 = tmp38 * tmp38
tmp40 = tmp37 + tmp39
tmp41 = tmp40 / tmp28
tl.store(out_ptr0 + x0, tmp29, xmask)
tl.store(out_ptr1 + x0, tmp41, xmask)
@triton.jit
def triton_poi_fused_mul_native_layer_norm_sigmoid_1(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp15 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tmp4 = 2.0
tmp5 = tmp3 * tmp4
tmp7 = tmp5 - tmp6
tmp9 = 1e-05
tmp10 = tmp8 + tmp9
tmp11 = libdevice.rsqrt(tmp10)
tmp12 = tmp7 * tmp11
tmp14 = tmp12 * tmp13
tmp16 = tmp14 + tmp15
tl.store(out_ptr0 + x2, tmp16, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_native_layer_norm_sigmoid_0[grid(64)](primals_2,
primals_1, buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_native_layer_norm_sigmoid_1[grid(256)](primals_2,
primals_1, buf0, buf1, primals_3, primals_4, buf2, 256, XBLOCK=
128, num_warps=4, num_stages=1)
del buf0
del buf1
del primals_4
return buf2, primals_1, primals_2, primals_3
class TimeDistributedInterpolation(nn.Module):
def __init__(self, output_size: 'int', batch_first: 'bool'=False,
trainable: 'bool'=False):
super().__init__()
self.output_size = output_size
self.batch_first = batch_first
self.trainable = trainable
if self.trainable:
self.mask = nn.Parameter(torch.zeros(self.output_size, dtype=
torch.float32))
self.gate = nn.Sigmoid()
def interpolate(self, x):
upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode=
'linear', align_corners=True).squeeze(1)
if self.trainable:
upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0
return upsampled
def forward(self, x):
if len(x.size()) <= 2:
return self.interpolate(x)
x_reshape = x.contiguous().view(-1, x.size(-1))
y = self.interpolate(x_reshape)
if self.batch_first:
y = y.contiguous().view(x.size(0), -1, y.size(-1))
else:
y = y.view(-1, x.size(1), y.size(-1))
return y
class ResampleNormNew(nn.Module):
def __init__(self, input_size: 'int', output_size: 'int'=None,
trainable_add: 'bool'=True):
super().__init__()
self.input_size = input_size
self.trainable_add = trainable_add
self.output_size = output_size or input_size
if self.input_size != self.output_size:
self.resample = TimeDistributedInterpolation(self.output_size,
batch_first=True, trainable=False)
if self.trainable_add:
self.mask = nn.Parameter(torch.zeros(self.output_size, dtype=
torch.float))
self.gate = nn.Sigmoid()
self.norm = nn.LayerNorm(self.output_size)
def forward(self, input_0):
primals_1 = self.mask
primals_3 = self.norm.weight
primals_4 = self.norm.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
GoldbergData/pytorch-forecasting
|
ResampleNorm
| false
| 2,333
|
[
"MIT"
] | 0
|
e2ef3794da5d996c9740d932a4f55269bb4003f2
|
https://github.com/GoldbergData/pytorch-forecasting/tree/e2ef3794da5d996c9740d932a4f55269bb4003f2
|
JaccardLoss
|
import torch
import torch.nn as nn
class JaccardLoss(nn.Module):
def __init__(self, apply_softmax: 'bool'=False, eps: 'float'=1e-06):
super().__init__()
self.apply_softmax = apply_softmax
self.eps = eps
def forward(self, x, y, eps=1e-06):
if self.apply_softmax:
x = torch.softmax(x, dim=1)
x = x.view(-1)
y = y.reshape(-1)
intersection = (x * y).sum()
total = (x + y).sum()
union = total - intersection
IoU = (intersection + eps) / (union + eps)
return 1 - IoU
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_div_mul_rsub_sub_sum_0(in_out_ptr0, in_ptr0,
in_ptr1, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.load(in_ptr1 + r0, None)
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tmp0 + tmp1
tmp7 = tl.broadcast_to(tmp6, [RBLOCK])
tmp9 = triton_helpers.promote_to_tensor(tl.sum(tmp7, 0))
tmp10 = 1e-06
tmp11 = tmp5 + tmp10
tmp12 = tmp9 - tmp5
tmp13 = tmp12 + tmp10
tmp14 = tmp11 / tmp13
tmp15 = 1.0
tmp16 = tmp15 - tmp14
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp16, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf2 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_div_mul_rsub_sub_sum_0[grid(1)](buf2, arg0_1,
arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf2,
class JaccardLossNew(nn.Module):
def __init__(self, apply_softmax: 'bool'=False, eps: 'float'=1e-06):
super().__init__()
self.apply_softmax = apply_softmax
self.eps = eps
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
HalestormAI/efficientnet-unet
|
JaccardLoss
| false
| 2,334
|
[
"MIT"
] | 0
|
b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
https://github.com/HalestormAI/efficientnet-unet/tree/b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
TwoMLPHead
|
import torch
from torch import nn
import torch.nn.functional as F
class TwoMLPHead(nn.Module):
"""
Standard heads for FPN-based models
Arguments:
in_channels (int): number of input channels
representation_size (int): size of the intermediate representation
"""
def __init__(self, in_channels, representation_size):
super(TwoMLPHead, self).__init__()
self.fc6 = nn.Linear(in_channels, representation_size)
self.fc7 = nn.Linear(representation_size, representation_size)
def forward(self, x):
x = x.flatten(start_dim=1)
x = F.relu(self.fc6(x))
x = F.relu(self.fc7(x))
return x
def get_inputs():
return [torch.rand([4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'representation_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_1, reinterpret_tensor(primals_2, (4, 4),
(1, 4), 0), out=buf0)
del primals_2
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_relu_0[grid(16)](buf1, primals_3, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf1, reinterpret_tensor(primals_4, (4, 4), (1, 4
), 0), out=buf2)
buf3 = buf2
del buf2
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(16)](buf3,
primals_5, buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
del primals_5
return buf3, primals_1, buf1, buf4, primals_4
class TwoMLPHeadNew(nn.Module):
"""
Standard heads for FPN-based models
Arguments:
in_channels (int): number of input channels
representation_size (int): size of the intermediate representation
"""
def __init__(self, in_channels, representation_size):
super(TwoMLPHeadNew, self).__init__()
self.fc6 = nn.Linear(in_channels, representation_size)
self.fc7 = nn.Linear(representation_size, representation_size)
def forward(self, input_0):
primals_1 = self.fc6.weight
primals_3 = self.fc6.bias
primals_2 = self.fc7.weight
primals_5 = self.fc7.bias
primals_4 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
GreenCUBIC/Gas-Prices-of-America
|
TwoMLPHead
| false
| 2,335
|
[
"MIT"
] | 0
|
e2a045db99d061b5d2acbe208da8cc19af12659d
|
https://github.com/GreenCUBIC/Gas-Prices-of-America/tree/e2a045db99d061b5d2acbe208da8cc19af12659d
|
IndexedSegmentationMap
|
import torch
import torch.nn as nn
class IndexedSegmentationMap(nn.Module):
"""
Takes the raw logits from the n-channel output convolution and uses argmax to convert to an indexed output map.
"""
def __init__(self):
super().__init__()
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
return torch.argmax(x.squeeze(), dim=0)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_argmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + (64 + x0), xmask)
tmp17 = tl.load(in_ptr0 + (128 + x0), xmask)
tmp32 = tl.load(in_ptr0 + (192 + x0), xmask)
tmp2 = tmp0 > tmp1
tmp3 = tmp0 == tmp1
tmp4 = tmp0 != tmp0
tmp5 = tmp1 != tmp1
tmp6 = tmp4 > tmp5
tmp7 = tmp2 | tmp6
tmp8 = tmp4 & tmp5
tmp9 = tmp3 | tmp8
tmp10 = tl.full([1], 0, tl.int64)
tmp11 = tl.full([1], 1, tl.int64)
tmp12 = tmp10 < tmp11
tmp13 = tmp9 & tmp12
tmp14 = tmp7 | tmp13
tmp15 = tl.where(tmp14, tmp0, tmp1)
tmp16 = tl.where(tmp14, tmp10, tmp11)
tmp18 = tmp15 > tmp17
tmp19 = tmp15 == tmp17
tmp20 = tmp15 != tmp15
tmp21 = tmp17 != tmp17
tmp22 = tmp20 > tmp21
tmp23 = tmp18 | tmp22
tmp24 = tmp20 & tmp21
tmp25 = tmp19 | tmp24
tmp26 = tl.full([1], 2, tl.int64)
tmp27 = tmp16 < tmp26
tmp28 = tmp25 & tmp27
tmp29 = tmp23 | tmp28
tmp30 = tl.where(tmp29, tmp15, tmp17)
tmp31 = tl.where(tmp29, tmp16, tmp26)
tmp33 = tmp30 > tmp32
tmp34 = tmp30 == tmp32
tmp35 = tmp30 != tmp30
tmp36 = tmp32 != tmp32
tmp37 = tmp35 > tmp36
tmp38 = tmp33 | tmp37
tmp39 = tmp35 & tmp36
tmp40 = tmp34 | tmp39
tmp41 = tl.full([1], 3, tl.int64)
tmp42 = tmp31 < tmp41
tmp43 = tmp40 & tmp42
tmp44 = tmp38 | tmp43
tl.where(tmp44, tmp30, tmp32)
tmp46 = tl.where(tmp44, tmp31, tmp41)
tl.store(out_ptr0 + x0, tmp46, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.int64)
get_raw_stream(0)
triton_poi_fused_argmax_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del arg0_1
return buf0,
class IndexedSegmentationMapNew(nn.Module):
"""
Takes the raw logits from the n-channel output convolution and uses argmax to convert to an indexed output map.
"""
def __init__(self):
super().__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
HalestormAI/efficientnet-unet
|
IndexedSegmentationMap
| false
| 2,336
|
[
"MIT"
] | 0
|
b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
https://github.com/HalestormAI/efficientnet-unet/tree/b6d5ec86d667ce7ac1f689bc16269dca83a079f0
|
Attention
|
import math
import torch
import torch.nn as nn
from abc import *
import torch.nn.functional as F
from torch import optim as optim
class Attention(nn.Module):
"""
Compute 'Scaled Dot Product Attention
"""
def forward(self, query, key, value, mask=None, dropout=None):
scores = torch.matmul(query, key.transpose(-2, -1)) / math.sqrt(query
.size(-1))
if mask is not None:
scores = scores.masked_fill(mask == 0, -1000000000.0)
p_attn = F.softmax(scores, dim=-1)
if dropout is not None:
p_attn = dropout(p_attn)
return torch.matmul(p_attn, value), p_attn
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
from abc import *
from torch import optim as optim
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = 0.5
tmp16 = tmp14 * tmp15
tmp17 = tl_math.exp(tmp16)
tl.store(out_ptr0 + x2, tmp17, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg1_1, (16, 4, 4), (16, 4, 1
), 0), reinterpret_tensor(arg0_1, (16, 4, 4), (16, 1, 4), 0),
out=buf0)
del arg0_1
del arg1_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(256)](buf0, buf1, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf2 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
triton_poi_fused__softmax_1[grid(256)](buf1, buf2, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf3 = reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0)
del buf1
extern_kernels.bmm(reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg2_1, (16, 4, 4), (16, 4, 1), 0), out=buf3
)
del arg2_1
return reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0), buf2
class AttentionNew(nn.Module):
"""
Compute 'Scaled Dot Product Attention
"""
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0], output[1]
|
HeegyuKim/RecSys-MovieLens100k
|
Attention
| false
| 2,337
|
[
"MIT"
] | 0
|
aa3a272e6045d8230ecbabbf94a6f68170a26c9e
|
https://github.com/HeegyuKim/RecSys-MovieLens100k/tree/aa3a272e6045d8230ecbabbf94a6f68170a26c9e
|
CBAM
|
import torch
from torch import nn
class ChannelAttention(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = avg_out + max_out
return self.sigmoid(out)
class SpatialAttention(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttention, self).__init__()
assert kernel_size in (3, 7), 'kernel size must be 3 or 7'
padding = 3 if kernel_size == 7 else 1
self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
x = torch.cat([avg_out, max_out], dim=1)
x = self.conv1(x)
return self.sigmoid(x)
class CBAM(nn.Module):
def __init__(self, channel, ratio=8, kernel_size=7):
super(CBAM, self).__init__()
self.channelattention = ChannelAttention(channel, ratio=ratio)
self.spatialattention = SpatialAttention(kernel_size=kernel_size)
def forward(self, x):
x = x * self.channelattention(x)
x = x * self.spatialattention(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channel': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_1(in_out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(in_out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_adaptive_max_pool2d_2(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = triton_helpers.maximum(tmp11, tmp10)
tmp14 = triton_helpers.maximum(tmp13, tmp12)
tmp16 = triton_helpers.maximum(tmp15, tmp14)
tmp18 = triton_helpers.maximum(tmp17, tmp16)
tmp20 = triton_helpers.maximum(tmp19, tmp18)
tmp22 = triton_helpers.maximum(tmp21, tmp20)
tmp24 = triton_helpers.maximum(tmp23, tmp22)
tmp26 = triton_helpers.maximum(tmp25, tmp24)
tmp28 = triton_helpers.maximum(tmp27, tmp26)
tmp30 = triton_helpers.maximum(tmp29, tmp28)
tl.store(out_ptr0 + x0, tmp30, xmask)
@triton.jit
def triton_poi_fused_add_sigmoid_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask)
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x0, tmp3, xmask)
@triton.jit
def triton_poi_fused_cat_4(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 2
x0 = xindex % 16
x2 = xindex // 32
x4 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr1 + 4 * x2, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp5 * tmp6
tmp8 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp9 = tl.load(in_ptr1 + (1 + 4 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tmp8 * tmp9
tmp11 = tmp7 + tmp10
tmp12 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp13 = tl.load(in_ptr1 + (2 + 4 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp14 = tmp12 * tmp13
tmp15 = tmp11 + tmp14
tmp16 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp17 = tl.load(in_ptr1 + (3 + 4 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp16 * tmp17
tmp19 = tmp15 + tmp18
tmp20 = 4.0
tmp21 = tmp19 / tmp20
tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
tmp23 = tl.where(tmp4, tmp21, tmp22)
tmp24 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp27 = tl.load(in_ptr0 + (x0 + 64 * x2), tmp24 & xmask,
eviction_policy='evict_last', other=0.0)
tmp28 = tl.load(in_ptr1 + 4 * x2, tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp29 = tmp27 * tmp28
tmp30 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), tmp24 & xmask,
eviction_policy='evict_last', other=0.0)
tmp31 = tl.load(in_ptr1 + (1 + 4 * x2), tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp32 = tmp30 * tmp31
tmp33 = triton_helpers.maximum(tmp29, tmp32)
tmp34 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), tmp24 & xmask,
eviction_policy='evict_last', other=0.0)
tmp35 = tl.load(in_ptr1 + (2 + 4 * x2), tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp36 = tmp34 * tmp35
tmp37 = triton_helpers.maximum(tmp33, tmp36)
tmp38 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), tmp24 & xmask,
eviction_policy='evict_last', other=0.0)
tmp39 = tl.load(in_ptr1 + (3 + 4 * x2), tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp40 = tmp38 * tmp39
tmp41 = triton_helpers.maximum(tmp37, tmp40)
tmp42 = tl.full(tmp41.shape, 0.0, tmp41.dtype)
tmp43 = tl.where(tmp24, tmp41, tmp42)
tmp44 = tl.where(tmp4, tmp23, tmp43)
tl.store(out_ptr0 + x4, tmp44, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex // 16
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 * tmp1
tmp4 = tl.sigmoid(tmp3)
tmp5 = tmp2 * tmp4
tl.store(out_ptr0 + x3, tmp5, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (8, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (4, 8, 1, 1), (8, 1, 1, 1))
assert_size_stride(primals_4, (1, 2, 7, 7), (98, 49, 7, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 8, 1, 1), (8, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_relu_1[grid(32)](buf3, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf4 = extern_kernels.convolution(buf3, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1))
buf5 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused_adaptive_max_pool2d_2[grid(16)](primals_1, buf5,
16, XBLOCK=16, num_warps=1, num_stages=1)
buf6 = extern_kernels.convolution(buf5, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 8, 1, 1), (8, 1, 1, 1))
buf7 = buf6
del buf6
triton_poi_fused_relu_1[grid(32)](buf7, 32, XBLOCK=32, num_warps=1,
num_stages=1)
buf8 = extern_kernels.convolution(buf7, primals_3, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 4, 1, 1), (4, 1, 1, 1))
buf9 = buf4
del buf4
triton_poi_fused_add_sigmoid_3[grid(16)](buf9, buf8, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf8
buf10 = empty_strided_cuda((4, 2, 4, 4), (32, 16, 4, 1), torch.float32)
triton_poi_fused_cat_4[grid(128)](primals_1, buf9, buf10, 128,
XBLOCK=128, num_warps=4, num_stages=1)
buf11 = extern_kernels.convolution(buf10, primals_4, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf11, (4, 1, 4, 4), (16, 16, 4, 1))
buf12 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_5[grid(256)](primals_1, buf9, buf11,
buf12, 256, XBLOCK=128, num_warps=4, num_stages=1)
return (buf12, primals_1, primals_2, primals_3, primals_4, buf1, buf3,
buf5, buf7, buf9, buf10, buf11)
class ChannelAttention(nn.Module):
def __init__(self, in_planes, ratio=8):
super(ChannelAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, ratio, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(ratio, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = avg_out + max_out
return self.sigmoid(out)
class SpatialAttention(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttention, self).__init__()
assert kernel_size in (3, 7), 'kernel size must be 3 or 7'
padding = 3 if kernel_size == 7 else 1
self.conv1 = nn.Conv2d(2, 1, kernel_size, padding=padding, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
avg_out = torch.mean(x, dim=1, keepdim=True)
max_out, _ = torch.max(x, dim=1, keepdim=True)
x = torch.cat([avg_out, max_out], dim=1)
x = self.conv1(x)
return self.sigmoid(x)
class CBAMNew(nn.Module):
def __init__(self, channel, ratio=8, kernel_size=7):
super(CBAMNew, self).__init__()
self.channelattention = ChannelAttention(channel, ratio=ratio)
self.spatialattention = SpatialAttention(kernel_size=kernel_size)
def forward(self, input_0):
primals_2 = self.channelattention.fc1.weight
primals_3 = self.channelattention.fc2.weight
primals_4 = self.spatialattention.conv1.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
HT-hlf/mmdetection_miner-2.22.0
|
CBAM
| false
| 2,338
|
[
"Apache-2.0"
] | 0
|
76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
https://github.com/HT-hlf/mmdetection_miner-2.22.0/tree/76eb94d6547f9f95cd58f41bb5c91941e82322b9
|
ActorNetwork
|
import torch
import torch.nn.functional as F
import torch.nn as nn
class ActorNetwork(nn.Module):
def __init__(self, state_dim, action_dim, seed, fc1_units=256,
fc2_units=128):
""" Initialize parameters of model and build its.
Parameters:
===========
state_dim (int): State space dimension
action_dim (int): Action space dimension
seed (int): Random seed
fcX_units (int): No. of hidden layers units
"""
super(ActorNetwork, self).__init__()
self.seed = torch.manual_seed(seed)
self.fc1 = nn.Linear(state_dim, fc1_units)
self.bn1 = nn.LayerNorm(fc1_units)
self.fc2 = nn.Linear(fc1_units, fc2_units)
self.fc3 = nn.Linear(fc2_units, action_dim)
self.init_parameters()
def init_parameters(self):
""" Initialize network weights. """
self.fc3.weight.data.uniform_(-0.003, 0.003)
def forward(self, state):
x = F.relu(self.bn1(self.fc1(state)))
x = F.relu(self.fc2(x))
x = torch.tanh(self.fc3(x))
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'state_dim': 4, 'action_dim': 4, 'seed': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_native_layer_norm_relu_threshold_backward_0(in_out_ptr0,
in_ptr0, in_ptr1, in_ptr2, out_ptr0, out_ptr1, out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = tl.full([1], xoffset, tl.int32)
tl.full([RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[:]
tl.full([RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 256 * x0), None)
tmp21 = tl.load(in_ptr1 + r1, None, eviction_policy='evict_last')
tmp23 = tl.load(in_ptr2 + r1, None, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = tl.broadcast_to(tmp1, [RBLOCK])
tmp5 = triton_helpers.promote_to_tensor(tl.sum(tmp3, 0))
tmp6 = tl.full([1], 256, tl.int32)
tmp7 = tmp6.to(tl.float32)
tmp8 = tmp5 / tmp7
tmp9 = tmp1 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [RBLOCK])
tmp13 = triton_helpers.promote_to_tensor(tl.sum(tmp11, 0))
tmp14 = 256.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tmp19 = tmp0 - tmp8
tmp20 = tmp19 * tmp18
tmp22 = tmp20 * tmp21
tmp24 = tmp22 + tmp23
tmp25 = tl.full([1], 0, tl.int32)
tmp26 = triton_helpers.maximum(tmp25, tmp24)
tmp27 = 0.0
tmp28 = tmp26 <= tmp27
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp18, None)
tl.store(out_ptr1 + (r1 + 256 * x0), tmp26, None)
tl.store(out_ptr2 + (r1 + 256 * x0), tmp28, None)
tl.store(out_ptr0 + x0, tmp8, None)
@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 128
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, None)
tl.store(out_ptr0 + x2, tmp6, None)
@triton.jit
def triton_poi_fused_tanh_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = libdevice.tanh(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9) = args
args.clear()
assert_size_stride(primals_1, (256, 4), (4, 1))
assert_size_stride(primals_2, (256,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (256,), (1,))
assert_size_stride(primals_5, (256,), (1,))
assert_size_stride(primals_6, (128, 256), (256, 1))
assert_size_stride(primals_7, (128,), (1,))
assert_size_stride(primals_8, (4, 128), (128, 1))
assert_size_stride(primals_9, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 256), (1, 4),
0), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf4 = reinterpret_tensor(buf2, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf2
buf5 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1),
torch.float32)
buf11 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1),
torch.bool)
get_raw_stream(0)
triton_per_fused_native_layer_norm_relu_threshold_backward_0[grid(64)](
buf4, buf0, primals_4, primals_5, buf1, buf5, buf11, 64, 256,
num_warps=2, num_stages=1)
del primals_5
buf6 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf5, (64, 256), (256, 1), 0),
reinterpret_tensor(primals_6, (256, 128), (1, 256), 0), out=buf6)
buf7 = reinterpret_tensor(buf6, (4, 4, 4, 128), (2048, 512, 128, 1), 0)
del buf6
buf10 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(8192)](buf7,
primals_7, buf10, 8192, XBLOCK=128, num_warps=4, num_stages=1)
del primals_7
buf8 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf7, (64, 128), (128, 1), 0),
reinterpret_tensor(primals_8, (128, 4), (1, 128), 0), out=buf8)
buf9 = reinterpret_tensor(buf8, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf8
triton_poi_fused_tanh_2[grid(256)](buf9, primals_9, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del primals_9
return buf9, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0, buf1, buf4, reinterpret_tensor(buf5, (64, 256), (256, 1), 0
), reinterpret_tensor(buf7, (64, 128), (128, 1), 0
), buf9, primals_8, buf10, primals_6, buf11
class ActorNetworkNew(nn.Module):
def __init__(self, state_dim, action_dim, seed, fc1_units=256,
fc2_units=128):
""" Initialize parameters of model and build its.
Parameters:
===========
state_dim (int): State space dimension
action_dim (int): Action space dimension
seed (int): Random seed
fcX_units (int): No. of hidden layers units
"""
super(ActorNetworkNew, self).__init__()
self.seed = torch.manual_seed(seed)
self.fc1 = nn.Linear(state_dim, fc1_units)
self.bn1 = nn.LayerNorm(fc1_units)
self.fc2 = nn.Linear(fc1_units, fc2_units)
self.fc3 = nn.Linear(fc2_units, action_dim)
self.init_parameters()
def init_parameters(self):
""" Initialize network weights. """
self.fc3.weight.data.uniform_(-0.003, 0.003)
def forward(self, input_0):
primals_1 = self.fc1.weight
primals_2 = self.fc1.bias
primals_4 = self.bn1.weight
primals_5 = self.bn1.bias
primals_6 = self.fc2.weight
primals_7 = self.fc2.bias
primals_8 = self.fc3.weight
primals_9 = self.fc3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9])
return output[0]
|
HatemSelim94/RL-MADDPG
|
ActorNetwork
| false
| 2,339
|
[
"MIT"
] | 0
|
037a722f59e2e461fe6615685b434365fc5540b1
|
https://github.com/HatemSelim94/RL-MADDPG/tree/037a722f59e2e461fe6615685b434365fc5540b1
|
ShuffleBlock
|
import torch
import torch.nn as nn
class ShuffleBlock(nn.Module):
def __init__(self, groups=2):
super(ShuffleBlock, self).__init__()
self.groups = groups
def forward(self, x):
"""Channel shuffle: [N,C,H,W] -> [N,g,C/g,H,W] -> [N,C/g,g,H,w] -> [N,C,H,W]"""
N, C, H, W = x.size()
g = self.groups
return x.view(N, g, C // g, H, W).permute(0, 2, 1, 3, 4).reshape(N,
C, H, W)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16 % 2
x2 = xindex // 32 % 2
x3 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2 + 32 * x1 + 64 * x3), xmask)
tl.store(out_ptr0 + x4, tmp0, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 2, 2, 4, 4), (64, 32, 16, 4, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0),
class ShuffleBlockNew(nn.Module):
def __init__(self, groups=2):
super(ShuffleBlockNew, self).__init__()
self.groups = groups
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Geunwoo-Jeon/pytorch-cifar
|
ShuffleBlock
| false
| 2,340
|
[
"MIT"
] | 0
|
b06eeb65bbc0a4eccd124ed3c5367da70ab1ed20
|
https://github.com/Geunwoo-Jeon/pytorch-cifar/tree/b06eeb65bbc0a4eccd124ed3c5367da70ab1ed20
|
ScaledDotProductAttention
|
import torch
import torch.nn as nn
class ScaledDotProductAttention(nn.Module):
def __init__(self, dropout: 'float'=None, scale: 'bool'=True):
super(ScaledDotProductAttention, self).__init__()
if dropout is not None:
self.dropout = nn.Dropout(p=dropout)
else:
self.dropout = dropout
self.softmax = nn.Softmax(dim=2)
self.scale = scale
def forward(self, q, k, v, mask=None):
attn = torch.bmm(q, k.permute(0, 2, 1))
if self.scale:
dimension = torch.sqrt(torch.tensor(k.shape[-1]))
attn = attn / dimension
if mask is not None:
attn = attn.masked_fill(mask, -1000000000.0)
attn = self.softmax(attn)
if self.dropout is not None:
attn = self.dropout(attn)
output = torch.bmm(attn, v)
return output, attn
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4, 4])
]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_sqrt_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp8 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp13 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp16 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = 2.0
tmp2 = 0.0
tmp3 = tmp1 >= tmp2
tmp4 = 1.0
tmp5 = -1.0
tmp6 = tl.where(tmp3, tmp4, tmp5)
tmp7 = tmp0 * tmp6
tmp9 = tmp8 * tmp6
tmp11 = tmp10 * tmp6
tmp12 = triton_helpers.maximum(tmp9, tmp11)
tmp14 = tmp13 * tmp6
tmp15 = triton_helpers.maximum(tmp12, tmp14)
tmp17 = tmp16 * tmp6
tmp18 = triton_helpers.maximum(tmp15, tmp17)
tmp19 = tmp7 - tmp18
tmp20 = tmp6 * tmp1
tmp21 = tmp19 / tmp20
tmp22 = tl_math.exp(tmp21)
tl.store(out_ptr0 + x2, tmp22, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), (
16, 1, 4), 0), out=buf0)
del arg0_1
del arg1_1
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_sqrt_0[grid(64)](buf0, buf1, 64, XBLOCK=
64, num_warps=1, num_stages=1)
buf2 = buf0
del buf0
triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = buf1
del buf1
extern_kernels.bmm(buf2, arg2_1, out=buf3)
del arg2_1
return buf3, buf2
class ScaledDotProductAttentionNew(nn.Module):
def __init__(self, dropout: 'float'=None, scale: 'bool'=True):
super(ScaledDotProductAttentionNew, self).__init__()
if dropout is not None:
self.dropout = nn.Dropout(p=dropout)
else:
self.dropout = dropout
self.softmax = nn.Softmax(dim=2)
self.scale = scale
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0], output[1]
|
GoldbergData/pytorch-forecasting
|
ScaledDotProductAttention
| false
| 2,341
|
[
"MIT"
] | 0
|
e2ef3794da5d996c9740d932a4f55269bb4003f2
|
https://github.com/GoldbergData/pytorch-forecasting/tree/e2ef3794da5d996c9740d932a4f55269bb4003f2
|
BiInteractionPooling
|
import torch
import torch.nn as nn
import torch.utils.data
class BiInteractionPooling(nn.Module):
def __init__(self):
super(BiInteractionPooling, self).__init__()
def forward(self, inputs):
concated_embeds_value = inputs
square_of_sum = torch.pow(torch.sum(concated_embeds_value, dim=1,
keepdim=True), 2)
sum_of_square = torch.sum(concated_embeds_value *
concated_embeds_value, dim=1, keepdim=True)
cross_term = 0.5 * (square_of_sum - sum_of_square)
return cross_term
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_pow_sub_sum_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = tmp6 * tmp6
tmp8 = tmp0 * tmp0
tmp9 = tmp1 * tmp1
tmp10 = tmp8 + tmp9
tmp11 = tmp3 * tmp3
tmp12 = tmp10 + tmp11
tmp13 = tmp5 * tmp5
tmp14 = tmp12 + tmp13
tmp15 = tmp7 - tmp14
tmp16 = 0.5
tmp17 = tmp15 * tmp16
tl.store(out_ptr0 + x2, tmp17, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_pow_sub_sum_0[grid(64)](arg0_1, buf0, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del arg0_1
return buf0,
class BiInteractionPoolingNew(nn.Module):
def __init__(self):
super(BiInteractionPoolingNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Holldean/pytorch-models
|
BiInteractionPooling
| false
| 2,342
|
[
"MIT"
] | 0
|
9509d0d462b1a98164b266d49ada199071a855ac
|
https://github.com/Holldean/pytorch-models/tree/9509d0d462b1a98164b266d49ada199071a855ac
|
AddNorm
|
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.functional as F
class TimeDistributedInterpolation(nn.Module):
def __init__(self, output_size: 'int', batch_first: 'bool'=False,
trainable: 'bool'=False):
super().__init__()
self.output_size = output_size
self.batch_first = batch_first
self.trainable = trainable
if self.trainable:
self.mask = nn.Parameter(torch.zeros(self.output_size, dtype=
torch.float32))
self.gate = nn.Sigmoid()
def interpolate(self, x):
upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode=
'linear', align_corners=True).squeeze(1)
if self.trainable:
upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0
return upsampled
def forward(self, x):
if len(x.size()) <= 2:
return self.interpolate(x)
x_reshape = x.contiguous().view(-1, x.size(-1))
y = self.interpolate(x_reshape)
if self.batch_first:
y = y.contiguous().view(x.size(0), -1, y.size(-1))
else:
y = y.view(-1, x.size(1), y.size(-1))
return y
class AddNorm(nn.Module):
def __init__(self, input_size: 'int', skip_size: 'int'=None,
trainable_add: 'bool'=True):
super().__init__()
self.input_size = input_size
self.trainable_add = trainable_add
self.skip_size = skip_size or input_size
if self.input_size != self.skip_size:
self.resample = TimeDistributedInterpolation(self.input_size,
batch_first=True, trainable=False)
if self.trainable_add:
self.mask = nn.Parameter(torch.zeros(self.input_size, dtype=
torch.float))
self.gate = nn.Sigmoid()
self.norm = nn.LayerNorm(self.input_size)
def forward(self, x: 'torch.Tensor', skip: 'torch.Tensor'):
if self.input_size != self.skip_size:
skip = self.resample(skip)
if self.trainable_add:
skip = skip * self.gate(self.mask) * 2.0
output = self.norm(x + skip)
return output
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn.functional as F
import torch.nn as nn
import torch.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_mul_native_layer_norm_sigmoid_0(in_ptr0, in_ptr1,
in_ptr2, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + 0)
tmp3 = tl.broadcast_to(tmp2, [XBLOCK])
tmp9 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr2 + 1)
tmp12 = tl.broadcast_to(tmp11, [XBLOCK])
tmp18 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp19 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp20 = tl.load(in_ptr2 + 2)
tmp21 = tl.broadcast_to(tmp20, [XBLOCK])
tmp27 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp28 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp29 = tl.load(in_ptr2 + 3)
tmp30 = tl.broadcast_to(tmp29, [XBLOCK])
tmp4 = tl.sigmoid(tmp3)
tmp5 = tmp1 * tmp4
tmp6 = 2.0
tmp7 = tmp5 * tmp6
tmp8 = tmp0 + tmp7
tmp13 = tl.sigmoid(tmp12)
tmp14 = tmp10 * tmp13
tmp15 = tmp14 * tmp6
tmp16 = tmp9 + tmp15
tmp17 = tmp8 + tmp16
tmp22 = tl.sigmoid(tmp21)
tmp23 = tmp19 * tmp22
tmp24 = tmp23 * tmp6
tmp25 = tmp18 + tmp24
tmp26 = tmp17 + tmp25
tmp31 = tl.sigmoid(tmp30)
tmp32 = tmp28 * tmp31
tmp33 = tmp32 * tmp6
tmp34 = tmp27 + tmp33
tmp35 = tmp26 + tmp34
tmp36 = 4.0
tmp37 = tmp35 / tmp36
tmp38 = tmp8 - tmp37
tmp39 = tmp38 * tmp38
tmp40 = tmp16 - tmp37
tmp41 = tmp40 * tmp40
tmp42 = tmp39 + tmp41
tmp43 = tmp25 - tmp37
tmp44 = tmp43 * tmp43
tmp45 = tmp42 + tmp44
tmp46 = tmp34 - tmp37
tmp47 = tmp46 * tmp46
tmp48 = tmp45 + tmp47
tmp49 = tmp48 / tmp36
tl.store(out_ptr0 + x0, tmp37, xmask)
tl.store(out_ptr1 + x0, tmp49, xmask)
@triton.jit
def triton_poi_fused_add_mul_native_layer_norm_sigmoid_1(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
tmp15 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
tmp17 = tl.load(in_ptr6 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.sigmoid(tmp2)
tmp4 = tmp1 * tmp3
tmp5 = 2.0
tmp6 = tmp4 * tmp5
tmp7 = tmp0 + tmp6
tmp9 = tmp7 - tmp8
tmp11 = 1e-05
tmp12 = tmp10 + tmp11
tmp13 = libdevice.rsqrt(tmp12)
tmp14 = tmp9 * tmp13
tmp16 = tmp14 * tmp15
tmp18 = tmp16 + tmp17
tl.store(out_ptr0 + x2, tmp18, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_mul_native_layer_norm_sigmoid_0[grid(64)](
primals_3, primals_2, primals_1, buf0, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_native_layer_norm_sigmoid_1[grid(256)](
primals_3, primals_2, primals_1, buf0, buf1, primals_4,
primals_5, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del buf1
del primals_5
return buf2, primals_1, primals_2, primals_3, primals_4
class TimeDistributedInterpolation(nn.Module):
def __init__(self, output_size: 'int', batch_first: 'bool'=False,
trainable: 'bool'=False):
super().__init__()
self.output_size = output_size
self.batch_first = batch_first
self.trainable = trainable
if self.trainable:
self.mask = nn.Parameter(torch.zeros(self.output_size, dtype=
torch.float32))
self.gate = nn.Sigmoid()
def interpolate(self, x):
upsampled = F.interpolate(x.unsqueeze(1), self.output_size, mode=
'linear', align_corners=True).squeeze(1)
if self.trainable:
upsampled = upsampled * self.gate(self.mask.unsqueeze(0)) * 2.0
return upsampled
def forward(self, x):
if len(x.size()) <= 2:
return self.interpolate(x)
x_reshape = x.contiguous().view(-1, x.size(-1))
y = self.interpolate(x_reshape)
if self.batch_first:
y = y.contiguous().view(x.size(0), -1, y.size(-1))
else:
y = y.view(-1, x.size(1), y.size(-1))
return y
class AddNormNew(nn.Module):
def __init__(self, input_size: 'int', skip_size: 'int'=None,
trainable_add: 'bool'=True):
super().__init__()
self.input_size = input_size
self.trainable_add = trainable_add
self.skip_size = skip_size or input_size
if self.input_size != self.skip_size:
self.resample = TimeDistributedInterpolation(self.input_size,
batch_first=True, trainable=False)
if self.trainable_add:
self.mask = nn.Parameter(torch.zeros(self.input_size, dtype=
torch.float))
self.gate = nn.Sigmoid()
self.norm = nn.LayerNorm(self.input_size)
def forward(self, input_0, input_1):
primals_1 = self.mask
primals_4 = self.norm.weight
primals_5 = self.norm.bias
primals_2 = input_0
primals_3 = input_1
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
GoldbergData/pytorch-forecasting
|
AddNorm
| false
| 2,343
|
[
"MIT"
] | 0
|
e2ef3794da5d996c9740d932a4f55269bb4003f2
|
https://github.com/GoldbergData/pytorch-forecasting/tree/e2ef3794da5d996c9740d932a4f55269bb4003f2
|
SE
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class SE(nn.Module):
"""Squeeze-and-Excitation block."""
def __init__(self, in_planes, se_planes):
super(SE, self).__init__()
self.se1 = nn.Conv2d(in_planes, se_planes, kernel_size=1, bias=True)
self.se2 = nn.Conv2d(se_planes, in_planes, kernel_size=1, bias=True)
def forward(self, x):
out = F.adaptive_avg_pool2d(x, (1, 1))
out = F.relu(self.se1(out))
out = self.se2(out).sigmoid()
out = x * out
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_planes': 4, 'se_planes': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_3(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = tmp0 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = extern_kernels.convolution(buf1, primals_2, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 1, 1), (4, 1, 1, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_relu_1[grid(16)](buf3, primals_3, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 1, 1), (4, 1, 1, 1))
buf5 = buf4
del buf4
triton_poi_fused_convolution_2[grid(16)](buf5, primals_5, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_5
buf6 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_3[grid(256)](primals_1, buf5, buf6,
256, XBLOCK=128, num_warps=4, num_stages=1)
return buf6, primals_1, primals_2, primals_4, buf1, buf3, buf5
class SENew(nn.Module):
"""Squeeze-and-Excitation block."""
def __init__(self, in_planes, se_planes):
super(SENew, self).__init__()
self.se1 = nn.Conv2d(in_planes, se_planes, kernel_size=1, bias=True)
self.se2 = nn.Conv2d(se_planes, in_planes, kernel_size=1, bias=True)
def forward(self, input_0):
primals_2 = self.se1.weight
primals_3 = self.se1.bias
primals_4 = self.se2.weight
primals_5 = self.se2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Geunwoo-Jeon/pytorch-cifar
|
SE
| false
| 2,344
|
[
"MIT"
] | 0
|
b06eeb65bbc0a4eccd124ed3c5367da70ab1ed20
|
https://github.com/Geunwoo-Jeon/pytorch-cifar/tree/b06eeb65bbc0a4eccd124ed3c5367da70ab1ed20
|
PositionwiseFeedForward
|
import torch
import torch.nn as nn
class PositionwiseFeedForward(nn.Module):
""" A two-feed-forward-layer module """
def __init__(self, d_hid, d_inner_hid=None, dropout=0):
super(PositionwiseFeedForward, self).__init__()
if d_inner_hid is None:
d_inner_hid = d_hid
self.w_1 = nn.Conv1d(d_hid, d_inner_hid, 1)
self.w_2 = nn.Conv1d(d_inner_hid, d_hid, 1)
self.dropout = nn.Dropout(dropout)
self.relu = nn.ReLU()
def forward(self, x):
output = self.relu(self.w_1(x.transpose(1, 2)))
output = self.w_2(output).transpose(2, 1)
output = self.dropout(output)
return output
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'d_hid': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_convolution_0(in_ptr0, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4, 1), (4, 1, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 1), (4, 1, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(16, 4)](primals_1, buf0, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4), (16, 4, 1))
del buf0
buf2 = buf1
del buf1
triton_poi_fused_convolution_relu_1[grid(64)](buf2, primals_3, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_3
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 4), (16, 4, 1))
buf4 = buf3
del buf3
triton_poi_fused_convolution_2[grid(64)](buf4, primals_5, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_5
return reinterpret_tensor(buf4, (4, 4, 4), (16, 1, 4), 0
), primals_2, primals_4, reinterpret_tensor(primals_1, (4, 4, 4), (
16, 1, 4), 0), buf2
class PositionwiseFeedForwardNew(nn.Module):
""" A two-feed-forward-layer module """
def __init__(self, d_hid, d_inner_hid=None, dropout=0):
super(PositionwiseFeedForwardNew, self).__init__()
if d_inner_hid is None:
d_inner_hid = d_hid
self.w_1 = nn.Conv1d(d_hid, d_inner_hid, 1)
self.w_2 = nn.Conv1d(d_inner_hid, d_hid, 1)
self.dropout = nn.Dropout(dropout)
self.relu = nn.ReLU()
def forward(self, input_0):
primals_2 = self.w_1.weight
primals_3 = self.w_1.bias
primals_4 = self.w_2.weight
primals_5 = self.w_2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
HeGuanyuan/ABSA-PyTorch
|
PositionwiseFeedForward
| false
| 2,345
|
[
"MIT"
] | 0
|
8244aeb39007a2714ccbfd54629ddbbb013ea87e
|
https://github.com/HeGuanyuan/ABSA-PyTorch/tree/8244aeb39007a2714ccbfd54629ddbbb013ea87e
|
Conv2dZeros
|
import torch
import torch.nn as nn
class _ActNorm(nn.Module):
"""
Activation Normalization
Initialize the bias and scale with a given minibatch,
so that the output per-channel have zero mean and unit variance for that.
After initialization, `bias` and `logs` will be trained as parameters.
"""
def __init__(self, num_features, scale=1.0):
super().__init__()
size = [1, num_features, 1, 1]
self.register_parameter('bias', nn.Parameter(torch.zeros(*size)))
self.register_parameter('logs', nn.Parameter(torch.zeros(*size)))
self.num_features = num_features
self.scale = float(scale)
self.inited = False
def _check_input_dim(self, input):
return NotImplemented
def initialize_parameters(self, input):
self._check_input_dim(input)
if not self.training:
return
assert input.device == self.bias.device
with torch.no_grad():
bias = thops.mean(input.clone(), dim=[0, 2, 3], keepdim=True
) * -1.0
vars = thops.mean((input.clone() + bias) ** 2, dim=[0, 2, 3],
keepdim=True)
logs = torch.log(self.scale / (torch.sqrt(vars) + 1e-06))
self.bias.data.copy_(bias.data)
self.logs.data.copy_(logs.data)
self.inited = True
def _center(self, input, reverse=False):
if not reverse:
return input + self.bias
else:
return input - self.bias
def _scale(self, input, logdet=None, reverse=False):
logs = self.logs
if not reverse:
input = input * torch.exp(logs)
else:
input = input * torch.exp(-logs)
if logdet is not None:
"""
logs is log_std of `mean of channels`
so we need to multiply pixels
"""
dlogdet = thops.sum(logs) * thops.pixels(input)
if reverse:
dlogdet *= -1
logdet = logdet + dlogdet
return input, logdet
def forward(self, input, logdet=None, reverse=False):
if not self.inited:
self.initialize_parameters(input)
self._check_input_dim(input)
if not reverse:
input = self._center(input, reverse)
input, logdet = self._scale(input, logdet, reverse)
else:
input, logdet = self._scale(input, logdet, reverse)
input = self._center(input, reverse)
return input, logdet
class ActNorm2d(_ActNorm):
def __init__(self, num_features, scale=1.0):
super().__init__(num_features, scale)
def _check_input_dim(self, input):
assert len(input.size()) == 4
assert input.size(1
) == self.num_features, '[ActNorm]: input should be in shape as `BCHW`, channels should be {} rather than {}'.format(
self.num_features, input.size())
class Conv2d(nn.Conv2d):
pad_dict = {'same': lambda kernel, stride: [(((k - 1) * s + 1) // 2) for
k, s in zip(kernel, stride)], 'valid': lambda kernel, stride: [(0) for
_ in kernel]}
@staticmethod
def get_padding(padding, kernel_size, stride):
if isinstance(padding, str):
if isinstance(kernel_size, int):
kernel_size = [kernel_size, kernel_size]
if isinstance(stride, int):
stride = [stride, stride]
padding = padding.lower()
try:
padding = Conv2d.pad_dict[padding](kernel_size, stride)
except KeyError:
raise ValueError('{} is not supported'.format(padding))
return padding
def __init__(self, in_channels, out_channels, kernel_size=[3, 3],
stride=[1, 1], padding='same', do_actnorm=True, weight_std=0.05):
padding = Conv2d.get_padding(padding, kernel_size, stride)
super().__init__(in_channels, out_channels, kernel_size, stride,
padding, bias=not do_actnorm)
self.weight.data.normal_(mean=0.0, std=weight_std)
if not do_actnorm:
self.bias.data.zero_()
else:
self.actnorm = ActNorm2d(out_channels)
self.do_actnorm = do_actnorm
def forward(self, input):
x = super().forward(input)
if self.do_actnorm:
x, _ = self.actnorm(x)
return x
class Conv2dZeros(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size=[3, 3],
stride=[1, 1], padding='same', logscale_factor=3):
padding = Conv2d.get_padding(padding, kernel_size, stride)
super().__init__(in_channels, out_channels, kernel_size, stride,
padding)
self.logscale_factor = logscale_factor
self.register_parameter('logs', nn.Parameter(torch.zeros(
out_channels, 1, 1)))
self.weight.data.zero_()
self.bias.data.zero_()
def forward(self, input):
output = super().forward(input)
return output * torch.exp(self.logs * self.logscale_factor)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_exp_mul_0(in_out_ptr0, in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = 3.0
tmp5 = tmp3 * tmp4
tmp6 = tl_math.exp(tmp5)
tmp7 = tmp2 * tmp6
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp7, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 1, 1), (1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_exp_mul_0[grid(256)](buf1, primals_2,
primals_4, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
return buf2, primals_1, primals_3, primals_4, buf1
class _ActNorm(nn.Module):
"""
Activation Normalization
Initialize the bias and scale with a given minibatch,
so that the output per-channel have zero mean and unit variance for that.
After initialization, `bias` and `logs` will be trained as parameters.
"""
def __init__(self, num_features, scale=1.0):
super().__init__()
size = [1, num_features, 1, 1]
self.register_parameter('bias', nn.Parameter(torch.zeros(*size)))
self.register_parameter('logs', nn.Parameter(torch.zeros(*size)))
self.num_features = num_features
self.scale = float(scale)
self.inited = False
def _check_input_dim(self, input):
return NotImplemented
def initialize_parameters(self, input):
self._check_input_dim(input)
if not self.training:
return
assert input.device == self.bias.device
with torch.no_grad():
bias = thops.mean(input.clone(), dim=[0, 2, 3], keepdim=True
) * -1.0
vars = thops.mean((input.clone() + bias) ** 2, dim=[0, 2, 3],
keepdim=True)
logs = torch.log(self.scale / (torch.sqrt(vars) + 1e-06))
self.bias.data.copy_(bias.data)
self.logs.data.copy_(logs.data)
self.inited = True
def _center(self, input, reverse=False):
if not reverse:
return input + self.bias
else:
return input - self.bias
def _scale(self, input, logdet=None, reverse=False):
logs = self.logs
if not reverse:
input = input * torch.exp(logs)
else:
input = input * torch.exp(-logs)
if logdet is not None:
"""
logs is log_std of `mean of channels`
so we need to multiply pixels
"""
dlogdet = thops.sum(logs) * thops.pixels(input)
if reverse:
dlogdet *= -1
logdet = logdet + dlogdet
return input, logdet
def forward(self, input, logdet=None, reverse=False):
if not self.inited:
self.initialize_parameters(input)
self._check_input_dim(input)
if not reverse:
input = self._center(input, reverse)
input, logdet = self._scale(input, logdet, reverse)
else:
input, logdet = self._scale(input, logdet, reverse)
input = self._center(input, reverse)
return input, logdet
class ActNorm2d(_ActNorm):
def __init__(self, num_features, scale=1.0):
super().__init__(num_features, scale)
def _check_input_dim(self, input):
assert len(input.size()) == 4
assert input.size(1
) == self.num_features, '[ActNorm]: input should be in shape as `BCHW`, channels should be {} rather than {}'.format(
self.num_features, input.size())
class Conv2d(nn.Conv2d):
pad_dict = {'same': lambda kernel, stride: [(((k - 1) * s + 1) // 2) for
k, s in zip(kernel, stride)], 'valid': lambda kernel, stride: [(0) for
_ in kernel]}
@staticmethod
def get_padding(padding, kernel_size, stride):
if isinstance(padding, str):
if isinstance(kernel_size, int):
kernel_size = [kernel_size, kernel_size]
if isinstance(stride, int):
stride = [stride, stride]
padding = padding.lower()
try:
padding = Conv2d.pad_dict[padding](kernel_size, stride)
except KeyError:
raise ValueError('{} is not supported'.format(padding))
return padding
def __init__(self, in_channels, out_channels, kernel_size=[3, 3],
stride=[1, 1], padding='same', do_actnorm=True, weight_std=0.05):
padding = Conv2d.get_padding(padding, kernel_size, stride)
super().__init__(in_channels, out_channels, kernel_size, stride,
padding, bias=not do_actnorm)
self.weight.data.normal_(mean=0.0, std=weight_std)
if not do_actnorm:
self.bias.data.zero_()
else:
self.actnorm = ActNorm2d(out_channels)
self.do_actnorm = do_actnorm
def forward(self, input):
x = super().forward(input)
if self.do_actnorm:
x, _ = self.actnorm(x)
return x
class Conv2dZerosNew(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size=[3, 3],
stride=[1, 1], padding='same', logscale_factor=3):
padding = Conv2d.get_padding(padding, kernel_size, stride)
super().__init__(in_channels, out_channels, kernel_size, stride,
padding)
self.logscale_factor = logscale_factor
self.register_parameter('logs', nn.Parameter(torch.zeros(
out_channels, 1, 1)))
self.weight.data.zero_()
self.bias.data.zero_()
def forward(self, input_0):
primals_1 = self.weight
primals_2 = self.bias
primals_4 = self.logs
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
GauriJagatap/glow-pytorch
|
Conv2dZeros
| false
| 2,346
|
[
"MIT"
] | 0
|
e379f524b7cc0b57a9bc2849f4115f97bda5a1de
|
https://github.com/GauriJagatap/glow-pytorch/tree/e379f524b7cc0b57a9bc2849f4115f97bda5a1de
|
PredictionLayer
|
import torch
import torch.nn as nn
import torch.utils.data
class PredictionLayer(nn.Module):
def __init__(self, task='binary', use_bias=True, **kwargs):
if task not in ['binary', 'multiclass', 'regression']:
raise ValueError('task must be binary, multiclass or regression')
super(PredictionLayer, self).__init__()
self.use_bias = use_bias
self.task = task
if self.use_bias:
self.bias = nn.Parameter(torch.zeros((1,)))
def forward(self, X):
output = X
if self.use_bias:
output += self.bias
if self.task == 'binary':
output = torch.sigmoid(output)
return output
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr1 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.sigmoid(tmp3)
tl.store(out_ptr0 + x0, tmp3, xmask)
tl.store(out_ptr1 + x0, tmp4, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_sigmoid_0[grid(256)](primals_1, primals_2,
buf0, buf1, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_2
return buf0, buf1, buf1
class PredictionLayerNew(nn.Module):
def __init__(self, task='binary', use_bias=True, **kwargs):
if task not in ['binary', 'multiclass', 'regression']:
raise ValueError('task must be binary, multiclass or regression')
super(PredictionLayerNew, self).__init__()
self.use_bias = use_bias
self.task = task
if self.use_bias:
self.bias = nn.Parameter(torch.zeros((1,)))
def forward(self, input_0):
primals_2 = self.bias
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
Holldean/pytorch-models
|
PredictionLayer
| false
| 2,347
|
[
"MIT"
] | 0
|
9509d0d462b1a98164b266d49ada199071a855ac
|
https://github.com/Holldean/pytorch-models/tree/9509d0d462b1a98164b266d49ada199071a855ac
|
Pool
|
from torch.nn import Module
import torch
from torch import nn
class Pool(Module):
"""多尺度特征融合,借鉴Inception网络结构"""
def __init__(self):
super(Pool, self).__init__()
self.max1 = nn.MaxPool2d(5, 1, 2)
self.max2 = nn.MaxPool2d(9, 1, 4)
self.max3 = nn.MaxPool2d(13, 1, 6)
def forward(self, input_):
return torch.cat((self.max1(input_), self.max2(input_), self.max3(
input_), input_), dim=1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch.nn import Module
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_cat_max_pool2d_with_indices_0(in_ptr0, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 4
x0 = xindex % 4
x7 = xindex
x3 = xindex // 64
x4 = xindex % 64
tmp116 = tl.load(in_ptr0 + x7, xmask)
tmp0 = -2 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -2 + x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (-10 + x7), tmp10 & xmask, other=float('-inf'))
tmp12 = -1 + x0
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp13 & tmp14
tmp16 = tmp5 & tmp15
tmp17 = tl.load(in_ptr0 + (-9 + x7), tmp16 & xmask, other=float('-inf'))
tmp18 = triton_helpers.maximum(tmp17, tmp11)
tmp19 = x0
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp20 & tmp21
tmp23 = tmp5 & tmp22
tmp24 = tl.load(in_ptr0 + (-8 + x7), tmp23 & xmask, other=float('-inf'))
tmp25 = triton_helpers.maximum(tmp24, tmp18)
tmp26 = 1 + x0
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp5 & tmp29
tmp31 = tl.load(in_ptr0 + (-7 + x7), tmp30 & xmask, other=float('-inf'))
tmp32 = triton_helpers.maximum(tmp31, tmp25)
tmp33 = 2 + x0
tmp34 = tmp33 >= tmp1
tmp35 = tmp33 < tmp3
tmp36 = tmp34 & tmp35
tmp37 = tmp5 & tmp36
tmp38 = tl.load(in_ptr0 + (-6 + x7), tmp37 & xmask, other=float('-inf'))
tmp39 = triton_helpers.maximum(tmp38, tmp32)
tmp40 = -1 + x1
tmp41 = tmp40 >= tmp1
tmp42 = tmp40 < tmp3
tmp43 = tmp41 & tmp42
tmp44 = tmp43 & tmp9
tmp45 = tl.load(in_ptr0 + (-6 + x7), tmp44 & xmask, other=float('-inf'))
tmp46 = triton_helpers.maximum(tmp45, tmp39)
tmp47 = tmp43 & tmp15
tmp48 = tl.load(in_ptr0 + (-5 + x7), tmp47 & xmask, other=float('-inf'))
tmp49 = triton_helpers.maximum(tmp48, tmp46)
tmp50 = tmp43 & tmp22
tmp51 = tl.load(in_ptr0 + (-4 + x7), tmp50 & xmask, other=float('-inf'))
tmp52 = triton_helpers.maximum(tmp51, tmp49)
tmp53 = tmp43 & tmp29
tmp54 = tl.load(in_ptr0 + (-3 + x7), tmp53 & xmask, other=float('-inf'))
tmp55 = triton_helpers.maximum(tmp54, tmp52)
tmp56 = tmp43 & tmp36
tmp57 = tl.load(in_ptr0 + (-2 + x7), tmp56 & xmask, other=float('-inf'))
tmp58 = triton_helpers.maximum(tmp57, tmp55)
tmp59 = x1
tmp60 = tmp59 >= tmp1
tmp61 = tmp59 < tmp3
tmp62 = tmp60 & tmp61
tmp63 = tmp62 & tmp9
tmp64 = tl.load(in_ptr0 + (-2 + x7), tmp63 & xmask, other=float('-inf'))
tmp65 = triton_helpers.maximum(tmp64, tmp58)
tmp66 = tmp62 & tmp15
tmp67 = tl.load(in_ptr0 + (-1 + x7), tmp66 & xmask, other=float('-inf'))
tmp68 = triton_helpers.maximum(tmp67, tmp65)
tmp69 = tmp62 & tmp22
tmp70 = tl.load(in_ptr0 + x7, tmp69 & xmask, other=float('-inf'))
tmp71 = triton_helpers.maximum(tmp70, tmp68)
tmp72 = tmp62 & tmp29
tmp73 = tl.load(in_ptr0 + (1 + x7), tmp72 & xmask, other=float('-inf'))
tmp74 = triton_helpers.maximum(tmp73, tmp71)
tmp75 = tmp62 & tmp36
tmp76 = tl.load(in_ptr0 + (2 + x7), tmp75 & xmask, other=float('-inf'))
tmp77 = triton_helpers.maximum(tmp76, tmp74)
tmp78 = 1 + x1
tmp79 = tmp78 >= tmp1
tmp80 = tmp78 < tmp3
tmp81 = tmp79 & tmp80
tmp82 = tmp81 & tmp9
tmp83 = tl.load(in_ptr0 + (2 + x7), tmp82 & xmask, other=float('-inf'))
tmp84 = triton_helpers.maximum(tmp83, tmp77)
tmp85 = tmp81 & tmp15
tmp86 = tl.load(in_ptr0 + (3 + x7), tmp85 & xmask, other=float('-inf'))
tmp87 = triton_helpers.maximum(tmp86, tmp84)
tmp88 = tmp81 & tmp22
tmp89 = tl.load(in_ptr0 + (4 + x7), tmp88 & xmask, other=float('-inf'))
tmp90 = triton_helpers.maximum(tmp89, tmp87)
tmp91 = tmp81 & tmp29
tmp92 = tl.load(in_ptr0 + (5 + x7), tmp91 & xmask, other=float('-inf'))
tmp93 = triton_helpers.maximum(tmp92, tmp90)
tmp94 = tmp81 & tmp36
tmp95 = tl.load(in_ptr0 + (6 + x7), tmp94 & xmask, other=float('-inf'))
tmp96 = triton_helpers.maximum(tmp95, tmp93)
tmp97 = 2 + x1
tmp98 = tmp97 >= tmp1
tmp99 = tmp97 < tmp3
tmp100 = tmp98 & tmp99
tmp101 = tmp100 & tmp9
tmp102 = tl.load(in_ptr0 + (6 + x7), tmp101 & xmask, other=float('-inf'))
tmp103 = triton_helpers.maximum(tmp102, tmp96)
tmp104 = tmp100 & tmp15
tmp105 = tl.load(in_ptr0 + (7 + x7), tmp104 & xmask, other=float('-inf'))
tmp106 = triton_helpers.maximum(tmp105, tmp103)
tmp107 = tmp100 & tmp22
tmp108 = tl.load(in_ptr0 + (8 + x7), tmp107 & xmask, other=float('-inf'))
tmp109 = triton_helpers.maximum(tmp108, tmp106)
tmp110 = tmp100 & tmp29
tmp111 = tl.load(in_ptr0 + (9 + x7), tmp110 & xmask, other=float('-inf'))
tmp112 = triton_helpers.maximum(tmp111, tmp109)
tmp113 = tmp100 & tmp36
tmp114 = tl.load(in_ptr0 + (10 + x7), tmp113 & xmask, other=float('-inf'))
tmp115 = triton_helpers.maximum(tmp114, tmp112)
tl.store(out_ptr0 + (x4 + 256 * x3), tmp115, xmask)
tl.store(out_ptr1 + (x4 + 256 * x3), tmp116, xmask)
@triton.jit
def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 64
x1 = xindex // 64
tmp0 = tl.load(in_ptr0 + x2, xmask)
tl.store(out_ptr0 + (x0 + 256 * x1), tmp0, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf10 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.
float32)
buf0 = reinterpret_tensor(buf10, (4, 4, 4, 4), (256, 16, 4, 1), 0)
buf9 = reinterpret_tensor(buf10, (4, 4, 4, 4), (256, 16, 4, 1), 192)
get_raw_stream(0)
triton_poi_fused_cat_max_pool2d_with_indices_0[grid(256)](arg0_1,
buf0, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1)
buf1 = torch.ops.aten.max_pool2d_with_indices.default(arg0_1, [9, 9
], [1, 1], [4, 4])
buf2 = buf1[0]
del buf1
buf4 = torch.ops.aten.max_pool2d_with_indices.default(arg0_1, [13,
13], [1, 1], [6, 6])
del arg0_1
buf5 = buf4[0]
del buf4
buf7 = reinterpret_tensor(buf10, (4, 4, 4, 4), (256, 16, 4, 1), 64)
triton_poi_fused_cat_1[grid(256)](buf2, buf7, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf2
buf8 = reinterpret_tensor(buf10, (4, 4, 4, 4), (256, 16, 4, 1), 128)
triton_poi_fused_cat_1[grid(256)](buf5, buf8, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf5
return buf10,
class PoolNew(Module):
"""多尺度特征融合,借鉴Inception网络结构"""
def __init__(self):
super(PoolNew, self).__init__()
self.max1 = nn.MaxPool2d(5, 1, 2)
self.max2 = nn.MaxPool2d(9, 1, 4)
self.max3 = nn.MaxPool2d(13, 1, 6)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
HibikiJie/MONet
|
Pool
| false
| 2,348
|
[
"Apache-2.0"
] | 0
|
931400df28cb62aab90662abe00acd1d3688073d
|
https://github.com/HibikiJie/MONet/tree/931400df28cb62aab90662abe00acd1d3688073d
|
ConvRelu
|
import torch
import torch.utils.data
import torch.nn as nn
import torch.backends.cudnn
class ConvRelu(nn.Module):
"""3x3 convolution followed by ReLU activation building block."""
def __init__(self, num_in, num_out):
super().__init__()
self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1,
bias=False)
def forward(self, x):
return nn.functional.relu(self.block(x), inplace=True)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_in': 4, 'num_out': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.utils.data
import torch.nn as nn
import torch.backends.cudnn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp3 = 0.0
tmp4 = tmp2 <= tmp3
tl.store(in_out_ptr0 + x0, tmp2, xmask)
tl.store(out_ptr0 + x0, tmp4, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_2, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1, buf2,
256, XBLOCK=256, num_warps=4, num_stages=1)
return buf1, primals_1, primals_2, buf2
class ConvReluNew(nn.Module):
"""3x3 convolution followed by ReLU activation building block."""
def __init__(self, num_in, num_out):
super().__init__()
self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1,
bias=False)
def forward(self, input_0):
primals_1 = self.block.weight
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
HugoPopo/robosat.pink
|
ConvRelu
| false
| 2,349
|
[
"MIT"
] | 0
|
daa6a0cd6dff68103b9bcc78a8c9a15d8912c42d
|
https://github.com/HugoPopo/robosat.pink/tree/daa6a0cd6dff68103b9bcc78a8c9a15d8912c42d
|
FM
|
import torch
import torch.nn as nn
import torch.utils.data
class FM(nn.Module):
def __init__(self):
super(FM, self).__init__()
def forward(self, X):
square_of_sum = torch.pow(torch.sum(X, dim=1, keepdim=True), 2)
sum_of_square = torch.sum(X * X, dim=1, keepdim=True)
cross_term = square_of_sum - sum_of_square
cross_term = 0.5 * torch.sum(cross_term, dim=2, keepdim=False)
return cross_term
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mul_pow_sub_sum_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (32 + x0 + 64 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (48 + x0 + 64 * x1), xmask)
tmp16 = tl.load(in_ptr0 + (4 + x0 + 64 * x1), xmask)
tmp17 = tl.load(in_ptr0 + (20 + x0 + 64 * x1), xmask)
tmp19 = tl.load(in_ptr0 + (36 + x0 + 64 * x1), xmask)
tmp21 = tl.load(in_ptr0 + (52 + x0 + 64 * x1), xmask)
tmp33 = tl.load(in_ptr0 + (8 + x0 + 64 * x1), xmask)
tmp34 = tl.load(in_ptr0 + (24 + x0 + 64 * x1), xmask)
tmp36 = tl.load(in_ptr0 + (40 + x0 + 64 * x1), xmask)
tmp38 = tl.load(in_ptr0 + (56 + x0 + 64 * x1), xmask)
tmp50 = tl.load(in_ptr0 + (12 + x0 + 64 * x1), xmask)
tmp51 = tl.load(in_ptr0 + (28 + x0 + 64 * x1), xmask)
tmp53 = tl.load(in_ptr0 + (44 + x0 + 64 * x1), xmask)
tmp55 = tl.load(in_ptr0 + (60 + x0 + 64 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = tmp6 * tmp6
tmp8 = tmp0 * tmp0
tmp9 = tmp1 * tmp1
tmp10 = tmp8 + tmp9
tmp11 = tmp3 * tmp3
tmp12 = tmp10 + tmp11
tmp13 = tmp5 * tmp5
tmp14 = tmp12 + tmp13
tmp15 = tmp7 - tmp14
tmp18 = tmp16 + tmp17
tmp20 = tmp18 + tmp19
tmp22 = tmp20 + tmp21
tmp23 = tmp22 * tmp22
tmp24 = tmp16 * tmp16
tmp25 = tmp17 * tmp17
tmp26 = tmp24 + tmp25
tmp27 = tmp19 * tmp19
tmp28 = tmp26 + tmp27
tmp29 = tmp21 * tmp21
tmp30 = tmp28 + tmp29
tmp31 = tmp23 - tmp30
tmp32 = tmp15 + tmp31
tmp35 = tmp33 + tmp34
tmp37 = tmp35 + tmp36
tmp39 = tmp37 + tmp38
tmp40 = tmp39 * tmp39
tmp41 = tmp33 * tmp33
tmp42 = tmp34 * tmp34
tmp43 = tmp41 + tmp42
tmp44 = tmp36 * tmp36
tmp45 = tmp43 + tmp44
tmp46 = tmp38 * tmp38
tmp47 = tmp45 + tmp46
tmp48 = tmp40 - tmp47
tmp49 = tmp32 + tmp48
tmp52 = tmp50 + tmp51
tmp54 = tmp52 + tmp53
tmp56 = tmp54 + tmp55
tmp57 = tmp56 * tmp56
tmp58 = tmp50 * tmp50
tmp59 = tmp51 * tmp51
tmp60 = tmp58 + tmp59
tmp61 = tmp53 * tmp53
tmp62 = tmp60 + tmp61
tmp63 = tmp55 * tmp55
tmp64 = tmp62 + tmp63
tmp65 = tmp57 - tmp64
tmp66 = tmp49 + tmp65
tmp67 = 0.5
tmp68 = tmp66 * tmp67
tl.store(in_out_ptr0 + x2, tmp68, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4), (4, 16, 1), torch.float32)
buf1 = reinterpret_tensor(buf0, (4, 1, 4), (4, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_mul_pow_sub_sum_0[grid(16)](buf1, arg0_1, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del arg0_1
return buf1,
class FMNew(nn.Module):
def __init__(self):
super(FMNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Holldean/pytorch-models
|
FM
| false
| 2,350
|
[
"MIT"
] | 0
|
9509d0d462b1a98164b266d49ada199071a855ac
|
https://github.com/Holldean/pytorch-models/tree/9509d0d462b1a98164b266d49ada199071a855ac
|
ReOrgLayer
|
import torch
import torch.nn as nn
import torch.utils.data
import torch.utils.data.distributed
import torch._utils
class ReOrgLayer(nn.Module):
def __init__(self, stride=2):
super(ReOrgLayer, self).__init__()
self.stride = stride
def forward(self, x):
assert x.data.dim() == 4
B, C, H, W = x.data.shape
hs = self.stride
ws = self.stride
assert H % hs == 0, 'The stride ' + str(self.stride
) + ' is not a proper divisor of height ' + str(H)
assert W % ws == 0, 'The stride ' + str(self.stride
) + ' is not a proper divisor of height ' + str(W)
x = x.view(B, C, H // hs, hs, W // ws, ws).transpose(-2, -3
).contiguous()
x = x.view(B, C, H // hs * W // ws, hs, ws)
x = x.view(B, C, H // hs * W // ws, hs * ws).transpose(-1, -2
).contiguous()
x = x.view(B, C, ws * hs, H // ws, W // ws).transpose(1, 2).contiguous(
)
x = x.view(B, C * ws * hs, H // ws, W // ws)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
import torch.utils.data.distributed
import torch._utils
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex % 2
x3 = xindex // 2
y0 = yindex % 4
y1 = yindex // 4
x5 = xindex
y4 = yindex
tmp0 = tl.load(in_ptr0 + (2 * x2 + 4 * (y0 // 2) + 8 * x3 + 64 * y1 +
y0 % 2), xmask & ymask)
tl.store(out_ptr0 + (x5 + 16 * y4), tmp0, xmask & ymask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 2, 2), (64, 16, 4, 2, 1), torch
.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 16)](arg0_1, buf0, 16, 16, XBLOCK
=16, YBLOCK=16, num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 16, 2, 2), (64, 4, 2, 1), 0),
class ReOrgLayerNew(nn.Module):
def __init__(self, stride=2):
super(ReOrgLayerNew, self).__init__()
self.stride = stride
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Humoon/motion_reconstruction
|
ReOrgLayer
| false
| 2,351
|
[
"BSD-3-Clause"
] | 0
|
9f0d0af3aeafa97455ec19dc4988f1577005c294
|
https://github.com/Humoon/motion_reconstruction/tree/9f0d0af3aeafa97455ec19dc4988f1577005c294
|
Attention
|
import math
import torch
import torch.nn.functional as F
import torch.nn as nn
class Attention(nn.Module):
def __init__(self, embed_dim, hidden_dim=None, out_dim=None, n_head=1,
score_function='dot_product', dropout=0):
""" Attention Mechanism
:param embed_dim:
:param hidden_dim:
:param out_dim:
:param n_head: num of head (Multi-Head Attention)
:param score_function: scaled_dot_product / mlp (concat) / bi_linear (general dot)
:return (?, q_len, out_dim,)
"""
super(Attention, self).__init__()
if hidden_dim is None:
hidden_dim = embed_dim // n_head
if out_dim is None:
out_dim = embed_dim
self.embed_dim = embed_dim
self.hidden_dim = hidden_dim
self.n_head = n_head
self.score_function = score_function
self.w_k = nn.Linear(embed_dim, n_head * hidden_dim)
self.w_q = nn.Linear(embed_dim, n_head * hidden_dim)
self.proj = nn.Linear(n_head * hidden_dim, out_dim)
self.dropout = nn.Dropout(dropout)
if score_function == 'mlp':
self.weight = nn.Parameter(torch.Tensor(hidden_dim * 2))
elif self.score_function == 'bi_linear':
self.weight = nn.Parameter(torch.Tensor(hidden_dim, hidden_dim))
else:
self.register_parameter('weight', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1.0 / math.sqrt(self.hidden_dim)
if self.weight is not None:
self.weight.data.uniform_(-stdv, stdv)
def forward(self, k, q):
if len(q.shape) == 2:
q = torch.unsqueeze(q, dim=1)
if len(k.shape) == 2:
k = torch.unsqueeze(k, dim=1)
mb_size = k.shape[0]
k_len = k.shape[1]
q_len = q.shape[1]
kx = self.w_k(k).view(mb_size, k_len, self.n_head, self.hidden_dim)
kx = kx.permute(2, 0, 1, 3).contiguous().view(-1, k_len, self.
hidden_dim)
qx = self.w_q(q).view(mb_size, q_len, self.n_head, self.hidden_dim)
qx = qx.permute(2, 0, 1, 3).contiguous().view(-1, q_len, self.
hidden_dim)
if self.score_function == 'dot_product':
kt = kx.permute(0, 2, 1)
score = torch.bmm(qx, kt)
elif self.score_function == 'scaled_dot_product':
kt = kx.permute(0, 2, 1)
qkt = torch.bmm(qx, kt)
score = torch.div(qkt, math.sqrt(self.hidden_dim))
elif self.score_function == 'mlp':
kxx = torch.unsqueeze(kx, dim=1).expand(-1, q_len, -1, -1)
qxx = torch.unsqueeze(qx, dim=2).expand(-1, -1, k_len, -1)
kq = torch.cat((kxx, qxx), dim=-1)
score = F.tanh(torch.matmul(kq, self.weight))
elif self.score_function == 'bi_linear':
qw = torch.matmul(qx, self.weight)
kt = kx.permute(0, 2, 1)
score = torch.bmm(qw, kt)
else:
raise RuntimeError('invalid score_function')
score = F.softmax(score, dim=-1)
output = torch.bmm(score, kx)
output = torch.cat(torch.split(output, mb_size, dim=0), dim=-1)
output = self.proj(output)
output = self.dropout(output)
return output, score
def get_inputs():
return [torch.rand([4, 4, 1, 4]), torch.rand([4, 4, 1, 4])]
def get_init_inputs():
return [[], {'embed_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 1, 4), (16, 4, 4, 1))
assert_size_stride(primals_2, (4, 4, 1, 4), (16, 4, 4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_4, reinterpret_tensor(primals_2, (16,
4), (4, 1), 0), reinterpret_tensor(primals_3, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_3
del primals_4
buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_6, reinterpret_tensor(primals_1, (16,
4), (4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf1)
del primals_5
del primals_6
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (4, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0), out=buf2)
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(64)](buf2, buf3, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf4 = buf2
del buf2
triton_poi_fused__softmax_1[grid(64)](buf3, buf4, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf5 = buf3
del buf3
extern_kernels.bmm(buf4, reinterpret_tensor(buf0, (4, 4, 4), (16, 4,
1), 0), out=buf5)
buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_8, reinterpret_tensor(buf5, (16, 4), (
4, 1), 0), reinterpret_tensor(primals_7, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf6)
del primals_8
return reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0
), buf4, reinterpret_tensor(primals_2, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0
), buf4, reinterpret_tensor(buf5, (16, 4), (4, 1), 0
), primals_7, reinterpret_tensor(buf1, (4, 4, 4), (16, 1, 4), 0)
class AttentionNew(nn.Module):
def __init__(self, embed_dim, hidden_dim=None, out_dim=None, n_head=1,
score_function='dot_product', dropout=0):
""" Attention Mechanism
:param embed_dim:
:param hidden_dim:
:param out_dim:
:param n_head: num of head (Multi-Head Attention)
:param score_function: scaled_dot_product / mlp (concat) / bi_linear (general dot)
:return (?, q_len, out_dim,)
"""
super(AttentionNew, self).__init__()
if hidden_dim is None:
hidden_dim = embed_dim // n_head
if out_dim is None:
out_dim = embed_dim
self.embed_dim = embed_dim
self.hidden_dim = hidden_dim
self.n_head = n_head
self.score_function = score_function
self.w_k = nn.Linear(embed_dim, n_head * hidden_dim)
self.w_q = nn.Linear(embed_dim, n_head * hidden_dim)
self.proj = nn.Linear(n_head * hidden_dim, out_dim)
self.dropout = nn.Dropout(dropout)
if score_function == 'mlp':
self.weight = nn.Parameter(torch.Tensor(hidden_dim * 2))
elif self.score_function == 'bi_linear':
self.weight = nn.Parameter(torch.Tensor(hidden_dim, hidden_dim))
else:
self.register_parameter('weight', None)
self.reset_parameters()
def reset_parameters(self):
stdv = 1.0 / math.sqrt(self.hidden_dim)
if self.weight is not None:
self.weight.data.uniform_(-stdv, stdv)
def forward(self, input_0, input_1):
primals_3 = self.w_k.weight
primals_4 = self.w_k.bias
primals_5 = self.w_q.weight
primals_6 = self.w_q.bias
primals_7 = self.proj.weight
primals_8 = self.proj.bias
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8])
return output[0], output[1]
|
HeGuanyuan/ABSA-PyTorch
|
Attention
| false
| 2,352
|
[
"MIT"
] | 0
|
8244aeb39007a2714ccbfd54629ddbbb013ea87e
|
https://github.com/HeGuanyuan/ABSA-PyTorch/tree/8244aeb39007a2714ccbfd54629ddbbb013ea87e
|
DecoderBlock
|
import torch
import torch.utils.data
import torch.nn as nn
import torch.backends.cudnn
class ConvRelu(nn.Module):
"""3x3 convolution followed by ReLU activation building block."""
def __init__(self, num_in, num_out):
super().__init__()
self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1,
bias=False)
def forward(self, x):
return nn.functional.relu(self.block(x), inplace=True)
class DecoderBlock(nn.Module):
"""Decoder building block upsampling resolution by a factor of two."""
def __init__(self, num_in, num_out):
super().__init__()
self.block = ConvRelu(num_in, num_out)
def forward(self, x):
return self.block(nn.functional.interpolate(x, scale_factor=2, mode
='nearest'))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_in': 4, 'num_out': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.utils.data
import torch.nn as nn
import torch.backends.cudnn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__unsafe_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 8 % 8
x0 = xindex % 8
x2 = xindex // 64
x4 = xindex
tmp0 = x1
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tmp5 = x0
tmp6 = tmp5.to(tl.float32)
tmp7 = tmp6 * tmp2
tmp8 = tmp7.to(tl.int32)
tmp9 = tl.load(in_ptr0 + (tmp8 + 4 * tmp4 + 16 * x2), xmask,
eviction_policy='evict_last')
tl.store(out_ptr0 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp3 = 0.0
tmp4 = tmp2 <= tmp3
tl.store(in_out_ptr0 + x0, tmp2, xmask)
tl.store(out_ptr0 + x0, tmp4, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__unsafe_index_0[grid(1024)](primals_1, buf0, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 8, 8), (256, 64, 8, 1))
buf2 = buf1
del buf1
buf3 = empty_strided_cuda((4, 4, 8, 8), (256, 64, 8, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(1024)](buf2, buf3,
1024, XBLOCK=128, num_warps=4, num_stages=1)
return buf2, primals_2, buf0, buf3
class ConvRelu(nn.Module):
"""3x3 convolution followed by ReLU activation building block."""
def __init__(self, num_in, num_out):
super().__init__()
self.block = nn.Conv2d(num_in, num_out, kernel_size=3, padding=1,
bias=False)
def forward(self, x):
return nn.functional.relu(self.block(x), inplace=True)
class DecoderBlockNew(nn.Module):
"""Decoder building block upsampling resolution by a factor of two."""
def __init__(self, num_in, num_out):
super().__init__()
self.block = ConvRelu(num_in, num_out)
def forward(self, input_0):
primals_2 = self.block.block.weight
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
HugoPopo/robosat.pink
|
DecoderBlock
| false
| 2,353
|
[
"MIT"
] | 0
|
daa6a0cd6dff68103b9bcc78a8c9a15d8912c42d
|
https://github.com/HugoPopo/robosat.pink/tree/daa6a0cd6dff68103b9bcc78a8c9a15d8912c42d
|
MaxPoolStride1
|
import torch
import torch.nn as nn
import torch.utils.data
import torch.utils.data.distributed
import torch.nn.functional as F
import torch._utils
class MaxPoolStride1(nn.Module):
def __init__(self, kernel_size):
super(MaxPoolStride1, self).__init__()
self.kernel_size = kernel_size
self.pad = kernel_size - 1
def forward(self, x):
padding = int(self.pad / 2)
padded_x = F.pad(x, (padding, padding, padding, padding), mode=
'constant', value=0)
pooled_x = nn.MaxPool2d(self.kernel_size, 1)(padded_x)
return pooled_x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'kernel_size': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.utils.data
import torch.utils.data.distributed
import torch._utils
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 144
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 3 % 3
x0 = xindex % 3
x2 = xindex // 9
x4 = xindex
tmp0 = -1 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = -1 + x0
tmp6 = tmp5 >= tmp1
tmp7 = tmp5 < tmp3
tmp8 = tmp2 & tmp4
tmp9 = tmp8 & tmp6
tmp10 = tmp9 & tmp7
tmp11 = tl.load(in_ptr0 + (-5 + x0 + 4 * x1 + 16 * x2), tmp10 & xmask,
other=0.0)
tmp12 = x0
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp8 & tmp13
tmp16 = tmp15 & tmp14
tmp17 = tl.load(in_ptr0 + (-4 + x0 + 4 * x1 + 16 * x2), tmp16 & xmask,
other=0.0)
tmp18 = triton_helpers.maximum(tmp17, tmp11)
tmp19 = 1 + x0
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp8 & tmp20
tmp23 = tmp22 & tmp21
tmp24 = tl.load(in_ptr0 + (-3 + x0 + 4 * x1 + 16 * x2), tmp23 & xmask,
other=0.0)
tmp25 = triton_helpers.maximum(tmp24, tmp18)
tmp26 = 2 + x0
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp8 & tmp27
tmp30 = tmp29 & tmp28
tmp31 = tl.load(in_ptr0 + (-2 + x0 + 4 * x1 + 16 * x2), tmp30 & xmask,
other=0.0)
tmp32 = triton_helpers.maximum(tmp31, tmp25)
tmp33 = x1
tmp34 = tmp33 >= tmp1
tmp35 = tmp33 < tmp3
tmp36 = tmp34 & tmp35
tmp37 = tmp36 & tmp6
tmp38 = tmp37 & tmp7
tmp39 = tl.load(in_ptr0 + (-1 + x0 + 4 * x1 + 16 * x2), tmp38 & xmask,
other=0.0)
tmp40 = triton_helpers.maximum(tmp39, tmp32)
tmp41 = tmp36 & tmp13
tmp42 = tmp41 & tmp14
tmp43 = tl.load(in_ptr0 + (x0 + 4 * x1 + 16 * x2), tmp42 & xmask, other=0.0
)
tmp44 = triton_helpers.maximum(tmp43, tmp40)
tmp45 = tmp36 & tmp20
tmp46 = tmp45 & tmp21
tmp47 = tl.load(in_ptr0 + (1 + x0 + 4 * x1 + 16 * x2), tmp46 & xmask,
other=0.0)
tmp48 = triton_helpers.maximum(tmp47, tmp44)
tmp49 = tmp36 & tmp27
tmp50 = tmp49 & tmp28
tmp51 = tl.load(in_ptr0 + (2 + x0 + 4 * x1 + 16 * x2), tmp50 & xmask,
other=0.0)
tmp52 = triton_helpers.maximum(tmp51, tmp48)
tmp53 = 1 + x1
tmp54 = tmp53 >= tmp1
tmp55 = tmp53 < tmp3
tmp56 = tmp54 & tmp55
tmp57 = tmp56 & tmp6
tmp58 = tmp57 & tmp7
tmp59 = tl.load(in_ptr0 + (3 + x0 + 4 * x1 + 16 * x2), tmp58 & xmask,
other=0.0)
tmp60 = triton_helpers.maximum(tmp59, tmp52)
tmp61 = tmp56 & tmp13
tmp62 = tmp61 & tmp14
tmp63 = tl.load(in_ptr0 + (4 + x0 + 4 * x1 + 16 * x2), tmp62 & xmask,
other=0.0)
tmp64 = triton_helpers.maximum(tmp63, tmp60)
tmp65 = tmp56 & tmp20
tmp66 = tmp65 & tmp21
tmp67 = tl.load(in_ptr0 + (5 + x0 + 4 * x1 + 16 * x2), tmp66 & xmask,
other=0.0)
tmp68 = triton_helpers.maximum(tmp67, tmp64)
tmp69 = tmp56 & tmp27
tmp70 = tmp69 & tmp28
tmp71 = tl.load(in_ptr0 + (6 + x0 + 4 * x1 + 16 * x2), tmp70 & xmask,
other=0.0)
tmp72 = triton_helpers.maximum(tmp71, tmp68)
tmp73 = 2 + x1
tmp74 = tmp73 >= tmp1
tmp75 = tmp73 < tmp3
tmp76 = tmp74 & tmp75
tmp77 = tmp76 & tmp6
tmp78 = tmp77 & tmp7
tmp79 = tl.load(in_ptr0 + (7 + x0 + 4 * x1 + 16 * x2), tmp78 & xmask,
other=0.0)
tmp80 = triton_helpers.maximum(tmp79, tmp72)
tmp81 = tmp76 & tmp13
tmp82 = tmp81 & tmp14
tmp83 = tl.load(in_ptr0 + (8 + x0 + 4 * x1 + 16 * x2), tmp82 & xmask,
other=0.0)
tmp84 = triton_helpers.maximum(tmp83, tmp80)
tmp85 = tmp76 & tmp20
tmp86 = tmp85 & tmp21
tmp87 = tl.load(in_ptr0 + (9 + x0 + 4 * x1 + 16 * x2), tmp86 & xmask,
other=0.0)
tmp88 = triton_helpers.maximum(tmp87, tmp84)
tmp89 = tmp76 & tmp27
tmp90 = tmp89 & tmp28
tmp91 = tl.load(in_ptr0 + (10 + x0 + 4 * x1 + 16 * x2), tmp90 & xmask,
other=0.0)
tmp92 = triton_helpers.maximum(tmp91, tmp88)
tl.store(out_ptr0 + x4, tmp92, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_max_pool2d_with_indices_0[grid(144)](arg0_1, buf0,
144, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class MaxPoolStride1New(nn.Module):
def __init__(self, kernel_size):
super(MaxPoolStride1New, self).__init__()
self.kernel_size = kernel_size
self.pad = kernel_size - 1
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Humoon/motion_reconstruction
|
MaxPoolStride1
| false
| 2,354
|
[
"BSD-3-Clause"
] | 0
|
9f0d0af3aeafa97455ec19dc4988f1577005c294
|
https://github.com/Humoon/motion_reconstruction/tree/9f0d0af3aeafa97455ec19dc4988f1577005c294
|
sSEmodule
|
import torch
import torch.nn as nn
class sSEmodule(nn.Module):
""" ChannelSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.conv2d = nn.Conv2d(in_channel, 1, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
skip_connection = x
x = self.conv2d(x)
x = self.sigmoid(x)
None
x = x * skip_connection
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channel': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tl.store(in_out_ptr0 + x0, tmp3, xmask)
@triton.jit
def triton_poi_fused_mul_sigmoid_1(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr1 + x3, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp3 = tmp1 * tmp2
tl.store(out_ptr0 + x3, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 1, 4, 4), (16, 16, 4, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(64)](buf1, primals_3, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_sigmoid_1[grid(256)](buf1, primals_1, buf2,
256, XBLOCK=256, num_warps=4, num_stages=1)
return buf2, primals_1, primals_2, buf1
class sSEmoduleNew(nn.Module):
""" ChannelSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.conv2d = nn.Conv2d(in_channel, 1, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.conv2d.weight
primals_3 = self.conv2d.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
HwangJohn/feature_representation
|
sSEmodule
| false
| 2,355
|
[
"MIT"
] | 0
|
27389caacc9c026b65f47ab0cbb4e6d0465e6a60
|
https://github.com/HwangJohn/feature_representation/tree/27389caacc9c026b65f47ab0cbb4e6d0465e6a60
|
cSEmodule
|
import torch
import torch.nn as nn
class cSEmodule(nn.Module):
""" SpatialSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.global_avg = nn.AdaptiveAvgPool2d(1)
self.flatten = nn.Flatten()
self.down_linear = nn.Linear(in_channel, in_channel // 2)
self.up_linear = nn.Linear(in_channel // 2, in_channel)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
def forward(self, x):
b, c, _h, _w = x.shape
skip_connection = x
x = self.global_avg(x)
x = self.flatten(x)
x = self.down_linear(x)
x = self.relu(x)
x = self.up_linear(x)
x = self.sigmoid(x)
x = x.reshape(b, c, 1, 1)
x = x * skip_connection
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channel': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 8
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_mul_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr1 + x2, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp3 = tmp1 * tmp2
tl.store(out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (2, 4), (4, 1))
assert_size_stride(primals_3, (2,), (1,))
assert_size_stride(primals_4, (4, 2), (2, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = empty_strided_cuda((4, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 2), (1, 4), 0), out=buf2)
del primals_2
buf3 = buf2
del buf2
triton_poi_fused_relu_1[grid(8)](buf3, primals_3, 8, XBLOCK=8,
num_warps=1, num_stages=1)
del primals_3
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, buf3, reinterpret_tensor(primals_4,
(2, 4), (1, 2), 0), alpha=1, beta=1, out=buf4)
del primals_5
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_2[grid(256)](buf4, primals_1, buf5, 256,
XBLOCK=256, num_warps=4, num_stages=1)
return buf5, primals_1, reinterpret_tensor(buf1, (4, 4), (4, 1), 0
), buf3, buf4, primals_4
class cSEmoduleNew(nn.Module):
""" SpatialSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.global_avg = nn.AdaptiveAvgPool2d(1)
self.flatten = nn.Flatten()
self.down_linear = nn.Linear(in_channel, in_channel // 2)
self.up_linear = nn.Linear(in_channel // 2, in_channel)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.down_linear.weight
primals_3 = self.down_linear.bias
primals_4 = self.up_linear.weight
primals_5 = self.up_linear.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
HwangJohn/feature_representation
|
cSEmodule
| false
| 2,356
|
[
"MIT"
] | 0
|
27389caacc9c026b65f47ab0cbb4e6d0465e6a60
|
https://github.com/HwangJohn/feature_representation/tree/27389caacc9c026b65f47ab0cbb4e6d0465e6a60
|
JointsMSELoss
|
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
class JointsMSELoss(nn.Module):
def __init__(self, use_target_weight):
super(JointsMSELoss, self).__init__()
self.criterion = nn.MSELoss(reduction='mean')
self.use_target_weight = use_target_weight
def forward(self, output, target, target_weight):
batch_size = output.size(0)
num_joints = output.size(1)
heatmaps_pred = output.reshape((batch_size, num_joints, -1)).split(1, 1
)
heatmaps_gt = target.reshape((batch_size, num_joints, -1)).split(1, 1)
loss = 0
for idx in range(num_joints):
heatmap_pred = heatmaps_pred[idx].squeeze()
heatmap_gt = heatmaps_gt[idx].squeeze()
if self.use_target_weight:
loss += 0.5 * self.criterion(heatmap_pred.mul(target_weight
[:, idx]), heatmap_gt.mul(target_weight[:, idx]))
else:
loss += 0.5 * self.criterion(heatmap_pred, heatmap_gt)
return loss / num_joints
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'use_target_weight': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_per_fused_add_div_mse_loss_mul_0(in_out_ptr0, in_ptr0, in_ptr1,
in_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + 4 * r0, None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr2 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp20 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last')
tmp21 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last')
tmp23 = tl.load(in_ptr2 + (2 + 4 * r0), None, eviction_policy='evict_last')
tmp30 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last')
tmp31 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last')
tmp33 = tl.load(in_ptr2 + (3 + 4 * r0), None, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp5 = tmp2 - tmp4
tmp6 = tmp5 * tmp5
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.sum(tmp7, 1)[:, None]
tmp12 = tmp10 * tmp11
tmp14 = tmp13 * tmp11
tmp15 = tmp12 - tmp14
tmp16 = tmp15 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.sum(tmp17, 1)[:, None]
tmp22 = tmp20 * tmp21
tmp24 = tmp23 * tmp21
tmp25 = tmp22 - tmp24
tmp26 = tmp25 * tmp25
tmp27 = tl.broadcast_to(tmp26, [XBLOCK, RBLOCK])
tmp29 = tl.sum(tmp27, 1)[:, None]
tmp32 = tmp30 * tmp31
tmp34 = tmp33 * tmp31
tmp35 = tmp32 - tmp34
tmp36 = tmp35 * tmp35
tmp37 = tl.broadcast_to(tmp36, [XBLOCK, RBLOCK])
tmp39 = tl.sum(tmp37, 1)[:, None]
tmp40 = 4.0
tmp41 = tmp9 / tmp40
tmp42 = 0.5
tmp43 = tmp41 * tmp42
tmp44 = 0.0
tmp45 = tmp43 + tmp44
tmp46 = tmp19 / tmp40
tmp47 = tmp46 * tmp42
tmp48 = tmp45 + tmp47
tmp49 = tmp29 / tmp40
tmp50 = tmp49 * tmp42
tmp51 = tmp48 + tmp50
tmp52 = tmp39 / tmp40
tmp53 = tmp52 * tmp42
tmp54 = tmp51 + tmp53
tmp55 = 0.25
tmp56 = tmp54 * tmp55
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp56, None)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4), (4, 1))
assert_size_stride(arg2_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((), (), torch.float32)
buf4 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_div_mse_loss_mul_0[grid(1)](buf4, arg0_1,
arg2_1, arg1_1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf4,
class JointsMSELossNew(nn.Module):
def __init__(self, use_target_weight):
super(JointsMSELossNew, self).__init__()
self.criterion = nn.MSELoss(reduction='mean')
self.use_target_weight = use_target_weight
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
HongJinSeong/COW_KEY_POINT_DETECTION
|
JointsMSELoss
| false
| 2,357
|
[
"MIT"
] | 0
|
ea62ed875e9b8533f1c09b56eb8aefba94b1b906
|
https://github.com/HongJinSeong/COW_KEY_POINT_DETECTION/tree/ea62ed875e9b8533f1c09b56eb8aefba94b1b906
|
scSEmodule
|
import torch
import torch.nn as nn
class cSEmodule(nn.Module):
""" SpatialSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.global_avg = nn.AdaptiveAvgPool2d(1)
self.flatten = nn.Flatten()
self.down_linear = nn.Linear(in_channel, in_channel // 2)
self.up_linear = nn.Linear(in_channel // 2, in_channel)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
def forward(self, x):
b, c, _h, _w = x.shape
skip_connection = x
x = self.global_avg(x)
x = self.flatten(x)
x = self.down_linear(x)
x = self.relu(x)
x = self.up_linear(x)
x = self.sigmoid(x)
x = x.reshape(b, c, 1, 1)
x = x * skip_connection
return x
class sSEmodule(nn.Module):
""" ChannelSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.conv2d = nn.Conv2d(in_channel, 1, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
skip_connection = x
x = self.conv2d(x)
x = self.sigmoid(x)
None
x = x * skip_connection
return x
class scSEmodule(nn.Module):
""" ConcurrentSpatialChannelSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.cSEmodule = cSEmodule(in_channel=in_channel)
self.sSEmodule = sSEmodule(in_channel=in_channel)
def forward(self, x):
cse_branch = self.cSEmodule(x)
sse_branch = self.sSEmodule(x)
return torch.max(cse_branch, sse_branch)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channel': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mean_0(in_out_ptr0, in_ptr0, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp6, xmask)
@triton.jit
def triton_poi_fused_relu_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 8
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tl.store(in_out_ptr0 + x0, tmp3, xmask)
@triton.jit
def triton_poi_fused_maximum_mul_sigmoid_3(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex // 16
x4 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr1 + x4, xmask)
tmp4 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp1 = tl.sigmoid(tmp0)
tmp3 = tmp1 * tmp2
tmp5 = tl.sigmoid(tmp4)
tmp6 = tmp5 * tmp2
tmp7 = triton_helpers.maximum(tmp3, tmp6)
tl.store(out_ptr0 + x4, tmp7, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (2, 4), (4, 1))
assert_size_stride(primals_3, (2,), (1,))
assert_size_stride(primals_4, (4, 2), (2, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_7, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, primals_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
buf2 = empty_strided_cuda((4, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (4, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 2), (1, 4), 0), out=buf2)
del primals_2
buf3 = buf2
del buf2
triton_poi_fused_relu_1[grid(8)](buf3, primals_3, 8, XBLOCK=8,
num_warps=1, num_stages=1)
del primals_3
buf4 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, buf3, reinterpret_tensor(primals_4,
(2, 4), (1, 2), 0), alpha=1, beta=1, out=buf4)
del primals_5
buf5 = extern_kernels.convolution(primals_1, primals_6, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf5, (4, 1, 4, 4), (16, 16, 4, 1))
buf6 = buf5
del buf5
triton_poi_fused_convolution_2[grid(64)](buf6, primals_7, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_7
buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_maximum_mul_sigmoid_3[grid(256)](buf4, primals_1,
buf6, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1)
return buf7, primals_1, primals_6, reinterpret_tensor(buf1, (4, 4), (4,
1), 0), buf3, buf4, buf6, primals_4
class cSEmodule(nn.Module):
""" SpatialSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.global_avg = nn.AdaptiveAvgPool2d(1)
self.flatten = nn.Flatten()
self.down_linear = nn.Linear(in_channel, in_channel // 2)
self.up_linear = nn.Linear(in_channel // 2, in_channel)
self.relu = nn.ReLU()
self.sigmoid = nn.Sigmoid()
def forward(self, x):
b, c, _h, _w = x.shape
skip_connection = x
x = self.global_avg(x)
x = self.flatten(x)
x = self.down_linear(x)
x = self.relu(x)
x = self.up_linear(x)
x = self.sigmoid(x)
x = x.reshape(b, c, 1, 1)
x = x * skip_connection
return x
class sSEmodule(nn.Module):
""" ChannelSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.conv2d = nn.Conv2d(in_channel, 1, 1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
skip_connection = x
x = self.conv2d(x)
x = self.sigmoid(x)
None
x = x * skip_connection
return x
class scSEmoduleNew(nn.Module):
""" ConcurrentSpatialChannelSequeezeExcitationModule
input: [B, C, H, W] torch tensor
output: [B, C, H, W] torch tensor
"""
def __init__(self, in_channel):
super().__init__()
self.cSEmodule = cSEmodule(in_channel=in_channel)
self.sSEmodule = sSEmodule(in_channel=in_channel)
def forward(self, input_0):
primals_2 = self.cSEmodule.down_linear.weight
primals_3 = self.cSEmodule.down_linear.bias
primals_4 = self.cSEmodule.up_linear.weight
primals_5 = self.cSEmodule.up_linear.bias
primals_6 = self.sSEmodule.conv2d.weight
primals_7 = self.sSEmodule.conv2d.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
HwangJohn/feature_representation
|
scSEmodule
| false
| 2,358
|
[
"MIT"
] | 0
|
27389caacc9c026b65f47ab0cbb4e6d0465e6a60
|
https://github.com/HwangJohn/feature_representation/tree/27389caacc9c026b65f47ab0cbb4e6d0465e6a60
|
Hsigmoid
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Hsigmoid(nn.Module):
def __init__(self, inplace=True):
super(Hsigmoid, self).__init__()
self.inplace = inplace
def forward(self, x):
return F.relu6(x + 3.0, inplace=self.inplace) / 6.0
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_div_hardtanh_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 3.0
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 6.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = 0.16666666666666666
tmp8 = tmp6 * tmp7
tl.store(out_ptr0 + x0, tmp8, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_hardtanh_0[grid(256)](arg0_1, buf0, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class HsigmoidNew(nn.Module):
def __init__(self, inplace=True):
super(HsigmoidNew, self).__init__()
self.inplace = inplace
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
IgorDavidyuk/pytorch-mobilenet-v3
|
Hsigmoid
| false
| 2,359
|
[
"Apache-2.0"
] | 0
|
48678f80d9390b530cb97966db492cf01d1c4a43
|
https://github.com/IgorDavidyuk/pytorch-mobilenet-v3/tree/48678f80d9390b530cb97966db492cf01d1c4a43
|
Hswish
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Hswish(nn.Module):
def __init__(self, inplace=True):
super(Hswish, self).__init__()
self.inplace = inplace
def forward(self, x):
return x * F.relu6(x + 3.0, inplace=self.inplace) / 6.0
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_div_hardtanh_mul_0(in_ptr0, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 3.0
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 6.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = tmp0 * tmp6
tmp8 = 0.16666666666666666
tmp9 = tmp7 * tmp8
tl.store(out_ptr0 + x0, tmp9, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_hardtanh_mul_0[grid(256)](arg0_1, buf0,
256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class HswishNew(nn.Module):
def __init__(self, inplace=True):
super(HswishNew, self).__init__()
self.inplace = inplace
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
IgorDavidyuk/pytorch-mobilenet-v3
|
Hswish
| false
| 2,360
|
[
"Apache-2.0"
] | 0
|
48678f80d9390b530cb97966db492cf01d1c4a43
|
https://github.com/IgorDavidyuk/pytorch-mobilenet-v3/tree/48678f80d9390b530cb97966db492cf01d1c4a43
|
ConvTemporalGraphical
|
import torch
import torch.nn as nn
class ConvTemporalGraphical(nn.Module):
"""The basic module for applying a graph convolution.
Args:
in_channels (int): Number of channels in the input sequence data
out_channels (int): Number of channels produced by the convolution
kernel_size (int): Size of the graph convolving kernel
t_kernel_size (int): Size of the temporal convolving kernel
t_stride (int, optional): Stride of the temporal convolution. Default: 1
t_padding (int, optional): Temporal zero-padding added to both sides of
the input. Default: 0
t_dilation (int, optional): Spacing between temporal kernel elements.
Default: 1
bias (bool, optional): If ``True``, adds a learnable bias to the output.
Default: ``True``
Shape:
- Input[0]: Input graph sequence in :math:`(N, in_channels, T_{in}, V)` format
- Input[1]: Input graph adjacency matrix in :math:`(K, V, V)` format
- Output[0]: Output graph sequence in :math:`(N, out_channels, T_{out}, V)` format
- Output[1]: Graph adjacency matrix for output data in :math:`(K, V, V)` format
where
:math:`N` is a batch size,
:math:`K` is the spatial kernel size, as :math:`K == kernel_size[1]`,
:math:`T_{in}/T_{out}` is a length of input/output sequence,
:math:`V` is the number of graph nodes.
"""
def __init__(self, in_channels, out_channels, kernel_size,
t_kernel_size=1, t_stride=1, t_padding=0, t_dilation=1, bias=True):
super().__init__()
self.kernel_size = kernel_size
self.conv = nn.Conv2d(in_channels, out_channels * kernel_size,
kernel_size=(t_kernel_size, 1), padding=(t_padding, 0), stride=
(t_stride, 1), dilation=(t_dilation, 1), bias=bias)
def forward(self, x, A):
assert A.size(0) == self.kernel_size
x = self.conv(x)
n, kc, t, v = x.size()
x = x.view(n, self.kernel_size, kc // self.kernel_size, t, v)
x = torch.einsum('nkctv,kvw->nctw', (x, A))
return x.contiguous(), A
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'out_channels': 4, 'kernel_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x4 = xindex // 256
x5 = xindex // 16 % 16
x3 = xindex // 64 % 4
x6 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x5 + 64 * x1 + 256 * x4), xmask)
tmp1 = tl.load(in_ptr1 + (x3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + x6, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (16, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_3, (16,), (1,))
assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_4, primals_2, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 4, 4), (256, 16, 4, 1))
buf1 = empty_strided_cuda((4, 4, 4, 4, 4, 1), (256, 64, 16, 4, 1, 1
), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(1024)](buf0, primals_3, buf1, 1024,
XBLOCK=128, num_warps=4, num_stages=1)
del buf0
del primals_3
buf2 = empty_strided_cuda((1, 64, 4), (256, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (1, 64, 16), (0, 16, 1),
0), reinterpret_tensor(primals_1, (1, 16, 4), (64, 4, 1), 0),
out=buf2)
del buf1
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_2, primals_4, reinterpret_tensor(primals_1, (1, 4, 16),
(64, 1, 4), 0)
class ConvTemporalGraphicalNew(nn.Module):
"""The basic module for applying a graph convolution.
Args:
in_channels (int): Number of channels in the input sequence data
out_channels (int): Number of channels produced by the convolution
kernel_size (int): Size of the graph convolving kernel
t_kernel_size (int): Size of the temporal convolving kernel
t_stride (int, optional): Stride of the temporal convolution. Default: 1
t_padding (int, optional): Temporal zero-padding added to both sides of
the input. Default: 0
t_dilation (int, optional): Spacing between temporal kernel elements.
Default: 1
bias (bool, optional): If ``True``, adds a learnable bias to the output.
Default: ``True``
Shape:
- Input[0]: Input graph sequence in :math:`(N, in_channels, T_{in}, V)` format
- Input[1]: Input graph adjacency matrix in :math:`(K, V, V)` format
- Output[0]: Output graph sequence in :math:`(N, out_channels, T_{out}, V)` format
- Output[1]: Graph adjacency matrix for output data in :math:`(K, V, V)` format
where
:math:`N` is a batch size,
:math:`K` is the spatial kernel size, as :math:`K == kernel_size[1]`,
:math:`T_{in}/T_{out}` is a length of input/output sequence,
:math:`V` is the number of graph nodes.
"""
def __init__(self, in_channels, out_channels, kernel_size,
t_kernel_size=1, t_stride=1, t_padding=0, t_dilation=1, bias=True):
super().__init__()
self.kernel_size = kernel_size
self.conv = nn.Conv2d(in_channels, out_channels * kernel_size,
kernel_size=(t_kernel_size, 1), padding=(t_padding, 0), stride=
(t_stride, 1), dilation=(t_dilation, 1), bias=bias)
def forward(self, input_0, input_1):
primals_2 = self.conv.weight
primals_3 = self.conv.bias
primals_4 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0], output[1]
|
Hunkzer/mmskeleton
|
ConvTemporalGraphical
| false
| 2,361
|
[
"Apache-2.0"
] | 0
|
551e3b4fa01330b23caab5815a40fbd848400b15
|
https://github.com/Hunkzer/mmskeleton/tree/551e3b4fa01330b23caab5815a40fbd848400b15
|
L1Part
|
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
from itertools import chain as chain
from collections import OrderedDict
import torch.hub
class concatLayer(nn.Module):
def __init__(self, in_channels, out_channels_perSub, i, j, appendix):
super(concatLayer, self).__init__()
self.firstSub = self.concatLayerSub(in_channels,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_0')
self.secondSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_1')
self.thirdSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_2')
def forward(self, x):
firstSub = self.firstSub(x)
secondSub = self.secondSub(firstSub)
thirdSub = self.thirdSub(secondSub)
out = torch.cat([firstSub, secondSub, thirdSub], 1)
return out
def concatLayerSub(self, in_channels, out_channels, layerName):
concatLayerSubOrdered = OrderedDict()
conv2d = nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1)
concatLayerSubOrdered.update({('Mconv' + layerName): conv2d})
concatLayerSubOrdered.update({('Mprelu' + layerName): nn.PReLU(
out_channels)})
return nn.Sequential(concatLayerSubOrdered)
class stage(nn.Module):
def __init__(self, stageID, in_channels, out_channels_perSub,
mid_channels, out_channels, appendix):
super(stage, self).__init__()
self.firstConcat = concatLayer(in_channels, out_channels_perSub, 1,
stageID, appendix)
self.secondConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 2, stageID, appendix)
self.thirdConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 3, stageID, appendix)
self.fourthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 4, stageID, appendix)
self.fifthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 5, stageID, appendix)
conv2d = nn.Conv2d(3 * out_channels_perSub, mid_channels,
kernel_size=1, padding=0)
prelu = nn.PReLU(mid_channels)
self.afterConcatsFirst = nn.Sequential(OrderedDict({(
'Mconv6_stage%d_%s' % (stageID, appendix)): conv2d, (
'Mprelu6_stage%d_%s' % (stageID, appendix)): prelu}))
conv2d = nn.Conv2d(mid_channels, out_channels, kernel_size=1, padding=0
)
self.afterConcatsSecond = nn.Sequential(OrderedDict({(
'Mconv7_stage%d_%s' % (stageID, appendix)): conv2d}))
def forward(self, x):
x = self.firstConcat(x)
x = self.secondConcat(x)
x = self.thirdConcat(x)
x = self.fourthConcat(x)
x = self.fifthConcat(x)
x = self.afterConcatsFirst(x)
out = self.afterConcatsSecond(x)
return out
class L1Part(nn.Module):
def __init__(self, in_channels, stage_out_channels):
super(L1Part, self).__init__()
self.firstStage = stage(0, in_channels, 96, 256, stage_out_channels,
'L1')
self.secondStage = stage(1, in_channels + stage_out_channels, 128,
512, stage_out_channels, 'L1')
def forward(self, features, L2Out):
x = torch.cat([features, L2Out], 1)
x = self.firstStage(x)
x = torch.cat([features, x, L2Out], 1)
out = self.secondStage(x)
return out
def get_inputs():
return [torch.rand([4, 1, 4, 4]), torch.rand([4, 3, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'stage_out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
from itertools import chain as chain
from collections import OrderedDict
import torch.hub
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 4
x0 = xindex % 16
x2 = xindex // 64
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 4, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-1 + x1) + 48 * x2), tmp6 & xmask,
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x3, tmp10, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_1(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 96
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, None)
tl.store(out_ptr0 + x3, tmp7, None)
@triton.jit
def triton_poi_fused_convolution_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 96
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, None)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 16 % 288
x0 = xindex % 16
x2 = xindex // 4608
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 96, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 1536 * x2), tmp4, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 192, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-96 + x1) + 1536 * x2), tmp9,
other=0.0)
tmp11 = tmp0 >= tmp7
tl.full([1], 288, tl.int64)
tmp14 = tl.load(in_ptr2 + (x0 + 16 * (-192 + x1) + 1536 * x2), tmp11,
other=0.0)
tmp15 = 0.0
tmp16 = tmp14 > tmp15
tmp17 = tl.load(in_ptr3 + (-192 + x1), tmp11, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp17 * tmp14
tmp19 = tl.where(tmp16, tmp14, tmp18)
tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
tmp21 = tl.where(tmp11, tmp19, tmp20)
tmp22 = tl.where(tmp9, tmp10, tmp21)
tmp23 = tl.where(tmp4, tmp5, tmp22)
tl.store(out_ptr0 + x3, tmp23, None)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_4(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 256
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, None)
tl.store(out_ptr0 + x3, tmp7, None)
@triton.jit
def triton_poi_fused_cat_5(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 8
x0 = xindex % 16
x2 = xindex // 128
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 5, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-1 + x1) + 64 * x2), tmp9 & xmask,
other=0.0)
tmp11 = tl.load(in_ptr2 + (-1 + x1), tmp9 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp12 = tmp10 + tmp11
tmp13 = tl.full(tmp12.shape, 0.0, tmp12.dtype)
tmp14 = tl.where(tmp9, tmp12, tmp13)
tmp15 = tmp0 >= tmp7
tl.full([1], 8, tl.int64)
tmp18 = tl.load(in_ptr3 + (x0 + 16 * (-5 + x1) + 48 * x2), tmp15 &
xmask, other=0.0)
tmp19 = tl.where(tmp9, tmp14, tmp18)
tmp20 = tl.where(tmp4, tmp5, tmp19)
tl.store(out_ptr0 + x3, tmp20, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_6(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 128
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, None)
tl.store(out_ptr0 + x3, tmp7, None)
@triton.jit
def triton_poi_fused_convolution_7(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 128
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, None)
@triton.jit
def triton_poi_fused_cat_8(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 16 % 384
x0 = xindex % 16
x2 = xindex // 6144
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 128, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 2048 * x2), tmp4, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 256, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-128 + x1) + 2048 * x2), tmp9,
other=0.0)
tmp11 = tmp0 >= tmp7
tl.full([1], 384, tl.int64)
tmp14 = tl.load(in_ptr2 + (x0 + 16 * (-256 + x1) + 2048 * x2), tmp11,
other=0.0)
tmp15 = 0.0
tmp16 = tmp14 > tmp15
tmp17 = tl.load(in_ptr3 + (-256 + x1), tmp11, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp17 * tmp14
tmp19 = tl.where(tmp16, tmp14, tmp18)
tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
tmp21 = tl.where(tmp11, tmp19, tmp20)
tmp22 = tl.where(tmp9, tmp10, tmp21)
tmp23 = tl.where(tmp4, tmp5, tmp22)
tl.store(out_ptr0 + x3, tmp23, None)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_9(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 512
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, None)
tl.store(out_ptr0 + x3, tmp7, None)
@triton.jit
def triton_poi_fused_convolution_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19, primals_20, primals_21, primals_22,
primals_23, primals_24, primals_25, primals_26, primals_27,
primals_28, primals_29, primals_30, primals_31, primals_32,
primals_33, primals_34, primals_35, primals_36, primals_37,
primals_38, primals_39, primals_40, primals_41, primals_42,
primals_43, primals_44, primals_45, primals_46, primals_47,
primals_48, primals_49, primals_50, primals_51, primals_52,
primals_53, primals_54, primals_55, primals_56, primals_57,
primals_58, primals_59, primals_60, primals_61, primals_62,
primals_63, primals_64, primals_65, primals_66, primals_67,
primals_68, primals_69, primals_70, primals_71, primals_72,
primals_73, primals_74, primals_75, primals_76, primals_77,
primals_78, primals_79, primals_80, primals_81, primals_82,
primals_83, primals_84, primals_85, primals_86, primals_87,
primals_88, primals_89, primals_90, primals_91, primals_92,
primals_93, primals_94, primals_95, primals_96, primals_97,
primals_98, primals_99, primals_100, primals_101, primals_102) = args
args.clear()
assert_size_stride(primals_1, (4, 1, 4, 4), (16, 16, 4, 1))
assert_size_stride(primals_2, (4, 3, 4, 4), (48, 16, 4, 1))
assert_size_stride(primals_3, (96, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_4, (96,), (1,))
assert_size_stride(primals_5, (96,), (1,))
assert_size_stride(primals_6, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_7, (96,), (1,))
assert_size_stride(primals_8, (96,), (1,))
assert_size_stride(primals_9, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_10, (96,), (1,))
assert_size_stride(primals_11, (96,), (1,))
assert_size_stride(primals_12, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_13, (96,), (1,))
assert_size_stride(primals_14, (96,), (1,))
assert_size_stride(primals_15, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_16, (96,), (1,))
assert_size_stride(primals_17, (96,), (1,))
assert_size_stride(primals_18, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_19, (96,), (1,))
assert_size_stride(primals_20, (96,), (1,))
assert_size_stride(primals_21, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_22, (96,), (1,))
assert_size_stride(primals_23, (96,), (1,))
assert_size_stride(primals_24, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_25, (96,), (1,))
assert_size_stride(primals_26, (96,), (1,))
assert_size_stride(primals_27, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_28, (96,), (1,))
assert_size_stride(primals_29, (96,), (1,))
assert_size_stride(primals_30, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_31, (96,), (1,))
assert_size_stride(primals_32, (96,), (1,))
assert_size_stride(primals_33, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_34, (96,), (1,))
assert_size_stride(primals_35, (96,), (1,))
assert_size_stride(primals_36, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_37, (96,), (1,))
assert_size_stride(primals_38, (96,), (1,))
assert_size_stride(primals_39, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_40, (96,), (1,))
assert_size_stride(primals_41, (96,), (1,))
assert_size_stride(primals_42, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_43, (96,), (1,))
assert_size_stride(primals_44, (96,), (1,))
assert_size_stride(primals_45, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_46, (96,), (1,))
assert_size_stride(primals_47, (96,), (1,))
assert_size_stride(primals_48, (256, 288, 1, 1), (288, 1, 1, 1))
assert_size_stride(primals_49, (256,), (1,))
assert_size_stride(primals_50, (256,), (1,))
assert_size_stride(primals_51, (4, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_52, (4,), (1,))
assert_size_stride(primals_53, (128, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_54, (128,), (1,))
assert_size_stride(primals_55, (128,), (1,))
assert_size_stride(primals_56, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_57, (128,), (1,))
assert_size_stride(primals_58, (128,), (1,))
assert_size_stride(primals_59, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_60, (128,), (1,))
assert_size_stride(primals_61, (128,), (1,))
assert_size_stride(primals_62, (128, 384, 3, 3), (3456, 9, 3, 1))
assert_size_stride(primals_63, (128,), (1,))
assert_size_stride(primals_64, (128,), (1,))
assert_size_stride(primals_65, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_66, (128,), (1,))
assert_size_stride(primals_67, (128,), (1,))
assert_size_stride(primals_68, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_69, (128,), (1,))
assert_size_stride(primals_70, (128,), (1,))
assert_size_stride(primals_71, (128, 384, 3, 3), (3456, 9, 3, 1))
assert_size_stride(primals_72, (128,), (1,))
assert_size_stride(primals_73, (128,), (1,))
assert_size_stride(primals_74, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_75, (128,), (1,))
assert_size_stride(primals_76, (128,), (1,))
assert_size_stride(primals_77, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_78, (128,), (1,))
assert_size_stride(primals_79, (128,), (1,))
assert_size_stride(primals_80, (128, 384, 3, 3), (3456, 9, 3, 1))
assert_size_stride(primals_81, (128,), (1,))
assert_size_stride(primals_82, (128,), (1,))
assert_size_stride(primals_83, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_84, (128,), (1,))
assert_size_stride(primals_85, (128,), (1,))
assert_size_stride(primals_86, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_87, (128,), (1,))
assert_size_stride(primals_88, (128,), (1,))
assert_size_stride(primals_89, (128, 384, 3, 3), (3456, 9, 3, 1))
assert_size_stride(primals_90, (128,), (1,))
assert_size_stride(primals_91, (128,), (1,))
assert_size_stride(primals_92, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_93, (128,), (1,))
assert_size_stride(primals_94, (128,), (1,))
assert_size_stride(primals_95, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_96, (128,), (1,))
assert_size_stride(primals_97, (128,), (1,))
assert_size_stride(primals_98, (512, 384, 1, 1), (384, 1, 1, 1))
assert_size_stride(primals_99, (512,), (1,))
assert_size_stride(primals_100, (512,), (1,))
assert_size_stride(primals_101, (4, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_102, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(256)](primals_1, primals_2, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_3, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 96, 4, 4), (1536, 16, 4, 1))
buf2 = buf1
del buf1
buf3 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf2,
primals_4, primals_5, buf3, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_4
buf4 = extern_kernels.convolution(buf3, primals_6, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 96, 4, 4), (1536, 16, 4, 1))
buf5 = buf4
del buf4
buf6 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf5,
primals_7, primals_8, buf6, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_7
buf7 = extern_kernels.convolution(buf6, primals_9, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf7, (4, 96, 4, 4), (1536, 16, 4, 1))
buf8 = buf7
del buf7
triton_poi_fused_convolution_2[grid(6144)](buf8, primals_10, 6144,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_10
buf9 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_3[grid(18432)](buf3, buf6, buf8, primals_11,
buf9, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf10 = extern_kernels.convolution(buf9, primals_12, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf10, (4, 96, 4, 4), (1536, 16, 4, 1))
buf11 = buf10
del buf10
buf12 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf11,
primals_13, primals_14, buf12, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_13
buf13 = extern_kernels.convolution(buf12, primals_15, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf13, (4, 96, 4, 4), (1536, 16, 4, 1))
buf14 = buf13
del buf13
buf15 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf14,
primals_16, primals_17, buf15, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_16
buf16 = extern_kernels.convolution(buf15, primals_18, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf16, (4, 96, 4, 4), (1536, 16, 4, 1))
buf17 = buf16
del buf16
triton_poi_fused_convolution_2[grid(6144)](buf17, primals_19, 6144,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_19
buf18 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_3[grid(18432)](buf12, buf15, buf17, primals_20,
buf18, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf19 = extern_kernels.convolution(buf18, primals_21, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf19, (4, 96, 4, 4), (1536, 16, 4, 1))
buf20 = buf19
del buf19
buf21 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf20,
primals_22, primals_23, buf21, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_22
buf22 = extern_kernels.convolution(buf21, primals_24, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf22, (4, 96, 4, 4), (1536, 16, 4, 1))
buf23 = buf22
del buf22
buf24 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf23,
primals_25, primals_26, buf24, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_25
buf25 = extern_kernels.convolution(buf24, primals_27, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf25, (4, 96, 4, 4), (1536, 16, 4, 1))
buf26 = buf25
del buf25
triton_poi_fused_convolution_2[grid(6144)](buf26, primals_28, 6144,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_28
buf27 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_3[grid(18432)](buf21, buf24, buf26, primals_29,
buf27, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf28 = extern_kernels.convolution(buf27, primals_30, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf28, (4, 96, 4, 4), (1536, 16, 4, 1))
buf29 = buf28
del buf28
buf30 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf29,
primals_31, primals_32, buf30, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_31
buf31 = extern_kernels.convolution(buf30, primals_33, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf31, (4, 96, 4, 4), (1536, 16, 4, 1))
buf32 = buf31
del buf31
buf33 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf32,
primals_34, primals_35, buf33, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_34
buf34 = extern_kernels.convolution(buf33, primals_36, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf34, (4, 96, 4, 4), (1536, 16, 4, 1))
buf35 = buf34
del buf34
triton_poi_fused_convolution_2[grid(6144)](buf35, primals_37, 6144,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_37
buf36 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_3[grid(18432)](buf30, buf33, buf35, primals_38,
buf36, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf37 = extern_kernels.convolution(buf36, primals_39, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf37, (4, 96, 4, 4), (1536, 16, 4, 1))
buf38 = buf37
del buf37
buf39 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf38,
primals_40, primals_41, buf39, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_40
buf40 = extern_kernels.convolution(buf39, primals_42, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf40, (4, 96, 4, 4), (1536, 16, 4, 1))
buf41 = buf40
del buf40
buf42 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_1[grid(6144)](buf41,
primals_43, primals_44, buf42, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_43
buf43 = extern_kernels.convolution(buf42, primals_45, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf43, (4, 96, 4, 4), (1536, 16, 4, 1))
buf44 = buf43
del buf43
triton_poi_fused_convolution_2[grid(6144)](buf44, primals_46, 6144,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_46
buf45 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_3[grid(18432)](buf39, buf42, buf44, primals_47,
buf45, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf46 = extern_kernels.convolution(buf45, primals_48, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf46, (4, 256, 4, 4), (4096, 16, 4, 1))
buf47 = buf46
del buf46
buf48 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_4[grid(16384)](buf47,
primals_49, primals_50, buf48, 16384, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_49
buf49 = extern_kernels.convolution(buf48, primals_51, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf49, (4, 4, 4, 4), (64, 16, 4, 1))
buf50 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
)
triton_poi_fused_cat_5[grid(512)](primals_1, buf49, primals_52,
primals_2, buf50, 512, XBLOCK=128, num_warps=4, num_stages=1)
del buf49
del primals_1
del primals_2
del primals_52
buf51 = extern_kernels.convolution(buf50, primals_53, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf51, (4, 128, 4, 4), (2048, 16, 4, 1))
buf52 = buf51
del buf51
buf53 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf52,
primals_54, primals_55, buf53, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_54
buf54 = extern_kernels.convolution(buf53, primals_56, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf54, (4, 128, 4, 4), (2048, 16, 4, 1))
buf55 = buf54
del buf54
buf56 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf55,
primals_57, primals_58, buf56, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_57
buf57 = extern_kernels.convolution(buf56, primals_59, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf57, (4, 128, 4, 4), (2048, 16, 4, 1))
buf58 = buf57
del buf57
triton_poi_fused_convolution_7[grid(8192)](buf58, primals_60, 8192,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_60
buf59 = empty_strided_cuda((4, 384, 4, 4), (6144, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_8[grid(24576)](buf53, buf56, buf58, primals_61,
buf59, 24576, XBLOCK=256, num_warps=4, num_stages=1)
buf60 = extern_kernels.convolution(buf59, primals_62, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf60, (4, 128, 4, 4), (2048, 16, 4, 1))
buf61 = buf60
del buf60
buf62 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf61,
primals_63, primals_64, buf62, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_63
buf63 = extern_kernels.convolution(buf62, primals_65, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf63, (4, 128, 4, 4), (2048, 16, 4, 1))
buf64 = buf63
del buf63
buf65 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf64,
primals_66, primals_67, buf65, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_66
buf66 = extern_kernels.convolution(buf65, primals_68, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf66, (4, 128, 4, 4), (2048, 16, 4, 1))
buf67 = buf66
del buf66
triton_poi_fused_convolution_7[grid(8192)](buf67, primals_69, 8192,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_69
buf68 = empty_strided_cuda((4, 384, 4, 4), (6144, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_8[grid(24576)](buf62, buf65, buf67, primals_70,
buf68, 24576, XBLOCK=256, num_warps=4, num_stages=1)
buf69 = extern_kernels.convolution(buf68, primals_71, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf69, (4, 128, 4, 4), (2048, 16, 4, 1))
buf70 = buf69
del buf69
buf71 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf70,
primals_72, primals_73, buf71, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_72
buf72 = extern_kernels.convolution(buf71, primals_74, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf72, (4, 128, 4, 4), (2048, 16, 4, 1))
buf73 = buf72
del buf72
buf74 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf73,
primals_75, primals_76, buf74, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_75
buf75 = extern_kernels.convolution(buf74, primals_77, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf75, (4, 128, 4, 4), (2048, 16, 4, 1))
buf76 = buf75
del buf75
triton_poi_fused_convolution_7[grid(8192)](buf76, primals_78, 8192,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_78
buf77 = empty_strided_cuda((4, 384, 4, 4), (6144, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_8[grid(24576)](buf71, buf74, buf76, primals_79,
buf77, 24576, XBLOCK=256, num_warps=4, num_stages=1)
buf78 = extern_kernels.convolution(buf77, primals_80, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf78, (4, 128, 4, 4), (2048, 16, 4, 1))
buf79 = buf78
del buf78
buf80 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf79,
primals_81, primals_82, buf80, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_81
buf81 = extern_kernels.convolution(buf80, primals_83, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf81, (4, 128, 4, 4), (2048, 16, 4, 1))
buf82 = buf81
del buf81
buf83 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf82,
primals_84, primals_85, buf83, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_84
buf84 = extern_kernels.convolution(buf83, primals_86, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf84, (4, 128, 4, 4), (2048, 16, 4, 1))
buf85 = buf84
del buf84
triton_poi_fused_convolution_7[grid(8192)](buf85, primals_87, 8192,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_87
buf86 = empty_strided_cuda((4, 384, 4, 4), (6144, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_8[grid(24576)](buf80, buf83, buf85, primals_88,
buf86, 24576, XBLOCK=256, num_warps=4, num_stages=1)
buf87 = extern_kernels.convolution(buf86, primals_89, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf87, (4, 128, 4, 4), (2048, 16, 4, 1))
buf88 = buf87
del buf87
buf89 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf88,
primals_90, primals_91, buf89, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_90
buf90 = extern_kernels.convolution(buf89, primals_92, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf90, (4, 128, 4, 4), (2048, 16, 4, 1))
buf91 = buf90
del buf90
buf92 = empty_strided_cuda((4, 128, 4, 4), (2048, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_6[grid(8192)](buf91,
primals_93, primals_94, buf92, 8192, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_93
buf93 = extern_kernels.convolution(buf92, primals_95, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf93, (4, 128, 4, 4), (2048, 16, 4, 1))
buf94 = buf93
del buf93
triton_poi_fused_convolution_7[grid(8192)](buf94, primals_96, 8192,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_96
buf95 = empty_strided_cuda((4, 384, 4, 4), (6144, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_8[grid(24576)](buf89, buf92, buf94, primals_97,
buf95, 24576, XBLOCK=256, num_warps=4, num_stages=1)
buf96 = extern_kernels.convolution(buf95, primals_98, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf96, (4, 512, 4, 4), (8192, 16, 4, 1))
buf97 = buf96
del buf96
buf98 = empty_strided_cuda((4, 512, 4, 4), (8192, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_9[grid(32768)](buf97,
primals_99, primals_100, buf98, 32768, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_99
buf99 = extern_kernels.convolution(buf98, primals_101, stride=(1, 1
), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf99, (4, 4, 4, 4), (64, 16, 4, 1))
buf100 = buf99
del buf99
triton_poi_fused_convolution_10[grid(256)](buf100, primals_102, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_102
return (buf100, primals_3, primals_5, primals_6, primals_8, primals_9,
primals_11, primals_12, primals_14, primals_15, primals_17,
primals_18, primals_20, primals_21, primals_23, primals_24,
primals_26, primals_27, primals_29, primals_30, primals_32,
primals_33, primals_35, primals_36, primals_38, primals_39,
primals_41, primals_42, primals_44, primals_45, primals_47,
primals_48, primals_50, primals_51, primals_53, primals_55,
primals_56, primals_58, primals_59, primals_61, primals_62,
primals_64, primals_65, primals_67, primals_68, primals_70,
primals_71, primals_73, primals_74, primals_76, primals_77,
primals_79, primals_80, primals_82, primals_83, primals_85,
primals_86, primals_88, primals_89, primals_91, primals_92,
primals_94, primals_95, primals_97, primals_98, primals_100,
primals_101, buf0, buf2, buf3, buf5, buf6, buf8, buf9, buf11, buf12,
buf14, buf15, buf17, buf18, buf20, buf21, buf23, buf24, buf26,
buf27, buf29, buf30, buf32, buf33, buf35, buf36, buf38, buf39,
buf41, buf42, buf44, buf45, buf47, buf48, buf50, buf52, buf53,
buf55, buf56, buf58, buf59, buf61, buf62, buf64, buf65, buf67,
buf68, buf70, buf71, buf73, buf74, buf76, buf77, buf79, buf80,
buf82, buf83, buf85, buf86, buf88, buf89, buf91, buf92, buf94,
buf95, buf97, buf98)
class concatLayer(nn.Module):
def __init__(self, in_channels, out_channels_perSub, i, j, appendix):
super(concatLayer, self).__init__()
self.firstSub = self.concatLayerSub(in_channels,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_0')
self.secondSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_1')
self.thirdSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_2')
def forward(self, x):
firstSub = self.firstSub(x)
secondSub = self.secondSub(firstSub)
thirdSub = self.thirdSub(secondSub)
out = torch.cat([firstSub, secondSub, thirdSub], 1)
return out
def concatLayerSub(self, in_channels, out_channels, layerName):
concatLayerSubOrdered = OrderedDict()
conv2d = nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1)
concatLayerSubOrdered.update({('Mconv' + layerName): conv2d})
concatLayerSubOrdered.update({('Mprelu' + layerName): nn.PReLU(
out_channels)})
return nn.Sequential(concatLayerSubOrdered)
class stage(nn.Module):
def __init__(self, stageID, in_channels, out_channels_perSub,
mid_channels, out_channels, appendix):
super(stage, self).__init__()
self.firstConcat = concatLayer(in_channels, out_channels_perSub, 1,
stageID, appendix)
self.secondConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 2, stageID, appendix)
self.thirdConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 3, stageID, appendix)
self.fourthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 4, stageID, appendix)
self.fifthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 5, stageID, appendix)
conv2d = nn.Conv2d(3 * out_channels_perSub, mid_channels,
kernel_size=1, padding=0)
prelu = nn.PReLU(mid_channels)
self.afterConcatsFirst = nn.Sequential(OrderedDict({(
'Mconv6_stage%d_%s' % (stageID, appendix)): conv2d, (
'Mprelu6_stage%d_%s' % (stageID, appendix)): prelu}))
conv2d = nn.Conv2d(mid_channels, out_channels, kernel_size=1, padding=0
)
self.afterConcatsSecond = nn.Sequential(OrderedDict({(
'Mconv7_stage%d_%s' % (stageID, appendix)): conv2d}))
def forward(self, x):
x = self.firstConcat(x)
x = self.secondConcat(x)
x = self.thirdConcat(x)
x = self.fourthConcat(x)
x = self.fifthConcat(x)
x = self.afterConcatsFirst(x)
out = self.afterConcatsSecond(x)
return out
class L1PartNew(nn.Module):
def __init__(self, in_channels, stage_out_channels):
super(L1PartNew, self).__init__()
self.firstStage = stage(0, in_channels, 96, 256, stage_out_channels,
'L1')
self.secondStage = stage(1, in_channels + stage_out_channels, 128,
512, stage_out_channels, 'L1')
def forward(self, input_0, input_1):
primals_3 = (self.firstStage.firstConcat.firstSub.
Mconv1_stage0_L1_0.weight)
primals_4 = (self.firstStage.firstConcat.firstSub.
Mconv1_stage0_L1_0.bias)
primals_5 = (self.firstStage.firstConcat.firstSub.
Mprelu1_stage0_L1_0.weight)
primals_6 = (self.firstStage.firstConcat.secondSub.
Mconv1_stage0_L1_1.weight)
primals_7 = (self.firstStage.firstConcat.secondSub.
Mconv1_stage0_L1_1.bias)
primals_8 = (self.firstStage.firstConcat.secondSub.
Mprelu1_stage0_L1_1.weight)
primals_9 = (self.firstStage.firstConcat.thirdSub.
Mconv1_stage0_L1_2.weight)
primals_10 = (self.firstStage.firstConcat.thirdSub.
Mconv1_stage0_L1_2.bias)
primals_11 = (self.firstStage.firstConcat.thirdSub.
Mprelu1_stage0_L1_2.weight)
primals_12 = (self.firstStage.secondConcat.firstSub.
Mconv2_stage0_L1_0.weight)
primals_13 = (self.firstStage.secondConcat.firstSub.
Mconv2_stage0_L1_0.bias)
primals_14 = (self.firstStage.secondConcat.firstSub.
Mprelu2_stage0_L1_0.weight)
primals_15 = (self.firstStage.secondConcat.secondSub.
Mconv2_stage0_L1_1.weight)
primals_16 = (self.firstStage.secondConcat.secondSub.
Mconv2_stage0_L1_1.bias)
primals_17 = (self.firstStage.secondConcat.secondSub.
Mprelu2_stage0_L1_1.weight)
primals_18 = (self.firstStage.secondConcat.thirdSub.
Mconv2_stage0_L1_2.weight)
primals_19 = (self.firstStage.secondConcat.thirdSub.
Mconv2_stage0_L1_2.bias)
primals_20 = (self.firstStage.secondConcat.thirdSub.
Mprelu2_stage0_L1_2.weight)
primals_21 = (self.firstStage.thirdConcat.firstSub.
Mconv3_stage0_L1_0.weight)
primals_22 = (self.firstStage.thirdConcat.firstSub.
Mconv3_stage0_L1_0.bias)
primals_23 = (self.firstStage.thirdConcat.firstSub.
Mprelu3_stage0_L1_0.weight)
primals_24 = (self.firstStage.thirdConcat.secondSub.
Mconv3_stage0_L1_1.weight)
primals_25 = (self.firstStage.thirdConcat.secondSub.
Mconv3_stage0_L1_1.bias)
primals_26 = (self.firstStage.thirdConcat.secondSub.
Mprelu3_stage0_L1_1.weight)
primals_27 = (self.firstStage.thirdConcat.thirdSub.
Mconv3_stage0_L1_2.weight)
primals_28 = (self.firstStage.thirdConcat.thirdSub.
Mconv3_stage0_L1_2.bias)
primals_29 = (self.firstStage.thirdConcat.thirdSub.
Mprelu3_stage0_L1_2.weight)
primals_30 = (self.firstStage.fourthConcat.firstSub.
Mconv4_stage0_L1_0.weight)
primals_31 = (self.firstStage.fourthConcat.firstSub.
Mconv4_stage0_L1_0.bias)
primals_32 = (self.firstStage.fourthConcat.firstSub.
Mprelu4_stage0_L1_0.weight)
primals_33 = (self.firstStage.fourthConcat.secondSub.
Mconv4_stage0_L1_1.weight)
primals_34 = (self.firstStage.fourthConcat.secondSub.
Mconv4_stage0_L1_1.bias)
primals_35 = (self.firstStage.fourthConcat.secondSub.
Mprelu4_stage0_L1_1.weight)
primals_36 = (self.firstStage.fourthConcat.thirdSub.
Mconv4_stage0_L1_2.weight)
primals_37 = (self.firstStage.fourthConcat.thirdSub.
Mconv4_stage0_L1_2.bias)
primals_38 = (self.firstStage.fourthConcat.thirdSub.
Mprelu4_stage0_L1_2.weight)
primals_39 = (self.firstStage.fifthConcat.firstSub.
Mconv5_stage0_L1_0.weight)
primals_40 = (self.firstStage.fifthConcat.firstSub.
Mconv5_stage0_L1_0.bias)
primals_41 = (self.firstStage.fifthConcat.firstSub.
Mprelu5_stage0_L1_0.weight)
primals_42 = (self.firstStage.fifthConcat.secondSub.
Mconv5_stage0_L1_1.weight)
primals_43 = (self.firstStage.fifthConcat.secondSub.
Mconv5_stage0_L1_1.bias)
primals_44 = (self.firstStage.fifthConcat.secondSub.
Mprelu5_stage0_L1_1.weight)
primals_45 = (self.firstStage.fifthConcat.thirdSub.
Mconv5_stage0_L1_2.weight)
primals_46 = (self.firstStage.fifthConcat.thirdSub.
Mconv5_stage0_L1_2.bias)
primals_47 = (self.firstStage.fifthConcat.thirdSub.
Mprelu5_stage0_L1_2.weight)
primals_48 = self.firstStage.afterConcatsFirst.Mconv6_stage0_L1.weight
primals_49 = self.firstStage.afterConcatsFirst.Mconv6_stage0_L1.bias
primals_50 = self.firstStage.afterConcatsFirst.Mprelu6_stage0_L1.weight
primals_51 = self.firstStage.afterConcatsSecond.Mconv7_stage0_L1.weight
primals_52 = self.firstStage.afterConcatsSecond.Mconv7_stage0_L1.bias
primals_53 = (self.secondStage.firstConcat.firstSub.
Mconv1_stage1_L1_0.weight)
primals_54 = (self.secondStage.firstConcat.firstSub.
Mconv1_stage1_L1_0.bias)
primals_55 = (self.secondStage.firstConcat.firstSub.
Mprelu1_stage1_L1_0.weight)
primals_56 = (self.secondStage.firstConcat.secondSub.
Mconv1_stage1_L1_1.weight)
primals_57 = (self.secondStage.firstConcat.secondSub.
Mconv1_stage1_L1_1.bias)
primals_58 = (self.secondStage.firstConcat.secondSub.
Mprelu1_stage1_L1_1.weight)
primals_59 = (self.secondStage.firstConcat.thirdSub.
Mconv1_stage1_L1_2.weight)
primals_60 = (self.secondStage.firstConcat.thirdSub.
Mconv1_stage1_L1_2.bias)
primals_61 = (self.secondStage.firstConcat.thirdSub.
Mprelu1_stage1_L1_2.weight)
primals_62 = (self.secondStage.secondConcat.firstSub.
Mconv2_stage1_L1_0.weight)
primals_63 = (self.secondStage.secondConcat.firstSub.
Mconv2_stage1_L1_0.bias)
primals_64 = (self.secondStage.secondConcat.firstSub.
Mprelu2_stage1_L1_0.weight)
primals_65 = (self.secondStage.secondConcat.secondSub.
Mconv2_stage1_L1_1.weight)
primals_66 = (self.secondStage.secondConcat.secondSub.
Mconv2_stage1_L1_1.bias)
primals_67 = (self.secondStage.secondConcat.secondSub.
Mprelu2_stage1_L1_1.weight)
primals_68 = (self.secondStage.secondConcat.thirdSub.
Mconv2_stage1_L1_2.weight)
primals_69 = (self.secondStage.secondConcat.thirdSub.
Mconv2_stage1_L1_2.bias)
primals_70 = (self.secondStage.secondConcat.thirdSub.
Mprelu2_stage1_L1_2.weight)
primals_71 = (self.secondStage.thirdConcat.firstSub.
Mconv3_stage1_L1_0.weight)
primals_72 = (self.secondStage.thirdConcat.firstSub.
Mconv3_stage1_L1_0.bias)
primals_73 = (self.secondStage.thirdConcat.firstSub.
Mprelu3_stage1_L1_0.weight)
primals_74 = (self.secondStage.thirdConcat.secondSub.
Mconv3_stage1_L1_1.weight)
primals_75 = (self.secondStage.thirdConcat.secondSub.
Mconv3_stage1_L1_1.bias)
primals_76 = (self.secondStage.thirdConcat.secondSub.
Mprelu3_stage1_L1_1.weight)
primals_77 = (self.secondStage.thirdConcat.thirdSub.
Mconv3_stage1_L1_2.weight)
primals_78 = (self.secondStage.thirdConcat.thirdSub.
Mconv3_stage1_L1_2.bias)
primals_79 = (self.secondStage.thirdConcat.thirdSub.
Mprelu3_stage1_L1_2.weight)
primals_80 = (self.secondStage.fourthConcat.firstSub.
Mconv4_stage1_L1_0.weight)
primals_81 = (self.secondStage.fourthConcat.firstSub.
Mconv4_stage1_L1_0.bias)
primals_82 = (self.secondStage.fourthConcat.firstSub.
Mprelu4_stage1_L1_0.weight)
primals_83 = (self.secondStage.fourthConcat.secondSub.
Mconv4_stage1_L1_1.weight)
primals_84 = (self.secondStage.fourthConcat.secondSub.
Mconv4_stage1_L1_1.bias)
primals_85 = (self.secondStage.fourthConcat.secondSub.
Mprelu4_stage1_L1_1.weight)
primals_86 = (self.secondStage.fourthConcat.thirdSub.
Mconv4_stage1_L1_2.weight)
primals_87 = (self.secondStage.fourthConcat.thirdSub.
Mconv4_stage1_L1_2.bias)
primals_88 = (self.secondStage.fourthConcat.thirdSub.
Mprelu4_stage1_L1_2.weight)
primals_89 = (self.secondStage.fifthConcat.firstSub.
Mconv5_stage1_L1_0.weight)
primals_90 = (self.secondStage.fifthConcat.firstSub.
Mconv5_stage1_L1_0.bias)
primals_91 = (self.secondStage.fifthConcat.firstSub.
Mprelu5_stage1_L1_0.weight)
primals_92 = (self.secondStage.fifthConcat.secondSub.
Mconv5_stage1_L1_1.weight)
primals_93 = (self.secondStage.fifthConcat.secondSub.
Mconv5_stage1_L1_1.bias)
primals_94 = (self.secondStage.fifthConcat.secondSub.
Mprelu5_stage1_L1_1.weight)
primals_95 = (self.secondStage.fifthConcat.thirdSub.
Mconv5_stage1_L1_2.weight)
primals_96 = (self.secondStage.fifthConcat.thirdSub.
Mconv5_stage1_L1_2.bias)
primals_97 = (self.secondStage.fifthConcat.thirdSub.
Mprelu5_stage1_L1_2.weight)
primals_98 = self.secondStage.afterConcatsFirst.Mconv6_stage1_L1.weight
primals_99 = self.secondStage.afterConcatsFirst.Mconv6_stage1_L1.bias
primals_100 = (self.secondStage.afterConcatsFirst.Mprelu6_stage1_L1
.weight)
primals_101 = (self.secondStage.afterConcatsSecond.Mconv7_stage1_L1
.weight)
primals_102 = self.secondStage.afterConcatsSecond.Mconv7_stage1_L1.bias
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19,
primals_20, primals_21, primals_22, primals_23, primals_24,
primals_25, primals_26, primals_27, primals_28, primals_29,
primals_30, primals_31, primals_32, primals_33, primals_34,
primals_35, primals_36, primals_37, primals_38, primals_39,
primals_40, primals_41, primals_42, primals_43, primals_44,
primals_45, primals_46, primals_47, primals_48, primals_49,
primals_50, primals_51, primals_52, primals_53, primals_54,
primals_55, primals_56, primals_57, primals_58, primals_59,
primals_60, primals_61, primals_62, primals_63, primals_64,
primals_65, primals_66, primals_67, primals_68, primals_69,
primals_70, primals_71, primals_72, primals_73, primals_74,
primals_75, primals_76, primals_77, primals_78, primals_79,
primals_80, primals_81, primals_82, primals_83, primals_84,
primals_85, primals_86, primals_87, primals_88, primals_89,
primals_90, primals_91, primals_92, primals_93, primals_94,
primals_95, primals_96, primals_97, primals_98, primals_99,
primals_100, primals_101, primals_102])
return output[0]
|
EddieMG/LateTemporalModeling3DCNN
|
L1Part
| false
| 2,362
|
[
"MIT"
] | 0
|
94c87dc1d31d09bc310d0e735a2e55453976cb0d
|
https://github.com/EddieMG/LateTemporalModeling3DCNN/tree/94c87dc1d31d09bc310d0e735a2e55453976cb0d
|
L2Part
|
import torch
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
from itertools import chain as chain
from collections import OrderedDict
import torch.hub
class concatLayer(nn.Module):
def __init__(self, in_channels, out_channels_perSub, i, j, appendix):
super(concatLayer, self).__init__()
self.firstSub = self.concatLayerSub(in_channels,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_0')
self.secondSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_1')
self.thirdSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_2')
def forward(self, x):
firstSub = self.firstSub(x)
secondSub = self.secondSub(firstSub)
thirdSub = self.thirdSub(secondSub)
out = torch.cat([firstSub, secondSub, thirdSub], 1)
return out
def concatLayerSub(self, in_channels, out_channels, layerName):
concatLayerSubOrdered = OrderedDict()
conv2d = nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1)
concatLayerSubOrdered.update({('Mconv' + layerName): conv2d})
concatLayerSubOrdered.update({('Mprelu' + layerName): nn.PReLU(
out_channels)})
return nn.Sequential(concatLayerSubOrdered)
class stage(nn.Module):
def __init__(self, stageID, in_channels, out_channels_perSub,
mid_channels, out_channels, appendix):
super(stage, self).__init__()
self.firstConcat = concatLayer(in_channels, out_channels_perSub, 1,
stageID, appendix)
self.secondConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 2, stageID, appendix)
self.thirdConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 3, stageID, appendix)
self.fourthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 4, stageID, appendix)
self.fifthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 5, stageID, appendix)
conv2d = nn.Conv2d(3 * out_channels_perSub, mid_channels,
kernel_size=1, padding=0)
prelu = nn.PReLU(mid_channels)
self.afterConcatsFirst = nn.Sequential(OrderedDict({(
'Mconv6_stage%d_%s' % (stageID, appendix)): conv2d, (
'Mprelu6_stage%d_%s' % (stageID, appendix)): prelu}))
conv2d = nn.Conv2d(mid_channels, out_channels, kernel_size=1, padding=0
)
self.afterConcatsSecond = nn.Sequential(OrderedDict({(
'Mconv7_stage%d_%s' % (stageID, appendix)): conv2d}))
def forward(self, x):
x = self.firstConcat(x)
x = self.secondConcat(x)
x = self.thirdConcat(x)
x = self.fourthConcat(x)
x = self.fifthConcat(x)
x = self.afterConcatsFirst(x)
out = self.afterConcatsSecond(x)
return out
class L2Part(nn.Module):
def __init__(self, in_channels, stage_out_channels):
super(L2Part, self).__init__()
self.firstStage = stage(0, in_channels, 96, in_channels * 2,
stage_out_channels, 'L2')
self.secondStage = stage(1, in_channels + stage_out_channels,
in_channels, in_channels * 4, stage_out_channels, 'L2')
self.thirdStage = stage(2, in_channels + stage_out_channels,
in_channels, in_channels * 4, stage_out_channels, 'L2')
self.fourthStage = stage(3, in_channels + stage_out_channels,
in_channels, in_channels * 4, stage_out_channels, 'L2')
def forward(self, features):
x = self.firstStage(features)
x = torch.cat([features, x], 1)
x = self.secondStage(x)
x = torch.cat([features, x], 1)
x = self.thirdStage(x)
x = torch.cat([features, x], 1)
out = self.fourthStage(x)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_channels': 4, 'stage_out_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
from itertools import chain as chain
from collections import OrderedDict
import torch.hub
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_0(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 96
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, None)
tl.store(out_ptr0 + x3, tmp7, None)
@triton.jit
def triton_poi_fused_convolution_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 16 % 96
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, None)
@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 16 % 288
x0 = xindex % 16
x2 = xindex // 4608
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 96, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 1536 * x2), tmp4, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 192, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-96 + x1) + 1536 * x2), tmp9,
other=0.0)
tmp11 = tmp0 >= tmp7
tl.full([1], 288, tl.int64)
tmp14 = tl.load(in_ptr2 + (x0 + 16 * (-192 + x1) + 1536 * x2), tmp11,
other=0.0)
tmp15 = 0.0
tmp16 = tmp14 > tmp15
tmp17 = tl.load(in_ptr3 + (-192 + x1), tmp11, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp17 * tmp14
tmp19 = tl.where(tmp16, tmp14, tmp18)
tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
tmp21 = tl.where(tmp11, tmp19, tmp20)
tmp22 = tl.where(tmp9, tmp10, tmp21)
tmp23 = tl.where(tmp4, tmp5, tmp22)
tl.store(out_ptr0 + x3, tmp23, None)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_3(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 8
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_cat_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 8
x0 = xindex % 16
x2 = xindex // 128
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp6 & xmask,
other=0.0)
tmp10 = tl.load(in_ptr2 + (-4 + x1), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
tmp13 = tl.where(tmp6, tmp11, tmp12)
tmp14 = tl.where(tmp4, tmp5, tmp13)
tl.store(out_ptr0 + x3, tmp14, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_5(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_convolution_6(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_cat_7(in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 768
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 16 % 12
x0 = xindex % 16
x2 = xindex // 192
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 16 * x1 + 64 * x2), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tmp7 = tl.full([1], 8, tl.int64)
tmp8 = tmp0 < tmp7
tmp9 = tmp6 & tmp8
tmp10 = tl.load(in_ptr1 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp9 & xmask,
other=0.0)
tmp11 = tmp0 >= tmp7
tl.full([1], 12, tl.int64)
tmp14 = tl.load(in_ptr2 + (x0 + 16 * (-8 + x1) + 64 * x2), tmp11 &
xmask, other=0.0)
tmp15 = 0.0
tmp16 = tmp14 > tmp15
tmp17 = tl.load(in_ptr3 + (-8 + x1), tmp11 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tmp17 * tmp14
tmp19 = tl.where(tmp16, tmp14, tmp18)
tmp20 = tl.full(tmp19.shape, 0.0, tmp19.dtype)
tmp21 = tl.where(tmp11, tmp19, tmp20)
tmp22 = tl.where(tmp9, tmp10, tmp21)
tmp23 = tl.where(tmp4, tmp5, tmp22)
tl.store(out_ptr0 + x3, tmp23, xmask)
@triton.jit
def triton_poi_fused__prelu_kernel_convolution_8(in_out_ptr0, in_ptr0,
in_ptr1, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp6 = tmp5 * tmp2
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp7, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
primals_13, primals_14, primals_15, primals_16, primals_17,
primals_18, primals_19, primals_20, primals_21, primals_22,
primals_23, primals_24, primals_25, primals_26, primals_27,
primals_28, primals_29, primals_30, primals_31, primals_32,
primals_33, primals_34, primals_35, primals_36, primals_37,
primals_38, primals_39, primals_40, primals_41, primals_42,
primals_43, primals_44, primals_45, primals_46, primals_47,
primals_48, primals_49, primals_50, primals_51, primals_52,
primals_53, primals_54, primals_55, primals_56, primals_57,
primals_58, primals_59, primals_60, primals_61, primals_62,
primals_63, primals_64, primals_65, primals_66, primals_67,
primals_68, primals_69, primals_70, primals_71, primals_72,
primals_73, primals_74, primals_75, primals_76, primals_77,
primals_78, primals_79, primals_80, primals_81, primals_82,
primals_83, primals_84, primals_85, primals_86, primals_87,
primals_88, primals_89, primals_90, primals_91, primals_92,
primals_93, primals_94, primals_95, primals_96, primals_97,
primals_98, primals_99, primals_100, primals_101, primals_102,
primals_103, primals_104, primals_105, primals_106, primals_107,
primals_108, primals_109, primals_110, primals_111, primals_112,
primals_113, primals_114, primals_115, primals_116, primals_117,
primals_118, primals_119, primals_120, primals_121, primals_122,
primals_123, primals_124, primals_125, primals_126, primals_127,
primals_128, primals_129, primals_130, primals_131, primals_132,
primals_133, primals_134, primals_135, primals_136, primals_137,
primals_138, primals_139, primals_140, primals_141, primals_142,
primals_143, primals_144, primals_145, primals_146, primals_147,
primals_148, primals_149, primals_150, primals_151, primals_152,
primals_153, primals_154, primals_155, primals_156, primals_157,
primals_158, primals_159, primals_160, primals_161, primals_162,
primals_163, primals_164, primals_165, primals_166, primals_167,
primals_168, primals_169, primals_170, primals_171, primals_172,
primals_173, primals_174, primals_175, primals_176, primals_177,
primals_178, primals_179, primals_180, primals_181, primals_182,
primals_183, primals_184, primals_185, primals_186, primals_187,
primals_188, primals_189, primals_190, primals_191, primals_192,
primals_193, primals_194, primals_195, primals_196, primals_197,
primals_198, primals_199, primals_200, primals_201) = args
args.clear()
assert_size_stride(primals_1, (96, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (96,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (96,), (1,))
assert_size_stride(primals_5, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_6, (96,), (1,))
assert_size_stride(primals_7, (96,), (1,))
assert_size_stride(primals_8, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_9, (96,), (1,))
assert_size_stride(primals_10, (96,), (1,))
assert_size_stride(primals_11, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_12, (96,), (1,))
assert_size_stride(primals_13, (96,), (1,))
assert_size_stride(primals_14, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_15, (96,), (1,))
assert_size_stride(primals_16, (96,), (1,))
assert_size_stride(primals_17, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_18, (96,), (1,))
assert_size_stride(primals_19, (96,), (1,))
assert_size_stride(primals_20, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_21, (96,), (1,))
assert_size_stride(primals_22, (96,), (1,))
assert_size_stride(primals_23, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_24, (96,), (1,))
assert_size_stride(primals_25, (96,), (1,))
assert_size_stride(primals_26, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_27, (96,), (1,))
assert_size_stride(primals_28, (96,), (1,))
assert_size_stride(primals_29, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_30, (96,), (1,))
assert_size_stride(primals_31, (96,), (1,))
assert_size_stride(primals_32, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_33, (96,), (1,))
assert_size_stride(primals_34, (96,), (1,))
assert_size_stride(primals_35, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_36, (96,), (1,))
assert_size_stride(primals_37, (96,), (1,))
assert_size_stride(primals_38, (96, 288, 3, 3), (2592, 9, 3, 1))
assert_size_stride(primals_39, (96,), (1,))
assert_size_stride(primals_40, (96,), (1,))
assert_size_stride(primals_41, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_42, (96,), (1,))
assert_size_stride(primals_43, (96,), (1,))
assert_size_stride(primals_44, (96, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_45, (96,), (1,))
assert_size_stride(primals_46, (96,), (1,))
assert_size_stride(primals_47, (8, 288, 1, 1), (288, 1, 1, 1))
assert_size_stride(primals_48, (8,), (1,))
assert_size_stride(primals_49, (8,), (1,))
assert_size_stride(primals_50, (4, 8, 1, 1), (8, 1, 1, 1))
assert_size_stride(primals_51, (4,), (1,))
assert_size_stride(primals_52, (4, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_53, (4,), (1,))
assert_size_stride(primals_54, (4,), (1,))
assert_size_stride(primals_55, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_56, (4,), (1,))
assert_size_stride(primals_57, (4,), (1,))
assert_size_stride(primals_58, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_59, (4,), (1,))
assert_size_stride(primals_60, (4,), (1,))
assert_size_stride(primals_61, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_62, (4,), (1,))
assert_size_stride(primals_63, (4,), (1,))
assert_size_stride(primals_64, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_65, (4,), (1,))
assert_size_stride(primals_66, (4,), (1,))
assert_size_stride(primals_67, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_68, (4,), (1,))
assert_size_stride(primals_69, (4,), (1,))
assert_size_stride(primals_70, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_71, (4,), (1,))
assert_size_stride(primals_72, (4,), (1,))
assert_size_stride(primals_73, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_74, (4,), (1,))
assert_size_stride(primals_75, (4,), (1,))
assert_size_stride(primals_76, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_77, (4,), (1,))
assert_size_stride(primals_78, (4,), (1,))
assert_size_stride(primals_79, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_80, (4,), (1,))
assert_size_stride(primals_81, (4,), (1,))
assert_size_stride(primals_82, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_83, (4,), (1,))
assert_size_stride(primals_84, (4,), (1,))
assert_size_stride(primals_85, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_86, (4,), (1,))
assert_size_stride(primals_87, (4,), (1,))
assert_size_stride(primals_88, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_89, (4,), (1,))
assert_size_stride(primals_90, (4,), (1,))
assert_size_stride(primals_91, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_92, (4,), (1,))
assert_size_stride(primals_93, (4,), (1,))
assert_size_stride(primals_94, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_95, (4,), (1,))
assert_size_stride(primals_96, (4,), (1,))
assert_size_stride(primals_97, (16, 12, 1, 1), (12, 1, 1, 1))
assert_size_stride(primals_98, (16,), (1,))
assert_size_stride(primals_99, (16,), (1,))
assert_size_stride(primals_100, (4, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_101, (4,), (1,))
assert_size_stride(primals_102, (4, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_103, (4,), (1,))
assert_size_stride(primals_104, (4,), (1,))
assert_size_stride(primals_105, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_106, (4,), (1,))
assert_size_stride(primals_107, (4,), (1,))
assert_size_stride(primals_108, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_109, (4,), (1,))
assert_size_stride(primals_110, (4,), (1,))
assert_size_stride(primals_111, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_112, (4,), (1,))
assert_size_stride(primals_113, (4,), (1,))
assert_size_stride(primals_114, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_115, (4,), (1,))
assert_size_stride(primals_116, (4,), (1,))
assert_size_stride(primals_117, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_118, (4,), (1,))
assert_size_stride(primals_119, (4,), (1,))
assert_size_stride(primals_120, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_121, (4,), (1,))
assert_size_stride(primals_122, (4,), (1,))
assert_size_stride(primals_123, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_124, (4,), (1,))
assert_size_stride(primals_125, (4,), (1,))
assert_size_stride(primals_126, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_127, (4,), (1,))
assert_size_stride(primals_128, (4,), (1,))
assert_size_stride(primals_129, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_130, (4,), (1,))
assert_size_stride(primals_131, (4,), (1,))
assert_size_stride(primals_132, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_133, (4,), (1,))
assert_size_stride(primals_134, (4,), (1,))
assert_size_stride(primals_135, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_136, (4,), (1,))
assert_size_stride(primals_137, (4,), (1,))
assert_size_stride(primals_138, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_139, (4,), (1,))
assert_size_stride(primals_140, (4,), (1,))
assert_size_stride(primals_141, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_142, (4,), (1,))
assert_size_stride(primals_143, (4,), (1,))
assert_size_stride(primals_144, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_145, (4,), (1,))
assert_size_stride(primals_146, (4,), (1,))
assert_size_stride(primals_147, (16, 12, 1, 1), (12, 1, 1, 1))
assert_size_stride(primals_148, (16,), (1,))
assert_size_stride(primals_149, (16,), (1,))
assert_size_stride(primals_150, (4, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_151, (4,), (1,))
assert_size_stride(primals_152, (4, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_153, (4,), (1,))
assert_size_stride(primals_154, (4,), (1,))
assert_size_stride(primals_155, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_156, (4,), (1,))
assert_size_stride(primals_157, (4,), (1,))
assert_size_stride(primals_158, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_159, (4,), (1,))
assert_size_stride(primals_160, (4,), (1,))
assert_size_stride(primals_161, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_162, (4,), (1,))
assert_size_stride(primals_163, (4,), (1,))
assert_size_stride(primals_164, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_165, (4,), (1,))
assert_size_stride(primals_166, (4,), (1,))
assert_size_stride(primals_167, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_168, (4,), (1,))
assert_size_stride(primals_169, (4,), (1,))
assert_size_stride(primals_170, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_171, (4,), (1,))
assert_size_stride(primals_172, (4,), (1,))
assert_size_stride(primals_173, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_174, (4,), (1,))
assert_size_stride(primals_175, (4,), (1,))
assert_size_stride(primals_176, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_177, (4,), (1,))
assert_size_stride(primals_178, (4,), (1,))
assert_size_stride(primals_179, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_180, (4,), (1,))
assert_size_stride(primals_181, (4,), (1,))
assert_size_stride(primals_182, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_183, (4,), (1,))
assert_size_stride(primals_184, (4,), (1,))
assert_size_stride(primals_185, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_186, (4,), (1,))
assert_size_stride(primals_187, (4,), (1,))
assert_size_stride(primals_188, (4, 12, 3, 3), (108, 9, 3, 1))
assert_size_stride(primals_189, (4,), (1,))
assert_size_stride(primals_190, (4,), (1,))
assert_size_stride(primals_191, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_192, (4,), (1,))
assert_size_stride(primals_193, (4,), (1,))
assert_size_stride(primals_194, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_195, (4,), (1,))
assert_size_stride(primals_196, (4,), (1,))
assert_size_stride(primals_197, (16, 12, 1, 1), (12, 1, 1, 1))
assert_size_stride(primals_198, (16,), (1,))
assert_size_stride(primals_199, (16,), (1,))
assert_size_stride(primals_200, (4, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_201, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 96, 4, 4), (1536, 16, 4, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
get_raw_stream(0)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf1,
primals_2, primals_4, buf2, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_2
buf3 = extern_kernels.convolution(buf2, primals_5, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 96, 4, 4), (1536, 16, 4, 1))
buf4 = buf3
del buf3
buf5 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf4,
primals_6, primals_7, buf5, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_6
buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 96, 4, 4), (1536, 16, 4, 1))
buf7 = buf6
del buf6
triton_poi_fused_convolution_1[grid(6144)](buf7, primals_9, 6144,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_9
buf8 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_2[grid(18432)](buf2, buf5, buf7, primals_10,
buf8, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf9 = extern_kernels.convolution(buf8, primals_11, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf9, (4, 96, 4, 4), (1536, 16, 4, 1))
buf10 = buf9
del buf9
buf11 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf10,
primals_12, primals_13, buf11, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_12
buf12 = extern_kernels.convolution(buf11, primals_14, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf12, (4, 96, 4, 4), (1536, 16, 4, 1))
buf13 = buf12
del buf12
buf14 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf13,
primals_15, primals_16, buf14, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_15
buf15 = extern_kernels.convolution(buf14, primals_17, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf15, (4, 96, 4, 4), (1536, 16, 4, 1))
buf16 = buf15
del buf15
triton_poi_fused_convolution_1[grid(6144)](buf16, primals_18, 6144,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_18
buf17 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_2[grid(18432)](buf11, buf14, buf16, primals_19,
buf17, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf18 = extern_kernels.convolution(buf17, primals_20, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf18, (4, 96, 4, 4), (1536, 16, 4, 1))
buf19 = buf18
del buf18
buf20 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf19,
primals_21, primals_22, buf20, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_21
buf21 = extern_kernels.convolution(buf20, primals_23, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf21, (4, 96, 4, 4), (1536, 16, 4, 1))
buf22 = buf21
del buf21
buf23 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf22,
primals_24, primals_25, buf23, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_24
buf24 = extern_kernels.convolution(buf23, primals_26, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf24, (4, 96, 4, 4), (1536, 16, 4, 1))
buf25 = buf24
del buf24
triton_poi_fused_convolution_1[grid(6144)](buf25, primals_27, 6144,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_27
buf26 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_2[grid(18432)](buf20, buf23, buf25, primals_28,
buf26, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf27 = extern_kernels.convolution(buf26, primals_29, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf27, (4, 96, 4, 4), (1536, 16, 4, 1))
buf28 = buf27
del buf27
buf29 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf28,
primals_30, primals_31, buf29, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_30
buf30 = extern_kernels.convolution(buf29, primals_32, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf30, (4, 96, 4, 4), (1536, 16, 4, 1))
buf31 = buf30
del buf30
buf32 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf31,
primals_33, primals_34, buf32, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_33
buf33 = extern_kernels.convolution(buf32, primals_35, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf33, (4, 96, 4, 4), (1536, 16, 4, 1))
buf34 = buf33
del buf33
triton_poi_fused_convolution_1[grid(6144)](buf34, primals_36, 6144,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_36
buf35 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_2[grid(18432)](buf29, buf32, buf34, primals_37,
buf35, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf36 = extern_kernels.convolution(buf35, primals_38, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf36, (4, 96, 4, 4), (1536, 16, 4, 1))
buf37 = buf36
del buf36
buf38 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf37,
primals_39, primals_40, buf38, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_39
buf39 = extern_kernels.convolution(buf38, primals_41, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf39, (4, 96, 4, 4), (1536, 16, 4, 1))
buf40 = buf39
del buf39
buf41 = empty_strided_cuda((4, 96, 4, 4), (1536, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_0[grid(6144)](buf40,
primals_42, primals_43, buf41, 6144, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_42
buf42 = extern_kernels.convolution(buf41, primals_44, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf42, (4, 96, 4, 4), (1536, 16, 4, 1))
buf43 = buf42
del buf42
triton_poi_fused_convolution_1[grid(6144)](buf43, primals_45, 6144,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_45
buf44 = empty_strided_cuda((4, 288, 4, 4), (4608, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_2[grid(18432)](buf38, buf41, buf43, primals_46,
buf44, 18432, XBLOCK=256, num_warps=4, num_stages=1)
buf45 = extern_kernels.convolution(buf44, primals_47, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf45, (4, 8, 4, 4), (128, 16, 4, 1))
buf46 = buf45
del buf45
buf47 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_3[grid(512)](buf46,
primals_48, primals_49, buf47, 512, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_48
buf48 = extern_kernels.convolution(buf47, primals_50, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf48, (4, 4, 4, 4), (64, 16, 4, 1))
buf49 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
)
triton_poi_fused_cat_4[grid(512)](primals_3, buf48, primals_51,
buf49, 512, XBLOCK=256, num_warps=4, num_stages=1)
del primals_51
buf50 = extern_kernels.convolution(buf49, primals_52, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf50, (4, 4, 4, 4), (64, 16, 4, 1))
buf51 = buf50
del buf50
buf52 = buf48
del buf48
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf51,
primals_53, primals_54, buf52, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_53
buf53 = extern_kernels.convolution(buf52, primals_55, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf53, (4, 4, 4, 4), (64, 16, 4, 1))
buf54 = buf53
del buf53
buf55 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf54,
primals_56, primals_57, buf55, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_56
buf56 = extern_kernels.convolution(buf55, primals_58, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf56, (4, 4, 4, 4), (64, 16, 4, 1))
buf57 = buf56
del buf56
triton_poi_fused_convolution_6[grid(256)](buf57, primals_59, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_59
buf58 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf52, buf55, buf57, primals_60,
buf58, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf59 = extern_kernels.convolution(buf58, primals_61, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf59, (4, 4, 4, 4), (64, 16, 4, 1))
buf60 = buf59
del buf59
buf61 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf60,
primals_62, primals_63, buf61, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_62
buf62 = extern_kernels.convolution(buf61, primals_64, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf62, (4, 4, 4, 4), (64, 16, 4, 1))
buf63 = buf62
del buf62
buf64 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf63,
primals_65, primals_66, buf64, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_65
buf65 = extern_kernels.convolution(buf64, primals_67, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf65, (4, 4, 4, 4), (64, 16, 4, 1))
buf66 = buf65
del buf65
triton_poi_fused_convolution_6[grid(256)](buf66, primals_68, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_68
buf67 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf61, buf64, buf66, primals_69,
buf67, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf68 = extern_kernels.convolution(buf67, primals_70, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf68, (4, 4, 4, 4), (64, 16, 4, 1))
buf69 = buf68
del buf68
buf70 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf69,
primals_71, primals_72, buf70, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_71
buf71 = extern_kernels.convolution(buf70, primals_73, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf71, (4, 4, 4, 4), (64, 16, 4, 1))
buf72 = buf71
del buf71
buf73 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf72,
primals_74, primals_75, buf73, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_74
buf74 = extern_kernels.convolution(buf73, primals_76, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf74, (4, 4, 4, 4), (64, 16, 4, 1))
buf75 = buf74
del buf74
triton_poi_fused_convolution_6[grid(256)](buf75, primals_77, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_77
buf76 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf70, buf73, buf75, primals_78,
buf76, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf77 = extern_kernels.convolution(buf76, primals_79, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf77, (4, 4, 4, 4), (64, 16, 4, 1))
buf78 = buf77
del buf77
buf79 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf78,
primals_80, primals_81, buf79, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_80
buf80 = extern_kernels.convolution(buf79, primals_82, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf80, (4, 4, 4, 4), (64, 16, 4, 1))
buf81 = buf80
del buf80
buf82 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf81,
primals_83, primals_84, buf82, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_83
buf83 = extern_kernels.convolution(buf82, primals_85, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf83, (4, 4, 4, 4), (64, 16, 4, 1))
buf84 = buf83
del buf83
triton_poi_fused_convolution_6[grid(256)](buf84, primals_86, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_86
buf85 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf79, buf82, buf84, primals_87,
buf85, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf86 = extern_kernels.convolution(buf85, primals_88, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf86, (4, 4, 4, 4), (64, 16, 4, 1))
buf87 = buf86
del buf86
buf88 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf87,
primals_89, primals_90, buf88, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_89
buf89 = extern_kernels.convolution(buf88, primals_91, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf89, (4, 4, 4, 4), (64, 16, 4, 1))
buf90 = buf89
del buf89
buf91 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf90,
primals_92, primals_93, buf91, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_92
buf92 = extern_kernels.convolution(buf91, primals_94, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf92, (4, 4, 4, 4), (64, 16, 4, 1))
buf93 = buf92
del buf92
triton_poi_fused_convolution_6[grid(256)](buf93, primals_95, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_95
buf94 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf88, buf91, buf93, primals_96,
buf94, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf95 = extern_kernels.convolution(buf94, primals_97, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf95, (4, 16, 4, 4), (256, 16, 4, 1))
buf96 = buf95
del buf95
buf97 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_8[grid(1024)](buf96,
primals_98, primals_99, buf97, 1024, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_98
buf98 = extern_kernels.convolution(buf97, primals_100, stride=(1, 1
), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf98, (4, 4, 4, 4), (64, 16, 4, 1))
buf99 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32
)
triton_poi_fused_cat_4[grid(512)](primals_3, buf98, primals_101,
buf99, 512, XBLOCK=256, num_warps=4, num_stages=1)
del primals_101
buf100 = extern_kernels.convolution(buf99, primals_102, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf100, (4, 4, 4, 4), (64, 16, 4, 1))
buf101 = buf100
del buf100
buf102 = buf98
del buf98
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf101,
primals_103, primals_104, buf102, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_103
buf103 = extern_kernels.convolution(buf102, primals_105, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf103, (4, 4, 4, 4), (64, 16, 4, 1))
buf104 = buf103
del buf103
buf105 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf104,
primals_106, primals_107, buf105, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_106
buf106 = extern_kernels.convolution(buf105, primals_108, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf106, (4, 4, 4, 4), (64, 16, 4, 1))
buf107 = buf106
del buf106
triton_poi_fused_convolution_6[grid(256)](buf107, primals_109, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_109
buf108 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf102, buf105, buf107,
primals_110, buf108, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf109 = extern_kernels.convolution(buf108, primals_111, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf109, (4, 4, 4, 4), (64, 16, 4, 1))
buf110 = buf109
del buf109
buf111 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf110,
primals_112, primals_113, buf111, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_112
buf112 = extern_kernels.convolution(buf111, primals_114, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf112, (4, 4, 4, 4), (64, 16, 4, 1))
buf113 = buf112
del buf112
buf114 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf113,
primals_115, primals_116, buf114, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_115
buf115 = extern_kernels.convolution(buf114, primals_117, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf115, (4, 4, 4, 4), (64, 16, 4, 1))
buf116 = buf115
del buf115
triton_poi_fused_convolution_6[grid(256)](buf116, primals_118, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_118
buf117 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf111, buf114, buf116,
primals_119, buf117, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf118 = extern_kernels.convolution(buf117, primals_120, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf118, (4, 4, 4, 4), (64, 16, 4, 1))
buf119 = buf118
del buf118
buf120 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf119,
primals_121, primals_122, buf120, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_121
buf121 = extern_kernels.convolution(buf120, primals_123, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf121, (4, 4, 4, 4), (64, 16, 4, 1))
buf122 = buf121
del buf121
buf123 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf122,
primals_124, primals_125, buf123, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_124
buf124 = extern_kernels.convolution(buf123, primals_126, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf124, (4, 4, 4, 4), (64, 16, 4, 1))
buf125 = buf124
del buf124
triton_poi_fused_convolution_6[grid(256)](buf125, primals_127, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_127
buf126 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf120, buf123, buf125,
primals_128, buf126, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf127 = extern_kernels.convolution(buf126, primals_129, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf127, (4, 4, 4, 4), (64, 16, 4, 1))
buf128 = buf127
del buf127
buf129 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf128,
primals_130, primals_131, buf129, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_130
buf130 = extern_kernels.convolution(buf129, primals_132, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf130, (4, 4, 4, 4), (64, 16, 4, 1))
buf131 = buf130
del buf130
buf132 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf131,
primals_133, primals_134, buf132, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_133
buf133 = extern_kernels.convolution(buf132, primals_135, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf133, (4, 4, 4, 4), (64, 16, 4, 1))
buf134 = buf133
del buf133
triton_poi_fused_convolution_6[grid(256)](buf134, primals_136, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_136
buf135 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf129, buf132, buf134,
primals_137, buf135, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf136 = extern_kernels.convolution(buf135, primals_138, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf136, (4, 4, 4, 4), (64, 16, 4, 1))
buf137 = buf136
del buf136
buf138 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf137,
primals_139, primals_140, buf138, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_139
buf139 = extern_kernels.convolution(buf138, primals_141, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf139, (4, 4, 4, 4), (64, 16, 4, 1))
buf140 = buf139
del buf139
buf141 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf140,
primals_142, primals_143, buf141, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_142
buf142 = extern_kernels.convolution(buf141, primals_144, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf142, (4, 4, 4, 4), (64, 16, 4, 1))
buf143 = buf142
del buf142
triton_poi_fused_convolution_6[grid(256)](buf143, primals_145, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_145
buf144 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf138, buf141, buf143,
primals_146, buf144, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf145 = extern_kernels.convolution(buf144, primals_147, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf145, (4, 16, 4, 4), (256, 16, 4, 1))
buf146 = buf145
del buf145
buf147 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_8[grid(1024)](buf146,
primals_148, primals_149, buf147, 1024, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_148
buf148 = extern_kernels.convolution(buf147, primals_150, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf148, (4, 4, 4, 4), (64, 16, 4, 1))
buf149 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_4[grid(512)](primals_3, buf148, primals_151,
buf149, 512, XBLOCK=256, num_warps=4, num_stages=1)
del primals_151
buf150 = extern_kernels.convolution(buf149, primals_152, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf150, (4, 4, 4, 4), (64, 16, 4, 1))
buf151 = buf150
del buf150
buf152 = buf148
del buf148
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf151,
primals_153, primals_154, buf152, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_153
buf153 = extern_kernels.convolution(buf152, primals_155, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf153, (4, 4, 4, 4), (64, 16, 4, 1))
buf154 = buf153
del buf153
buf155 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf154,
primals_156, primals_157, buf155, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_156
buf156 = extern_kernels.convolution(buf155, primals_158, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf156, (4, 4, 4, 4), (64, 16, 4, 1))
buf157 = buf156
del buf156
triton_poi_fused_convolution_6[grid(256)](buf157, primals_159, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_159
buf158 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf152, buf155, buf157,
primals_160, buf158, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf159 = extern_kernels.convolution(buf158, primals_161, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf159, (4, 4, 4, 4), (64, 16, 4, 1))
buf160 = buf159
del buf159
buf161 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf160,
primals_162, primals_163, buf161, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_162
buf162 = extern_kernels.convolution(buf161, primals_164, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf162, (4, 4, 4, 4), (64, 16, 4, 1))
buf163 = buf162
del buf162
buf164 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf163,
primals_165, primals_166, buf164, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_165
buf165 = extern_kernels.convolution(buf164, primals_167, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf165, (4, 4, 4, 4), (64, 16, 4, 1))
buf166 = buf165
del buf165
triton_poi_fused_convolution_6[grid(256)](buf166, primals_168, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_168
buf167 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf161, buf164, buf166,
primals_169, buf167, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf168 = extern_kernels.convolution(buf167, primals_170, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf168, (4, 4, 4, 4), (64, 16, 4, 1))
buf169 = buf168
del buf168
buf170 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf169,
primals_171, primals_172, buf170, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_171
buf171 = extern_kernels.convolution(buf170, primals_173, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf171, (4, 4, 4, 4), (64, 16, 4, 1))
buf172 = buf171
del buf171
buf173 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf172,
primals_174, primals_175, buf173, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_174
buf174 = extern_kernels.convolution(buf173, primals_176, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf174, (4, 4, 4, 4), (64, 16, 4, 1))
buf175 = buf174
del buf174
triton_poi_fused_convolution_6[grid(256)](buf175, primals_177, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_177
buf176 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf170, buf173, buf175,
primals_178, buf176, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf177 = extern_kernels.convolution(buf176, primals_179, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf177, (4, 4, 4, 4), (64, 16, 4, 1))
buf178 = buf177
del buf177
buf179 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf178,
primals_180, primals_181, buf179, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_180
buf180 = extern_kernels.convolution(buf179, primals_182, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf180, (4, 4, 4, 4), (64, 16, 4, 1))
buf181 = buf180
del buf180
buf182 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf181,
primals_183, primals_184, buf182, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_183
buf183 = extern_kernels.convolution(buf182, primals_185, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf183, (4, 4, 4, 4), (64, 16, 4, 1))
buf184 = buf183
del buf183
triton_poi_fused_convolution_6[grid(256)](buf184, primals_186, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_186
buf185 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf179, buf182, buf184,
primals_187, buf185, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf186 = extern_kernels.convolution(buf185, primals_188, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf186, (4, 4, 4, 4), (64, 16, 4, 1))
buf187 = buf186
del buf186
buf188 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf187,
primals_189, primals_190, buf188, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_189
buf189 = extern_kernels.convolution(buf188, primals_191, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf189, (4, 4, 4, 4), (64, 16, 4, 1))
buf190 = buf189
del buf189
buf191 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32
)
triton_poi_fused__prelu_kernel_convolution_5[grid(256)](buf190,
primals_192, primals_193, buf191, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_192
buf192 = extern_kernels.convolution(buf191, primals_194, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf192, (4, 4, 4, 4), (64, 16, 4, 1))
buf193 = buf192
del buf192
triton_poi_fused_convolution_6[grid(256)](buf193, primals_195, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_195
buf194 = empty_strided_cuda((4, 12, 4, 4), (192, 16, 4, 1), torch.
float32)
triton_poi_fused_cat_7[grid(768)](buf188, buf191, buf193,
primals_196, buf194, 768, XBLOCK=128, num_warps=4, num_stages=1)
buf195 = extern_kernels.convolution(buf194, primals_197, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf195, (4, 16, 4, 4), (256, 16, 4, 1))
buf196 = buf195
del buf195
buf197 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.
float32)
triton_poi_fused__prelu_kernel_convolution_8[grid(1024)](buf196,
primals_198, primals_199, buf197, 1024, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_198
buf198 = extern_kernels.convolution(buf197, primals_200, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf198, (4, 4, 4, 4), (64, 16, 4, 1))
buf199 = buf198
del buf198
triton_poi_fused_convolution_6[grid(256)](buf199, primals_201, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_201
return (buf199, primals_1, primals_3, primals_4, primals_5, primals_7,
primals_8, primals_10, primals_11, primals_13, primals_14,
primals_16, primals_17, primals_19, primals_20, primals_22,
primals_23, primals_25, primals_26, primals_28, primals_29,
primals_31, primals_32, primals_34, primals_35, primals_37,
primals_38, primals_40, primals_41, primals_43, primals_44,
primals_46, primals_47, primals_49, primals_50, primals_52,
primals_54, primals_55, primals_57, primals_58, primals_60,
primals_61, primals_63, primals_64, primals_66, primals_67,
primals_69, primals_70, primals_72, primals_73, primals_75,
primals_76, primals_78, primals_79, primals_81, primals_82,
primals_84, primals_85, primals_87, primals_88, primals_90,
primals_91, primals_93, primals_94, primals_96, primals_97,
primals_99, primals_100, primals_102, primals_104, primals_105,
primals_107, primals_108, primals_110, primals_111, primals_113,
primals_114, primals_116, primals_117, primals_119, primals_120,
primals_122, primals_123, primals_125, primals_126, primals_128,
primals_129, primals_131, primals_132, primals_134, primals_135,
primals_137, primals_138, primals_140, primals_141, primals_143,
primals_144, primals_146, primals_147, primals_149, primals_150,
primals_152, primals_154, primals_155, primals_157, primals_158,
primals_160, primals_161, primals_163, primals_164, primals_166,
primals_167, primals_169, primals_170, primals_172, primals_173,
primals_175, primals_176, primals_178, primals_179, primals_181,
primals_182, primals_184, primals_185, primals_187, primals_188,
primals_190, primals_191, primals_193, primals_194, primals_196,
primals_197, primals_199, primals_200, buf1, buf2, buf4, buf5, buf7,
buf8, buf10, buf11, buf13, buf14, buf16, buf17, buf19, buf20, buf22,
buf23, buf25, buf26, buf28, buf29, buf31, buf32, buf34, buf35,
buf37, buf38, buf40, buf41, buf43, buf44, buf46, buf47, buf49,
buf51, buf52, buf54, buf55, buf57, buf58, buf60, buf61, buf63,
buf64, buf66, buf67, buf69, buf70, buf72, buf73, buf75, buf76,
buf78, buf79, buf81, buf82, buf84, buf85, buf87, buf88, buf90,
buf91, buf93, buf94, buf96, buf97, buf99, buf101, buf102, buf104,
buf105, buf107, buf108, buf110, buf111, buf113, buf114, buf116,
buf117, buf119, buf120, buf122, buf123, buf125, buf126, buf128,
buf129, buf131, buf132, buf134, buf135, buf137, buf138, buf140,
buf141, buf143, buf144, buf146, buf147, buf149, buf151, buf152,
buf154, buf155, buf157, buf158, buf160, buf161, buf163, buf164,
buf166, buf167, buf169, buf170, buf172, buf173, buf175, buf176,
buf178, buf179, buf181, buf182, buf184, buf185, buf187, buf188,
buf190, buf191, buf193, buf194, buf196, buf197)
class concatLayer(nn.Module):
def __init__(self, in_channels, out_channels_perSub, i, j, appendix):
super(concatLayer, self).__init__()
self.firstSub = self.concatLayerSub(in_channels,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_0')
self.secondSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_1')
self.thirdSub = self.concatLayerSub(out_channels_perSub,
out_channels_perSub, '%d_stage%d_' % (i, j) + appendix + '_2')
def forward(self, x):
firstSub = self.firstSub(x)
secondSub = self.secondSub(firstSub)
thirdSub = self.thirdSub(secondSub)
out = torch.cat([firstSub, secondSub, thirdSub], 1)
return out
def concatLayerSub(self, in_channels, out_channels, layerName):
concatLayerSubOrdered = OrderedDict()
conv2d = nn.Conv2d(in_channels, out_channels, kernel_size=3, padding=1)
concatLayerSubOrdered.update({('Mconv' + layerName): conv2d})
concatLayerSubOrdered.update({('Mprelu' + layerName): nn.PReLU(
out_channels)})
return nn.Sequential(concatLayerSubOrdered)
class stage(nn.Module):
def __init__(self, stageID, in_channels, out_channels_perSub,
mid_channels, out_channels, appendix):
super(stage, self).__init__()
self.firstConcat = concatLayer(in_channels, out_channels_perSub, 1,
stageID, appendix)
self.secondConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 2, stageID, appendix)
self.thirdConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 3, stageID, appendix)
self.fourthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 4, stageID, appendix)
self.fifthConcat = concatLayer(3 * out_channels_perSub,
out_channels_perSub, 5, stageID, appendix)
conv2d = nn.Conv2d(3 * out_channels_perSub, mid_channels,
kernel_size=1, padding=0)
prelu = nn.PReLU(mid_channels)
self.afterConcatsFirst = nn.Sequential(OrderedDict({(
'Mconv6_stage%d_%s' % (stageID, appendix)): conv2d, (
'Mprelu6_stage%d_%s' % (stageID, appendix)): prelu}))
conv2d = nn.Conv2d(mid_channels, out_channels, kernel_size=1, padding=0
)
self.afterConcatsSecond = nn.Sequential(OrderedDict({(
'Mconv7_stage%d_%s' % (stageID, appendix)): conv2d}))
def forward(self, x):
x = self.firstConcat(x)
x = self.secondConcat(x)
x = self.thirdConcat(x)
x = self.fourthConcat(x)
x = self.fifthConcat(x)
x = self.afterConcatsFirst(x)
out = self.afterConcatsSecond(x)
return out
class L2PartNew(nn.Module):
def __init__(self, in_channels, stage_out_channels):
super(L2PartNew, self).__init__()
self.firstStage = stage(0, in_channels, 96, in_channels * 2,
stage_out_channels, 'L2')
self.secondStage = stage(1, in_channels + stage_out_channels,
in_channels, in_channels * 4, stage_out_channels, 'L2')
self.thirdStage = stage(2, in_channels + stage_out_channels,
in_channels, in_channels * 4, stage_out_channels, 'L2')
self.fourthStage = stage(3, in_channels + stage_out_channels,
in_channels, in_channels * 4, stage_out_channels, 'L2')
def forward(self, input_0):
primals_1 = (self.firstStage.firstConcat.firstSub.
Mconv1_stage0_L2_0.weight)
primals_2 = (self.firstStage.firstConcat.firstSub.
Mconv1_stage0_L2_0.bias)
primals_4 = (self.firstStage.firstConcat.firstSub.
Mprelu1_stage0_L2_0.weight)
primals_5 = (self.firstStage.firstConcat.secondSub.
Mconv1_stage0_L2_1.weight)
primals_6 = (self.firstStage.firstConcat.secondSub.
Mconv1_stage0_L2_1.bias)
primals_7 = (self.firstStage.firstConcat.secondSub.
Mprelu1_stage0_L2_1.weight)
primals_8 = (self.firstStage.firstConcat.thirdSub.
Mconv1_stage0_L2_2.weight)
primals_9 = (self.firstStage.firstConcat.thirdSub.
Mconv1_stage0_L2_2.bias)
primals_10 = (self.firstStage.firstConcat.thirdSub.
Mprelu1_stage0_L2_2.weight)
primals_11 = (self.firstStage.secondConcat.firstSub.
Mconv2_stage0_L2_0.weight)
primals_12 = (self.firstStage.secondConcat.firstSub.
Mconv2_stage0_L2_0.bias)
primals_13 = (self.firstStage.secondConcat.firstSub.
Mprelu2_stage0_L2_0.weight)
primals_14 = (self.firstStage.secondConcat.secondSub.
Mconv2_stage0_L2_1.weight)
primals_15 = (self.firstStage.secondConcat.secondSub.
Mconv2_stage0_L2_1.bias)
primals_16 = (self.firstStage.secondConcat.secondSub.
Mprelu2_stage0_L2_1.weight)
primals_17 = (self.firstStage.secondConcat.thirdSub.
Mconv2_stage0_L2_2.weight)
primals_18 = (self.firstStage.secondConcat.thirdSub.
Mconv2_stage0_L2_2.bias)
primals_19 = (self.firstStage.secondConcat.thirdSub.
Mprelu2_stage0_L2_2.weight)
primals_20 = (self.firstStage.thirdConcat.firstSub.
Mconv3_stage0_L2_0.weight)
primals_21 = (self.firstStage.thirdConcat.firstSub.
Mconv3_stage0_L2_0.bias)
primals_22 = (self.firstStage.thirdConcat.firstSub.
Mprelu3_stage0_L2_0.weight)
primals_23 = (self.firstStage.thirdConcat.secondSub.
Mconv3_stage0_L2_1.weight)
primals_24 = (self.firstStage.thirdConcat.secondSub.
Mconv3_stage0_L2_1.bias)
primals_25 = (self.firstStage.thirdConcat.secondSub.
Mprelu3_stage0_L2_1.weight)
primals_26 = (self.firstStage.thirdConcat.thirdSub.
Mconv3_stage0_L2_2.weight)
primals_27 = (self.firstStage.thirdConcat.thirdSub.
Mconv3_stage0_L2_2.bias)
primals_28 = (self.firstStage.thirdConcat.thirdSub.
Mprelu3_stage0_L2_2.weight)
primals_29 = (self.firstStage.fourthConcat.firstSub.
Mconv4_stage0_L2_0.weight)
primals_30 = (self.firstStage.fourthConcat.firstSub.
Mconv4_stage0_L2_0.bias)
primals_31 = (self.firstStage.fourthConcat.firstSub.
Mprelu4_stage0_L2_0.weight)
primals_32 = (self.firstStage.fourthConcat.secondSub.
Mconv4_stage0_L2_1.weight)
primals_33 = (self.firstStage.fourthConcat.secondSub.
Mconv4_stage0_L2_1.bias)
primals_34 = (self.firstStage.fourthConcat.secondSub.
Mprelu4_stage0_L2_1.weight)
primals_35 = (self.firstStage.fourthConcat.thirdSub.
Mconv4_stage0_L2_2.weight)
primals_36 = (self.firstStage.fourthConcat.thirdSub.
Mconv4_stage0_L2_2.bias)
primals_37 = (self.firstStage.fourthConcat.thirdSub.
Mprelu4_stage0_L2_2.weight)
primals_38 = (self.firstStage.fifthConcat.firstSub.
Mconv5_stage0_L2_0.weight)
primals_39 = (self.firstStage.fifthConcat.firstSub.
Mconv5_stage0_L2_0.bias)
primals_40 = (self.firstStage.fifthConcat.firstSub.
Mprelu5_stage0_L2_0.weight)
primals_41 = (self.firstStage.fifthConcat.secondSub.
Mconv5_stage0_L2_1.weight)
primals_42 = (self.firstStage.fifthConcat.secondSub.
Mconv5_stage0_L2_1.bias)
primals_43 = (self.firstStage.fifthConcat.secondSub.
Mprelu5_stage0_L2_1.weight)
primals_44 = (self.firstStage.fifthConcat.thirdSub.
Mconv5_stage0_L2_2.weight)
primals_45 = (self.firstStage.fifthConcat.thirdSub.
Mconv5_stage0_L2_2.bias)
primals_46 = (self.firstStage.fifthConcat.thirdSub.
Mprelu5_stage0_L2_2.weight)
primals_47 = self.firstStage.afterConcatsFirst.Mconv6_stage0_L2.weight
primals_48 = self.firstStage.afterConcatsFirst.Mconv6_stage0_L2.bias
primals_49 = self.firstStage.afterConcatsFirst.Mprelu6_stage0_L2.weight
primals_50 = self.firstStage.afterConcatsSecond.Mconv7_stage0_L2.weight
primals_51 = self.firstStage.afterConcatsSecond.Mconv7_stage0_L2.bias
primals_52 = (self.secondStage.firstConcat.firstSub.
Mconv1_stage1_L2_0.weight)
primals_53 = (self.secondStage.firstConcat.firstSub.
Mconv1_stage1_L2_0.bias)
primals_54 = (self.secondStage.firstConcat.firstSub.
Mprelu1_stage1_L2_0.weight)
primals_55 = (self.secondStage.firstConcat.secondSub.
Mconv1_stage1_L2_1.weight)
primals_56 = (self.secondStage.firstConcat.secondSub.
Mconv1_stage1_L2_1.bias)
primals_57 = (self.secondStage.firstConcat.secondSub.
Mprelu1_stage1_L2_1.weight)
primals_58 = (self.secondStage.firstConcat.thirdSub.
Mconv1_stage1_L2_2.weight)
primals_59 = (self.secondStage.firstConcat.thirdSub.
Mconv1_stage1_L2_2.bias)
primals_60 = (self.secondStage.firstConcat.thirdSub.
Mprelu1_stage1_L2_2.weight)
primals_61 = (self.secondStage.secondConcat.firstSub.
Mconv2_stage1_L2_0.weight)
primals_62 = (self.secondStage.secondConcat.firstSub.
Mconv2_stage1_L2_0.bias)
primals_63 = (self.secondStage.secondConcat.firstSub.
Mprelu2_stage1_L2_0.weight)
primals_64 = (self.secondStage.secondConcat.secondSub.
Mconv2_stage1_L2_1.weight)
primals_65 = (self.secondStage.secondConcat.secondSub.
Mconv2_stage1_L2_1.bias)
primals_66 = (self.secondStage.secondConcat.secondSub.
Mprelu2_stage1_L2_1.weight)
primals_67 = (self.secondStage.secondConcat.thirdSub.
Mconv2_stage1_L2_2.weight)
primals_68 = (self.secondStage.secondConcat.thirdSub.
Mconv2_stage1_L2_2.bias)
primals_69 = (self.secondStage.secondConcat.thirdSub.
Mprelu2_stage1_L2_2.weight)
primals_70 = (self.secondStage.thirdConcat.firstSub.
Mconv3_stage1_L2_0.weight)
primals_71 = (self.secondStage.thirdConcat.firstSub.
Mconv3_stage1_L2_0.bias)
primals_72 = (self.secondStage.thirdConcat.firstSub.
Mprelu3_stage1_L2_0.weight)
primals_73 = (self.secondStage.thirdConcat.secondSub.
Mconv3_stage1_L2_1.weight)
primals_74 = (self.secondStage.thirdConcat.secondSub.
Mconv3_stage1_L2_1.bias)
primals_75 = (self.secondStage.thirdConcat.secondSub.
Mprelu3_stage1_L2_1.weight)
primals_76 = (self.secondStage.thirdConcat.thirdSub.
Mconv3_stage1_L2_2.weight)
primals_77 = (self.secondStage.thirdConcat.thirdSub.
Mconv3_stage1_L2_2.bias)
primals_78 = (self.secondStage.thirdConcat.thirdSub.
Mprelu3_stage1_L2_2.weight)
primals_79 = (self.secondStage.fourthConcat.firstSub.
Mconv4_stage1_L2_0.weight)
primals_80 = (self.secondStage.fourthConcat.firstSub.
Mconv4_stage1_L2_0.bias)
primals_81 = (self.secondStage.fourthConcat.firstSub.
Mprelu4_stage1_L2_0.weight)
primals_82 = (self.secondStage.fourthConcat.secondSub.
Mconv4_stage1_L2_1.weight)
primals_83 = (self.secondStage.fourthConcat.secondSub.
Mconv4_stage1_L2_1.bias)
primals_84 = (self.secondStage.fourthConcat.secondSub.
Mprelu4_stage1_L2_1.weight)
primals_85 = (self.secondStage.fourthConcat.thirdSub.
Mconv4_stage1_L2_2.weight)
primals_86 = (self.secondStage.fourthConcat.thirdSub.
Mconv4_stage1_L2_2.bias)
primals_87 = (self.secondStage.fourthConcat.thirdSub.
Mprelu4_stage1_L2_2.weight)
primals_88 = (self.secondStage.fifthConcat.firstSub.
Mconv5_stage1_L2_0.weight)
primals_89 = (self.secondStage.fifthConcat.firstSub.
Mconv5_stage1_L2_0.bias)
primals_90 = (self.secondStage.fifthConcat.firstSub.
Mprelu5_stage1_L2_0.weight)
primals_91 = (self.secondStage.fifthConcat.secondSub.
Mconv5_stage1_L2_1.weight)
primals_92 = (self.secondStage.fifthConcat.secondSub.
Mconv5_stage1_L2_1.bias)
primals_93 = (self.secondStage.fifthConcat.secondSub.
Mprelu5_stage1_L2_1.weight)
primals_94 = (self.secondStage.fifthConcat.thirdSub.
Mconv5_stage1_L2_2.weight)
primals_95 = (self.secondStage.fifthConcat.thirdSub.
Mconv5_stage1_L2_2.bias)
primals_96 = (self.secondStage.fifthConcat.thirdSub.
Mprelu5_stage1_L2_2.weight)
primals_97 = self.secondStage.afterConcatsFirst.Mconv6_stage1_L2.weight
primals_98 = self.secondStage.afterConcatsFirst.Mconv6_stage1_L2.bias
primals_99 = (self.secondStage.afterConcatsFirst.Mprelu6_stage1_L2.
weight)
primals_100 = (self.secondStage.afterConcatsSecond.Mconv7_stage1_L2
.weight)
primals_101 = self.secondStage.afterConcatsSecond.Mconv7_stage1_L2.bias
primals_102 = (self.thirdStage.firstConcat.firstSub.
Mconv1_stage2_L2_0.weight)
primals_103 = (self.thirdStage.firstConcat.firstSub.
Mconv1_stage2_L2_0.bias)
primals_104 = (self.thirdStage.firstConcat.firstSub.
Mprelu1_stage2_L2_0.weight)
primals_105 = (self.thirdStage.firstConcat.secondSub.
Mconv1_stage2_L2_1.weight)
primals_106 = (self.thirdStage.firstConcat.secondSub.
Mconv1_stage2_L2_1.bias)
primals_107 = (self.thirdStage.firstConcat.secondSub.
Mprelu1_stage2_L2_1.weight)
primals_108 = (self.thirdStage.firstConcat.thirdSub.
Mconv1_stage2_L2_2.weight)
primals_109 = (self.thirdStage.firstConcat.thirdSub.
Mconv1_stage2_L2_2.bias)
primals_110 = (self.thirdStage.firstConcat.thirdSub.
Mprelu1_stage2_L2_2.weight)
primals_111 = (self.thirdStage.secondConcat.firstSub.
Mconv2_stage2_L2_0.weight)
primals_112 = (self.thirdStage.secondConcat.firstSub.
Mconv2_stage2_L2_0.bias)
primals_113 = (self.thirdStage.secondConcat.firstSub.
Mprelu2_stage2_L2_0.weight)
primals_114 = (self.thirdStage.secondConcat.secondSub.
Mconv2_stage2_L2_1.weight)
primals_115 = (self.thirdStage.secondConcat.secondSub.
Mconv2_stage2_L2_1.bias)
primals_116 = (self.thirdStage.secondConcat.secondSub.
Mprelu2_stage2_L2_1.weight)
primals_117 = (self.thirdStage.secondConcat.thirdSub.
Mconv2_stage2_L2_2.weight)
primals_118 = (self.thirdStage.secondConcat.thirdSub.
Mconv2_stage2_L2_2.bias)
primals_119 = (self.thirdStage.secondConcat.thirdSub.
Mprelu2_stage2_L2_2.weight)
primals_120 = (self.thirdStage.thirdConcat.firstSub.
Mconv3_stage2_L2_0.weight)
primals_121 = (self.thirdStage.thirdConcat.firstSub.
Mconv3_stage2_L2_0.bias)
primals_122 = (self.thirdStage.thirdConcat.firstSub.
Mprelu3_stage2_L2_0.weight)
primals_123 = (self.thirdStage.thirdConcat.secondSub.
Mconv3_stage2_L2_1.weight)
primals_124 = (self.thirdStage.thirdConcat.secondSub.
Mconv3_stage2_L2_1.bias)
primals_125 = (self.thirdStage.thirdConcat.secondSub.
Mprelu3_stage2_L2_1.weight)
primals_126 = (self.thirdStage.thirdConcat.thirdSub.
Mconv3_stage2_L2_2.weight)
primals_127 = (self.thirdStage.thirdConcat.thirdSub.
Mconv3_stage2_L2_2.bias)
primals_128 = (self.thirdStage.thirdConcat.thirdSub.
Mprelu3_stage2_L2_2.weight)
primals_129 = (self.thirdStage.fourthConcat.firstSub.
Mconv4_stage2_L2_0.weight)
primals_130 = (self.thirdStage.fourthConcat.firstSub.
Mconv4_stage2_L2_0.bias)
primals_131 = (self.thirdStage.fourthConcat.firstSub.
Mprelu4_stage2_L2_0.weight)
primals_132 = (self.thirdStage.fourthConcat.secondSub.
Mconv4_stage2_L2_1.weight)
primals_133 = (self.thirdStage.fourthConcat.secondSub.
Mconv4_stage2_L2_1.bias)
primals_134 = (self.thirdStage.fourthConcat.secondSub.
Mprelu4_stage2_L2_1.weight)
primals_135 = (self.thirdStage.fourthConcat.thirdSub.
Mconv4_stage2_L2_2.weight)
primals_136 = (self.thirdStage.fourthConcat.thirdSub.
Mconv4_stage2_L2_2.bias)
primals_137 = (self.thirdStage.fourthConcat.thirdSub.
Mprelu4_stage2_L2_2.weight)
primals_138 = (self.thirdStage.fifthConcat.firstSub.
Mconv5_stage2_L2_0.weight)
primals_139 = (self.thirdStage.fifthConcat.firstSub.
Mconv5_stage2_L2_0.bias)
primals_140 = (self.thirdStage.fifthConcat.firstSub.
Mprelu5_stage2_L2_0.weight)
primals_141 = (self.thirdStage.fifthConcat.secondSub.
Mconv5_stage2_L2_1.weight)
primals_142 = (self.thirdStage.fifthConcat.secondSub.
Mconv5_stage2_L2_1.bias)
primals_143 = (self.thirdStage.fifthConcat.secondSub.
Mprelu5_stage2_L2_1.weight)
primals_144 = (self.thirdStage.fifthConcat.thirdSub.
Mconv5_stage2_L2_2.weight)
primals_145 = (self.thirdStage.fifthConcat.thirdSub.
Mconv5_stage2_L2_2.bias)
primals_146 = (self.thirdStage.fifthConcat.thirdSub.
Mprelu5_stage2_L2_2.weight)
primals_147 = self.thirdStage.afterConcatsFirst.Mconv6_stage2_L2.weight
primals_148 = self.thirdStage.afterConcatsFirst.Mconv6_stage2_L2.bias
primals_149 = (self.thirdStage.afterConcatsFirst.Mprelu6_stage2_L2.
weight)
primals_150 = (self.thirdStage.afterConcatsSecond.Mconv7_stage2_L2.
weight)
primals_151 = self.thirdStage.afterConcatsSecond.Mconv7_stage2_L2.bias
primals_152 = (self.fourthStage.firstConcat.firstSub.
Mconv1_stage3_L2_0.weight)
primals_153 = (self.fourthStage.firstConcat.firstSub.
Mconv1_stage3_L2_0.bias)
primals_154 = (self.fourthStage.firstConcat.firstSub.
Mprelu1_stage3_L2_0.weight)
primals_155 = (self.fourthStage.firstConcat.secondSub.
Mconv1_stage3_L2_1.weight)
primals_156 = (self.fourthStage.firstConcat.secondSub.
Mconv1_stage3_L2_1.bias)
primals_157 = (self.fourthStage.firstConcat.secondSub.
Mprelu1_stage3_L2_1.weight)
primals_158 = (self.fourthStage.firstConcat.thirdSub.
Mconv1_stage3_L2_2.weight)
primals_159 = (self.fourthStage.firstConcat.thirdSub.
Mconv1_stage3_L2_2.bias)
primals_160 = (self.fourthStage.firstConcat.thirdSub.
Mprelu1_stage3_L2_2.weight)
primals_161 = (self.fourthStage.secondConcat.firstSub.
Mconv2_stage3_L2_0.weight)
primals_162 = (self.fourthStage.secondConcat.firstSub.
Mconv2_stage3_L2_0.bias)
primals_163 = (self.fourthStage.secondConcat.firstSub.
Mprelu2_stage3_L2_0.weight)
primals_164 = (self.fourthStage.secondConcat.secondSub.
Mconv2_stage3_L2_1.weight)
primals_165 = (self.fourthStage.secondConcat.secondSub.
Mconv2_stage3_L2_1.bias)
primals_166 = (self.fourthStage.secondConcat.secondSub.
Mprelu2_stage3_L2_1.weight)
primals_167 = (self.fourthStage.secondConcat.thirdSub.
Mconv2_stage3_L2_2.weight)
primals_168 = (self.fourthStage.secondConcat.thirdSub.
Mconv2_stage3_L2_2.bias)
primals_169 = (self.fourthStage.secondConcat.thirdSub.
Mprelu2_stage3_L2_2.weight)
primals_170 = (self.fourthStage.thirdConcat.firstSub.
Mconv3_stage3_L2_0.weight)
primals_171 = (self.fourthStage.thirdConcat.firstSub.
Mconv3_stage3_L2_0.bias)
primals_172 = (self.fourthStage.thirdConcat.firstSub.
Mprelu3_stage3_L2_0.weight)
primals_173 = (self.fourthStage.thirdConcat.secondSub.
Mconv3_stage3_L2_1.weight)
primals_174 = (self.fourthStage.thirdConcat.secondSub.
Mconv3_stage3_L2_1.bias)
primals_175 = (self.fourthStage.thirdConcat.secondSub.
Mprelu3_stage3_L2_1.weight)
primals_176 = (self.fourthStage.thirdConcat.thirdSub.
Mconv3_stage3_L2_2.weight)
primals_177 = (self.fourthStage.thirdConcat.thirdSub.
Mconv3_stage3_L2_2.bias)
primals_178 = (self.fourthStage.thirdConcat.thirdSub.
Mprelu3_stage3_L2_2.weight)
primals_179 = (self.fourthStage.fourthConcat.firstSub.
Mconv4_stage3_L2_0.weight)
primals_180 = (self.fourthStage.fourthConcat.firstSub.
Mconv4_stage3_L2_0.bias)
primals_181 = (self.fourthStage.fourthConcat.firstSub.
Mprelu4_stage3_L2_0.weight)
primals_182 = (self.fourthStage.fourthConcat.secondSub.
Mconv4_stage3_L2_1.weight)
primals_183 = (self.fourthStage.fourthConcat.secondSub.
Mconv4_stage3_L2_1.bias)
primals_184 = (self.fourthStage.fourthConcat.secondSub.
Mprelu4_stage3_L2_1.weight)
primals_185 = (self.fourthStage.fourthConcat.thirdSub.
Mconv4_stage3_L2_2.weight)
primals_186 = (self.fourthStage.fourthConcat.thirdSub.
Mconv4_stage3_L2_2.bias)
primals_187 = (self.fourthStage.fourthConcat.thirdSub.
Mprelu4_stage3_L2_2.weight)
primals_188 = (self.fourthStage.fifthConcat.firstSub.
Mconv5_stage3_L2_0.weight)
primals_189 = (self.fourthStage.fifthConcat.firstSub.
Mconv5_stage3_L2_0.bias)
primals_190 = (self.fourthStage.fifthConcat.firstSub.
Mprelu5_stage3_L2_0.weight)
primals_191 = (self.fourthStage.fifthConcat.secondSub.
Mconv5_stage3_L2_1.weight)
primals_192 = (self.fourthStage.fifthConcat.secondSub.
Mconv5_stage3_L2_1.bias)
primals_193 = (self.fourthStage.fifthConcat.secondSub.
Mprelu5_stage3_L2_1.weight)
primals_194 = (self.fourthStage.fifthConcat.thirdSub.
Mconv5_stage3_L2_2.weight)
primals_195 = (self.fourthStage.fifthConcat.thirdSub.
Mconv5_stage3_L2_2.bias)
primals_196 = (self.fourthStage.fifthConcat.thirdSub.
Mprelu5_stage3_L2_2.weight)
primals_197 = (self.fourthStage.afterConcatsFirst.Mconv6_stage3_L2.
weight)
primals_198 = self.fourthStage.afterConcatsFirst.Mconv6_stage3_L2.bias
primals_199 = (self.fourthStage.afterConcatsFirst.Mprelu6_stage3_L2
.weight)
primals_200 = (self.fourthStage.afterConcatsSecond.Mconv7_stage3_L2
.weight)
primals_201 = self.fourthStage.afterConcatsSecond.Mconv7_stage3_L2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12, primals_13, primals_14,
primals_15, primals_16, primals_17, primals_18, primals_19,
primals_20, primals_21, primals_22, primals_23, primals_24,
primals_25, primals_26, primals_27, primals_28, primals_29,
primals_30, primals_31, primals_32, primals_33, primals_34,
primals_35, primals_36, primals_37, primals_38, primals_39,
primals_40, primals_41, primals_42, primals_43, primals_44,
primals_45, primals_46, primals_47, primals_48, primals_49,
primals_50, primals_51, primals_52, primals_53, primals_54,
primals_55, primals_56, primals_57, primals_58, primals_59,
primals_60, primals_61, primals_62, primals_63, primals_64,
primals_65, primals_66, primals_67, primals_68, primals_69,
primals_70, primals_71, primals_72, primals_73, primals_74,
primals_75, primals_76, primals_77, primals_78, primals_79,
primals_80, primals_81, primals_82, primals_83, primals_84,
primals_85, primals_86, primals_87, primals_88, primals_89,
primals_90, primals_91, primals_92, primals_93, primals_94,
primals_95, primals_96, primals_97, primals_98, primals_99,
primals_100, primals_101, primals_102, primals_103, primals_104,
primals_105, primals_106, primals_107, primals_108, primals_109,
primals_110, primals_111, primals_112, primals_113, primals_114,
primals_115, primals_116, primals_117, primals_118, primals_119,
primals_120, primals_121, primals_122, primals_123, primals_124,
primals_125, primals_126, primals_127, primals_128, primals_129,
primals_130, primals_131, primals_132, primals_133, primals_134,
primals_135, primals_136, primals_137, primals_138, primals_139,
primals_140, primals_141, primals_142, primals_143, primals_144,
primals_145, primals_146, primals_147, primals_148, primals_149,
primals_150, primals_151, primals_152, primals_153, primals_154,
primals_155, primals_156, primals_157, primals_158, primals_159,
primals_160, primals_161, primals_162, primals_163, primals_164,
primals_165, primals_166, primals_167, primals_168, primals_169,
primals_170, primals_171, primals_172, primals_173, primals_174,
primals_175, primals_176, primals_177, primals_178, primals_179,
primals_180, primals_181, primals_182, primals_183, primals_184,
primals_185, primals_186, primals_187, primals_188, primals_189,
primals_190, primals_191, primals_192, primals_193, primals_194,
primals_195, primals_196, primals_197, primals_198, primals_199,
primals_200, primals_201])
return output[0]
|
EddieMG/LateTemporalModeling3DCNN
|
L2Part
| false
| 2,363
|
[
"MIT"
] | 0
|
94c87dc1d31d09bc310d0e735a2e55453976cb0d
|
https://github.com/EddieMG/LateTemporalModeling3DCNN/tree/94c87dc1d31d09bc310d0e735a2e55453976cb0d
|
BasicBlock
|
import torch
import torch.nn as nn
import torch.nn.functional as F
def apply_init_(modules):
"""
Initialize NN modules
"""
for m in modules:
if isinstance(m, nn.Conv2d):
nn.init.xavier_uniform_(m.weight)
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
nn.init.constant_(m.weight, 1)
if m.bias is not None:
nn.init.constant_(m.bias, 0)
class Conv2d_tf(nn.Conv2d):
"""
Conv2d with the padding behavior from TF
"""
def __init__(self, *args, **kwargs):
super(Conv2d_tf, self).__init__(*args, **kwargs)
self.padding = kwargs.get('padding', 'SAME')
def _compute_padding(self, input, dim):
input_size = input.size(dim + 2)
filter_size = self.weight.size(dim + 2)
effective_filter_size = (filter_size - 1) * self.dilation[dim] + 1
out_size = (input_size + self.stride[dim] - 1) // self.stride[dim]
total_padding = max(0, (out_size - 1) * self.stride[dim] +
effective_filter_size - input_size)
additional_padding = int(total_padding % 2 != 0)
return additional_padding, total_padding
def forward(self, input):
if self.padding == 'VALID':
return F.conv2d(input, self.weight, self.bias, self.stride,
padding=0, dilation=self.dilation, groups=self.groups)
rows_odd, padding_rows = self._compute_padding(input, dim=0)
cols_odd, padding_cols = self._compute_padding(input, dim=1)
if rows_odd or cols_odd:
input = F.pad(input, [0, cols_odd, 0, rows_odd])
return F.conv2d(input, self.weight, self.bias, self.stride, padding
=(padding_rows // 2, padding_cols // 2), dilation=self.dilation,
groups=self.groups)
class BasicBlock(nn.Module):
"""
Residual Network Block
"""
def __init__(self, n_channels, stride=1):
super(BasicBlock, self).__init__()
self.conv1 = Conv2d_tf(n_channels, n_channels, kernel_size=3,
stride=1, padding=(1, 1))
self.relu = nn.ReLU(inplace=True)
self.conv2 = Conv2d_tf(n_channels, n_channels, kernel_size=3,
stride=1, padding=(1, 1))
self.stride = stride
apply_init_(self.modules())
self.train()
def forward(self, x):
identity = x
out = self.relu(x)
out = self.conv1(out)
out = self.relu(out)
out = self.conv2(out)
out += identity
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'n_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_relu_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = tl.full([1], 0, tl.int32)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(in_out_ptr0 + x3, tmp4, xmask)
@triton.jit
def triton_poi_fused_add_convolution_2(in_out_ptr0, in_ptr0, in_ptr1,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x3, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr0 + x3, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_relu_0[grid(256)](primals_1, buf0, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 4, 4), (64, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_relu_1[grid(256)](buf2, primals_3, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 4, 4, 4), (64, 16, 4, 1))
buf4 = buf3
del buf3
triton_poi_fused_add_convolution_2[grid(256)](buf4, primals_5, buf0,
primals_1, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_5
return buf4, primals_2, primals_4, buf0, buf2
def apply_init_(modules):
"""
Initialize NN modules
"""
for m in modules:
if isinstance(m, nn.Conv2d):
nn.init.xavier_uniform_(m.weight)
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
nn.init.constant_(m.weight, 1)
if m.bias is not None:
nn.init.constant_(m.bias, 0)
class Conv2d_tf(nn.Conv2d):
"""
Conv2d with the padding behavior from TF
"""
def __init__(self, *args, **kwargs):
super(Conv2d_tf, self).__init__(*args, **kwargs)
self.padding = kwargs.get('padding', 'SAME')
def _compute_padding(self, input, dim):
input_size = input.size(dim + 2)
filter_size = self.weight.size(dim + 2)
effective_filter_size = (filter_size - 1) * self.dilation[dim] + 1
out_size = (input_size + self.stride[dim] - 1) // self.stride[dim]
total_padding = max(0, (out_size - 1) * self.stride[dim] +
effective_filter_size - input_size)
additional_padding = int(total_padding % 2 != 0)
return additional_padding, total_padding
def forward(self, input):
if self.padding == 'VALID':
return F.conv2d(input, self.weight, self.bias, self.stride,
padding=0, dilation=self.dilation, groups=self.groups)
rows_odd, padding_rows = self._compute_padding(input, dim=0)
cols_odd, padding_cols = self._compute_padding(input, dim=1)
if rows_odd or cols_odd:
input = F.pad(input, [0, cols_odd, 0, rows_odd])
return F.conv2d(input, self.weight, self.bias, self.stride, padding
=(padding_rows // 2, padding_cols // 2), dilation=self.dilation,
groups=self.groups)
class BasicBlockNew(nn.Module):
"""
Residual Network Block
"""
def __init__(self, n_channels, stride=1):
super(BasicBlockNew, self).__init__()
self.conv1 = Conv2d_tf(n_channels, n_channels, kernel_size=3,
stride=1, padding=(1, 1))
self.relu = nn.ReLU(inplace=True)
self.conv2 = Conv2d_tf(n_channels, n_channels, kernel_size=3,
stride=1, padding=(1, 1))
self.stride = stride
apply_init_(self.modules())
self.train()
def forward(self, input_0):
primals_2 = self.conv1.weight
primals_3 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
IanYHWu/msc_2021
|
BasicBlock
| false
| 2,364
|
[
"MIT"
] | 0
|
0ae09ed392cce5fdf0e85d1f96b7af82900835f8
|
https://github.com/IanYHWu/msc_2021/tree/0ae09ed392cce5fdf0e85d1f96b7af82900835f8
|
InputInjection
|
import torch
import torch.nn as nn
import torch._C
import torch.serialization
class InputInjection(nn.Module):
"""Downsampling module for CGNet."""
def __init__(self, num_downsampling):
super(InputInjection, self).__init__()
self.pool = nn.ModuleList()
for i in range(num_downsampling):
self.pool.append(nn.AvgPool2d(3, stride=2, padding=1))
def forward(self, x):
for pool in self.pool:
x = pool(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_downsampling': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch._C
import torch.serialization
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 2 % 2
x0 = xindex % 2
x3 = xindex // 2
x4 = xindex
tmp0 = -1 + 2 * x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + 2 * x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (-5 + 2 * x0 + 8 * x3), tmp10 & xmask,
eviction_policy='evict_last', other=0.0)
tmp12 = 2 * x0
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp13 & tmp14
tmp16 = tmp5 & tmp15
tmp17 = tl.load(in_ptr0 + (-4 + 2 * x0 + 8 * x3), tmp16 & xmask,
eviction_policy='evict_last', other=0.0)
tmp18 = tmp17 + tmp11
tmp19 = 1 + 2 * x0
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp20 & tmp21
tmp23 = tmp5 & tmp22
tmp24 = tl.load(in_ptr0 + (-3 + 2 * x0 + 8 * x3), tmp23 & xmask,
eviction_policy='evict_last', other=0.0)
tmp25 = tmp24 + tmp18
tmp26 = 2 * x1
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp29 & tmp9
tmp31 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x3), tmp30 & xmask,
eviction_policy='evict_last', other=0.0)
tmp32 = tmp31 + tmp25
tmp33 = tmp29 & tmp15
tmp34 = tl.load(in_ptr0 + (2 * x0 + 8 * x3), tmp33 & xmask,
eviction_policy='evict_last', other=0.0)
tmp35 = tmp34 + tmp32
tmp36 = tmp29 & tmp22
tmp37 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x3), tmp36 & xmask,
eviction_policy='evict_last', other=0.0)
tmp38 = tmp37 + tmp35
tmp39 = 1 + 2 * x1
tmp40 = tmp39 >= tmp1
tmp41 = tmp39 < tmp3
tmp42 = tmp40 & tmp41
tmp43 = tmp42 & tmp9
tmp44 = tl.load(in_ptr0 + (3 + 2 * x0 + 8 * x3), tmp43 & xmask,
eviction_policy='evict_last', other=0.0)
tmp45 = tmp44 + tmp38
tmp46 = tmp42 & tmp15
tmp47 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x3), tmp46 & xmask,
eviction_policy='evict_last', other=0.0)
tmp48 = tmp47 + tmp45
tmp49 = tmp42 & tmp22
tmp50 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x3), tmp49 & xmask,
eviction_policy='evict_last', other=0.0)
tmp51 = tmp50 + tmp48
tmp52 = 1 + -2 * x0 + -2 * x1 + (5 * (5 <= 2 + 2 * x0) + (2 + 2 * x0) *
(2 + 2 * x0 < 5)) * (5 * (5 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 *
x1 < 5)) + -2 * x0 * (5 * (5 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 *
x1 < 5)) + -2 * x1 * (5 * (5 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 + 2 *
x0 < 5)) + 4 * x0 * x1 + (5 * (5 <= 2 + 2 * x0) + (2 + 2 * x0) * (2 +
2 * x0 < 5)) + (5 * (5 <= 2 + 2 * x1) + (2 + 2 * x1) * (2 + 2 * x1 < 5)
)
tmp53 = tmp51 / tmp52
tl.store(out_ptr0 + x4, tmp53, xmask)
@triton.jit
def triton_poi_fused_avg_pool2d_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.full([1], -1, tl.int64)
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = tmp5 & tmp5
tmp7 = tl.load(in_ptr0 + (-3 + 4 * x0), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp8 = tmp1 >= tmp1
tmp9 = tmp1 < tmp3
tmp10 = tmp8 & tmp9
tmp11 = tmp5 & tmp10
tmp12 = tl.load(in_ptr0 + (-2 + 4 * x0), tmp11 & xmask, eviction_policy
='evict_last', other=0.0)
tmp13 = tmp12 + tmp7
tmp14 = tl.full([1], 1, tl.int64)
tmp15 = tmp14 >= tmp1
tmp16 = tmp14 < tmp3
tmp17 = tmp15 & tmp16
tmp18 = tmp5 & tmp17
tmp19 = tl.load(in_ptr0 + (-1 + 4 * x0), tmp18 & xmask, eviction_policy
='evict_last', other=0.0)
tmp20 = tmp19 + tmp13
tmp21 = tmp10 & tmp5
tmp22 = tl.load(in_ptr0 + (-1 + 4 * x0), tmp21 & xmask, eviction_policy
='evict_last', other=0.0)
tmp23 = tmp22 + tmp20
tmp24 = tmp10 & tmp10
tmp25 = tl.load(in_ptr0 + 4 * x0, tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp26 = tmp25 + tmp23
tmp27 = tmp10 & tmp17
tmp28 = tl.load(in_ptr0 + (1 + 4 * x0), tmp27 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp29 = tmp28 + tmp26
tmp30 = tmp17 & tmp5
tmp31 = tl.load(in_ptr0 + (1 + 4 * x0), tmp30 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp32 = tmp31 + tmp29
tmp33 = tmp17 & tmp10
tmp34 = tl.load(in_ptr0 + (2 + 4 * x0), tmp33 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp35 = tmp34 + tmp32
tmp36 = tmp17 & tmp17
tmp37 = tl.load(in_ptr0 + (3 + 4 * x0), tmp36 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp38 = tmp37 + tmp35
tmp39 = tl.full([1], 9, tl.int32)
tmp40 = tmp38 / tmp39
tmp41 = tmp0 < tmp14
tmp42 = tmp2 & tmp41
tmp42 & tmp42
tmp44 = tmp1 < tmp14
tmp45 = tmp8 & tmp44
tmp42 & tmp45
tmp47 = tmp40 + tmp40
tmp48 = tmp14 < tmp14
tmp49 = tmp15 & tmp48
tmp42 & tmp49
tmp51 = tmp40 + tmp47
tmp45 & tmp42
tmp53 = tmp40 + tmp51
tmp45 & tmp45
tmp55 = tmp40 + tmp53
tmp45 & tmp49
tmp57 = tmp40 + tmp55
tmp49 & tmp42
tmp59 = tmp40 + tmp57
tmp49 & tmp45
tmp61 = tmp40 + tmp59
tmp49 & tmp49
tmp63 = tmp40 + tmp61
tmp64 = tmp63 / tmp39
tmp65 = tmp64 + tmp64
tmp66 = tmp64 + tmp65
tmp67 = tmp64 + tmp66
tmp68 = tmp64 + tmp67
tmp69 = tmp64 + tmp68
tmp70 = tmp64 + tmp69
tmp71 = tmp64 + tmp70
tmp72 = tmp64 + tmp71
tmp73 = tmp72 / tmp39
tl.store(in_out_ptr0 + x0, tmp73, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_avg_pool2d_0[grid(64)](arg0_1, buf0, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
buf2 = buf1
del buf1
buf3 = reinterpret_tensor(buf2, (4, 4, 1, 1), (4, 1, 1, 1), 0)
del buf2
triton_poi_fused_avg_pool2d_1[grid(16)](buf3, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf0
return buf3,
class InputInjectionNew(nn.Module):
"""Downsampling module for CGNet."""
def __init__(self, num_downsampling):
super(InputInjectionNew, self).__init__()
self.pool = nn.ModuleList()
for i in range(num_downsampling):
self.pool.append(nn.AvgPool2d(3, stride=2, padding=1))
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
ImportPaddle/APCNet
|
InputInjection
| false
| 2,365
|
[
"MIT"
] | 0
|
68ade1f83827b4cdd60ee4b6ac25454397100316
|
https://github.com/ImportPaddle/APCNet/tree/68ade1f83827b4cdd60ee4b6ac25454397100316
|
MultiHeadAttn
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class MultiHeadAttn(nn.Module):
def __init__(self, n_head, d_model, d_head, dropout, dropatt=0,
pre_lnorm=False):
super(MultiHeadAttn, self).__init__()
self.n_head = n_head
self.d_model = d_model
self.d_head = d_head
self.dropout = dropout
self.q_net = nn.Linear(d_model, n_head * d_head, bias=False)
self.kv_net = nn.Linear(d_model, 2 * n_head * d_head, bias=False)
self.drop = nn.Dropout(dropout)
self.dropatt = nn.Dropout(dropatt)
self.o_net = nn.Linear(n_head * d_head, d_model, bias=False)
self.layer_norm = nn.LayerNorm(d_model)
self.scale = 1 / d_head ** 0.5
self.pre_lnorm = pre_lnorm
def forward(self, h, attn_mask=None, mems=None):
if mems is not None:
c = torch.cat([mems, h], 0)
else:
c = h
if self.pre_lnorm:
c = self.layer_norm(c)
head_q = self.q_net(h)
head_k, head_v = torch.chunk(self.kv_net(c), 2, -1)
head_q = head_q.view(h.size(0), h.size(1), self.n_head, self.d_head)
head_k = head_k.view(c.size(0), c.size(1), self.n_head, self.d_head)
head_v = head_v.view(c.size(0), c.size(1), self.n_head, self.d_head)
attn_score = torch.einsum('ibnd,jbnd->ijbn', (head_q, head_k))
attn_score.mul_(self.scale)
if attn_mask is not None and attn_mask.any().item():
if attn_mask.dim() == 2:
attn_score.masked_fill_(attn_mask[None, :, :, None], -float
('inf'))
elif attn_mask.dim() == 3:
attn_score.masked_fill_(attn_mask[:, :, :, None], -float('inf')
)
attn_prob = F.softmax(attn_score, dim=1)
attn_prob = self.dropatt(attn_prob)
attn_vec = torch.einsum('ijbn,jbnd->ibnd', (attn_prob, head_v))
attn_vec = attn_vec.contiguous().view(attn_vec.size(0), attn_vec.
size(1), self.n_head * self.d_head)
attn_out = self.o_net(attn_vec)
attn_out = self.drop(attn_out)
if self.pre_lnorm:
output = h + attn_out
else:
output = self.layer_norm(h + attn_out)
return output
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'n_head': 4, 'd_model': 4, 'd_head': 4, 'dropout': 0.5}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 16
y1 = yindex // 16
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 32 * y1 + 128 * x2), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp3 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp1 = 0.5
tmp2 = tmp0 * tmp1
tmp4 = tmp3 * tmp1
tmp6 = tmp5 * tmp1
tmp7 = triton_helpers.maximum(tmp4, tmp6)
tmp9 = tmp8 * tmp1
tmp10 = triton_helpers.maximum(tmp7, tmp9)
tmp12 = tmp11 * tmp1
tmp13 = triton_helpers.maximum(tmp10, tmp12)
tmp14 = tmp2 - tmp13
tmp15 = tl_math.exp(tmp14)
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK:
tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y1 = yindex // 4
tmp0 = tl.load(in_ptr0 + (y3 + 16 * x2), xmask & ymask)
tmp1 = tl.load(in_ptr0 + (4 * y1 + 16 * x2), xmask & ymask,
eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * y1 + 16 * x2), xmask & ymask,
eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * y1 + 16 * x2), xmask & ymask,
eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * y1 + 16 * x2), xmask & ymask,
eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + (x2 + 16 * y3), tmp8, xmask & ymask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16 % 4
x3 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + (16 + x0 + 4 * x2 + 32 * x3 + 128 * x1), xmask)
tl.store(out_ptr0 + x4, tmp0, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x2 + 16 * x1), xmask)
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_add_native_layer_norm_5(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp12 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 + tmp8
tmp10 = tmp6 + tmp9
tmp13 = tmp11 + tmp12
tmp14 = tmp10 + tmp13
tmp15 = 4.0
tmp16 = tmp14 / tmp15
tmp17 = tmp2 - tmp16
tmp18 = tmp17 * tmp17
tmp19 = tmp5 - tmp16
tmp20 = tmp19 * tmp19
tmp21 = tmp18 + tmp20
tmp22 = tmp9 - tmp16
tmp23 = tmp22 * tmp22
tmp24 = tmp21 + tmp23
tmp25 = tmp13 - tmp16
tmp26 = tmp25 * tmp25
tmp27 = tmp24 + tmp26
tmp28 = tmp27 / tmp15
tl.store(out_ptr0 + x0, tmp16, xmask)
tl.store(out_ptr1 + x0, tmp28, xmask)
@triton.jit
def triton_poi_fused_add_native_layer_norm_6(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, in_ptr5, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr5 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 - tmp3
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp4 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tl.store(out_ptr0 + x2, tmp13, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (16, 4), (4, 1))
assert_size_stride(primals_3, (32, 4), (4, 1))
assert_size_stride(primals_4, (4, 16), (16, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 16), (16, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 16), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((16, 32), (32, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 32), (1, 4), 0), out=buf1)
del primals_3
buf2 = empty_strided_cuda((4, 4, 4, 4, 1), (64, 16, 4, 1, 1), torch
.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(64, 4)](buf1, buf2, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf0, (16, 4, 4), (4, 64, 1),
0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4, 4, 4), (4, 1, 64, 16), torch.float32)
triton_poi_fused__softmax_1[grid(256)](buf3, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
buf5 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf3
triton_poi_fused__softmax_2[grid(16, 16)](buf4, buf5, 16, 16,
XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
buf6 = reinterpret_tensor(buf4, (4, 4, 4, 4, 1), (64, 16, 4, 1, 1), 0)
del buf4
triton_poi_fused_clone_3[grid(256)](buf1, buf6, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf1
buf7 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf5, (16, 4, 4), (1, 64, 16),
0), reinterpret_tensor(buf6, (16, 4, 4), (16, 4, 1), 0), out=buf7)
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_clone_4[grid(256)](buf7, buf8, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf7
buf9 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf8, (16, 16), (16, 1), 0),
reinterpret_tensor(primals_4, (16, 4), (1, 16), 0), out=buf9)
buf10 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf11 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_add_native_layer_norm_5[grid(16)](primals_1, buf9,
buf10, buf11, 16, XBLOCK=16, num_warps=1, num_stages=1)
buf12 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_add_native_layer_norm_6[grid(64)](primals_1, buf9,
buf10, buf11, primals_5, primals_6, buf12, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf10
del buf11
del primals_6
return buf12, primals_1, primals_5, buf5, reinterpret_tensor(buf8, (16,
16), (16, 1), 0), buf9, primals_4, reinterpret_tensor(buf6, (16, 4,
4), (16, 1, 4), 0), reinterpret_tensor(buf0, (16, 4, 4), (4, 1, 64), 0
), reinterpret_tensor(buf2, (16, 4, 4), (16, 1, 4), 0)
class MultiHeadAttnNew(nn.Module):
def __init__(self, n_head, d_model, d_head, dropout, dropatt=0,
pre_lnorm=False):
super(MultiHeadAttnNew, self).__init__()
self.n_head = n_head
self.d_model = d_model
self.d_head = d_head
self.dropout = dropout
self.q_net = nn.Linear(d_model, n_head * d_head, bias=False)
self.kv_net = nn.Linear(d_model, 2 * n_head * d_head, bias=False)
self.drop = nn.Dropout(dropout)
self.dropatt = nn.Dropout(dropatt)
self.o_net = nn.Linear(n_head * d_head, d_model, bias=False)
self.layer_norm = nn.LayerNorm(d_model)
self.scale = 1 / d_head ** 0.5
self.pre_lnorm = pre_lnorm
def forward(self, input_0):
primals_2 = self.q_net.weight
primals_3 = self.kv_net.weight
primals_4 = self.o_net.weight
primals_5 = self.layer_norm.weight
primals_6 = self.layer_norm.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
HikariNoMJ14/bebopnet-code
|
MultiHeadAttn
| false
| 2,366
|
[
"MIT"
] | 0
|
9dfa800d3e24c53de5dc948b87a7db2bc2919b54
|
https://github.com/HikariNoMJ14/bebopnet-code/tree/9dfa800d3e24c53de5dc948b87a7db2bc2919b54
|
Encoding
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch._C
import torch.serialization
class Encoding(nn.Module):
"""Encoding Layer: a learnable residual encoder.
Input is of shape (batch_size, channels, height, width).
Output is of shape (batch_size, num_codes, channels).
Args:
channels: dimension of the features or feature channels
num_codes: number of code words
"""
def __init__(self, channels, num_codes):
super(Encoding, self).__init__()
self.channels, self.num_codes = channels, num_codes
std = 1.0 / (num_codes * channels) ** 0.5
self.codewords = nn.Parameter(torch.empty(num_codes, channels,
dtype=torch.float).uniform_(-std, std), requires_grad=True)
self.scale = nn.Parameter(torch.empty(num_codes, dtype=torch.float)
.uniform_(-1, 0), requires_grad=True)
@staticmethod
def scaled_l2(x, codewords, scale):
num_codes, channels = codewords.size()
batch_size = x.size(0)
reshaped_scale = scale.view((1, 1, num_codes))
expanded_x = x.unsqueeze(2).expand((batch_size, x.size(1),
num_codes, channels))
reshaped_codewords = codewords.view((1, 1, num_codes, channels))
scaled_l2_norm = reshaped_scale * (expanded_x - reshaped_codewords
).pow(2).sum(dim=3)
return scaled_l2_norm
@staticmethod
def aggregate(assignment_weights, x, codewords):
num_codes, channels = codewords.size()
reshaped_codewords = codewords.view((1, 1, num_codes, channels))
batch_size = x.size(0)
expanded_x = x.unsqueeze(2).expand((batch_size, x.size(1),
num_codes, channels))
encoded_feat = (assignment_weights.unsqueeze(3) * (expanded_x -
reshaped_codewords)).sum(dim=1)
return encoded_feat
def forward(self, x):
assert x.dim() == 4 and x.size(1) == self.channels
batch_size = x.size(0)
x = x.view(batch_size, self.channels, -1).transpose(1, 2).contiguous()
assignment_weights = F.softmax(self.scaled_l2(x, self.codewords,
self.scale), dim=2)
encoded_feat = self.aggregate(assignment_weights, x, self.codewords)
return encoded_feat
def __repr__(self):
repr_str = self.__class__.__name__
repr_str += (
f'(Nx{self.channels}xHxW =>Nx{self.num_codes}x{self.channels})')
return repr_str
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channels': 4, 'num_codes': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch._C
import torch.serialization
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_mul_pow_sub_sum_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4 % 16
x2 = xindex // 64
x4 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr2 + 4 * x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + (16 + x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr2 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr1 + (32 + x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr2 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp15 = tl.load(in_ptr1 + (48 + x1 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp16 = tl.load(in_ptr2 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tmp1 - tmp2
tmp4 = tmp3 * tmp3
tmp7 = tmp5 - tmp6
tmp8 = tmp7 * tmp7
tmp9 = tmp4 + tmp8
tmp12 = tmp10 - tmp11
tmp13 = tmp12 * tmp12
tmp14 = tmp9 + tmp13
tmp17 = tmp15 - tmp16
tmp18 = tmp17 * tmp17
tmp19 = tmp14 + tmp18
tmp20 = tmp0 * tmp19
tl.store(out_ptr0 + x4, tmp20, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_per_fused_mul_sub_sum_3(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 64
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r3 = rindex
x1 = xindex // 4 % 4
x2 = xindex // 16
x0 = xindex % 4
x4 = xindex % 16
x5 = xindex
tmp0 = tl.load(in_ptr0 + (x1 + 4 * r3 + 64 * x2), xmask,
eviction_policy='evict_last', other=0.0)
tmp1 = tl.load(in_ptr1 + (r3 + 16 * x0 + 64 * x2), xmask,
eviction_policy='evict_last', other=0.0)
tmp2 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp3 = tmp1 - tmp2
tmp4 = tmp0 * tmp3
tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
tmp7 = tl.where(xmask, tmp5, 0)
tmp8 = tl.sum(tmp7, 1)[:, None]
tl.store(out_ptr0 + x5, tmp8, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_pow_sub_sum_0[grid(256)](primals_3, primals_1,
primals_2, buf0, 256, XBLOCK=128, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(256)](buf0, buf1, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf2 = buf0
del buf0
triton_poi_fused__softmax_2[grid(256)](buf1, buf2, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del buf1
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_per_fused_mul_sub_sum_3[grid(64)](buf2, primals_1, primals_2,
buf3, 64, 16, XBLOCK=1, num_warps=2, num_stages=1)
del buf2
return buf3, primals_1, primals_2, primals_3
class EncodingNew(nn.Module):
"""Encoding Layer: a learnable residual encoder.
Input is of shape (batch_size, channels, height, width).
Output is of shape (batch_size, num_codes, channels).
Args:
channels: dimension of the features or feature channels
num_codes: number of code words
"""
def __init__(self, channels, num_codes):
super(EncodingNew, self).__init__()
self.channels, self.num_codes = channels, num_codes
std = 1.0 / (num_codes * channels) ** 0.5
self.codewords = nn.Parameter(torch.empty(num_codes, channels,
dtype=torch.float).uniform_(-std, std), requires_grad=True)
self.scale = nn.Parameter(torch.empty(num_codes, dtype=torch.float)
.uniform_(-1, 0), requires_grad=True)
@staticmethod
def scaled_l2(x, codewords, scale):
num_codes, channels = codewords.size()
batch_size = x.size(0)
reshaped_scale = scale.view((1, 1, num_codes))
expanded_x = x.unsqueeze(2).expand((batch_size, x.size(1),
num_codes, channels))
reshaped_codewords = codewords.view((1, 1, num_codes, channels))
scaled_l2_norm = reshaped_scale * (expanded_x - reshaped_codewords
).pow(2).sum(dim=3)
return scaled_l2_norm
@staticmethod
def aggregate(assignment_weights, x, codewords):
num_codes, channels = codewords.size()
reshaped_codewords = codewords.view((1, 1, num_codes, channels))
batch_size = x.size(0)
expanded_x = x.unsqueeze(2).expand((batch_size, x.size(1),
num_codes, channels))
encoded_feat = (assignment_weights.unsqueeze(3) * (expanded_x -
reshaped_codewords)).sum(dim=1)
return encoded_feat
def __repr__(self):
repr_str = self.__class__.__name__
repr_str += (
f'(Nx{self.channels}xHxW =>Nx{self.num_codes}x{self.channels})')
return repr_str
def forward(self, input_0):
primals_2 = self.codewords
primals_3 = self.scale
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
ImportPaddle/APCNet
|
Encoding
| false
| 2,367
|
[
"MIT"
] | 0
|
68ade1f83827b4cdd60ee4b6ac25454397100316
|
https://github.com/ImportPaddle/APCNet/tree/68ade1f83827b4cdd60ee4b6ac25454397100316
|
PositionwiseFeedForward
|
import math
import torch
import torch.distributed
import torch.nn as nn
def gelu(x):
return 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 *
torch.pow(x, 3))))
class PositionwiseFeedForward(nn.Module):
""" A two-layer Feed-Forward-Network with residual layer norm.
Args:
d_model (int): the size of input for the first-layer of the FFN.
d_ff (int): the hidden layer size of the second-layer
of the FNN.
dropout (float): dropout probability in :math:`[0, 1)`.
"""
def __init__(self, d_model, d_ff, dropout=0.1):
super(PositionwiseFeedForward, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.layer_norm = nn.LayerNorm(d_model, eps=1e-06)
self.actv = gelu
self.dropout_1 = nn.Dropout(dropout)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
inter = self.dropout_1(self.actv(self.w_1(self.layer_norm(x))))
output = self.dropout_2(self.w_2(inter))
return output + x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'd_ff': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import math
import torch.distributed
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_native_layer_norm_0(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 4 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 4 * x0), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 4 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp7 = 4.0
tmp8 = tmp6 / tmp7
tmp9 = tmp0 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tmp1 - tmp8
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tmp3 - tmp8
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = tmp5 - tmp8
tmp18 = tmp17 * tmp17
tmp19 = tmp16 + tmp18
tmp20 = tmp19 / tmp7
tmp21 = 1e-06
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp23, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_add_mul_pow_tanh_2(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.5
tmp2 = tmp0 * tmp1
tmp3 = tmp0 * tmp0
tmp4 = tmp3 * tmp0
tmp5 = 0.044715
tmp6 = tmp4 * tmp5
tmp7 = tmp0 + tmp6
tmp8 = 0.7978845608028654
tmp9 = tmp7 * tmp8
tmp10 = libdevice.tanh(tmp9)
tmp11 = 1.0
tmp12 = tmp10 + tmp11
tmp13 = tmp2 * tmp12
tl.store(out_ptr0 + x0, tmp13, xmask)
@triton.jit
def triton_poi_fused_add_3(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
buf1 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
get_raw_stream(0)
triton_poi_fused_native_layer_norm_0[grid(64)](primals_3, buf0,
buf1, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(256)](primals_3, buf0,
buf1, primals_1, primals_2, buf2, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del buf0
del buf1
del primals_1
del primals_2
buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf2, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf3)
del primals_5
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_pow_tanh_2[grid(256)](buf3, buf4, 256,
XBLOCK=256, num_warps=4, num_stages=1)
buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf4, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf5)
buf6 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf5
triton_poi_fused_add_3[grid(256)](buf6, primals_7, primals_3, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_7
return buf6, primals_3, reinterpret_tensor(buf2, (64, 4), (4, 1), 0
), buf3, reinterpret_tensor(buf4, (64, 4), (4, 1), 0
), primals_6, primals_4
def gelu(x):
return 0.5 * x * (1 + torch.tanh(math.sqrt(2 / math.pi) * (x + 0.044715 *
torch.pow(x, 3))))
class PositionwiseFeedForwardNew(nn.Module):
""" A two-layer Feed-Forward-Network with residual layer norm.
Args:
d_model (int): the size of input for the first-layer of the FFN.
d_ff (int): the hidden layer size of the second-layer
of the FNN.
dropout (float): dropout probability in :math:`[0, 1)`.
"""
def __init__(self, d_model, d_ff, dropout=0.1):
super(PositionwiseFeedForwardNew, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.layer_norm = nn.LayerNorm(d_model, eps=1e-06)
self.actv = gelu
self.dropout_1 = nn.Dropout(dropout)
self.dropout_2 = nn.Dropout(dropout)
def forward(self, input_0):
primals_4 = self.w_1.weight
primals_1 = self.w_1.bias
primals_6 = self.w_2.weight
primals_2 = self.w_2.bias
primals_5 = self.layer_norm.weight
primals_7 = self.layer_norm.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
GraphGrailAi/summ-abs-dev
|
PositionwiseFeedForward
| false
| 2,368
|
[
"MIT"
] | 0
|
512f253bf72b6529589b29d06959b560b79f1cde
|
https://github.com/GraphGrailAi/summ-abs-dev/tree/512f253bf72b6529589b29d06959b560b79f1cde
|
DiceLoss
|
import functools
import torch
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch._C
import torch.serialization
def reduce_loss(loss, reduction):
"""Reduce loss as specified.
Args:
loss (Tensor): Elementwise loss tensor.
reduction (str): Options are "none", "mean" and "sum".
Return:
Tensor: Reduced loss tensor.
"""
reduction_enum = F._Reduction.get_enum(reduction)
if reduction_enum == 0:
return loss
elif reduction_enum == 1:
return loss.mean()
elif reduction_enum == 2:
return loss.sum()
def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None):
"""Apply element-wise weight and reduce loss.
Args:
loss (Tensor): Element-wise loss.
weight (Tensor): Element-wise weights.
reduction (str): Same as built-in losses of PyTorch.
avg_factor (float): Average factor when computing the mean of losses.
Returns:
Tensor: Processed loss values.
"""
if weight is not None:
assert weight.dim() == loss.dim()
if weight.dim() > 1:
assert weight.size(1) == 1 or weight.size(1) == loss.size(1)
loss = loss * weight
if avg_factor is None:
loss = reduce_loss(loss, reduction)
elif reduction == 'mean':
loss = loss.sum() / avg_factor
elif reduction != 'none':
raise ValueError('avg_factor can not be used with reduction="sum"')
return loss
def get_class_weight(class_weight):
"""Get class weight for loss function.
Args:
class_weight (list[float] | str | None): If class_weight is a str,
take it as a file name and read from it.
"""
if isinstance(class_weight, str):
if class_weight.endswith('.npy'):
class_weight = np.load(class_weight)
else:
class_weight = mmcv.load(class_weight)
return class_weight
def weighted_loss(loss_func):
"""Create a weighted version of a given loss function.
To use this decorator, the loss function must have the signature like
`loss_func(pred, target, **kwargs)`. The function only needs to compute
element-wise loss without any reduction. This decorator will add weight
and reduction arguments to the function. The decorated function will have
the signature like `loss_func(pred, target, weight=None, reduction='mean',
avg_factor=None, **kwargs)`.
:Example:
>>> import torch
>>> @weighted_loss
>>> def l1_loss(pred, target):
>>> return (pred - target).abs()
>>> pred = torch.Tensor([0, 2, 3])
>>> target = torch.Tensor([1, 1, 1])
>>> weight = torch.Tensor([1, 0, 1])
>>> l1_loss(pred, target)
tensor(1.3333)
>>> l1_loss(pred, target, weight)
tensor(1.)
>>> l1_loss(pred, target, reduction='none')
tensor([1., 1., 2.])
>>> l1_loss(pred, target, weight, avg_factor=2)
tensor(1.5000)
"""
@functools.wraps(loss_func)
def wrapper(pred, target, weight=None, reduction='mean', avg_factor=
None, **kwargs):
loss = loss_func(pred, target, **kwargs)
loss = weight_reduce_loss(loss, weight, reduction, avg_factor)
return loss
return wrapper
@weighted_loss
def binary_dice_loss(pred, target, valid_mask, smooth=1, exponent=2, **kwards):
assert pred.shape[0] == target.shape[0]
pred = pred.reshape(pred.shape[0], -1)
target = target.reshape(target.shape[0], -1)
valid_mask = valid_mask.reshape(valid_mask.shape[0], -1)
num = torch.sum(torch.mul(pred, target) * valid_mask, dim=1) * 2 + smooth
den = torch.sum(pred.pow(exponent) + target.pow(exponent), dim=1) + smooth
return 1 - num / den
@weighted_loss
def dice_loss(pred, target, valid_mask, smooth=1, exponent=2, class_weight=
None, ignore_index=255):
assert pred.shape[0] == target.shape[0]
total_loss = 0
num_classes = pred.shape[1]
for i in range(num_classes):
if i != ignore_index:
dice_loss = binary_dice_loss(pred[:, i], target[..., i],
valid_mask=valid_mask, smooth=smooth, exponent=exponent)
if class_weight is not None:
dice_loss *= class_weight[i]
total_loss += dice_loss
return total_loss / num_classes
class DiceLoss(nn.Module):
"""DiceLoss.
This loss is proposed in `V-Net: Fully Convolutional Neural Networks for
Volumetric Medical Image Segmentation <https://arxiv.org/abs/1606.04797>`_.
Args:
loss_type (str, optional): Binary or multi-class loss.
Default: 'multi_class'. Options are "binary" and "multi_class".
smooth (float): A float number to smooth loss, and avoid NaN error.
Default: 1
exponent (float): An float number to calculate denominator
value: \\sum{x^exponent} + \\sum{y^exponent}. Default: 2.
reduction (str, optional): The method used to reduce the loss. Options
are "none", "mean" and "sum". This parameter only works when
per_image is True. Default: 'mean'.
class_weight (list[float] | str, optional): Weight of each class. If in
str format, read them from a file. Defaults to None.
loss_weight (float, optional): Weight of the loss. Default to 1.0.
ignore_index (int | None): The label index to be ignored. Default: 255.
loss_name (str, optional): Name of the loss item. If you want this loss
item to be included into the backward graph, `loss_` must be the
prefix of the name. Defaults to 'loss_dice'.
"""
def __init__(self, smooth=1, exponent=2, reduction='mean', class_weight
=None, loss_weight=1.0, ignore_index=255, loss_name='loss_dice', **
kwards):
super(DiceLoss, self).__init__()
self.smooth = smooth
self.exponent = exponent
self.reduction = reduction
self.class_weight = get_class_weight(class_weight)
self.loss_weight = loss_weight
self.ignore_index = ignore_index
self._loss_name = loss_name
def forward(self, pred, target, avg_factor=None, reduction_override=
None, **kwards):
assert reduction_override in (None, 'none', 'mean', 'sum')
reduction = (reduction_override if reduction_override else self.
reduction)
if self.class_weight is not None:
class_weight = pred.new_tensor(self.class_weight)
else:
class_weight = None
pred = F.softmax(pred, dim=1)
num_classes = pred.shape[1]
one_hot_target = F.one_hot(torch.clamp(target.long(), 0,
num_classes - 1), num_classes=num_classes)
valid_mask = (target != self.ignore_index).long()
loss = self.loss_weight * dice_loss(pred, one_hot_target,
valid_mask=valid_mask, reduction=reduction, avg_factor=
avg_factor, smooth=self.smooth, exponent=self.exponent,
class_weight=class_weight, ignore_index=self.ignore_index)
return loss
@property
def loss_name(self):
"""Loss Name.
This function must be implemented and will return the name of this
loss function. This name will be used to combine different loss items
by simple sum operation. In addition, if you want this loss item to be
included into the backward graph, `loss_` must be the prefix of the
name.
Returns:
str: The name of this loss item.
"""
return self._loss_name
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import functools
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch._C
import torch.serialization
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_per_fused__to_copy_add_div_mean_mul_ne_pow_rsub_sum_view_2(
in_out_ptr0, in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + 4 * r0, None, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * r0, None, eviction_policy='evict_last')
tmp16 = tl.load(in_ptr1 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp29 = tl.load(in_ptr1 + (2 + 4 * r0), None, eviction_policy='evict_last')
tmp42 = tl.load(in_ptr1 + (3 + 4 * r0), None, eviction_policy='evict_last')
tmp71 = tl.load(in_ptr0 + (1 + 4 * r0), None, eviction_policy='evict_last')
tmp112 = tl.load(in_ptr0 + (2 + 4 * r0), None, eviction_policy='evict_last'
)
tmp153 = tl.load(in_ptr0 + (3 + 4 * r0), None, eviction_policy='evict_last'
)
tmp2 = tmp1.to(tl.int64)
tmp3 = tl.full([1, 1], 0, tl.int64)
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = tl.full([1, 1], 3, tl.int64)
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = tmp6 == tmp3
tmp8 = tmp7.to(tl.int64)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp0 * tmp9
tmp11 = 255.0
tmp12 = tmp1 != tmp11
tmp13 = tmp12.to(tl.int64)
tmp14 = tmp13.to(tl.float32)
tmp15 = tmp10 * tmp14
tmp17 = tmp16.to(tl.int64)
tmp18 = triton_helpers.maximum(tmp17, tmp3)
tmp19 = triton_helpers.minimum(tmp18, tmp5)
tmp20 = tmp19 == tmp3
tmp21 = tmp20.to(tl.int64)
tmp22 = tmp21.to(tl.float32)
tmp23 = tmp0 * tmp22
tmp24 = tmp16 != tmp11
tmp25 = tmp24.to(tl.int64)
tmp26 = tmp25.to(tl.float32)
tmp27 = tmp23 * tmp26
tmp28 = tmp15 + tmp27
tmp30 = tmp29.to(tl.int64)
tmp31 = triton_helpers.maximum(tmp30, tmp3)
tmp32 = triton_helpers.minimum(tmp31, tmp5)
tmp33 = tmp32 == tmp3
tmp34 = tmp33.to(tl.int64)
tmp35 = tmp34.to(tl.float32)
tmp36 = tmp0 * tmp35
tmp37 = tmp29 != tmp11
tmp38 = tmp37.to(tl.int64)
tmp39 = tmp38.to(tl.float32)
tmp40 = tmp36 * tmp39
tmp41 = tmp28 + tmp40
tmp43 = tmp42.to(tl.int64)
tmp44 = triton_helpers.maximum(tmp43, tmp3)
tmp45 = triton_helpers.minimum(tmp44, tmp5)
tmp46 = tmp45 == tmp3
tmp47 = tmp46.to(tl.int64)
tmp48 = tmp47.to(tl.float32)
tmp49 = tmp0 * tmp48
tmp50 = tmp42 != tmp11
tmp51 = tmp50.to(tl.int64)
tmp52 = tmp51.to(tl.float32)
tmp53 = tmp49 * tmp52
tmp54 = tmp41 + tmp53
tmp55 = tmp0 * tmp0
tmp56 = tmp8 * tmp8
tmp57 = tmp56.to(tl.float32)
tmp58 = tmp55 + tmp57
tmp59 = tmp21 * tmp21
tmp60 = tmp59.to(tl.float32)
tmp61 = tmp55 + tmp60
tmp62 = tmp58 + tmp61
tmp63 = tmp34 * tmp34
tmp64 = tmp63.to(tl.float32)
tmp65 = tmp55 + tmp64
tmp66 = tmp62 + tmp65
tmp67 = tmp47 * tmp47
tmp68 = tmp67.to(tl.float32)
tmp69 = tmp55 + tmp68
tmp70 = tmp66 + tmp69
tmp72 = tl.full([1, 1], 1, tl.int64)
tmp73 = tmp6 == tmp72
tmp74 = tmp73.to(tl.int64)
tmp75 = tmp74.to(tl.float32)
tmp76 = tmp71 * tmp75
tmp77 = tmp76 * tmp14
tmp78 = tmp19 == tmp72
tmp79 = tmp78.to(tl.int64)
tmp80 = tmp79.to(tl.float32)
tmp81 = tmp71 * tmp80
tmp82 = tmp81 * tmp26
tmp83 = tmp77 + tmp82
tmp84 = tmp32 == tmp72
tmp85 = tmp84.to(tl.int64)
tmp86 = tmp85.to(tl.float32)
tmp87 = tmp71 * tmp86
tmp88 = tmp87 * tmp39
tmp89 = tmp83 + tmp88
tmp90 = tmp45 == tmp72
tmp91 = tmp90.to(tl.int64)
tmp92 = tmp91.to(tl.float32)
tmp93 = tmp71 * tmp92
tmp94 = tmp93 * tmp52
tmp95 = tmp89 + tmp94
tmp96 = tmp71 * tmp71
tmp97 = tmp74 * tmp74
tmp98 = tmp97.to(tl.float32)
tmp99 = tmp96 + tmp98
tmp100 = tmp79 * tmp79
tmp101 = tmp100.to(tl.float32)
tmp102 = tmp96 + tmp101
tmp103 = tmp99 + tmp102
tmp104 = tmp85 * tmp85
tmp105 = tmp104.to(tl.float32)
tmp106 = tmp96 + tmp105
tmp107 = tmp103 + tmp106
tmp108 = tmp91 * tmp91
tmp109 = tmp108.to(tl.float32)
tmp110 = tmp96 + tmp109
tmp111 = tmp107 + tmp110
tmp113 = tl.full([1, 1], 2, tl.int64)
tmp114 = tmp6 == tmp113
tmp115 = tmp114.to(tl.int64)
tmp116 = tmp115.to(tl.float32)
tmp117 = tmp112 * tmp116
tmp118 = tmp117 * tmp14
tmp119 = tmp19 == tmp113
tmp120 = tmp119.to(tl.int64)
tmp121 = tmp120.to(tl.float32)
tmp122 = tmp112 * tmp121
tmp123 = tmp122 * tmp26
tmp124 = tmp118 + tmp123
tmp125 = tmp32 == tmp113
tmp126 = tmp125.to(tl.int64)
tmp127 = tmp126.to(tl.float32)
tmp128 = tmp112 * tmp127
tmp129 = tmp128 * tmp39
tmp130 = tmp124 + tmp129
tmp131 = tmp45 == tmp113
tmp132 = tmp131.to(tl.int64)
tmp133 = tmp132.to(tl.float32)
tmp134 = tmp112 * tmp133
tmp135 = tmp134 * tmp52
tmp136 = tmp130 + tmp135
tmp137 = tmp112 * tmp112
tmp138 = tmp115 * tmp115
tmp139 = tmp138.to(tl.float32)
tmp140 = tmp137 + tmp139
tmp141 = tmp120 * tmp120
tmp142 = tmp141.to(tl.float32)
tmp143 = tmp137 + tmp142
tmp144 = tmp140 + tmp143
tmp145 = tmp126 * tmp126
tmp146 = tmp145.to(tl.float32)
tmp147 = tmp137 + tmp146
tmp148 = tmp144 + tmp147
tmp149 = tmp132 * tmp132
tmp150 = tmp149.to(tl.float32)
tmp151 = tmp137 + tmp150
tmp152 = tmp148 + tmp151
tmp154 = tmp6 == tmp5
tmp155 = tmp154.to(tl.int64)
tmp156 = tmp155.to(tl.float32)
tmp157 = tmp153 * tmp156
tmp158 = tmp157 * tmp14
tmp159 = tmp19 == tmp5
tmp160 = tmp159.to(tl.int64)
tmp161 = tmp160.to(tl.float32)
tmp162 = tmp153 * tmp161
tmp163 = tmp162 * tmp26
tmp164 = tmp158 + tmp163
tmp165 = tmp32 == tmp5
tmp166 = tmp165.to(tl.int64)
tmp167 = tmp166.to(tl.float32)
tmp168 = tmp153 * tmp167
tmp169 = tmp168 * tmp39
tmp170 = tmp164 + tmp169
tmp171 = tmp45 == tmp5
tmp172 = tmp171.to(tl.int64)
tmp173 = tmp172.to(tl.float32)
tmp174 = tmp153 * tmp173
tmp175 = tmp174 * tmp52
tmp176 = tmp170 + tmp175
tmp177 = tmp153 * tmp153
tmp178 = tmp155 * tmp155
tmp179 = tmp178.to(tl.float32)
tmp180 = tmp177 + tmp179
tmp181 = tmp160 * tmp160
tmp182 = tmp181.to(tl.float32)
tmp183 = tmp177 + tmp182
tmp184 = tmp180 + tmp183
tmp185 = tmp166 * tmp166
tmp186 = tmp185.to(tl.float32)
tmp187 = tmp177 + tmp186
tmp188 = tmp184 + tmp187
tmp189 = tmp172 * tmp172
tmp190 = tmp189.to(tl.float32)
tmp191 = tmp177 + tmp190
tmp192 = tmp188 + tmp191
tmp193 = 2.0
tmp194 = tmp54 * tmp193
tmp195 = 1.0
tmp196 = tmp194 + tmp195
tmp197 = tmp70 + tmp195
tmp198 = tmp196 / tmp197
tmp199 = tmp195 - tmp198
tmp200 = tl.broadcast_to(tmp199, [XBLOCK, RBLOCK])
tmp202 = tl.sum(tmp200, 1)[:, None]
tmp203 = tmp95 * tmp193
tmp204 = tmp203 + tmp195
tmp205 = tmp111 + tmp195
tmp206 = tmp204 / tmp205
tmp207 = tmp195 - tmp206
tmp208 = tl.broadcast_to(tmp207, [XBLOCK, RBLOCK])
tmp210 = tl.sum(tmp208, 1)[:, None]
tmp211 = tmp136 * tmp193
tmp212 = tmp211 + tmp195
tmp213 = tmp152 + tmp195
tmp214 = tmp212 / tmp213
tmp215 = tmp195 - tmp214
tmp216 = tl.broadcast_to(tmp215, [XBLOCK, RBLOCK])
tmp218 = tl.sum(tmp216, 1)[:, None]
tmp219 = tmp176 * tmp193
tmp220 = tmp219 + tmp195
tmp221 = tmp192 + tmp195
tmp222 = tmp220 / tmp221
tmp223 = tmp195 - tmp222
tmp224 = tl.broadcast_to(tmp223, [XBLOCK, RBLOCK])
tmp226 = tl.sum(tmp224, 1)[:, None]
tmp227 = 4.0
tmp228 = tmp202 / tmp227
tmp229 = 0.0
tmp230 = tmp228 + tmp229
tmp231 = tmp210 / tmp227
tmp232 = tmp230 + tmp231
tmp233 = tmp218 / tmp227
tmp234 = tmp232 + tmp233
tmp235 = tmp226 / tmp227
tmp236 = tmp234 + tmp235
tmp237 = 0.25
tmp238 = tmp236 * tmp237
tmp239 = tmp238 / tmp195
tmp240 = tmp239 * tmp195
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp240, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(16)](buf0, buf1, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del buf0
buf10 = empty_strided_cuda((), (), torch.float32)
buf14 = buf10
del buf10
triton_per_fused__to_copy_add_div_mean_mul_ne_pow_rsub_sum_view_2[grid
(1)](buf14, buf1, arg1_1, 1, 4, XBLOCK=1, num_warps=2, num_stages=1
)
del arg1_1
del buf1
return buf14,
def reduce_loss(loss, reduction):
"""Reduce loss as specified.
Args:
loss (Tensor): Elementwise loss tensor.
reduction (str): Options are "none", "mean" and "sum".
Return:
Tensor: Reduced loss tensor.
"""
reduction_enum = F._Reduction.get_enum(reduction)
if reduction_enum == 0:
return loss
elif reduction_enum == 1:
return loss.mean()
elif reduction_enum == 2:
return loss.sum()
def weight_reduce_loss(loss, weight=None, reduction='mean', avg_factor=None):
"""Apply element-wise weight and reduce loss.
Args:
loss (Tensor): Element-wise loss.
weight (Tensor): Element-wise weights.
reduction (str): Same as built-in losses of PyTorch.
avg_factor (float): Average factor when computing the mean of losses.
Returns:
Tensor: Processed loss values.
"""
if weight is not None:
assert weight.dim() == loss.dim()
if weight.dim() > 1:
assert weight.size(1) == 1 or weight.size(1) == loss.size(1)
loss = loss * weight
if avg_factor is None:
loss = reduce_loss(loss, reduction)
elif reduction == 'mean':
loss = loss.sum() / avg_factor
elif reduction != 'none':
raise ValueError('avg_factor can not be used with reduction="sum"')
return loss
def get_class_weight(class_weight):
"""Get class weight for loss function.
Args:
class_weight (list[float] | str | None): If class_weight is a str,
take it as a file name and read from it.
"""
if isinstance(class_weight, str):
if class_weight.endswith('.npy'):
class_weight = np.load(class_weight)
else:
class_weight = mmcv.load(class_weight)
return class_weight
def weighted_loss(loss_func):
"""Create a weighted version of a given loss function.
To use this decorator, the loss function must have the signature like
`loss_func(pred, target, **kwargs)`. The function only needs to compute
element-wise loss without any reduction. This decorator will add weight
and reduction arguments to the function. The decorated function will have
the signature like `loss_func(pred, target, weight=None, reduction='mean',
avg_factor=None, **kwargs)`.
:Example:
>>> import torch
>>> @weighted_loss
>>> def l1_loss(pred, target):
>>> return (pred - target).abs()
>>> pred = torch.Tensor([0, 2, 3])
>>> target = torch.Tensor([1, 1, 1])
>>> weight = torch.Tensor([1, 0, 1])
>>> l1_loss(pred, target)
tensor(1.3333)
>>> l1_loss(pred, target, weight)
tensor(1.)
>>> l1_loss(pred, target, reduction='none')
tensor([1., 1., 2.])
>>> l1_loss(pred, target, weight, avg_factor=2)
tensor(1.5000)
"""
@functools.wraps(loss_func)
def wrapper(pred, target, weight=None, reduction='mean', avg_factor=
None, **kwargs):
loss = loss_func(pred, target, **kwargs)
loss = weight_reduce_loss(loss, weight, reduction, avg_factor)
return loss
return wrapper
@weighted_loss
def binary_dice_loss(pred, target, valid_mask, smooth=1, exponent=2, **kwards):
assert pred.shape[0] == target.shape[0]
pred = pred.reshape(pred.shape[0], -1)
target = target.reshape(target.shape[0], -1)
valid_mask = valid_mask.reshape(valid_mask.shape[0], -1)
num = torch.sum(torch.mul(pred, target) * valid_mask, dim=1) * 2 + smooth
den = torch.sum(pred.pow(exponent) + target.pow(exponent), dim=1) + smooth
return 1 - num / den
@weighted_loss
def dice_loss(pred, target, valid_mask, smooth=1, exponent=2, class_weight=
None, ignore_index=255):
assert pred.shape[0] == target.shape[0]
total_loss = 0
num_classes = pred.shape[1]
for i in range(num_classes):
if i != ignore_index:
dice_loss = binary_dice_loss(pred[:, i], target[..., i],
valid_mask=valid_mask, smooth=smooth, exponent=exponent)
if class_weight is not None:
dice_loss *= class_weight[i]
total_loss += dice_loss
return total_loss / num_classes
class DiceLossNew(nn.Module):
"""DiceLoss.
This loss is proposed in `V-Net: Fully Convolutional Neural Networks for
Volumetric Medical Image Segmentation <https://arxiv.org/abs/1606.04797>`_.
Args:
loss_type (str, optional): Binary or multi-class loss.
Default: 'multi_class'. Options are "binary" and "multi_class".
smooth (float): A float number to smooth loss, and avoid NaN error.
Default: 1
exponent (float): An float number to calculate denominator
value: \\sum{x^exponent} + \\sum{y^exponent}. Default: 2.
reduction (str, optional): The method used to reduce the loss. Options
are "none", "mean" and "sum". This parameter only works when
per_image is True. Default: 'mean'.
class_weight (list[float] | str, optional): Weight of each class. If in
str format, read them from a file. Defaults to None.
loss_weight (float, optional): Weight of the loss. Default to 1.0.
ignore_index (int | None): The label index to be ignored. Default: 255.
loss_name (str, optional): Name of the loss item. If you want this loss
item to be included into the backward graph, `loss_` must be the
prefix of the name. Defaults to 'loss_dice'.
"""
def __init__(self, smooth=1, exponent=2, reduction='mean', class_weight
=None, loss_weight=1.0, ignore_index=255, loss_name='loss_dice', **
kwards):
super(DiceLossNew, self).__init__()
self.smooth = smooth
self.exponent = exponent
self.reduction = reduction
self.class_weight = get_class_weight(class_weight)
self.loss_weight = loss_weight
self.ignore_index = ignore_index
self._loss_name = loss_name
@property
def loss_name(self):
"""Loss Name.
This function must be implemented and will return the name of this
loss function. This name will be used to combine different loss items
by simple sum operation. In addition, if you want this loss item to be
included into the backward graph, `loss_` must be the prefix of the
name.
Returns:
str: The name of this loss item.
"""
return self._loss_name
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
ImportPaddle/APCNet
|
DiceLoss
| false
| 2,369
|
[
"MIT"
] | 0
|
68ade1f83827b4cdd60ee4b6ac25454397100316
|
https://github.com/ImportPaddle/APCNet/tree/68ade1f83827b4cdd60ee4b6ac25454397100316
|
MultiHeadAttention
|
import torch
import torch.nn as nn
import torch.nn.functional as F
def scaled_dot_product_attention(q, k, v, mask):
"""
q: query = (..., seq_len_q, depth)
k: key = (..., seq_len_k, depth)
v: value = (..., seq_len_v, depth_v)
mask: float tensor with shape broadcastable to
(..., seq_len_q, seq_len_k)
must have seq_len_k == seq_len_v
Returns:
output, attention_weights
"""
matmul_qk = torch.matmul(q, torch.transpose(k, -1, -2))
dk = torch.tensor(k.shape[-1], dtype=torch.float32)
scaled_attention_logits = matmul_qk / torch.sqrt(dk)
if mask is not None:
scaled_attention_logits += mask * -1000000000.0
attention_weights = F.softmax(scaled_attention_logits, dim=-1)
output = torch.matmul(attention_weights, v)
return output, attention_weights
class MultiHeadAttention(nn.Module):
def __init__(self, d_model, num_heads):
super(MultiHeadAttention, self).__init__()
self.num_heads = num_heads
self.d_model = d_model
assert d_model % self.num_heads == 0
self.depth = d_model // self.num_heads
self.wq = nn.Linear(d_model, d_model)
self.wk = nn.Linear(d_model, d_model)
self.wv = nn.Linear(d_model, d_model)
self.linear = nn.Linear(d_model, d_model)
def split_heads(self, x, batch_size):
"""
Split the last dimension into (num_heads, depth).
Transpose the result such that the shape is (batch_size, num_heads, seq_len, depth)
x : (batch_size, seq_len, d_model)
batch_size : int
Returns:
x : (batch_size, num_heads, seq_len, depth)
"""
x = x.view(batch_size, -1, self.num_heads, self.depth)
return x.permute(0, 2, 1, 3)
def forward(self, v, k, q, mask):
batch_size = q.size()[0]
q = self.wq(q)
k = self.wk(k)
v = self.wv(v)
q = self.split_heads(q, batch_size)
k = self.split_heads(k, batch_size)
v = self.split_heads(v, batch_size)
scaled_attention, attention_weights = scaled_dot_product_attention(q,
k, v, mask)
scaled_attention = scaled_attention.permute(0, 2, 1, 3)
concat_attention = scaled_attention.reshape(batch_size, -1, self.
d_model)
output = self.linear(concat_attention)
return output, attention_weights
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4]), torch.rand([4, 4, 16, 16])]
def get_init_inputs():
return [[], {'d_model': 4, 'num_heads': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 64 * y1), xmask & ymask)
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_per_fused__softmax_add_mul_1(in_ptr0, in_ptr1, out_ptr2, xnumel,
rnumel, XBLOCK: tl.constexpr):
xnumel = 256
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (r1 + 16 * x0), xmask, other=0.0)
tmp2 = -1000000000.0
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
tmp7 = tl.where(xmask, tmp5, float('-inf'))
tmp8 = triton_helpers.max2(tmp7, 1)[:, None]
tmp9 = tmp4 - tmp8
tmp10 = tl_math.exp(tmp9)
tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp13 = tl.where(xmask, tmp11, 0)
tmp14 = tl.sum(tmp13, 1)[:, None]
tmp15 = tmp10 / tmp14
tl.store(out_ptr2 + (r1 + 16 * x0), tmp15, xmask)
@triton.jit
def triton_poi_fused_clone_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 16
y1 = yindex // 16
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 16 * x2 + 64 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_add_3(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12
) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_10, (4, 4, 16, 16), (1024, 256, 16, 1))
assert_size_stride(primals_11, (4, 4), (4, 1))
assert_size_stride(primals_12, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_6, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_9, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
del primals_7
buf3 = empty_strided_cuda((4, 4, 16, 1), (64, 16, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 16)](buf0, primals_3, buf3, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_3
buf4 = reinterpret_tensor(buf0, (4, 4, 1, 16), (64, 16, 16, 1), 0)
del buf0
triton_poi_fused_clone_0[grid(16, 16)](buf1, primals_5, buf4, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((16, 16, 16), (256, 16, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 16, 1), (16, 1, 0),
0), reinterpret_tensor(buf4, (16, 1, 16), (16, 0, 1), 0), out=buf5)
buf8 = empty_strided_cuda((4, 4, 16, 16), (1024, 256, 16, 1), torch
.float32)
triton_per_fused__softmax_add_mul_1[grid(256)](buf5, primals_10,
buf8, 256, 16, XBLOCK=128, num_warps=8, num_stages=1)
del buf5
del primals_10
buf9 = reinterpret_tensor(buf1, (4, 4, 16, 1), (64, 16, 1, 1), 0)
del buf1
triton_poi_fused_clone_0[grid(16, 16)](buf2, primals_8, buf9, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del primals_8
buf10 = reinterpret_tensor(buf2, (16, 16, 1), (16, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf8, (16, 16, 16), (256, 16,
1), 0), reinterpret_tensor(buf9, (16, 16, 1), (16, 1, 0), 0),
out=buf10)
buf11 = empty_strided_cuda((4, 16, 4), (64, 4, 1), torch.float32)
triton_poi_fused_clone_2[grid(64, 4)](buf10, buf11, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
buf12 = reinterpret_tensor(buf10, (64, 4), (4, 1), 0)
del buf10
extern_kernels.mm(reinterpret_tensor(buf11, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_11, (4, 4), (1, 4), 0), out=buf12)
buf13 = reinterpret_tensor(buf12, (4, 16, 4), (64, 4, 1), 0)
del buf12
triton_poi_fused_add_3[grid(256)](buf13, primals_12, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_12
return buf13, buf8, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_6, (64, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (64, 4), (4, 1), 0
), buf8, reinterpret_tensor(buf11, (64, 4), (4, 1), 0
), primals_11, reinterpret_tensor(buf9, (16, 1, 16), (16, 1, 1), 0
), reinterpret_tensor(buf3, (16, 1, 16), (16, 1, 1), 0
), reinterpret_tensor(buf4, (16, 16, 1), (16, 1, 16), 0)
def scaled_dot_product_attention(q, k, v, mask):
"""
q: query = (..., seq_len_q, depth)
k: key = (..., seq_len_k, depth)
v: value = (..., seq_len_v, depth_v)
mask: float tensor with shape broadcastable to
(..., seq_len_q, seq_len_k)
must have seq_len_k == seq_len_v
Returns:
output, attention_weights
"""
matmul_qk = torch.matmul(q, torch.transpose(k, -1, -2))
dk = torch.tensor(k.shape[-1], dtype=torch.float32)
scaled_attention_logits = matmul_qk / torch.sqrt(dk)
if mask is not None:
scaled_attention_logits += mask * -1000000000.0
attention_weights = F.softmax(scaled_attention_logits, dim=-1)
output = torch.matmul(attention_weights, v)
return output, attention_weights
class MultiHeadAttentionNew(nn.Module):
def __init__(self, d_model, num_heads):
super(MultiHeadAttentionNew, self).__init__()
self.num_heads = num_heads
self.d_model = d_model
assert d_model % self.num_heads == 0
self.depth = d_model // self.num_heads
self.wq = nn.Linear(d_model, d_model)
self.wk = nn.Linear(d_model, d_model)
self.wv = nn.Linear(d_model, d_model)
self.linear = nn.Linear(d_model, d_model)
def split_heads(self, x, batch_size):
"""
Split the last dimension into (num_heads, depth).
Transpose the result such that the shape is (batch_size, num_heads, seq_len, depth)
x : (batch_size, seq_len, d_model)
batch_size : int
Returns:
x : (batch_size, num_heads, seq_len, depth)
"""
x = x.view(batch_size, -1, self.num_heads, self.depth)
return x.permute(0, 2, 1, 3)
def forward(self, input_0, input_1, input_2, input_3):
primals_2 = self.wq.weight
primals_3 = self.wq.bias
primals_4 = self.wk.weight
primals_5 = self.wk.bias
primals_7 = self.wv.weight
primals_8 = self.wv.bias
primals_11 = self.linear.weight
primals_12 = self.linear.bias
primals_1 = input_0
primals_6 = input_1
primals_9 = input_2
primals_10 = input_3
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12])
return output[0], output[1]
|
IanYHWu/transformers-for-translation
|
MultiHeadAttention
| false
| 2,370
|
[
"MIT"
] | 0
|
b763e58deb2263507eecd2eb569fbaf5c1dd9df8
|
https://github.com/IanYHWu/transformers-for-translation/tree/b763e58deb2263507eecd2eb569fbaf5c1dd9df8
|
BilinearUpsample
|
import torch
from typing import Union
from typing import List
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data
class BilinearUpsample(nn.Module):
"""
Overview:
Upsamples the input to the given member varible scale_factor using mode biliner
Interface:
forward
"""
def __init__(self, scale_factor: 'Union[float, List[float]]') ->None:
"""
Overview:
Init class BilinearUpsample
Arguments:
- scale_factor (:obj:`Union[float, List[float]]`): multiplier for spatial size
"""
super(BilinearUpsample, self).__init__()
self.scale_factor = scale_factor
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
"""
Overview:
Return the upsampled input
Arguments:
- x (:obj:`torch.Tensor`): the input tensor
Returns:
- upsample(:obj:`torch.Tensor`): the upsampled input tensor
"""
return F.interpolate(x, scale_factor=self.scale_factor, mode=
'bilinear', align_corners=False)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'scale_factor': 1.0}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from typing import Union
from typing import List
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(
in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 4
x0 = xindex % 4
x2 = xindex // 16
x4 = xindex
tmp0 = x1
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 + tmp2
tmp4 = 1.0
tmp5 = tmp3 * tmp4
tmp6 = tmp5 - tmp2
tmp7 = 0.0
tmp8 = triton_helpers.maximum(tmp6, tmp7)
tmp9 = tmp8.to(tl.int32)
tmp10 = tl.full([1], 1, tl.int64)
tmp11 = tmp9 + tmp10
tmp12 = tl.full([1], 3, tl.int64)
tmp13 = triton_helpers.minimum(tmp11, tmp12)
tmp14 = x0
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp15 + tmp2
tmp17 = tmp16 * tmp4
tmp18 = tmp17 - tmp2
tmp19 = triton_helpers.maximum(tmp18, tmp7)
tmp20 = tmp19.to(tl.int32)
tmp21 = tmp20 + tmp10
tmp22 = triton_helpers.minimum(tmp21, tmp12)
tmp23 = tl.load(in_ptr0 + (tmp22 + 4 * tmp13 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp24 = tl.load(in_ptr0 + (tmp20 + 4 * tmp13 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp25 = tmp23 - tmp24
tmp26 = tmp20.to(tl.float32)
tmp27 = tmp19 - tmp26
tmp28 = triton_helpers.maximum(tmp27, tmp7)
tmp29 = triton_helpers.minimum(tmp28, tmp4)
tmp30 = tmp25 * tmp29
tmp31 = tmp24 + tmp30
tmp32 = tl.load(in_ptr0 + (tmp20 + 4 * tmp9 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp33 = tl.load(in_ptr0 + (tmp22 + 4 * tmp9 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp34 = tmp33 - tmp32
tmp35 = tmp34 * tmp29
tmp36 = tmp32 + tmp35
tmp37 = tmp31 - tmp36
tmp38 = tmp9.to(tl.float32)
tmp39 = tmp8 - tmp38
tmp40 = triton_helpers.maximum(tmp39, tmp7)
tmp41 = triton_helpers.minimum(tmp40, tmp4)
tmp42 = tmp37 * tmp41
tmp43 = tmp36 + tmp42
tl.store(in_out_ptr0 + x4, tmp43, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf1 = buf0
del buf0
buf2 = buf1
del buf1
get_raw_stream(0)
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
(256)](buf2, arg0_1, 256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf2,
class BilinearUpsampleNew(nn.Module):
"""
Overview:
Upsamples the input to the given member varible scale_factor using mode biliner
Interface:
forward
"""
def __init__(self, scale_factor: 'Union[float, List[float]]') ->None:
"""
Overview:
Init class BilinearUpsample
Arguments:
- scale_factor (:obj:`Union[float, List[float]]`): multiplier for spatial size
"""
super(BilinearUpsampleNew, self).__init__()
self.scale_factor = scale_factor
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Hcnaeg/DI-engine
|
BilinearUpsample
| false
| 2,371
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
SpatialGatherModule
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch._C
import torch.serialization
class SpatialGatherModule(nn.Module):
"""Aggregate the context features according to the initial predicted
probability distribution.
Employ the soft-weighted method to aggregate the context.
"""
def __init__(self, scale):
super(SpatialGatherModule, self).__init__()
self.scale = scale
def forward(self, feats, probs):
"""Forward function."""
batch_size, num_classes, _height, _width = probs.size()
channels = feats.size(1)
probs = probs.view(batch_size, num_classes, -1)
feats = feats.view(batch_size, channels, -1)
feats = feats.permute(0, 2, 1)
probs = F.softmax(self.scale * probs, dim=2)
ocr_context = torch.matmul(probs, feats)
ocr_context = ocr_context.permute(0, 2, 1).contiguous().unsqueeze(3)
return ocr_context
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'scale': 1.0}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch._C
import torch.serialization
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused__softmax_0(in_ptr0, out_ptr2, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.where(xmask, tmp3, float('-inf'))
tmp6 = triton_helpers.max2(tmp5, 1)[:, None]
tmp7 = tmp2 - tmp6
tmp8 = tmp7 * tmp1
tmp9 = tl_math.exp(tmp8)
tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
tmp12 = tl.where(xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tmp14 = tmp9 / tmp13
tl.store(out_ptr2 + (r1 + 16 * x0), tmp14, xmask)
@triton.jit
def triton_poi_fused_clone_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf2 = empty_strided_cuda((4, 4, 16), (64, 16, 1), torch.float32)
get_raw_stream(0)
triton_per_fused__softmax_0[grid(16)](arg0_1, buf2, 16, 16, XBLOCK=
8, num_warps=2, num_stages=1)
del arg0_1
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(buf2, reinterpret_tensor(arg1_1, (4, 16, 4), (64,
1, 16), 0), out=buf3)
del arg1_1
del buf2
buf4 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_clone_1[grid(16, 4)](buf3, buf4, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
del buf3
return reinterpret_tensor(buf4, (4, 4, 4, 1), (16, 4, 1, 1), 0),
class SpatialGatherModuleNew(nn.Module):
"""Aggregate the context features according to the initial predicted
probability distribution.
Employ the soft-weighted method to aggregate the context.
"""
def __init__(self, scale):
super(SpatialGatherModuleNew, self).__init__()
self.scale = scale
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
ImportPaddle/APCNet
|
SpatialGatherModule
| false
| 2,372
|
[
"MIT"
] | 0
|
68ade1f83827b4cdd60ee4b6ac25454397100316
|
https://github.com/ImportPaddle/APCNet/tree/68ade1f83827b4cdd60ee4b6ac25454397100316
|
LabelSmoothCELoss
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data
def one_hot(val: 'torch.LongTensor', num: 'int', num_first: 'bool'=False
) ->torch.FloatTensor:
"""
Overview:
Convert a ``torch.LongTensor`` to one hot encoding.
This implementation can be slightly faster than ``torch.nn.functional.one_hot``
Arguments:
- val (:obj:`torch.LongTensor`): each element contains the state to be encoded, the range should be [0, num-1]
- num (:obj:`int`): number of states of the one hot encoding
- num_first (:obj:`bool`): If ``num_first`` is False, the one hot encoding is added as the last; \\
Otherwise as the first dimension.
Returns:
- one_hot (:obj:`torch.FloatTensor`)
Example:
>>> one_hot(2*torch.ones([2,2]).long(),3)
tensor([[[0., 0., 1.],
[0., 0., 1.]],
[[0., 0., 1.],
[0., 0., 1.]]])
>>> one_hot(2*torch.ones([2,2]).long(),3,num_first=True)
tensor([[[0., 0.], [1., 0.]],
[[0., 1.], [0., 0.]],
[[1., 0.], [0., 1.]]])
"""
assert isinstance(val, torch.Tensor), type(val)
assert val.dtype == torch.long
assert len(val.shape) >= 1
old_shape = val.shape
val_reshape = val.reshape(-1, 1)
ret = torch.zeros(val_reshape.shape[0], num, device=val.device)
index_neg_one = torch.eq(val_reshape, -1).long()
if index_neg_one.sum() != 0:
val_reshape = torch.where(val_reshape != -1, val_reshape, torch.
zeros(val_reshape.shape, device=val.device).long())
try:
ret.scatter_(1, val_reshape, 1)
if index_neg_one.sum() != 0:
ret = ret * (1 - index_neg_one)
except RuntimeError:
raise RuntimeError('value: {}\nnum: {}\t:val_shape: {}\n'.format(
val_reshape, num, val_reshape.shape))
if num_first:
return ret.permute(1, 0).reshape(num, *old_shape)
else:
return ret.reshape(*old_shape, num)
class LabelSmoothCELoss(nn.Module):
"""
Overview:
Label smooth cross entropy loss.
Interfaces:
forward
"""
def __init__(self, ratio: 'float') ->None:
super().__init__()
self.ratio = ratio
def forward(self, logits: 'torch.Tensor', labels: 'torch.LongTensor'
) ->torch.Tensor:
"""
Overview:
Calculate label smooth cross entropy loss.
Arguments:
- logits (:obj:`torch.Tensor`): Predicted logits.
- labels (:obj:`torch.LongTensor`): Ground truth.
Returns:
- loss (:obj:`torch.Tensor`): Calculated loss.
"""
B, N = logits.shape
val = float(self.ratio) / (N - 1)
one_hot = torch.full_like(logits, val)
one_hot.scatter_(1, labels.unsqueeze(1), 1 - val)
logits = F.log_softmax(logits, dim=1)
return -torch.sum(logits * one_hot.detach()) / B
def get_inputs():
return [torch.rand([4, 4]), torch.ones([4], dtype=torch.int64)]
def get_init_inputs():
return [[], {'ratio': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__log_softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_per_fused__log_softmax_div_mul_neg_scatter_sum_1(in_out_ptr0,
in_ptr0, in_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r2 = rindex
r1 = rindex // 4
r0 = rindex % 4
tmp0 = tl.load(in_ptr0 + r2, None)
tmp1 = tl.load(in_ptr0 + 4 * r1, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (1 + 4 * r1), None, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (2 + 4 * r1), None, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (3 + 4 * r1), None, eviction_policy='evict_last')
tmp14 = tl.load(in_ptr1 + r1, None, eviction_policy='evict_last')
tmp2 = tl_math.exp(tmp1)
tmp4 = tl_math.exp(tmp3)
tmp5 = tmp2 + tmp4
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp5 + tmp7
tmp10 = tl_math.exp(tmp9)
tmp11 = tmp8 + tmp10
tmp12 = tl_math.log(tmp11)
tmp13 = tmp0 - tmp12
tmp15 = r0
tmp16 = tmp14 == tmp15
tmp17 = -0.33333333333333326
tmp18 = 1.3333333333333333
tmp19 = tl.where(tmp16, tmp17, tmp18)
tmp20 = tmp13 * tmp19
tmp21 = tl.broadcast_to(tmp20, [XBLOCK, RBLOCK])
tmp23 = tl.sum(tmp21, 1)[:, None]
tmp24 = -tmp23
tmp25 = 0.25
tmp26 = tmp24 * tmp25
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp26, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
assert_size_stride(arg1_1, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__log_softmax_0[grid(16)](arg0_1, buf0, 16, XBLOCK=
16, num_warps=1, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = buf1
del buf1
triton_per_fused__log_softmax_div_mul_neg_scatter_sum_1[grid(1)](buf2,
buf0, arg1_1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
del arg1_1
del buf0
return buf2,
def one_hot(val: 'torch.LongTensor', num: 'int', num_first: 'bool'=False
) ->torch.FloatTensor:
"""
Overview:
Convert a ``torch.LongTensor`` to one hot encoding.
This implementation can be slightly faster than ``torch.nn.functional.one_hot``
Arguments:
- val (:obj:`torch.LongTensor`): each element contains the state to be encoded, the range should be [0, num-1]
- num (:obj:`int`): number of states of the one hot encoding
- num_first (:obj:`bool`): If ``num_first`` is False, the one hot encoding is added as the last; \\
Otherwise as the first dimension.
Returns:
- one_hot (:obj:`torch.FloatTensor`)
Example:
>>> one_hot(2*torch.ones([2,2]).long(),3)
tensor([[[0., 0., 1.],
[0., 0., 1.]],
[[0., 0., 1.],
[0., 0., 1.]]])
>>> one_hot(2*torch.ones([2,2]).long(),3,num_first=True)
tensor([[[0., 0.], [1., 0.]],
[[0., 1.], [0., 0.]],
[[1., 0.], [0., 1.]]])
"""
assert isinstance(val, torch.Tensor), type(val)
assert val.dtype == torch.long
assert len(val.shape) >= 1
old_shape = val.shape
val_reshape = val.reshape(-1, 1)
ret = torch.zeros(val_reshape.shape[0], num, device=val.device)
index_neg_one = torch.eq(val_reshape, -1).long()
if index_neg_one.sum() != 0:
val_reshape = torch.where(val_reshape != -1, val_reshape, torch.
zeros(val_reshape.shape, device=val.device).long())
try:
ret.scatter_(1, val_reshape, 1)
if index_neg_one.sum() != 0:
ret = ret * (1 - index_neg_one)
except RuntimeError:
raise RuntimeError('value: {}\nnum: {}\t:val_shape: {}\n'.format(
val_reshape, num, val_reshape.shape))
if num_first:
return ret.permute(1, 0).reshape(num, *old_shape)
else:
return ret.reshape(*old_shape, num)
class LabelSmoothCELossNew(nn.Module):
"""
Overview:
Label smooth cross entropy loss.
Interfaces:
forward
"""
def __init__(self, ratio: 'float') ->None:
super().__init__()
self.ratio = ratio
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Hcnaeg/DI-engine
|
LabelSmoothCELoss
| false
| 2,373
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
DiceLoss
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class BinaryDiceLoss(nn.Module):
"""Dice loss of binary class
Args:
smooth: A float number to smooth loss, and avoid NaN error, default: 1
p: Denominator value: \\sum{x^p} + \\sum{y^p}, default: 2
predict: A tensor of shape [N, *]
target: A tensor of shape same with predict
reduction: Reduction method to apply, return mean over batch if 'mean',
return sum if 'sum', return a tensor of shape [N,] if 'none'
Returns:
Loss tensor according to arg reduction
Raise:
Exception if unexpected reduction
"""
def __init__(self, smooth=1, p=2, reduction='sum'):
super(BinaryDiceLoss, self).__init__()
self.smooth = smooth
self.p = p
self.reduction = reduction
def forward(self, predict, target):
assert predict.shape[0] == target.shape[0
], "predict & target batch size don't match"
predict = predict.contiguous().view(predict.shape[0], -1)
target = target.contiguous().view(target.shape[0], -1)
num = torch.sum(torch.mul(predict, target), dim=1) + self.smooth
den = torch.sum(predict.pow(self.p) + target.pow(self.p), dim=1
) + self.smooth
loss = 1 - num / den
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'sum':
return loss.sum()
elif self.reduction == 'none':
return loss
else:
raise Exception('Unexpected reduction {}'.format(self.reduction))
class DiceLoss(nn.Module):
"""Dice loss, need one hot encode input
Args:
weight: An array of shape [num_classes,]
ignore_index: class index to ignore
predict: A tensor of shape [N, C, *]
target: A tensor of same shape with predict
other args pass to BinaryDiceLoss
Return:
same as BinaryDiceLoss
"""
def __init__(self, weight=None, ignore_index=None, **kwargs):
super(DiceLoss, self).__init__()
self.kwargs = kwargs
self.weight = weight
self.ignore_index = ignore_index
def forward(self, predict, target):
assert predict.shape == target.shape, 'predict & target shape do not match'
dice = BinaryDiceLoss(**self.kwargs)
total_loss = 0
predict = F.softmax(predict, dim=1)
for i in range(target.shape[1]):
if i != self.ignore_index:
dice_loss = dice(predict[:, i], target[:, i])
if self.weight is not None:
assert self.weight.shape[0] == target.shape[1
], 'Expect weight shape [{}], get[{}]'.format(target
.shape[1], self.weight.shape[0])
dice_loss *= self.weights[i]
total_loss += dice_loss
return total_loss / target.shape[1]
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_per_fused_add_mul_pow_sum_2(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (r1 + 64 * x0), xmask, other=0.0)
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.where(xmask, tmp3, 0)
tmp6 = tl.sum(tmp5, 1)[:, None]
tmp7 = tmp0 * tmp0
tmp8 = tmp1 * tmp1
tmp9 = tmp7 + tmp8
tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
tmp12 = tl.where(xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tl.store(out_ptr0 + x0, tmp6, xmask)
tl.store(out_ptr1 + x0, tmp13, xmask)
@triton.jit
def triton_per_fused_add_mul_pow_sum_3(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (48 + r1 + 64 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (48 + r1 + 64 * x0), xmask, other=0.0)
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.where(xmask, tmp3, 0)
tmp6 = tl.sum(tmp5, 1)[:, None]
tmp7 = tmp0 * tmp0
tmp8 = tmp1 * tmp1
tmp9 = tmp7 + tmp8
tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
tmp12 = tl.where(xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tl.store(out_ptr0 + x0, tmp6, xmask)
tl.store(out_ptr1 + x0, tmp13, xmask)
@triton.jit
def triton_per_fused_add_mul_pow_sum_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (16 + r1 + 64 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (16 + r1 + 64 * x0), xmask, other=0.0)
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.where(xmask, tmp3, 0)
tmp6 = tl.sum(tmp5, 1)[:, None]
tmp7 = tmp0 * tmp0
tmp8 = tmp1 * tmp1
tmp9 = tmp7 + tmp8
tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
tmp12 = tl.where(xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tl.store(out_ptr0 + x0, tmp6, xmask)
tl.store(out_ptr1 + x0, tmp13, xmask)
@triton.jit
def triton_per_fused_add_mul_pow_sum_5(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (32 + r1 + 64 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (32 + r1 + 64 * x0), xmask, other=0.0)
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.where(xmask, tmp3, 0)
tmp6 = tl.sum(tmp5, 1)[:, None]
tmp7 = tmp0 * tmp0
tmp8 = tmp1 * tmp1
tmp9 = tmp7 + tmp8
tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
tmp12 = tl.where(xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tl.store(out_ptr0 + x0, tmp6, xmask)
tl.store(out_ptr1 + x0, tmp13, xmask)
@triton.jit
def triton_per_fused_add_div_rsub_sum_6(in_out_ptr0, in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, in_ptr7, xnumel, rnumel,
XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 4
xoffset = tl.program_id(0) * XBLOCK
xoffset + tl.arange(0, XBLOCK)[:, None]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp3 = tl.load(in_ptr1 + r0, None)
tmp10 = tl.load(in_ptr2 + r0, None)
tmp12 = tl.load(in_ptr3 + r0, None)
tmp19 = tl.load(in_ptr4 + r0, None)
tmp21 = tl.load(in_ptr5 + r0, None)
tmp28 = tl.load(in_ptr6 + r0, None)
tmp30 = tl.load(in_ptr7 + r0, None)
tmp1 = 1.0
tmp2 = tmp0 + tmp1
tmp4 = tmp3 + tmp1
tmp5 = tmp2 / tmp4
tmp6 = tmp1 - tmp5
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp9 = tl.sum(tmp7, 1)[:, None]
tmp11 = tmp10 + tmp1
tmp13 = tmp12 + tmp1
tmp14 = tmp11 / tmp13
tmp15 = tmp1 - tmp14
tmp16 = tl.broadcast_to(tmp15, [XBLOCK, RBLOCK])
tmp18 = tl.sum(tmp16, 1)[:, None]
tmp20 = tmp19 + tmp1
tmp22 = tmp21 + tmp1
tmp23 = tmp20 / tmp22
tmp24 = tmp1 - tmp23
tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp27 = tl.sum(tmp25, 1)[:, None]
tmp29 = tmp28 + tmp1
tmp31 = tmp30 + tmp1
tmp32 = tmp29 / tmp31
tmp33 = tmp1 - tmp32
tmp34 = tl.broadcast_to(tmp33, [XBLOCK, RBLOCK])
tmp36 = tl.sum(tmp34, 1)[:, None]
tmp37 = 0.0
tmp38 = tmp9 + tmp37
tmp39 = tmp38 + tmp18
tmp40 = tmp39 + tmp27
tmp41 = tmp40 + tmp36
tmp42 = 0.25
tmp43 = tmp41 * tmp42
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp43, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(256)](arg0_1, buf0, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_1[grid(256)](buf0, buf1, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del buf0
buf2 = empty_strided_cuda((4,), (1,), torch.float32)
buf3 = empty_strided_cuda((4,), (1,), torch.float32)
triton_per_fused_add_mul_pow_sum_2[grid(4)](buf1, arg1_1, buf2,
buf3, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
buf11 = empty_strided_cuda((4,), (1,), torch.float32)
buf12 = empty_strided_cuda((4,), (1,), torch.float32)
triton_per_fused_add_mul_pow_sum_3[grid(4)](buf1, arg1_1, buf11,
buf12, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
buf5 = empty_strided_cuda((4,), (1,), torch.float32)
buf6 = empty_strided_cuda((4,), (1,), torch.float32)
triton_per_fused_add_mul_pow_sum_4[grid(4)](buf1, arg1_1, buf5,
buf6, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
buf8 = empty_strided_cuda((4,), (1,), torch.float32)
buf9 = empty_strided_cuda((4,), (1,), torch.float32)
triton_per_fused_add_mul_pow_sum_5[grid(4)](buf1, arg1_1, buf8,
buf9, 4, 16, XBLOCK=1, num_warps=2, num_stages=1)
del arg1_1
del buf1
buf10 = empty_strided_cuda((), (), torch.float32)
buf14 = buf10
del buf10
triton_per_fused_add_div_rsub_sum_6[grid(1)](buf14, buf2, buf3,
buf5, buf6, buf8, buf9, buf11, buf12, 1, 4, XBLOCK=1, num_warps
=2, num_stages=1)
del buf11
del buf12
del buf2
del buf3
del buf5
del buf6
del buf8
del buf9
return buf14,
class BinaryDiceLoss(nn.Module):
"""Dice loss of binary class
Args:
smooth: A float number to smooth loss, and avoid NaN error, default: 1
p: Denominator value: \\sum{x^p} + \\sum{y^p}, default: 2
predict: A tensor of shape [N, *]
target: A tensor of shape same with predict
reduction: Reduction method to apply, return mean over batch if 'mean',
return sum if 'sum', return a tensor of shape [N,] if 'none'
Returns:
Loss tensor according to arg reduction
Raise:
Exception if unexpected reduction
"""
def __init__(self, smooth=1, p=2, reduction='sum'):
super(BinaryDiceLoss, self).__init__()
self.smooth = smooth
self.p = p
self.reduction = reduction
def forward(self, predict, target):
assert predict.shape[0] == target.shape[0
], "predict & target batch size don't match"
predict = predict.contiguous().view(predict.shape[0], -1)
target = target.contiguous().view(target.shape[0], -1)
num = torch.sum(torch.mul(predict, target), dim=1) + self.smooth
den = torch.sum(predict.pow(self.p) + target.pow(self.p), dim=1
) + self.smooth
loss = 1 - num / den
if self.reduction == 'mean':
return loss.mean()
elif self.reduction == 'sum':
return loss.sum()
elif self.reduction == 'none':
return loss
else:
raise Exception('Unexpected reduction {}'.format(self.reduction))
class DiceLossNew(nn.Module):
"""Dice loss, need one hot encode input
Args:
weight: An array of shape [num_classes,]
ignore_index: class index to ignore
predict: A tensor of shape [N, C, *]
target: A tensor of same shape with predict
other args pass to BinaryDiceLoss
Return:
same as BinaryDiceLoss
"""
def __init__(self, weight=None, ignore_index=None, **kwargs):
super(DiceLossNew, self).__init__()
self.kwargs = kwargs
self.weight = weight
self.ignore_index = ignore_index
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
Ignas-S/retinanet-simple
|
DiceLoss
| false
| 2,374
|
[
"Apache-2.0"
] | 0
|
81b17f65fa5278e6b9a4918e6a20b77949a7e87d
|
https://github.com/Ignas-S/retinanet-simple/tree/81b17f65fa5278e6b9a4918e6a20b77949a7e87d
|
AttnScore
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.init as init
def sequence_mask(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max()
return torch.arange(0, max_len).type_as(lengths).repeat(batch_size, 1).lt(
lengths.unsqueeze(1))
class AttnScore(nn.Module):
def __init__(self, input_size, activation=nn.Tanh(), method='dot'):
super(AttnScore, self).__init__()
self.activation = activation
self.input_size = input_size
self.method = method
if method == 'general':
self.linear = nn.Linear(input_size, input_size)
init.uniform(self.linear.weight.data, -0.005, 0.005)
elif method == 'concat':
self.linear_1 = nn.Linear(input_size * 2, input_size)
self.linear_2 = nn.Linear(input_size, 1)
init.uniform(self.linear_1.weight.data, -0.005, 0.005)
init.uniform(self.linear_2.weight.data, -0.005, 0.005)
elif method == 'tri_concat':
self.linear = nn.Linear(input_size * 3, 1)
init.uniform(self.linear.weight.data, -0.005, 0.005)
def forward(self, h1, h2, h1_lens=None, h2_lens=None, normalize=True):
"""
:param h1: b x m x d
:param h2: b x n x d
:return: attn_weights: b x 1 x m
"""
_bsize, seq_l1, _dim = h1.size()
_bsize, seq_l2, _dim = h2.size()
assert h1.size(-1) == self.input_size
assert h2.size(-1) == self.input_size
if self.method == 'dot':
align = h2.bmm(h1.transpose(1, 2))
elif self.method == 'general':
align = h2.bmm(self.linear(h1).transpose(1, 2))
elif self.method == 'concat':
h1 = h1.unsqueeze(1).repeat(1, seq_l2, 1, 1)
h2 = h2.unsqueeze(2).repeat(1, 1, seq_l1, 1)
align = self.linear_2(self.activation(self.linear_1(torch.cat([
h1, h2], dim=3)))).squeeze(-1)
align = F.softmax(align, dim=2)
elif self.method == 'tri_concat':
h1 = h1.unsqueeze(1).repeat(1, seq_l2, 1, 1)
h2 = h2.unsqueeze(2).repeat(1, 1, seq_l1, 1)
align = self.linear(torch.cat([h1, h2, h1 * h2], dim=3)).squeeze(-1
)
if h1_lens is not None:
mask = sequence_mask(h1_lens, max_len=seq_l1).unsqueeze(1)
align.data.masked_fill_(1 - mask, -100000000.0)
if normalize:
attn_weights = F.softmax(align, dim=2)
else:
attn_weights = F.softmax(align, dim=2)
return attn_weights
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.init as init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), (
16, 1, 4), 0), out=buf0)
del arg0_1
del arg1_1
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf2 = buf0
del buf0
triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf1
return buf2,
def sequence_mask(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max()
return torch.arange(0, max_len).type_as(lengths).repeat(batch_size, 1).lt(
lengths.unsqueeze(1))
class AttnScoreNew(nn.Module):
def __init__(self, input_size, activation=nn.Tanh(), method='dot'):
super(AttnScoreNew, self).__init__()
self.activation = activation
self.input_size = input_size
self.method = method
if method == 'general':
self.linear = nn.Linear(input_size, input_size)
init.uniform(self.linear.weight.data, -0.005, 0.005)
elif method == 'concat':
self.linear_1 = nn.Linear(input_size * 2, input_size)
self.linear_2 = nn.Linear(input_size, 1)
init.uniform(self.linear_1.weight.data, -0.005, 0.005)
init.uniform(self.linear_2.weight.data, -0.005, 0.005)
elif method == 'tri_concat':
self.linear = nn.Linear(input_size * 3, 1)
init.uniform(self.linear.weight.data, -0.005, 0.005)
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
IndexFziQ/ASER
|
AttnScore
| false
| 2,375
|
[
"MIT"
] | 0
|
67dd1a2a25cec175c15675cc1f8a63ca065b447e
|
https://github.com/IndexFziQ/ASER/tree/67dd1a2a25cec175c15675cc1f8a63ca065b447e
|
CNN64x3
|
import torch
import torch.nn as nn
class CNN64x3(nn.Module):
def __init__(self, input_channels, output_channels):
super(CNN64x3, self).__init__()
self.conv = nn.Conv2d(in_channels=input_channels, kernel_size=3,
out_channels=output_channels)
self.relu = nn.ReLU()
self.pool = nn.AvgPool2d(5, stride=3, padding=0)
def forward(self, batch_data):
output = self.conv(batch_data)
output = self.relu(output)
output = self.pool(output)
return output
def get_inputs():
return [torch.rand([4, 4, 64, 64])]
def get_init_inputs():
return [[], {'input_channels': 4, 'output_channels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_relu_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 61504
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 3844 % 4
x0 = xindex % 3844
x4 = xindex // 3844
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(out_ptr0 + (x0 + 3872 * x4), tmp4, xmask)
@triton.jit
def triton_poi_fused_avg_pool2d_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 6400
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 20
x1 = xindex // 20 % 20
x2 = xindex // 400
x3 = xindex
tmp0 = tl.load(in_ptr0 + (3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp3 = tl.load(in_ptr0 + (2 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (3 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp7 = tl.load(in_ptr0 + (4 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (62 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (63 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp13 = tl.load(in_ptr0 + (64 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp15 = tl.load(in_ptr0 + (65 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp17 = tl.load(in_ptr0 + (66 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp19 = tl.load(in_ptr0 + (124 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp21 = tl.load(in_ptr0 + (125 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp23 = tl.load(in_ptr0 + (126 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp25 = tl.load(in_ptr0 + (127 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp27 = tl.load(in_ptr0 + (128 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp29 = tl.load(in_ptr0 + (186 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp31 = tl.load(in_ptr0 + (187 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp33 = tl.load(in_ptr0 + (188 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp35 = tl.load(in_ptr0 + (189 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp37 = tl.load(in_ptr0 + (190 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp39 = tl.load(in_ptr0 + (248 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp41 = tl.load(in_ptr0 + (249 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp43 = tl.load(in_ptr0 + (250 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp45 = tl.load(in_ptr0 + (251 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp47 = tl.load(in_ptr0 + (252 + 3 * x0 + 186 * x1 + 3872 * x2), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 + tmp0
tmp4 = tmp3 + tmp2
tmp6 = tmp5 + tmp4
tmp8 = tmp7 + tmp6
tmp10 = tmp9 + tmp8
tmp12 = tmp11 + tmp10
tmp14 = tmp13 + tmp12
tmp16 = tmp15 + tmp14
tmp18 = tmp17 + tmp16
tmp20 = tmp19 + tmp18
tmp22 = tmp21 + tmp20
tmp24 = tmp23 + tmp22
tmp26 = tmp25 + tmp24
tmp28 = tmp27 + tmp26
tmp30 = tmp29 + tmp28
tmp32 = tmp31 + tmp30
tmp34 = tmp33 + tmp32
tmp36 = tmp35 + tmp34
tmp38 = tmp37 + tmp36
tmp40 = tmp39 + tmp38
tmp42 = tmp41 + tmp40
tmp44 = tmp43 + tmp42
tmp46 = tmp45 + tmp44
tmp48 = tmp47 + tmp46
tmp49 = 0.04
tmp50 = tmp48 * tmp49
tl.store(out_ptr0 + x3, tmp50, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 64, 64), (16384, 4096, 64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 62, 62), (15376, 3844, 62, 1))
buf1 = empty_strided_cuda((4, 4, 62, 62), (15488, 3872, 62, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(61504)](buf0, primals_2,
buf1, 61504, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del primals_2
buf2 = empty_strided_cuda((4, 4, 20, 20), (1600, 400, 20, 1), torch
.float32)
triton_poi_fused_avg_pool2d_1[grid(6400)](buf1, buf2, 6400, XBLOCK=
256, num_warps=4, num_stages=1)
return buf2, primals_1, primals_3, buf1
class CNN64x3New(nn.Module):
def __init__(self, input_channels, output_channels):
super(CNN64x3New, self).__init__()
self.conv = nn.Conv2d(in_channels=input_channels, kernel_size=3,
out_channels=output_channels)
self.relu = nn.ReLU()
self.pool = nn.AvgPool2d(5, stride=3, padding=0)
def forward(self, input_0):
primals_1 = self.conv.weight
primals_2 = self.conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
InExp123/pytorch-self_driving_car
|
CNN64x3
| false
| 2,376
|
[
"MIT"
] | 0
|
b4e8c8a76079085bf0471dad1820ee9995cffc74
|
https://github.com/InExp123/pytorch-self_driving_car/tree/b4e8c8a76079085bf0471dad1820ee9995cffc74
|
ATOCAttentionUnit
|
import torch
from typing import Union
import torch.nn as nn
from typing import Dict
import torch.utils.data
class ATOCAttentionUnit(nn.Module):
"""
Overview:
the attention unit of the atoc network. We now implement it as two-layer MLP, same as the original paper
Interface:
__init__, forward
.. note::
"ATOC paper: We use two-layer MLP to implement the attention unit but it is also can be realized by RNN."
"""
def __init__(self, thought_size: 'int', embedding_size: 'int') ->None:
"""
Overview:
init the attention unit according to the size of input args
Arguments:
- thought_size (:obj:`int`): the size of input thought
- embedding_size (:obj:`int`): the size of hidden layers
"""
super(ATOCAttentionUnit, self).__init__()
self._thought_size = thought_size
self._hidden_size = embedding_size
self._output_size = 1
self._act1 = nn.ReLU()
self._fc1 = nn.Linear(self._thought_size, self._hidden_size, bias=True)
self._fc2 = nn.Linear(self._hidden_size, self._hidden_size, bias=True)
self._fc3 = nn.Linear(self._hidden_size, self._output_size, bias=True)
self._act2 = nn.Sigmoid()
def forward(self, data: 'Union[Dict, torch.Tensor]') ->torch.Tensor:
"""
Overview:
forward method take the thought of agents as input and output the prob of these agent\\
being initiator
Arguments:
- x (:obj:`Union[Dict, torch.Tensor`): the input tensor or dict contain the thoughts tensor
- ret (:obj:`torch.Tensor`): the output initiator prob
"""
x = data
if isinstance(data, Dict):
x = data['thought']
x = self._fc1(x)
x = self._act1(x)
x = self._fc2(x)
x = self._act1(x)
x = self._fc3(x)
x = self._act2(x)
return x.squeeze(-1)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'thought_size': 4, 'embedding_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_relu_threshold_backward_0(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_sigmoid_sigmoid_backward_1(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, xmask)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tmp4 = tl.sigmoid(tmp3)
tmp5 = 1.0
tmp6 = tmp5 - tmp4
tmp7 = tmp4 * tmp6
tl.store(in_out_ptr0 + x0, tmp4, xmask)
tl.store(out_ptr0 + x0, tmp7, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (1, 4), (4, 1))
assert_size_stride(primals_7, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf1,
primals_3, buf8, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2)
buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf2
buf7 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf3,
primals_5, buf7, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_6, (4, 1), (1, 4), 0), out=buf4)
buf5 = reinterpret_tensor(buf4, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf4
buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
triton_poi_fused_sigmoid_sigmoid_backward_1[grid(64)](buf5,
primals_7, buf6, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_7
return reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0
), reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(
buf3, (64, 4), (4, 1), 0), buf6, primals_6, buf7, primals_4, buf8
class ATOCAttentionUnitNew(nn.Module):
"""
Overview:
the attention unit of the atoc network. We now implement it as two-layer MLP, same as the original paper
Interface:
__init__, forward
.. note::
"ATOC paper: We use two-layer MLP to implement the attention unit but it is also can be realized by RNN."
"""
def __init__(self, thought_size: 'int', embedding_size: 'int') ->None:
"""
Overview:
init the attention unit according to the size of input args
Arguments:
- thought_size (:obj:`int`): the size of input thought
- embedding_size (:obj:`int`): the size of hidden layers
"""
super(ATOCAttentionUnitNew, self).__init__()
self._thought_size = thought_size
self._hidden_size = embedding_size
self._output_size = 1
self._act1 = nn.ReLU()
self._fc1 = nn.Linear(self._thought_size, self._hidden_size, bias=True)
self._fc2 = nn.Linear(self._hidden_size, self._hidden_size, bias=True)
self._fc3 = nn.Linear(self._hidden_size, self._output_size, bias=True)
self._act2 = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self._fc1.weight
primals_3 = self._fc1.bias
primals_4 = self._fc2.weight
primals_5 = self._fc2.bias
primals_6 = self._fc3.weight
primals_7 = self._fc3.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
Hcnaeg/DI-engine
|
ATOCAttentionUnit
| false
| 2,377
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
PositionwiseFeedForward
|
import torch
import torch.nn as nn
class LayerNorm(nn.Module):
"""
Layer Normalization class
"""
def __init__(self, features, eps=1e-06):
super(LayerNorm, self).__init__()
self.a_2 = nn.Parameter(torch.ones(features))
self.b_2 = nn.Parameter(torch.zeros(features))
self.eps = eps
def forward(self, x):
mean = x.mean(-1, keepdim=True)
std = x.std(-1, keepdim=True)
return self.a_2 * (x - mean) / (std + self.eps) + self.b_2
class PositionwiseFeedForward(nn.Module):
""" A two-layer Feed-Forward-Network with residual layer norm.
Args:
d_model (int): the size of input for the first-layer of the FFN.
d_ff (int): the hidden layer size of the second-layer
of the FNN.
dropout (float): dropout probability(0-1.0).
"""
def __init__(self, d_model, d_ff, dropout=0.1):
super(PositionwiseFeedForward, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.layer_norm = LayerNorm(d_model)
self.dropout_1 = nn.Dropout(dropout)
self.relu = nn.ReLU()
self.dropout_2 = nn.Dropout(dropout)
def forward(self, x):
"""
Layer definition.
Args:
input: [ batch_size, input_len, model_dim ]
Returns:
output: [ batch_size, input_len, model_dim ]
"""
inter = self.dropout_1(self.relu(self.w_1(self.layer_norm(x))))
output = self.dropout_2(self.w_2(inter))
return output + x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_model': 4, 'd_ff': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_div_mean_mul_std_sub_0(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tl.load(in_ptr1 + 4 * x1, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp30 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp8 = tmp6 + tmp7
tmp9 = 4.0
tmp10 = tmp8 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp0 * tmp11
tmp13 = tmp2 - tmp10
tmp14 = tmp13 * tmp13
tmp15 = tmp3 - tmp10
tmp16 = tmp15 * tmp15
tmp17 = tmp14 + tmp16
tmp18 = tmp5 - tmp10
tmp19 = tmp18 * tmp18
tmp20 = tmp17 + tmp19
tmp21 = tmp7 - tmp10
tmp22 = tmp21 * tmp21
tmp23 = tmp20 + tmp22
tmp24 = 3.0
tmp25 = tmp23 / tmp24
tmp26 = libdevice.sqrt(tmp25)
tmp27 = 1e-06
tmp28 = tmp26 + tmp27
tmp29 = tmp12 / tmp28
tmp31 = tmp29 + tmp30
tl.store(out_ptr0 + x2, tmp31, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_1(in_out_ptr0, in_ptr0,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_2(in_out_ptr0, in_ptr0, in_ptr1, xnumel, XBLOCK:
tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tl.store(in_out_ptr0 + x2, tmp4, xmask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_mean_mul_std_sub_0[grid(256)](primals_2,
primals_1, primals_3, buf0, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_2
del primals_3
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_1[grid(256)](buf2,
primals_5, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_5
buf3 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_6, (4, 4), (1, 4), 0), out=buf3)
buf4 = reinterpret_tensor(buf3, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf3
triton_poi_fused_add_2[grid(256)](buf4, primals_7, primals_1, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_7
return buf4, primals_1, reinterpret_tensor(buf0, (64, 4), (4, 1), 0
), reinterpret_tensor(buf2, (64, 4), (4, 1), 0
), primals_6, buf5, primals_4
class LayerNorm(nn.Module):
"""
Layer Normalization class
"""
def __init__(self, features, eps=1e-06):
super(LayerNorm, self).__init__()
self.a_2 = nn.Parameter(torch.ones(features))
self.b_2 = nn.Parameter(torch.zeros(features))
self.eps = eps
def forward(self, x):
mean = x.mean(-1, keepdim=True)
std = x.std(-1, keepdim=True)
return self.a_2 * (x - mean) / (std + self.eps) + self.b_2
class PositionwiseFeedForwardNew(nn.Module):
""" A two-layer Feed-Forward-Network with residual layer norm.
Args:
d_model (int): the size of input for the first-layer of the FFN.
d_ff (int): the hidden layer size of the second-layer
of the FNN.
dropout (float): dropout probability(0-1.0).
"""
def __init__(self, d_model, d_ff, dropout=0.1):
super(PositionwiseFeedForwardNew, self).__init__()
self.w_1 = nn.Linear(d_model, d_ff)
self.w_2 = nn.Linear(d_ff, d_model)
self.layer_norm = LayerNorm(d_model)
self.dropout_1 = nn.Dropout(dropout)
self.relu = nn.ReLU()
self.dropout_2 = nn.Dropout(dropout)
def forward(self, input_0):
primals_4 = self.w_1.weight
primals_2 = self.w_1.bias
primals_6 = self.w_2.weight
primals_3 = self.w_2.bias
primals_5 = self.layer_norm.a_2
primals_7 = self.layer_norm.b_2
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
IndexFziQ/ASER
|
PositionwiseFeedForward
| false
| 2,378
|
[
"MIT"
] | 0
|
67dd1a2a25cec175c15675cc1f8a63ca065b447e
|
https://github.com/IndexFziQ/ASER/tree/67dd1a2a25cec175c15675cc1f8a63ca065b447e
|
LinearFBSP
|
import torch
import numpy as np
from typing import Tuple
import torch.nn.functional as F
from typing import cast
def scale(old_value, old_min, old_max, new_min, new_max):
old_range = old_max - old_min
new_range = new_max - new_min
new_value = (old_value - old_min) * new_range / old_range + new_min
return new_value
class LinearFBSP(torch.nn.Module):
def __init__(self, out_features: 'int', bias: 'bool'=True, normalized:
'bool'=False):
super(LinearFBSP, self).__init__()
self.out_features = out_features
self.normalized = normalized
self.eps = 1e-08
default_dtype = torch.get_default_dtype()
self.register_parameter('m', torch.nn.Parameter(torch.zeros(self.
out_features, dtype=default_dtype)))
self.register_parameter('fb', torch.nn.Parameter(torch.ones(self.
out_features, dtype=default_dtype)))
self.register_parameter('fc', torch.nn.Parameter(torch.arange(self.
out_features, dtype=default_dtype)))
self.register_parameter('bias', torch.nn.Parameter(torch.normal(0.0,
0.5, (self.out_features, 2), dtype=default_dtype) if bias else
cast(torch.nn.Parameter, None)))
self.m.register_hook(lambda grad: grad / (torch.norm(grad, p=float(
'inf')) + self.eps))
self.fb.register_hook(lambda grad: grad / (torch.norm(grad, p=float
('inf')) + self.eps))
self.fc.register_hook(lambda grad: grad / (torch.norm(grad, p=float
('inf')) + self.eps))
@staticmethod
def power(x1: 'torch.Tensor', x2: 'torch.Tensor') ->torch.Tensor:
magnitudes = (x1[..., 0] ** 2 + x1[..., 1] ** 2) ** 0.5
phases = x1[..., 1].atan2(x1[..., 0])
power_real = x2[..., 0]
power_imag = x2[..., 1]
mag_out = (magnitudes ** 2) ** (0.5 * power_real) * torch.exp(-
power_imag * phases)
return mag_out.unsqueeze(-1) * torch.stack(((power_real * phases +
0.5 * power_imag * (magnitudes ** 2).log()).cos(), (power_real *
phases + 0.5 * power_imag * (magnitudes ** 2).log()).sin()), dim=-1
)
@staticmethod
def sinc(x: 'torch.Tensor') ->torch.Tensor:
return torch.where(cast(torch.Tensor, x == 0), torch.ones_like(x),
torch.sin(x) / x)
def _materialize_weights(self, x: 'torch.Tensor') ->Tuple[torch.Tensor,
bool]:
x_is_complex = x.shape[-1] == 2
in_features = x.shape[-1 - int(x_is_complex)]
t = np.pi * torch.linspace(-1.0, 1.0, in_features, dtype=x.dtype,
device=x.device).reshape(1, -1, 1) + self.eps
m = self.m.reshape(-1, 1, 1)
fb = self.fb.reshape(-1, 1, 1)
fc = self.fc.reshape(-1, 1, 1)
kernel = torch.cat((torch.cos(fc * t), -torch.sin(fc * t)), dim=-1)
scale = fb.sqrt()
win = self.sinc(fb * t / (m + self.eps))
win = self.power(torch.cat((win, torch.zeros_like(win)), dim=-1),
torch.cat((m, torch.zeros_like(m)), dim=-1))
weights = scale * torch.cat((win[..., :1] * kernel[..., :1] - win[
..., 1:] * kernel[..., 1:], win[..., :1] * kernel[..., 1:] +
win[..., 1:] * kernel[..., :1]), dim=-1)
if self.normalized:
weights = weights / in_features ** 0.5
return weights, x_is_complex
def forward(self, x: 'torch.Tensor') ->Tuple[torch.Tensor, torch.Tensor]:
weights, x_is_complex = self._materialize_weights(x)
if x_is_complex:
x = torch.stack((F.linear(x[..., 0], weights[..., 0]) - F.
linear(x[..., 1], weights[..., 1]), F.linear(x[..., 0],
weights[..., 1]) + F.linear(x[..., 1], weights[..., 0])),
dim=-1)
else:
x = torch.stack((F.linear(x, weights[..., 0]), F.linear(x,
weights[..., 1])), dim=-1)
if self.bias is not None and self.bias.numel(
) == self.out_features * 2:
x = x + self.bias
return x, weights
def extra_repr(self) ->str:
return 'out_features={}, bias={}, normalized={}'.format(self.
out_features, self.bias is not None and self.bias.numel() ==
self.out_features * 2, self.normalized)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'out_features': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
import numpy as np
from typing import Tuple
from typing import cast
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_linspace_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 2.0
tmp3 = tmp1 < tmp2
tl.store(out_ptr0 + x0, tmp3, xmask)
@triton.jit
def triton_poi_fused_cat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x2 = xindex // 8
x1 = xindex // 2 % 4
x3 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + x2, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp6 = x1
tmp7 = tmp6.to(tl.float32)
tmp8 = 2.0
tmp9 = tmp7 < tmp8
tmp10 = 0.6666666666666666
tmp11 = tmp7 * tmp10
tmp12 = -1.0
tmp13 = tmp11 + tmp12
tmp14 = 3 + -1 * x1
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp15 * tmp10
tmp17 = 1.0
tmp18 = tmp17 - tmp16
tmp19 = tl.where(tmp9, tmp13, tmp18)
tmp20 = 3.141592653589793
tmp21 = tmp19 * tmp20
tmp22 = 1e-08
tmp23 = tmp21 + tmp22
tmp24 = tmp5 * tmp23
tmp25 = tl_math.cos(tmp24)
tmp26 = tl.full(tmp25.shape, 0.0, tmp25.dtype)
tmp27 = tl.where(tmp4, tmp25, tmp26)
tmp28 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp31 = tl.load(in_ptr0 + x2, tmp28 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp32 = tmp31 * tmp23
tmp33 = tl_math.sin(tmp32)
tmp34 = -tmp33
tmp35 = tl.full(tmp34.shape, 0.0, tmp34.dtype)
tmp36 = tl.where(tmp28, tmp34, tmp35)
tmp37 = tl.where(tmp4, tmp27, tmp36)
tl.store(out_ptr0 + x3, tmp37, xmask)
@triton.jit
def triton_poi_fused_cat_2(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x2 = xindex // 8
x1 = xindex // 2 % 4
x3 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + x2, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp6 = x1
tmp7 = tmp6.to(tl.float32)
tmp8 = 2.0
tmp9 = tmp7 < tmp8
tmp10 = 0.6666666666666666
tmp11 = tmp7 * tmp10
tmp12 = -1.0
tmp13 = tmp11 + tmp12
tmp14 = 3 + -1 * x1
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp15 * tmp10
tmp17 = 1.0
tmp18 = tmp17 - tmp16
tmp19 = tl.where(tmp9, tmp13, tmp18)
tmp20 = 3.141592653589793
tmp21 = tmp19 * tmp20
tmp22 = 1e-08
tmp23 = tmp21 + tmp22
tmp24 = tmp5 * tmp23
tmp25 = tl.load(in_ptr1 + x2, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp26 = tmp25 + tmp22
tmp27 = tmp24 / tmp26
tmp28 = 0.0
tmp29 = tmp27 == tmp28
tmp30 = tl_math.sin(tmp27)
tmp31 = tmp30 / tmp27
tmp32 = tl.where(tmp29, tmp17, tmp31)
tmp33 = tl.full(tmp32.shape, 0.0, tmp32.dtype)
tmp34 = tl.where(tmp4, tmp32, tmp33)
tmp35 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp38 = tl.full(tmp28.shape, 0.0, tmp28.dtype)
tmp39 = tl.where(tmp35, tmp28, tmp38)
tmp40 = tl.where(tmp4, tmp34, tmp39)
tl.store(out_ptr0 + x3, tmp40, xmask)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 8
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + x1, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp9 = 0.0
tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
tmp11 = tl.where(tmp6, tmp9, tmp10)
tmp12 = tl.where(tmp4, tmp5, tmp11)
tl.store(out_ptr0 + x2, tmp12, xmask)
@triton.jit
def triton_poi_fused_mul_stack_4(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x2 = xindex // 8
x4 = xindex // 2
x5 = xindex
tmp46 = tl.load(in_ptr1 + 2 * x4, xmask, eviction_policy='evict_last')
tmp48 = tl.load(in_ptr1 + (1 + 2 * x4), xmask, eviction_policy='evict_last'
)
tmp53 = tl.load(in_ptr0 + 2 * x2, xmask, eviction_policy='evict_last')
tmp56 = tl.load(in_ptr0 + (1 + 2 * x2), xmask, eviction_policy='evict_last'
)
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + 2 * x2, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr1 + (1 + 2 * x4), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tl.load(in_ptr1 + 2 * x4, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp8 = libdevice.atan2(tmp6, tmp7)
tmp9 = tmp5 * tmp8
tmp10 = tl.load(in_ptr0 + (1 + 2 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp11 = 0.5
tmp12 = tmp10 * tmp11
tmp13 = tmp7 * tmp7
tmp14 = tmp6 * tmp6
tmp15 = tmp13 + tmp14
tmp16 = libdevice.sqrt(tmp15)
tmp17 = tmp16 * tmp16
tmp18 = tl_math.log(tmp17)
tmp19 = tmp12 * tmp18
tmp20 = tmp9 + tmp19
tmp21 = tl_math.cos(tmp20)
tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
tmp23 = tl.where(tmp4, tmp21, tmp22)
tmp24 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp27 = tl.load(in_ptr0 + 2 * x2, tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp28 = tl.load(in_ptr1 + (1 + 2 * x4), tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp29 = tl.load(in_ptr1 + 2 * x4, tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp30 = libdevice.atan2(tmp28, tmp29)
tmp31 = tmp27 * tmp30
tmp32 = tl.load(in_ptr0 + (1 + 2 * x2), tmp24 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp33 = tmp32 * tmp11
tmp34 = tmp29 * tmp29
tmp35 = tmp28 * tmp28
tmp36 = tmp34 + tmp35
tmp37 = libdevice.sqrt(tmp36)
tmp38 = tmp37 * tmp37
tmp39 = tl_math.log(tmp38)
tmp40 = tmp33 * tmp39
tmp41 = tmp31 + tmp40
tmp42 = tl_math.sin(tmp41)
tmp43 = tl.full(tmp42.shape, 0.0, tmp42.dtype)
tmp44 = tl.where(tmp24, tmp42, tmp43)
tmp45 = tl.where(tmp4, tmp23, tmp44)
tmp47 = tmp46 * tmp46
tmp49 = tmp48 * tmp48
tmp50 = tmp47 + tmp49
tmp51 = libdevice.sqrt(tmp50)
tmp52 = tmp51 * tmp51
tmp54 = tmp53 * tmp11
tmp55 = libdevice.pow(tmp52, tmp54)
tmp57 = -tmp56
tmp58 = libdevice.atan2(tmp48, tmp46)
tmp59 = tmp57 * tmp58
tmp60 = tl_math.exp(tmp59)
tmp61 = tmp55 * tmp60
tmp62 = tmp61 * tmp45
tl.store(out_ptr0 + x5, tmp45, xmask)
tl.store(out_ptr1 + x5, tmp62, xmask)
@triton.jit
def triton_poi_fused_cat_mul_sqrt_5(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2
x4 = xindex
x3 = xindex // 8
tmp27 = tl.load(in_ptr2 + x3, xmask, eviction_policy='evict_last')
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + 2 * x1, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr1 + 2 * x1, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp5 * tmp6
tmp8 = tl.load(in_ptr0 + (1 + 2 * x1), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp9 = tl.load(in_ptr1 + (1 + 2 * x1), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tmp8 * tmp9
tmp11 = tmp7 - tmp10
tmp12 = tl.full(tmp11.shape, 0.0, tmp11.dtype)
tmp13 = tl.where(tmp4, tmp11, tmp12)
tmp14 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp17 = tl.load(in_ptr0 + 2 * x1, tmp14 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp18 = tl.load(in_ptr1 + (1 + 2 * x1), tmp14 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp19 = tmp17 * tmp18
tmp20 = tl.load(in_ptr0 + (1 + 2 * x1), tmp14 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp21 = tl.load(in_ptr1 + 2 * x1, tmp14 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp22 = tmp20 * tmp21
tmp23 = tmp19 + tmp22
tmp24 = tl.full(tmp23.shape, 0.0, tmp23.dtype)
tmp25 = tl.where(tmp14, tmp23, tmp24)
tmp26 = tl.where(tmp4, tmp13, tmp25)
tmp28 = libdevice.sqrt(tmp27)
tmp29 = tmp28 * tmp26
tl.store(out_ptr0 + x4, tmp26, xmask)
tl.store(out_ptr1 + x4, tmp29, xmask)
@triton.jit
def triton_poi_fused_mm_6(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 2 * x0, xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_mm_7(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_add_stack_8(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 512
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x3 = xindex // 2
x4 = xindex % 8
x5 = xindex
tmp11 = tl.load(in_ptr2 + x4, xmask, eviction_policy='evict_last')
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + x3, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp9 = tl.load(in_ptr1 + x3, tmp6 & xmask, eviction_policy='evict_last',
other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tmp12 = tmp10 + tmp11
tl.store(out_ptr0 + x5, tmp12, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4, 2), (2, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4,), (1,), torch.bool)
get_raw_stream(0)
triton_poi_fused_linspace_0[grid(4)](buf0, 4, XBLOCK=4, num_warps=1,
num_stages=1)
buf1 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_cat_1[grid(32)](primals_4, buf1, 32, XBLOCK=32,
num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_cat_2[grid(32)](primals_3, primals_2, buf2, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((4, 1, 2), (2, 2, 1), torch.float32)
triton_poi_fused_cat_3[grid(8)](primals_2, buf3, 8, XBLOCK=8,
num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
buf5 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_mul_stack_4[grid(32)](buf3, buf2, buf4, buf5, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf6 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
buf7 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_cat_mul_sqrt_5[grid(32)](buf5, buf1, primals_3,
buf6, buf7, 32, XBLOCK=32, num_warps=1, num_stages=1)
del buf5
buf8 = empty_strided_cuda((4, 4), (1, 4), torch.float32)
triton_poi_fused_mm_6[grid(16)](buf7, buf8, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf9 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
buf8, out=buf9)
buf10 = buf8
del buf8
triton_poi_fused_mm_7[grid(16)](buf7, buf10, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf11 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
buf10, out=buf11)
del buf10
buf12 = empty_strided_cuda((4, 4, 4, 4, 2), (128, 32, 8, 2, 1),
torch.float32)
triton_poi_fused_add_stack_8[grid(512)](buf9, buf11, primals_5,
buf12, 512, XBLOCK=256, num_warps=4, num_stages=1)
del buf11
del buf9
del primals_5
return (buf12, buf7, primals_2, primals_3, primals_4, buf0, buf1, buf2,
buf3, buf4, buf6, reinterpret_tensor(primals_1, (4, 64), (1, 4), 0))
def scale(old_value, old_min, old_max, new_min, new_max):
old_range = old_max - old_min
new_range = new_max - new_min
new_value = (old_value - old_min) * new_range / old_range + new_min
return new_value
class LinearFBSPNew(torch.nn.Module):
def __init__(self, out_features: 'int', bias: 'bool'=True, normalized:
'bool'=False):
super(LinearFBSPNew, self).__init__()
self.out_features = out_features
self.normalized = normalized
self.eps = 1e-08
default_dtype = torch.get_default_dtype()
self.register_parameter('m', torch.nn.Parameter(torch.zeros(self.
out_features, dtype=default_dtype)))
self.register_parameter('fb', torch.nn.Parameter(torch.ones(self.
out_features, dtype=default_dtype)))
self.register_parameter('fc', torch.nn.Parameter(torch.arange(self.
out_features, dtype=default_dtype)))
self.register_parameter('bias', torch.nn.Parameter(torch.normal(0.0,
0.5, (self.out_features, 2), dtype=default_dtype) if bias else
cast(torch.nn.Parameter, None)))
self.m.register_hook(lambda grad: grad / (torch.norm(grad, p=float(
'inf')) + self.eps))
self.fb.register_hook(lambda grad: grad / (torch.norm(grad, p=float
('inf')) + self.eps))
self.fc.register_hook(lambda grad: grad / (torch.norm(grad, p=float
('inf')) + self.eps))
@staticmethod
def power(x1: 'torch.Tensor', x2: 'torch.Tensor') ->torch.Tensor:
magnitudes = (x1[..., 0] ** 2 + x1[..., 1] ** 2) ** 0.5
phases = x1[..., 1].atan2(x1[..., 0])
power_real = x2[..., 0]
power_imag = x2[..., 1]
mag_out = (magnitudes ** 2) ** (0.5 * power_real) * torch.exp(-
power_imag * phases)
return mag_out.unsqueeze(-1) * torch.stack(((power_real * phases +
0.5 * power_imag * (magnitudes ** 2).log()).cos(), (power_real *
phases + 0.5 * power_imag * (magnitudes ** 2).log()).sin()), dim=-1
)
@staticmethod
def sinc(x: 'torch.Tensor') ->torch.Tensor:
return torch.where(cast(torch.Tensor, x == 0), torch.ones_like(x),
torch.sin(x) / x)
def _materialize_weights(self, x: 'torch.Tensor') ->Tuple[torch.Tensor,
bool]:
x_is_complex = x.shape[-1] == 2
in_features = x.shape[-1 - int(x_is_complex)]
t = np.pi * torch.linspace(-1.0, 1.0, in_features, dtype=x.dtype,
device=x.device).reshape(1, -1, 1) + self.eps
m = self.m.reshape(-1, 1, 1)
fb = self.fb.reshape(-1, 1, 1)
fc = self.fc.reshape(-1, 1, 1)
kernel = torch.cat((torch.cos(fc * t), -torch.sin(fc * t)), dim=-1)
scale = fb.sqrt()
win = self.sinc(fb * t / (m + self.eps))
win = self.power(torch.cat((win, torch.zeros_like(win)), dim=-1),
torch.cat((m, torch.zeros_like(m)), dim=-1))
weights = scale * torch.cat((win[..., :1] * kernel[..., :1] - win[
..., 1:] * kernel[..., 1:], win[..., :1] * kernel[..., 1:] +
win[..., 1:] * kernel[..., :1]), dim=-1)
if self.normalized:
weights = weights / in_features ** 0.5
return weights, x_is_complex
def extra_repr(self) ->str:
return 'out_features={}, bias={}, normalized={}'.format(self.
out_features, self.bias is not None and self.bias.numel() ==
self.out_features * 2, self.normalized)
def forward(self, input_0):
primals_2 = self.m
primals_3 = self.fb
primals_4 = self.fc
primals_5 = self.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0], output[1]
|
Gikiman/executors
|
LinearFBSP
| false
| 2,379
|
[
"Apache-2.0"
] | 0
|
98658b4136859164390cfccbde8cf0f7cf843593
|
https://github.com/Gikiman/executors/tree/98658b4136859164390cfccbde8cf0f7cf843593
|
GLU
|
import torch
import torch.nn as nn
import torch.utils.data
class GLU(nn.Module):
"""
Overview:
Gating Linear Unit.
This class does a thing like this:
.. code:: python
# Inputs: input, context, output_size
# The gate value is a learnt function of the input.
gate = sigmoid(linear(input.size)(context))
# Gate the input and return an output of desired size.
gated_input = gate * input
output = linear(output_size)(gated_input)
return output
Interfaces:
forward
.. tip::
This module also supports 2D convolution, in which case, the input and context must have the same shape.
"""
def __init__(self, input_dim: 'int', output_dim: 'int', context_dim:
'int', input_type: 'str'='fc') ->None:
"""
Overview:
Init GLU
Arguments:
- input_dim (:obj:`int`): the input dimension
- output_dim (:obj:`int`): the output dimension
- context_dim (:obj:`int`): the context dimension
- input_type (:obj:`str`): the type of input, now support ['fc', 'conv2d']
"""
super(GLU, self).__init__()
assert input_type in ['fc', 'conv2d']
if input_type == 'fc':
self.layer1 = nn.Linear(context_dim, input_dim)
self.layer2 = nn.Linear(input_dim, output_dim)
elif input_type == 'conv2d':
self.layer1 = nn.Conv2d(context_dim, input_dim, 1, 1, 0)
self.layer2 = nn.Conv2d(input_dim, output_dim, 1, 1, 0)
def forward(self, x: 'torch.Tensor', context: 'torch.Tensor'
) ->torch.Tensor:
"""
Overview:
Return GLU computed tensor
Arguments:
- x (:obj:`torch.Tensor`) : the input tensor
- context (:obj:`torch.Tensor`) : the context tensor
Returns:
- x (:obj:`torch.Tensor`): the computed tensor
"""
gate = self.layer1(context)
gate = torch.sigmoid(gate)
x = gate * x
x = self.layer2(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4, 'output_dim': 4, 'context_dim': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_mul_sigmoid_0(in_ptr0, in_ptr1, out_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp2 = tl.load(in_ptr1 + x0, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp3 = tmp1 * tmp2
tl.store(out_ptr0 + x0, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5, primals_6 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_5, (4, 4), (4, 1))
assert_size_stride(primals_6, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_2, reinterpret_tensor(primals_3, (64,
4), (4, 1), 0), reinterpret_tensor(primals_1, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf0)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_sigmoid_0[grid(256)](buf0, primals_4, buf1,
256, XBLOCK=256, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_6, reinterpret_tensor(buf1, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_5, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf2)
del primals_6
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf0, reinterpret_tensor(buf1, (64, 4), (4, 1), 0), primals_5
class GLUNew(nn.Module):
"""
Overview:
Gating Linear Unit.
This class does a thing like this:
.. code:: python
# Inputs: input, context, output_size
# The gate value is a learnt function of the input.
gate = sigmoid(linear(input.size)(context))
# Gate the input and return an output of desired size.
gated_input = gate * input
output = linear(output_size)(gated_input)
return output
Interfaces:
forward
.. tip::
This module also supports 2D convolution, in which case, the input and context must have the same shape.
"""
def __init__(self, input_dim: 'int', output_dim: 'int', context_dim:
'int', input_type: 'str'='fc') ->None:
"""
Overview:
Init GLU
Arguments:
- input_dim (:obj:`int`): the input dimension
- output_dim (:obj:`int`): the output dimension
- context_dim (:obj:`int`): the context dimension
- input_type (:obj:`str`): the type of input, now support ['fc', 'conv2d']
"""
super(GLUNew, self).__init__()
assert input_type in ['fc', 'conv2d']
if input_type == 'fc':
self.layer1 = nn.Linear(context_dim, input_dim)
self.layer2 = nn.Linear(input_dim, output_dim)
elif input_type == 'conv2d':
self.layer1 = nn.Conv2d(context_dim, input_dim, 1, 1, 0)
self.layer2 = nn.Conv2d(input_dim, output_dim, 1, 1, 0)
def forward(self, input_0, input_1):
primals_1 = self.layer1.weight
primals_2 = self.layer1.bias
primals_5 = self.layer2.weight
primals_6 = self.layer2.bias
primals_3 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
Hcnaeg/DI-engine
|
GLU
| false
| 2,380
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
Attention
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.init as init
def sequence_mask(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max()
return torch.arange(0, max_len).type_as(lengths).repeat(batch_size, 1).lt(
lengths.unsqueeze(1))
class AttnScore(nn.Module):
def __init__(self, input_size, activation=nn.Tanh(), method='dot'):
super(AttnScore, self).__init__()
self.activation = activation
self.input_size = input_size
self.method = method
if method == 'general':
self.linear = nn.Linear(input_size, input_size)
init.uniform(self.linear.weight.data, -0.005, 0.005)
elif method == 'concat':
self.linear_1 = nn.Linear(input_size * 2, input_size)
self.linear_2 = nn.Linear(input_size, 1)
init.uniform(self.linear_1.weight.data, -0.005, 0.005)
init.uniform(self.linear_2.weight.data, -0.005, 0.005)
elif method == 'tri_concat':
self.linear = nn.Linear(input_size * 3, 1)
init.uniform(self.linear.weight.data, -0.005, 0.005)
def forward(self, h1, h2, h1_lens=None, h2_lens=None, normalize=True):
"""
:param h1: b x m x d
:param h2: b x n x d
:return: attn_weights: b x 1 x m
"""
_bsize, seq_l1, _dim = h1.size()
_bsize, seq_l2, _dim = h2.size()
assert h1.size(-1) == self.input_size
assert h2.size(-1) == self.input_size
if self.method == 'dot':
align = h2.bmm(h1.transpose(1, 2))
elif self.method == 'general':
align = h2.bmm(self.linear(h1).transpose(1, 2))
elif self.method == 'concat':
h1 = h1.unsqueeze(1).repeat(1, seq_l2, 1, 1)
h2 = h2.unsqueeze(2).repeat(1, 1, seq_l1, 1)
align = self.linear_2(self.activation(self.linear_1(torch.cat([
h1, h2], dim=3)))).squeeze(-1)
align = F.softmax(align, dim=2)
elif self.method == 'tri_concat':
h1 = h1.unsqueeze(1).repeat(1, seq_l2, 1, 1)
h2 = h2.unsqueeze(2).repeat(1, 1, seq_l1, 1)
align = self.linear(torch.cat([h1, h2, h1 * h2], dim=3)).squeeze(-1
)
if h1_lens is not None:
mask = sequence_mask(h1_lens, max_len=seq_l1).unsqueeze(1)
align.data.masked_fill_(1 - mask, -100000000.0)
if normalize:
attn_weights = F.softmax(align, dim=2)
else:
attn_weights = F.softmax(align, dim=2)
return attn_weights
class Attention(nn.Module):
def __init__(self, input_size, activation=nn.Tanh(), method='dot'):
super(Attention, self).__init__()
self.attn_score = AttnScore(input_size=input_size, activation=
activation, method=method)
def forward(self, query, keys, q_lens=None, k_lens=None):
"""
:param query: bsize x query_num x input_size
:param keys: bsize x key_num x input_size
:param q_lens: bsize x query_num
:param k_lens: bsize x key_num
:return: bsize x 1 x input_size
"""
attn_weights = self.attn_score(keys, query, k_lens, q_lens)
contexts = attn_weights.bmm(keys)
return contexts, attn_weights
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.init as init
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused__softmax_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(arg1_1, reinterpret_tensor(arg0_1, (4, 4, 4), (
16, 1, 4), 0), out=buf0)
del arg1_1
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_0[grid(64)](buf0, buf1, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf2 = buf0
del buf0
triton_poi_fused__softmax_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf3 = buf1
del buf1
extern_kernels.bmm(buf2, arg0_1, out=buf3)
del arg0_1
return buf3, buf2
def sequence_mask(lengths, max_len=None):
"""
Creates a boolean mask from sequence lengths.
"""
batch_size = lengths.numel()
max_len = max_len or lengths.max()
return torch.arange(0, max_len).type_as(lengths).repeat(batch_size, 1).lt(
lengths.unsqueeze(1))
class AttnScore(nn.Module):
def __init__(self, input_size, activation=nn.Tanh(), method='dot'):
super(AttnScore, self).__init__()
self.activation = activation
self.input_size = input_size
self.method = method
if method == 'general':
self.linear = nn.Linear(input_size, input_size)
init.uniform(self.linear.weight.data, -0.005, 0.005)
elif method == 'concat':
self.linear_1 = nn.Linear(input_size * 2, input_size)
self.linear_2 = nn.Linear(input_size, 1)
init.uniform(self.linear_1.weight.data, -0.005, 0.005)
init.uniform(self.linear_2.weight.data, -0.005, 0.005)
elif method == 'tri_concat':
self.linear = nn.Linear(input_size * 3, 1)
init.uniform(self.linear.weight.data, -0.005, 0.005)
def forward(self, h1, h2, h1_lens=None, h2_lens=None, normalize=True):
"""
:param h1: b x m x d
:param h2: b x n x d
:return: attn_weights: b x 1 x m
"""
_bsize, seq_l1, _dim = h1.size()
_bsize, seq_l2, _dim = h2.size()
assert h1.size(-1) == self.input_size
assert h2.size(-1) == self.input_size
if self.method == 'dot':
align = h2.bmm(h1.transpose(1, 2))
elif self.method == 'general':
align = h2.bmm(self.linear(h1).transpose(1, 2))
elif self.method == 'concat':
h1 = h1.unsqueeze(1).repeat(1, seq_l2, 1, 1)
h2 = h2.unsqueeze(2).repeat(1, 1, seq_l1, 1)
align = self.linear_2(self.activation(self.linear_1(torch.cat([
h1, h2], dim=3)))).squeeze(-1)
align = F.softmax(align, dim=2)
elif self.method == 'tri_concat':
h1 = h1.unsqueeze(1).repeat(1, seq_l2, 1, 1)
h2 = h2.unsqueeze(2).repeat(1, 1, seq_l1, 1)
align = self.linear(torch.cat([h1, h2, h1 * h2], dim=3)).squeeze(-1
)
if h1_lens is not None:
mask = sequence_mask(h1_lens, max_len=seq_l1).unsqueeze(1)
align.data.masked_fill_(1 - mask, -100000000.0)
if normalize:
attn_weights = F.softmax(align, dim=2)
else:
attn_weights = F.softmax(align, dim=2)
return attn_weights
class AttentionNew(nn.Module):
def __init__(self, input_size, activation=nn.Tanh(), method='dot'):
super(AttentionNew, self).__init__()
self.attn_score = AttnScore(input_size=input_size, activation=
activation, method=method)
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0], output[1]
|
IndexFziQ/ASER
|
Attention
| false
| 2,381
|
[
"MIT"
] | 0
|
67dd1a2a25cec175c15675cc1f8a63ca065b447e
|
https://github.com/IndexFziQ/ASER/tree/67dd1a2a25cec175c15675cc1f8a63ca065b447e
|
SpatialGate3D
|
import torch
import torch.nn as nn
class BasicConv3D(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride=1,
padding=0, dilation=1, groups=1, relu=True, bn=True, bias=False):
super(BasicConv3D, self).__init__()
self.out_channels = out_planes
self.conv = nn.Conv3d(in_planes, out_planes, kernel_size=
kernel_size, stride=stride, padding=padding, dilation=dilation,
groups=groups, bias=bias)
self.bn = nn.InstanceNorm3d(out_planes, eps=1e-05, momentum=0.01,
affine=True)
self.relu = nn.LeakyReLU() if relu else None
def forward(self, x):
x = self.conv(x)
if self.bn is not None:
x = self.bn(x)
if self.relu is not None:
x = self.relu(x)
return x
class ChannelPool3D(nn.Module):
def forward(self, x):
return torch.cat((torch.max(x, 1)[0].unsqueeze(1), torch.mean(x, 1)
.unsqueeze(1)), dim=1)
class SpatialGate3D(nn.Module):
def __init__(self):
super(SpatialGate3D, self).__init__()
kernel_size = 3
self.compress = ChannelPool3D()
self.spatial = BasicConv3D(2, 1, kernel_size, stride=1, padding=(
kernel_size - 1) // 2, relu=False)
def forward(self, x):
x_compress = self.compress(x)
x_out = self.spatial(x_compress)
scale = torch.sigmoid_(x_out)
return x * scale
def get_inputs():
return [torch.rand([4, 2, 64, 64, 64])]
def get_init_inputs():
return [[], {}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_cat_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x1 = xindex // 262144 % 2
x0 = xindex % 262144
x2 = xindex // 524288
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 1, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 524288 * x2), tmp4, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + (262144 + x0 + 524288 * x2), tmp4,
eviction_policy='evict_last', other=0.0)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
tmp9 = tl.where(tmp4, tmp7, tmp8)
tmp10 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp13 = tl.load(in_ptr0 + (x0 + 524288 * x2), tmp10, eviction_policy=
'evict_last', other=0.0)
tmp14 = tl.load(in_ptr0 + (262144 + x0 + 524288 * x2), tmp10,
eviction_policy='evict_last', other=0.0)
tmp15 = tmp13 + tmp14
tmp16 = 2.0
tmp17 = tmp15 / tmp16
tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
tmp19 = tl.where(tmp10, tmp17, tmp18)
tmp20 = tl.where(tmp4, tmp9, tmp19)
tl.store(out_ptr0 + x3, tmp20, None)
@triton.jit
def triton_poi_fused_repeat_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK])
tl.store(out_ptr0 + x0, tmp1, xmask)
@triton.jit
def triton_red_fused__native_batch_norm_legit_2(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 8192
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp0 = tl.load(in_ptr0 + (r1 + 8192 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp2_mean_next, tmp2_m2_next, tmp2_weight_next = (triton_helpers.
welford_reduce(tmp1, tmp2_mean, tmp2_m2, tmp2_weight, roffset == 0)
)
tmp2_mean = tl.where(rmask & xmask, tmp2_mean_next, tmp2_mean)
tmp2_m2 = tl.where(rmask & xmask, tmp2_m2_next, tmp2_m2)
tmp2_weight = tl.where(rmask & xmask, tmp2_weight_next, tmp2_weight)
tmp2_tmp, tmp3_tmp, tmp4_tmp = triton_helpers.welford(tmp2_mean,
tmp2_m2, tmp2_weight, 1)
tmp2 = tmp2_tmp[:, None]
tmp3 = tmp3_tmp[:, None]
tmp4 = tmp4_tmp[:, None]
tl.store(out_ptr0 + x0, tmp2, xmask)
tl.store(out_ptr1 + x0, tmp3, xmask)
tl.store(out_ptr2 + x0, tmp4, xmask)
@triton.jit
def triton_per_fused__native_batch_norm_legit_3(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 32
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 32 * x0), xmask, other=0.0)
tmp1 = tl.load(in_ptr1 + (r1 + 32 * x0), xmask, other=0.0)
tmp2 = tl.load(in_ptr2 + (r1 + 32 * x0), xmask, other=0.0)
tmp3 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp5 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp7 = tl.where(xmask, tmp3, 0)
tmp8 = tl.where(xmask, tmp4, 0)
tmp9 = tl.where(xmask, tmp5, 0)
tmp10, tmp11, tmp12 = triton_helpers.welford(tmp7, tmp8, tmp9, 1)
tmp13 = tmp10[:, None]
tmp14 = tmp11[:, None]
tmp12[:, None]
tmp16 = 262144.0
tmp17 = tmp14 / tmp16
tmp18 = 1e-05
tmp19 = tmp17 + tmp18
tmp20 = libdevice.rsqrt(tmp19)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp20, xmask)
tl.store(out_ptr0 + x0, tmp13, xmask)
@triton.jit
def triton_poi_fused_sigmoid_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x1 = xindex // 262144
tmp0 = tl.load(in_ptr0 + x2, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x1, None, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tmp9 = tl.sigmoid(tmp8)
tl.store(out_ptr0 + x2, tmp9, None)
@triton.jit
def triton_poi_fused_mul_5(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x0 = xindex % 262144
x2 = xindex // 524288
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (x0 + 262144 * x2), None, eviction_policy=
'evict_last')
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x3, tmp2, None)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 2, 64, 64, 64), (524288, 262144, 4096,
64, 1))
assert_size_stride(primals_2, (1, 2, 3, 3, 3), (54, 27, 9, 3, 1))
assert_size_stride(primals_3, (1,), (1,))
assert_size_stride(primals_4, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 2, 64, 64, 64), (524288, 262144, 4096,
64, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(2097152)](primals_1, buf0, 2097152,
XBLOCK=1024, num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(buf0, primals_2, stride=(1, 1, 1),
padding=(1, 1, 1), dilation=(1, 1, 1), transposed=False,
output_padding=(0, 0, 0), groups=1, bias=None)
assert_size_stride(buf1, (4, 1, 64, 64, 64), (262144, 262144, 4096,
64, 1))
buf2 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_repeat_1[grid(4)](primals_3, buf2, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del primals_3
buf3 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_repeat_1[grid(4)](primals_4, buf3, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del primals_4
buf4 = empty_strided_cuda((1, 4, 1, 1, 1, 32), (128, 32, 128, 128,
128, 1), torch.float32)
buf5 = empty_strided_cuda((1, 4, 1, 1, 1, 32), (128, 32, 128, 128,
128, 1), torch.float32)
buf6 = empty_strided_cuda((1, 4, 1, 1, 1, 32), (128, 32, 128, 128,
128, 1), torch.float32)
triton_red_fused__native_batch_norm_legit_2[grid(128)](buf1, buf4,
buf5, buf6, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf7 = empty_strided_cuda((1, 4, 1, 1, 1), (4, 1, 1, 1, 1), torch.
float32)
buf8 = empty_strided_cuda((1, 4, 1, 1, 1), (4, 1, 4, 4, 4), torch.
float32)
buf10 = reinterpret_tensor(buf8, (1, 4, 1, 1, 1), (4, 1, 1, 1, 1), 0)
del buf8
triton_per_fused__native_batch_norm_legit_3[grid(4)](buf10, buf4,
buf5, buf6, buf7, 4, 32, XBLOCK=1, num_warps=2, num_stages=1)
del buf4
del buf5
del buf6
buf11 = empty_strided_cuda((4, 1, 64, 64, 64), (262144, 1048576,
4096, 64, 1), torch.float32)
triton_poi_fused_sigmoid_4[grid(1048576)](buf1, buf7, buf10, buf2,
buf3, buf11, 1048576, XBLOCK=1024, num_warps=4, num_stages=1)
buf12 = empty_strided_cuda((4, 2, 64, 64, 64), (524288, 262144,
4096, 64, 1), torch.float32)
triton_poi_fused_mul_5[grid(2097152)](primals_1, buf11, buf12,
2097152, XBLOCK=1024, num_warps=4, num_stages=1)
del buf11
return buf12, primals_1, primals_2, buf0, buf1, buf2, buf3, buf7, buf10
class BasicConv3D(nn.Module):
def __init__(self, in_planes, out_planes, kernel_size, stride=1,
padding=0, dilation=1, groups=1, relu=True, bn=True, bias=False):
super(BasicConv3D, self).__init__()
self.out_channels = out_planes
self.conv = nn.Conv3d(in_planes, out_planes, kernel_size=
kernel_size, stride=stride, padding=padding, dilation=dilation,
groups=groups, bias=bias)
self.bn = nn.InstanceNorm3d(out_planes, eps=1e-05, momentum=0.01,
affine=True)
self.relu = nn.LeakyReLU() if relu else None
def forward(self, x):
x = self.conv(x)
if self.bn is not None:
x = self.bn(x)
if self.relu is not None:
x = self.relu(x)
return x
class ChannelPool3D(nn.Module):
def forward(self, x):
return torch.cat((torch.max(x, 1)[0].unsqueeze(1), torch.mean(x, 1)
.unsqueeze(1)), dim=1)
class SpatialGate3DNew(nn.Module):
def __init__(self):
super(SpatialGate3DNew, self).__init__()
kernel_size = 3
self.compress = ChannelPool3D()
self.spatial = BasicConv3D(2, 1, kernel_size, stride=1, padding=(
kernel_size - 1) // 2, relu=False)
def forward(self, input_0):
primals_2 = self.spatial.conv.weight
primals_3 = self.spatial.bn.weight
primals_4 = self.spatial.bn.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
Healingl/3DAPRNet
|
SpatialGate3D
| false
| 2,382
|
[
"BSD-2-Clause"
] | 0
|
7c5e0028ae844df4e1f26327e8b438532ca0745f
|
https://github.com/Healingl/3DAPRNet/tree/7c5e0028ae844df4e1f26327e8b438532ca0745f
|
AvgPool2dSame
|
import math
import torch
import numpy as np
from typing import List
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data
def get_same_padding(x: 'int', k: 'int', s: 'int', d: 'int'):
return max((math.ceil(x / s) - 1) * s + (k - 1) * d + 1 - x, 0)
def pad_same(x, k: 'List[int]', s: 'List[int]', d: 'List[int]'=(1, 1),
value: 'float'=0):
ih, iw = x.size()[-2:]
pad_h, pad_w = get_same_padding(ih, k[0], s[0], d[0]), get_same_padding(iw,
k[1], s[1], d[1])
if pad_h > 0 or pad_w > 0:
x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h -
pad_h // 2], value=value)
return x
def to_2tuple(item):
if np.isscalar(item):
return item, item
else:
return item
class AvgPool2dSame(nn.AvgPool2d):
""" Tensorflow like 'SAME' wrapper for 2D average pooling
"""
def __init__(self, kernel_size: 'int', stride=None, padding=0,
ceil_mode=False, count_include_pad=True):
kernel_size = to_2tuple(kernel_size)
stride = to_2tuple(stride)
super(AvgPool2dSame, self).__init__(kernel_size, stride, (0, 0),
ceil_mode, count_include_pad)
def forward(self, x):
x = pad_same(x, self.kernel_size, self.stride)
return F.avg_pool2d(x, self.kernel_size, self.stride, self.padding,
self.ceil_mode, self.count_include_pad)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'kernel_size': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import math
import numpy as np
from typing import List
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_avg_pool2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + 16 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr0 + (2 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr0 + (3 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp7 = tl.load(in_ptr0 + (4 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp9 = tl.load(in_ptr0 + (5 + 16 * x0), xmask, eviction_policy='evict_last'
)
tmp11 = tl.load(in_ptr0 + (6 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp13 = tl.load(in_ptr0 + (7 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp15 = tl.load(in_ptr0 + (8 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr0 + (9 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp19 = tl.load(in_ptr0 + (10 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp21 = tl.load(in_ptr0 + (11 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr0 + (12 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp25 = tl.load(in_ptr0 + (13 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp27 = tl.load(in_ptr0 + (14 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp29 = tl.load(in_ptr0 + (15 + 16 * x0), xmask, eviction_policy=
'evict_last')
tmp2 = tmp1 + tmp0
tmp4 = tmp3 + tmp2
tmp6 = tmp5 + tmp4
tmp8 = tmp7 + tmp6
tmp10 = tmp9 + tmp8
tmp12 = tmp11 + tmp10
tmp14 = tmp13 + tmp12
tmp16 = tmp15 + tmp14
tmp18 = tmp17 + tmp16
tmp20 = tmp19 + tmp18
tmp22 = tmp21 + tmp20
tmp24 = tmp23 + tmp22
tmp26 = tmp25 + tmp24
tmp28 = tmp27 + tmp26
tmp30 = tmp29 + tmp28
tmp31 = 0.0625
tmp32 = tmp30 * tmp31
tl.store(out_ptr0 + x0, tmp32, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_avg_pool2d_0[grid(16)](arg0_1, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del arg0_1
return buf0,
def get_same_padding(x: 'int', k: 'int', s: 'int', d: 'int'):
return max((math.ceil(x / s) - 1) * s + (k - 1) * d + 1 - x, 0)
def pad_same(x, k: 'List[int]', s: 'List[int]', d: 'List[int]'=(1, 1),
value: 'float'=0):
ih, iw = x.size()[-2:]
pad_h, pad_w = get_same_padding(ih, k[0], s[0], d[0]), get_same_padding(iw,
k[1], s[1], d[1])
if pad_h > 0 or pad_w > 0:
x = F.pad(x, [pad_w // 2, pad_w - pad_w // 2, pad_h // 2, pad_h -
pad_h // 2], value=value)
return x
def to_2tuple(item):
if np.isscalar(item):
return item, item
else:
return item
class AvgPool2dSameNew(nn.AvgPool2d):
""" Tensorflow like 'SAME' wrapper for 2D average pooling
"""
def __init__(self, kernel_size: 'int', stride=None, padding=0,
ceil_mode=False, count_include_pad=True):
kernel_size = to_2tuple(kernel_size)
stride = to_2tuple(stride)
super(AvgPool2dSameNew, self).__init__(kernel_size, stride, (0, 0),
ceil_mode, count_include_pad)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Hcnaeg/DI-engine
|
AvgPool2dSame
| false
| 2,383
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
EnsembleFC
|
import torch
import torch.nn as nn
import torch.utils.data
class EnsembleFC(nn.Module):
__constants__ = ['in_features', 'out_features']
in_features: 'int'
out_features: 'int'
ensemble_size: 'int'
weight: 'torch.Tensor'
def __init__(self, in_features: 'int', out_features: 'int',
ensemble_size: 'int', weight_decay: 'float'=0.0) ->None:
super(EnsembleFC, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.ensemble_size = ensemble_size
self.weight = nn.Parameter(torch.Tensor(ensemble_size, in_features,
out_features))
self.weight_decay = weight_decay
self.bias = nn.Parameter(torch.Tensor(ensemble_size, 1, out_features))
def forward(self, input: 'torch.Tensor') ->torch.Tensor:
assert input.shape[0] == self.ensemble_size and len(input.shape) == 3
return torch.bmm(input, self.weight) + self.bias
def extra_repr(self) ->str:
return 'in_features={}, out_features={}'.format(self.in_features,
self.out_features)
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'in_features': 4, 'out_features': 4, 'ensemble_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x3, tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_3, (4, 1, 4), (4, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(primals_1, primals_2, out=buf0)
del primals_2
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_add_0[grid(64)](buf1, primals_3, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_3
return buf1, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0)
class EnsembleFCNew(nn.Module):
__constants__ = ['in_features', 'out_features']
in_features: 'int'
out_features: 'int'
ensemble_size: 'int'
weight: 'torch.Tensor'
def __init__(self, in_features: 'int', out_features: 'int',
ensemble_size: 'int', weight_decay: 'float'=0.0) ->None:
super(EnsembleFCNew, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.ensemble_size = ensemble_size
self.weight = nn.Parameter(torch.Tensor(ensemble_size, in_features,
out_features))
self.weight_decay = weight_decay
self.bias = nn.Parameter(torch.Tensor(ensemble_size, 1, out_features))
def extra_repr(self) ->str:
return 'in_features={}, out_features={}'.format(self.in_features,
self.out_features)
def forward(self, input_0):
primals_1 = self.weight
primals_3 = self.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Hcnaeg/DI-engine
|
EnsembleFC
| false
| 2,384
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
Encoder
|
import torch
import torch.nn as nn
import torch.utils.data
class Conv(nn.Module):
def __init__(self, filters0, filters1, kernel_size, bn, bias=True):
super().__init__()
if bn:
bias = False
self.conv = nn.Conv2d(filters0, filters1, kernel_size, stride=1,
padding=kernel_size // 2, bias=bias)
self.bn = nn.BatchNorm2d(filters1) if bn else None
def forward(self, x):
h = self.conv(x)
if self.bn is not None:
h = self.bn(h)
return h
class Encoder(nn.Module):
def __init__(self, input_size, filters):
super().__init__()
self.input_size = input_size
self.conv = Conv(input_size[0], filters, 3, bn=False)
self.activation = nn.LeakyReLU(0.1)
def forward(self, x):
return self.activation(self.conv(x))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': [4, 4], 'filters': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.1
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf0,
primals_2, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del primals_2
return buf2, primals_1, primals_3, buf1
class Conv(nn.Module):
def __init__(self, filters0, filters1, kernel_size, bn, bias=True):
super().__init__()
if bn:
bias = False
self.conv = nn.Conv2d(filters0, filters1, kernel_size, stride=1,
padding=kernel_size // 2, bias=bias)
self.bn = nn.BatchNorm2d(filters1) if bn else None
def forward(self, x):
h = self.conv(x)
if self.bn is not None:
h = self.bn(h)
return h
class EncoderNew(nn.Module):
def __init__(self, input_size, filters):
super().__init__()
self.input_size = input_size
self.conv = Conv(input_size[0], filters, 3, bn=False)
self.activation = nn.LeakyReLU(0.1)
def forward(self, input_0):
primals_1 = self.conv.conv.weight
primals_2 = self.conv.conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
Hcnaeg/DI-engine
|
Encoder
| false
| 2,385
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
Head
|
import torch
import torch.nn as nn
import torch.utils.data
class Conv(nn.Module):
def __init__(self, filters0, filters1, kernel_size, bn, bias=True):
super().__init__()
if bn:
bias = False
self.conv = nn.Conv2d(filters0, filters1, kernel_size, stride=1,
padding=kernel_size // 2, bias=bias)
self.bn = nn.BatchNorm2d(filters1) if bn else None
def forward(self, x):
h = self.conv(x)
if self.bn is not None:
h = self.bn(h)
return h
class Head(nn.Module):
def __init__(self, input_size, out_filters, outputs):
super().__init__()
self.board_size = input_size[1] * input_size[2]
self.out_filters = out_filters
self.conv = Conv(input_size[0], out_filters, 1, bn=False)
self.activation = nn.LeakyReLU(0.1)
self.fc = nn.Linear(self.board_size * out_filters, outputs, bias=False)
def forward(self, x):
h = self.activation(self.conv(x))
h = self.fc(h.view(-1, self.board_size * self.out_filters))
return h
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': [4, 4, 4], 'out_filters': 4, 'outputs': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.1
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 64), (64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(256)](buf0,
primals_2, buf1, buf2, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del primals_2
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (4, 64), (64, 1), 0),
reinterpret_tensor(primals_4, (64, 4), (1, 64), 0), out=buf3)
return buf3, primals_1, primals_3, buf1, reinterpret_tensor(buf2, (4,
64), (64, 1), 0), primals_4
class Conv(nn.Module):
def __init__(self, filters0, filters1, kernel_size, bn, bias=True):
super().__init__()
if bn:
bias = False
self.conv = nn.Conv2d(filters0, filters1, kernel_size, stride=1,
padding=kernel_size // 2, bias=bias)
self.bn = nn.BatchNorm2d(filters1) if bn else None
def forward(self, x):
h = self.conv(x)
if self.bn is not None:
h = self.bn(h)
return h
class HeadNew(nn.Module):
def __init__(self, input_size, out_filters, outputs):
super().__init__()
self.board_size = input_size[1] * input_size[2]
self.out_filters = out_filters
self.conv = Conv(input_size[0], out_filters, 1, bn=False)
self.activation = nn.LeakyReLU(0.1)
self.fc = nn.Linear(self.board_size * out_filters, outputs, bias=False)
def forward(self, input_0):
primals_1 = self.conv.conv.weight
primals_2 = self.conv.conv.bias
primals_4 = self.fc.weight
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
Hcnaeg/DI-engine
|
Head
| false
| 2,386
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
PPMConcat
|
import torch
import torch.nn as nn
import torch._C
import torch.serialization
class PPMConcat(nn.ModuleList):
"""Pyramid Pooling Module that only concat the features of each layer.
Args:
pool_scales (tuple[int]): Pooling scales used in Pooling Pyramid
Module.
"""
def __init__(self, pool_scales=(1, 3, 6, 8)):
super(PPMConcat, self).__init__([nn.AdaptiveAvgPool2d(pool_scale) for
pool_scale in pool_scales])
def forward(self, feats):
"""Forward function."""
ppm_outs = []
for ppm in self:
ppm_out = ppm(feats)
ppm_outs.append(ppm_out.view(*feats.shape[:2], -1))
concat_outs = torch.cat(ppm_outs, dim=2)
return concat_outs
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch._C
import torch.serialization
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_cat_mean_0(in_ptr0, out_ptr1, xnumel, rnumel, XBLOCK:
tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 16
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
tl.full([XBLOCK, RBLOCK], True, tl.int1)
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tl.store(out_ptr1 + 110 * x0, tmp6, xmask)
@triton.jit
def triton_poi_fused__adaptive_avg_pool2d_cat_1(in_ptr0, out_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 144
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 3 % 3
x0 = xindex % 3
x2 = xindex // 9
x3 = xindex % 9
tmp0 = 4 * x1 // 3
tmp1 = 2 + 4 * x1 // 3
tmp2 = tmp0 < tmp1
tmp3 = 4 * x0 // 3
tmp4 = 2 + 4 * x0 // 3
tmp5 = tmp3 < tmp4
tmp6 = tmp2 & tmp5
tmp7 = tl.load(in_ptr0 + (4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 // 3),
tmp6 & xmask, other=0.0)
tmp8 = 1 + 4 * x0 // 3
tmp9 = tmp8 < tmp4
tmp10 = tmp2 & tmp9
tmp11 = tl.load(in_ptr0 + (1 + 4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 //
3), tmp10 & xmask, other=0.0)
tmp12 = tmp11 + tmp7
tmp13 = 1 + 4 * x1 // 3
tmp14 = tmp13 < tmp1
tmp15 = tmp14 & tmp5
tmp16 = tl.load(in_ptr0 + (4 + 4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 //
3), tmp15 & xmask, other=0.0)
tmp17 = tmp16 + tmp12
tmp18 = tmp14 & tmp9
tmp19 = tl.load(in_ptr0 + (5 + 4 * (4 * x1 // 3) + 16 * x2 + 4 * x0 //
3), tmp18 & xmask, other=0.0)
tmp20 = tmp19 + tmp17
tmp21 = 1.0
tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
tmp23 = tl.where(tmp6, tmp21, tmp22)
tmp24 = tl.where(tmp10, tmp21, tmp22)
tmp25 = tmp24 + tmp23
tmp26 = tl.where(tmp15, tmp21, tmp22)
tmp27 = tmp26 + tmp25
tmp28 = tl.where(tmp18, tmp21, tmp22)
tmp29 = tmp28 + tmp27
tmp30 = tmp20 / tmp29
tl.store(out_ptr1 + (x3 + 110 * x2), tmp30, xmask)
@triton.jit
def triton_poi_fused__adaptive_avg_pool2d_cat_2(in_ptr0, out_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 576
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 6 % 6
x0 = xindex % 6
x2 = xindex // 36
x3 = xindex % 36
tmp0 = 2 * x1 // 3
tmp1 = (9 + 4 * x1) // 6
tmp2 = tmp0 < tmp1
tmp3 = 2 * x0 // 3
tmp4 = (9 + 4 * x0) // 6
tmp5 = tmp3 < tmp4
tmp6 = tmp2 & tmp5
tmp7 = tl.load(in_ptr0 + (4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 // 3),
tmp6 & xmask, eviction_policy='evict_last', other=0.0)
tmp8 = 1 + 2 * x0 // 3
tmp9 = tmp8 < tmp4
tmp10 = tmp2 & tmp9
tmp11 = tl.load(in_ptr0 + (1 + 4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 //
3), tmp10 & xmask, eviction_policy='evict_last', other=0.0)
tmp12 = tmp11 + tmp7
tmp13 = 1 + 2 * x1 // 3
tmp14 = tmp13 < tmp1
tmp15 = tmp14 & tmp5
tmp16 = tl.load(in_ptr0 + (4 + 4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 //
3), tmp15 & xmask, eviction_policy='evict_last', other=0.0)
tmp17 = tmp16 + tmp12
tmp18 = tmp14 & tmp9
tmp19 = tl.load(in_ptr0 + (5 + 4 * (2 * x1 // 3) + 16 * x2 + 2 * x0 //
3), tmp18 & xmask, eviction_policy='evict_last', other=0.0)
tmp20 = tmp19 + tmp17
tmp21 = 1.0
tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
tmp23 = tl.where(tmp6, tmp21, tmp22)
tmp24 = tl.where(tmp10, tmp21, tmp22)
tmp25 = tmp24 + tmp23
tmp26 = tl.where(tmp15, tmp21, tmp22)
tmp27 = tmp26 + tmp25
tmp28 = tl.where(tmp18, tmp21, tmp22)
tmp29 = tmp28 + tmp27
tmp30 = tmp20 / tmp29
tl.store(out_ptr1 + (x3 + 110 * x2), tmp30, xmask)
@triton.jit
def triton_poi_fused__adaptive_avg_pool2d_cat_3(in_ptr0, out_ptr1, xnumel,
XBLOCK: tl.constexpr):
xnumel = 1024
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 8 % 8
x0 = xindex % 8
x2 = xindex // 64
x3 = xindex % 64
tmp0 = x1 // 2
tmp1 = (11 + 4 * x1) // 8
tmp2 = tmp0 < tmp1
tmp3 = x0 // 2
tmp4 = (11 + 4 * x0) // 8
tmp5 = tmp3 < tmp4
tmp6 = tmp2 & tmp5
tmp7 = tl.load(in_ptr0 + (4 * (x1 // 2) + 16 * x2 + x0 // 2), tmp6 &
xmask, eviction_policy='evict_last', other=0.0)
tmp8 = 1 + x0 // 2
tmp9 = tmp8 < tmp4
tmp10 = tmp2 & tmp9
tmp11 = tl.load(in_ptr0 + (1 + 4 * (x1 // 2) + 16 * x2 + x0 // 2),
tmp10 & xmask, eviction_policy='evict_last', other=0.0)
tmp12 = tmp11 + tmp7
tmp13 = 1 + x1 // 2
tmp14 = tmp13 < tmp1
tmp15 = tmp14 & tmp5
tmp16 = tl.load(in_ptr0 + (4 + 4 * (x1 // 2) + 16 * x2 + x0 // 2),
tmp15 & xmask, eviction_policy='evict_last', other=0.0)
tmp17 = tmp16 + tmp12
tmp18 = tmp14 & tmp9
tmp19 = tl.load(in_ptr0 + (5 + 4 * (x1 // 2) + 16 * x2 + x0 // 2),
tmp18 & xmask, eviction_policy='evict_last', other=0.0)
tmp20 = tmp19 + tmp17
tmp21 = 1.0
tmp22 = tl.full(tmp21.shape, 0.0, tmp21.dtype)
tmp23 = tl.where(tmp6, tmp21, tmp22)
tmp24 = tl.where(tmp10, tmp21, tmp22)
tmp25 = tmp24 + tmp23
tmp26 = tl.where(tmp15, tmp21, tmp22)
tmp27 = tmp26 + tmp25
tmp28 = tl.where(tmp18, tmp21, tmp22)
tmp29 = tmp28 + tmp27
tmp30 = tmp20 / tmp29
tl.store(out_ptr1 + (x3 + 110 * x2), tmp30, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf8 = empty_strided_cuda((4, 4, 110), (440, 110, 1), torch.float32)
buf4 = reinterpret_tensor(buf8, (4, 4, 1), (440, 110, 1), 0)
get_raw_stream(0)
triton_per_fused_cat_mean_0[grid(16)](arg0_1, buf4, 16, 16, XBLOCK=
1, num_warps=2, num_stages=1)
buf5 = reinterpret_tensor(buf8, (4, 4, 9), (440, 110, 1), 1)
triton_poi_fused__adaptive_avg_pool2d_cat_1[grid(144)](arg0_1, buf5,
144, XBLOCK=128, num_warps=4, num_stages=1)
buf6 = reinterpret_tensor(buf8, (4, 4, 36), (440, 110, 1), 10)
triton_poi_fused__adaptive_avg_pool2d_cat_2[grid(576)](arg0_1, buf6,
576, XBLOCK=128, num_warps=4, num_stages=1)
buf7 = reinterpret_tensor(buf8, (4, 4, 64), (440, 110, 1), 46)
triton_poi_fused__adaptive_avg_pool2d_cat_3[grid(1024)](arg0_1,
buf7, 1024, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
return buf8,
class PPMConcatNew(nn.ModuleList):
"""Pyramid Pooling Module that only concat the features of each layer.
Args:
pool_scales (tuple[int]): Pooling scales used in Pooling Pyramid
Module.
"""
def __init__(self, pool_scales=(1, 3, 6, 8)):
super(PPMConcatNew, self).__init__([nn.AdaptiveAvgPool2d(pool_scale
) for pool_scale in pool_scales])
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
ImportPaddle/APCNet
|
PPMConcat
| false
| 2,387
|
[
"MIT"
] | 0
|
68ade1f83827b4cdd60ee4b6ac25454397100316
|
https://github.com/ImportPaddle/APCNet/tree/68ade1f83827b4cdd60ee4b6ac25454397100316
|
MultiHeadedAttention
|
import math
import torch
from typing import Optional
from typing import Tuple
from torch import nn
class MultiHeadedAttention(nn.Module):
"""Multi-Head Attention layer.
Args:
n_head (int): The number of heads.
n_feat (int): The number of features.
dropout_rate (float): Dropout rate.
"""
def __init__(self, n_head: 'int', n_feat: 'int', dropout_rate: 'float'):
"""Construct an MultiHeadedAttention object."""
super().__init__()
assert n_feat % n_head == 0
self.d_k = n_feat // n_head
self.h = n_head
self.linear_q = nn.Linear(n_feat, n_feat)
self.linear_k = nn.Linear(n_feat, n_feat)
self.linear_v = nn.Linear(n_feat, n_feat)
self.linear_out = nn.Linear(n_feat, n_feat)
self.dropout = nn.Dropout(p=dropout_rate)
def forward_qkv(self, query: 'torch.Tensor', key: 'torch.Tensor', value:
'torch.Tensor') ->Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""Transform query, key and value.
Args:
query (torch.Tensor): Query tensor (#batch, time1, size).
key (torch.Tensor): Key tensor (#batch, time2, size).
value (torch.Tensor): Value tensor (#batch, time2, size).
Returns:
torch.Tensor: Transformed query tensor, size
(#batch, n_head, time1, d_k).
torch.Tensor: Transformed key tensor, size
(#batch, n_head, time2, d_k).
torch.Tensor: Transformed value tensor, size
(#batch, n_head, time2, d_k).
"""
n_batch = query.size(0)
q = self.linear_q(query).view(n_batch, -1, self.h, self.d_k)
k = self.linear_k(key).view(n_batch, -1, self.h, self.d_k)
v = self.linear_v(value).view(n_batch, -1, self.h, self.d_k)
q = q.transpose(1, 2)
k = k.transpose(1, 2)
v = v.transpose(1, 2)
return q, k, v
def forward_attention(self, value: 'torch.Tensor', scores:
'torch.Tensor', mask: 'Optional[torch.Tensor]') ->torch.Tensor:
"""Compute attention context vector.
Args:
value (torch.Tensor): Transformed value, size
(#batch, n_head, time2, d_k).
scores (torch.Tensor): Attention score, size
(#batch, n_head, time1, time2).
mask (torch.Tensor): Mask, size (#batch, 1, time2) or
(#batch, time1, time2).
Returns:
torch.Tensor: Transformed value (#batch, time1, d_model)
weighted by the attention score (#batch, time1, time2).
"""
n_batch = value.size(0)
if mask is not None:
mask = mask.unsqueeze(1).eq(0)
scores = scores.masked_fill(mask, -float('inf'))
attn = torch.softmax(scores, dim=-1).masked_fill(mask, 0.0)
else:
attn = torch.softmax(scores, dim=-1)
p_attn = self.dropout(attn)
x = torch.matmul(p_attn, value)
x = x.transpose(1, 2).contiguous().view(n_batch, -1, self.h * self.d_k)
return self.linear_out(x)
def forward(self, query: 'torch.Tensor', key: 'torch.Tensor', value:
'torch.Tensor', mask: 'Optional[torch.Tensor]', pos_emb:
'torch.Tensor'=torch.empty(0)) ->torch.Tensor:
"""Compute scaled dot product attention.
Args:
query (torch.Tensor): Query tensor (#batch, time1, size).
key (torch.Tensor): Key tensor (#batch, time2, size).
value (torch.Tensor): Value tensor (#batch, time2, size).
mask (torch.Tensor): Mask tensor (#batch, 1, time2) or
(#batch, time1, time2).
1.When applying cross attention between decoder and encoder,
the batch padding mask for input is in (#batch, 1, T) shape.
2.When applying self attention of encoder,
the mask is in (#batch, T, T) shape.
3.When applying self attention of decoder,
the mask is in (#batch, L, L) shape.
4.If the different position in decoder see different block
of the encoder, such as Mocha, the passed in mask could be
in (#batch, L, T) shape. But there is no such case in current
Wenet.
Returns:
torch.Tensor: Output tensor (#batch, time1, d_model).
"""
q, k, v = self.forward_qkv(query, key, value)
scores = torch.matmul(q, k.transpose(-2, -1)) / math.sqrt(self.d_k)
return self.forward_attention(v, scores, mask)
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4]), torch.rand([4, 4,
4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'n_head': 4, 'n_feat': 4, 'dropout_rate': 0.5}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
from typing import Optional
from typing import Tuple
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_clone_0(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, ymask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 4 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused_eq_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = tmp0 == tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_div_masked_fill_2(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x2 = xindex // 16
x3 = xindex
tmp0 = tl.load(in_ptr0 + (4 * x0 + 16 * x2), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp1 = tl.load(in_ptr1 + 4 * x3, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy
='evict_last').to(tl.int1)
tmp7 = tl.load(in_ptr1 + (1 + 4 * x3), xmask, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (2 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last').to(tl.int1)
tmp12 = tl.load(in_ptr1 + (2 + 4 * x3), xmask, eviction_policy='evict_last'
)
tmp16 = tl.load(in_ptr0 + (3 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last').to(tl.int1)
tmp17 = tl.load(in_ptr1 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
)
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = float('-inf')
tmp5 = tl.where(tmp0, tmp4, tmp3)
tmp8 = tmp7 * tmp2
tmp9 = tl.where(tmp6, tmp4, tmp8)
tmp10 = triton_helpers.maximum(tmp5, tmp9)
tmp13 = tmp12 * tmp2
tmp14 = tl.where(tmp11, tmp4, tmp13)
tmp15 = triton_helpers.maximum(tmp10, tmp14)
tmp18 = tmp17 * tmp2
tmp19 = tl.where(tmp16, tmp4, tmp18)
tmp20 = triton_helpers.maximum(tmp15, tmp19)
tmp21 = tmp5 - tmp20
tmp22 = tl_math.exp(tmp21)
tmp23 = tmp9 - tmp20
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp26 = tmp14 - tmp20
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tmp19 - tmp20
tmp30 = tl_math.exp(tmp29)
tmp31 = tmp28 + tmp30
tl.store(out_ptr0 + x3, tmp20, xmask)
tl.store(out_ptr1 + x3, tmp31, xmask)
@triton.jit
def triton_poi_fused__softmax_div_masked_fill_3(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex // 64
x4 = xindex % 16
x5 = xindex
x6 = xindex // 4
tmp0 = tl.load(in_ptr0 + (x4 + 16 * x3), xmask, eviction_policy=
'evict_last').to(tl.int1)
tmp1 = tl.load(in_ptr1 + x5, xmask)
tmp6 = tl.load(in_ptr2 + x6, xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr3 + x6, xmask, eviction_policy='evict_last')
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = float('-inf')
tmp5 = tl.where(tmp0, tmp4, tmp3)
tmp7 = tmp5 - tmp6
tmp8 = tl_math.exp(tmp7)
tmp10 = tmp8 / tmp9
tmp11 = 0.0
tmp12 = tl.where(tmp0, tmp11, tmp10)
tl.store(out_ptr0 + x5, tmp12, xmask)
@triton.jit
def triton_poi_fused_clone_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 16
xnumel = 4
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
ymask = yindex < ynumel
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 4
y1 = yindex // 4
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
def call(args):
(primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
primals_7, primals_8, primals_9, primals_10, primals_11, primals_12
) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_7, (4, 4), (4, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_10, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_11, (4, 4), (4, 1))
assert_size_stride(primals_12, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_6, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_9, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_7, (4, 4), (1, 4), 0), out=buf2)
del primals_7
buf3 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_0[grid(16, 4)](buf0, primals_3, buf3, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_3
buf4 = reinterpret_tensor(buf0, (4, 4, 1, 4), (16, 4, 4, 1), 0)
del buf0
triton_poi_fused_clone_0[grid(16, 4)](buf1, primals_5, buf4, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_5
buf5 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 0),
0), reinterpret_tensor(buf4, (16, 1, 4), (4, 0, 1), 0), out=buf5)
buf6 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.bool)
triton_poi_fused_eq_1[grid(64)](primals_10, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_10
buf7 = reinterpret_tensor(buf1, (4, 4, 4, 1), (16, 4, 1, 64), 0)
del buf1
buf8 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 64), torch.float32)
triton_poi_fused__softmax_div_masked_fill_2[grid(64)](buf6, buf5,
buf7, buf8, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_div_masked_fill_3[grid(256)](buf6, buf5,
buf7, buf8, buf9, 256, XBLOCK=256, num_warps=4, num_stages=1)
buf10 = reinterpret_tensor(buf8, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf8
triton_poi_fused_clone_0[grid(16, 4)](buf2, primals_8, buf10, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
del primals_8
buf11 = reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf9, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf10, (16, 4, 1), (4, 1, 0), 0), out=buf11)
buf12 = reinterpret_tensor(buf7, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf7
triton_poi_fused_clone_4[grid(16, 4)](buf11, buf12, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf13 = reinterpret_tensor(buf11, (16, 4), (4, 1), 0)
del buf11
extern_kernels.addmm(primals_12, reinterpret_tensor(buf12, (16, 4),
(4, 1), 0), reinterpret_tensor(primals_11, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf13)
del primals_12
return reinterpret_tensor(buf13, (4, 4, 4), (16, 4, 1), 0
), reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_6, (16, 4), (4, 1), 0
), reinterpret_tensor(primals_9, (16, 4), (4, 1), 0
), buf5, buf6, reinterpret_tensor(buf12, (16, 4), (4, 1), 0
), primals_11, reinterpret_tensor(buf9, (16, 4, 4), (16, 1, 4), 0
), reinterpret_tensor(buf10, (16, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf3, (16, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 4), 0)
class MultiHeadedAttentionNew(nn.Module):
"""Multi-Head Attention layer.
Args:
n_head (int): The number of heads.
n_feat (int): The number of features.
dropout_rate (float): Dropout rate.
"""
def __init__(self, n_head: 'int', n_feat: 'int', dropout_rate: 'float'):
"""Construct an MultiHeadedAttention object."""
super().__init__()
assert n_feat % n_head == 0
self.d_k = n_feat // n_head
self.h = n_head
self.linear_q = nn.Linear(n_feat, n_feat)
self.linear_k = nn.Linear(n_feat, n_feat)
self.linear_v = nn.Linear(n_feat, n_feat)
self.linear_out = nn.Linear(n_feat, n_feat)
self.dropout = nn.Dropout(p=dropout_rate)
def forward_qkv(self, query: 'torch.Tensor', key: 'torch.Tensor', value:
'torch.Tensor') ->Tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""Transform query, key and value.
Args:
query (torch.Tensor): Query tensor (#batch, time1, size).
key (torch.Tensor): Key tensor (#batch, time2, size).
value (torch.Tensor): Value tensor (#batch, time2, size).
Returns:
torch.Tensor: Transformed query tensor, size
(#batch, n_head, time1, d_k).
torch.Tensor: Transformed key tensor, size
(#batch, n_head, time2, d_k).
torch.Tensor: Transformed value tensor, size
(#batch, n_head, time2, d_k).
"""
n_batch = query.size(0)
q = self.linear_q(query).view(n_batch, -1, self.h, self.d_k)
k = self.linear_k(key).view(n_batch, -1, self.h, self.d_k)
v = self.linear_v(value).view(n_batch, -1, self.h, self.d_k)
q = q.transpose(1, 2)
k = k.transpose(1, 2)
v = v.transpose(1, 2)
return q, k, v
def forward_attention(self, value: 'torch.Tensor', scores:
'torch.Tensor', mask: 'Optional[torch.Tensor]') ->torch.Tensor:
"""Compute attention context vector.
Args:
value (torch.Tensor): Transformed value, size
(#batch, n_head, time2, d_k).
scores (torch.Tensor): Attention score, size
(#batch, n_head, time1, time2).
mask (torch.Tensor): Mask, size (#batch, 1, time2) or
(#batch, time1, time2).
Returns:
torch.Tensor: Transformed value (#batch, time1, d_model)
weighted by the attention score (#batch, time1, time2).
"""
n_batch = value.size(0)
if mask is not None:
mask = mask.unsqueeze(1).eq(0)
scores = scores.masked_fill(mask, -float('inf'))
attn = torch.softmax(scores, dim=-1).masked_fill(mask, 0.0)
else:
attn = torch.softmax(scores, dim=-1)
p_attn = self.dropout(attn)
x = torch.matmul(p_attn, value)
x = x.transpose(1, 2).contiguous().view(n_batch, -1, self.h * self.d_k)
return self.linear_out(x)
def forward(self, input_0, input_1, input_2, input_3):
primals_2 = self.linear_q.weight
primals_3 = self.linear_q.bias
primals_4 = self.linear_k.weight
primals_5 = self.linear_k.bias
primals_7 = self.linear_v.weight
primals_8 = self.linear_v.bias
primals_11 = self.linear_out.weight
primals_12 = self.linear_out.bias
primals_1 = input_0
primals_6 = input_1
primals_9 = input_2
primals_10 = input_3
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8, primals_9,
primals_10, primals_11, primals_12])
return output[0]
|
InfluencerNGZK/wenet
|
MultiHeadedAttention
| false
| 2,388
|
[
"Apache-2.0"
] | 0
|
9a3c7f70a78ce675f5e013b1f67a06d1d23fba3e
|
https://github.com/InfluencerNGZK/wenet/tree/9a3c7f70a78ce675f5e013b1f67a06d1d23fba3e
|
SENet
|
import torch
import torch.nn as nn
import torch.utils.data
class SENet(nn.Module):
"""support estimation network"""
def __init__(self, input_size: 'int', hidden_size: 'int', output_dims:
'int') ->None:
super(SENet, self).__init__()
self.l_1 = nn.Linear(input_size, hidden_size)
self.l_2 = nn.Linear(hidden_size, output_dims)
self.act = nn.Tanh()
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
out = self.l_1(x)
out = self.act(out)
out = self.l_2(out)
out = self.act(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4, 'hidden_size': 4, 'output_dims': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = libdevice.tanh(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4), (4, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 4), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_tanh_0[grid(256)](buf1, primals_2, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2)
buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf2
triton_poi_fused_tanh_0[grid(256)](buf3, primals_5, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_5
return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf1, buf3, primals_4
class SENetNew(nn.Module):
"""support estimation network"""
def __init__(self, input_size: 'int', hidden_size: 'int', output_dims:
'int') ->None:
super(SENetNew, self).__init__()
self.l_1 = nn.Linear(input_size, hidden_size)
self.l_2 = nn.Linear(hidden_size, output_dims)
self.act = nn.Tanh()
def forward(self, input_0):
primals_1 = self.l_1.weight
primals_2 = self.l_1.bias
primals_4 = self.l_2.weight
primals_5 = self.l_2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Hcnaeg/DI-engine
|
SENet
| false
| 2,389
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
ClippedLinearQuantization
|
import torch
from torch.optim.lr_scheduler import *
import torch.optim
import torch.nn as nn
import torch.optim.lr_scheduler
import torch.nn.parallel
import torch.utils.data
import torch.onnx
import torch.testing
def linear_dequantize(input, scale, zero_point, inplace=False):
if inplace:
input.add_(zero_point).div_(scale)
return input
return (input + zero_point) / scale
def linear_quantize(input, scale, zero_point, inplace=False):
if inplace:
input.mul_(scale).sub_(zero_point).round_()
return input
return torch.round(scale * input - zero_point)
def _prep_saturation_val_tensor(sat_val):
is_scalar = not isinstance(sat_val, torch.Tensor)
out = torch.tensor(sat_val) if is_scalar else sat_val.clone().detach()
if not out.is_floating_point():
out = out
if out.dim() == 0:
out = out.unsqueeze(0)
return is_scalar, out
def asymmetric_linear_quantization_params(num_bits, saturation_min,
saturation_max, integral_zero_point=True, signed=False):
scalar_min, sat_min = _prep_saturation_val_tensor(saturation_min)
scalar_max, sat_max = _prep_saturation_val_tensor(saturation_max)
is_scalar = scalar_min and scalar_max
if scalar_max and not scalar_min:
sat_max = sat_max
elif scalar_min and not scalar_max:
sat_min = sat_min
if any(sat_min > sat_max):
raise ValueError('saturation_min must be smaller than saturation_max')
n = 2 ** num_bits - 1
sat_min = torch.min(sat_min, torch.zeros_like(sat_min))
sat_max = torch.max(sat_max, torch.zeros_like(sat_max))
diff = sat_max - sat_min
diff[diff == 0] = n
scale = n / diff
zero_point = scale * sat_min
if integral_zero_point:
zero_point = zero_point.round()
if signed:
zero_point += 2 ** (num_bits - 1)
if is_scalar:
return scale.item(), zero_point.item()
return scale, zero_point
def clamp(input, min, max, inplace=False):
if inplace:
input.clamp_(min, max)
return input
return torch.clamp(input, min, max)
class LinearQuantizeSTE(torch.autograd.Function):
@staticmethod
def forward(ctx, input, scale, zero_point, dequantize, inplace):
if inplace:
ctx.mark_dirty(input)
output = linear_quantize(input, scale, zero_point, inplace)
if dequantize:
output = linear_dequantize(output, scale, zero_point, inplace)
return output
@staticmethod
def backward(ctx, grad_output):
return grad_output, None, None, None, None
class ClippedLinearQuantization(nn.Module):
def __init__(self, num_bits, clip_val, dequantize=True, inplace=False):
super(ClippedLinearQuantization, self).__init__()
self.num_bits = num_bits
self.clip_val = clip_val
self.scale, self.zero_point = asymmetric_linear_quantization_params(
num_bits, 0, clip_val, signed=False)
self.dequantize = dequantize
self.inplace = inplace
def forward(self, input):
input = clamp(input, 0, self.clip_val, self.inplace)
input = LinearQuantizeSTE.apply(input, self.scale, self.zero_point,
self.dequantize, self.inplace)
return input
def __repr__(self):
inplace_str = ', inplace' if self.inplace else ''
return '{0}(num_bits={1}, clip_val={2}{3})'.format(self.__class__.
__name__, self.num_bits, self.clip_val, inplace_str)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_bits': 4, 'clip_val': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
from torch.optim.lr_scheduler import *
import torch.optim
import torch.nn as nn
import torch.optim.lr_scheduler
import torch.nn.parallel
import torch.utils.data
import torch.onnx
import torch.testing
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_add_clamp_div_mul_round_sub_0(in_ptr0, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.0
tmp2 = triton_helpers.maximum(tmp0, tmp1)
tmp3 = 4.0
tmp4 = triton_helpers.minimum(tmp2, tmp3)
tmp5 = 3.75
tmp6 = tmp4 * tmp5
tmp7 = tmp6 - tmp1
tmp8 = libdevice.nearbyint(tmp7)
tmp9 = tmp8 + tmp1
tmp10 = 0.26666666666666666
tmp11 = tmp9 * tmp10
tl.store(out_ptr0 + x0, tmp11, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_clamp_div_mul_round_sub_0[grid(256)](arg0_1,
buf0, 256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
def linear_dequantize(input, scale, zero_point, inplace=False):
if inplace:
input.add_(zero_point).div_(scale)
return input
return (input + zero_point) / scale
def linear_quantize(input, scale, zero_point, inplace=False):
if inplace:
input.mul_(scale).sub_(zero_point).round_()
return input
return torch.round(scale * input - zero_point)
def _prep_saturation_val_tensor(sat_val):
is_scalar = not isinstance(sat_val, torch.Tensor)
out = torch.tensor(sat_val) if is_scalar else sat_val.clone().detach()
if not out.is_floating_point():
out = out
if out.dim() == 0:
out = out.unsqueeze(0)
return is_scalar, out
def asymmetric_linear_quantization_params(num_bits, saturation_min,
saturation_max, integral_zero_point=True, signed=False):
scalar_min, sat_min = _prep_saturation_val_tensor(saturation_min)
scalar_max, sat_max = _prep_saturation_val_tensor(saturation_max)
is_scalar = scalar_min and scalar_max
if scalar_max and not scalar_min:
sat_max = sat_max
elif scalar_min and not scalar_max:
sat_min = sat_min
if any(sat_min > sat_max):
raise ValueError('saturation_min must be smaller than saturation_max')
n = 2 ** num_bits - 1
sat_min = torch.min(sat_min, torch.zeros_like(sat_min))
sat_max = torch.max(sat_max, torch.zeros_like(sat_max))
diff = sat_max - sat_min
diff[diff == 0] = n
scale = n / diff
zero_point = scale * sat_min
if integral_zero_point:
zero_point = zero_point.round()
if signed:
zero_point += 2 ** (num_bits - 1)
if is_scalar:
return scale.item(), zero_point.item()
return scale, zero_point
def clamp(input, min, max, inplace=False):
if inplace:
input.clamp_(min, max)
return input
return torch.clamp(input, min, max)
class LinearQuantizeSTE(torch.autograd.Function):
@staticmethod
def forward(ctx, input, scale, zero_point, dequantize, inplace):
if inplace:
ctx.mark_dirty(input)
output = linear_quantize(input, scale, zero_point, inplace)
if dequantize:
output = linear_dequantize(output, scale, zero_point, inplace)
return output
@staticmethod
def backward(ctx, grad_output):
return grad_output, None, None, None, None
class ClippedLinearQuantizationNew(nn.Module):
def __init__(self, num_bits, clip_val, dequantize=True, inplace=False):
super(ClippedLinearQuantizationNew, self).__init__()
self.num_bits = num_bits
self.clip_val = clip_val
self.scale, self.zero_point = asymmetric_linear_quantization_params(
num_bits, 0, clip_val, signed=False)
self.dequantize = dequantize
self.inplace = inplace
def __repr__(self):
inplace_str = ', inplace' if self.inplace else ''
return '{0}(num_bits={1}, clip_val={2}{3})'.format(self.__class__.
__name__, self.num_bits, self.clip_val, inplace_str)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
HatsuneMiku4/distiller
|
ClippedLinearQuantization
| false
| 2,390
|
[
"Apache-2.0"
] | 0
|
8fbacb01ebcb7d70c5d3ecb6a88093e6c4d42137
|
https://github.com/HatsuneMiku4/distiller/tree/8fbacb01ebcb7d70c5d3ecb6a88093e6c4d42137
|
GEGLU
|
import torch
from torch import nn
import torch.nn.functional as F
class GEGLU(nn.Module):
def forward(self, x):
x, gates = x.chunk(2, dim=-1)
return x * F.gelu(gates)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_gelu_mul_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 2
x1 = xindex // 2
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (2 + x0 + 4 * x1), xmask)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = 0.7071067811865476
tmp5 = tmp1 * tmp4
tmp6 = libdevice.erf(tmp5)
tmp7 = 1.0
tmp8 = tmp6 + tmp7
tmp9 = tmp3 * tmp8
tmp10 = tmp0 * tmp9
tl.store(out_ptr0 + x2, tmp10, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_gelu_mul_0[grid(128)](arg0_1, buf0, 128, XBLOCK=
128, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class GEGLUNew(nn.Module):
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
JaireYu/perceiver-pytorch
|
GEGLU
| false
| 2,391
|
[
"MIT"
] | 0
|
23edd66a057bb0a6fc15126461b4409a522ca09e
|
https://github.com/JaireYu/perceiver-pytorch/tree/23edd66a057bb0a6fc15126461b4409a522ca09e
|
ScaledDotProductAttention
|
import torch
from typing import Optional
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.data
class ScaledDotProductAttention(nn.Module):
"""
Overview:
Implementation of dot product attentionn with scaling.
"""
def __init__(self, d_k: 'int', dropout: 'float'=0.0) ->None:
super(ScaledDotProductAttention, self).__init__()
self.d_k = d_k
self.dropout = nn.Dropout(dropout)
def forward(self, q: 'torch.Tensor', k: 'torch.Tensor', v:
'torch.Tensor', mask: 'Optional[torch.Tensor]'=None) ->torch.Tensor:
attn = torch.matmul(q / self.d_k ** 0.5, k.transpose(2, 3))
if mask is not None:
attn = attn.masked_fill(~mask, -1000000000.0)
attn = self.dropout(F.softmax(attn, dim=-1))
output = torch.matmul(attn, v)
return output
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 4])]
def get_init_inputs():
return [[], {'d_k': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_div_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.5
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused__softmax_1(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp0 - tmp7
tmp9 = tl_math.exp(tmp8)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused__softmax_2(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 4 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tl.store(out_ptr0 + x2, tmp8, xmask)
def call(args):
arg0_1, arg1_1, arg2_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg1_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg2_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_0[grid(256)](arg0_1, buf0, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del arg0_1
buf1 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf0, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg1_1, (16, 4, 4), (16, 1, 4), 0), out=buf1
)
del arg1_1
buf2 = buf0
del buf0
triton_poi_fused__softmax_1[grid(256)](buf1, buf2, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf3 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
triton_poi_fused__softmax_2[grid(256)](buf2, buf3, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf4 = reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(arg2_1, (16, 4, 4), (16, 4, 1), 0), out=buf4
)
del arg2_1
del buf3
return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0),
class ScaledDotProductAttentionNew(nn.Module):
"""
Overview:
Implementation of dot product attentionn with scaling.
"""
def __init__(self, d_k: 'int', dropout: 'float'=0.0) ->None:
super(ScaledDotProductAttentionNew, self).__init__()
self.d_k = d_k
self.dropout = nn.Dropout(dropout)
def forward(self, input_0, input_1, input_2):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
output = call([arg0_1, arg1_1, arg2_1])
return output[0]
|
Hcnaeg/DI-engine
|
ScaledDotProductAttention
| false
| 2,392
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
RewardModelNetwork
|
import torch
import torch.nn as nn
import torch.utils.data
class RewardModelNetwork(nn.Module):
def __init__(self, input_size: 'int', hidden_size: 'int', output_size:
'int') ->None:
super(RewardModelNetwork, self).__init__()
self.l1 = nn.Linear(input_size, hidden_size)
self.l2 = nn.Linear(hidden_size, output_size)
self.a1 = nn.Tanh()
self.a2 = nn.Sigmoid()
def forward(self, x: 'torch.Tensor') ->torch.Tensor:
out = x
out = self.l1(out)
out = self.a1(out)
out = self.l2(out)
out = self.a2(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_size': 4, 'hidden_size': 4, 'output_size': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn as nn
import torch.utils.data
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_tanh_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = libdevice.tanh(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, xmask)
@triton.jit
def triton_poi_fused_sigmoid_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_tanh_0[grid(256)](buf1, primals_3, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf2)
buf3 = reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf2
triton_poi_fused_sigmoid_1[grid(256)](buf3, primals_5, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_5
return buf3, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), buf1, buf3, primals_4
class RewardModelNetworkNew(nn.Module):
def __init__(self, input_size: 'int', hidden_size: 'int', output_size:
'int') ->None:
super(RewardModelNetworkNew, self).__init__()
self.l1 = nn.Linear(input_size, hidden_size)
self.l2 = nn.Linear(hidden_size, output_size)
self.a1 = nn.Tanh()
self.a2 = nn.Sigmoid()
def forward(self, input_0):
primals_2 = self.l1.weight
primals_3 = self.l1.bias
primals_4 = self.l2.weight
primals_5 = self.l2.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
Hcnaeg/DI-engine
|
RewardModelNetwork
| false
| 2,393
|
[
"Apache-2.0"
] | 0
|
aba0c629f87649854091e9e59d948f83962e3e1e
|
https://github.com/Hcnaeg/DI-engine/tree/aba0c629f87649854091e9e59d948f83962e3e1e
|
OutputTransition
|
import torch
from torch import nn
class OutputTransition(nn.Module):
def __init__(self, inChans, n_labels):
super(OutputTransition, self).__init__()
self.final_conv = nn.Conv3d(inChans, n_labels, kernel_size=1)
self.sigmoid = nn.Sigmoid()
def forward(self, x):
out = self.sigmoid(self.final_conv(x))
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'inChans': 4, 'n_labels': 4}]
|
import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch import nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_sigmoid_0(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x1 = xindex // 64
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 1, 1, 1), (4, 1, 1, 1, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(reinterpret_tensor(primals_3, (1,
4, 4, 4, 4), (256, 64, 16, 4, 1), 0), primals_1, stride=(1, 1,
1), padding=(0, 0, 0), dilation=(1, 1, 1), transposed=False,
output_padding=(0, 0, 0), groups=1, bias=None)
assert_size_stride(buf0, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1))
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_sigmoid_0[grid(256)](buf1, primals_2, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_2
return buf1, primals_1, reinterpret_tensor(primals_3, (1, 4, 4, 4, 4),
(256, 64, 16, 4, 1), 0), buf1
class OutputTransitionNew(nn.Module):
def __init__(self, inChans, n_labels):
super(OutputTransitionNew, self).__init__()
self.final_conv = nn.Conv3d(inChans, n_labels, kernel_size=1)
self.sigmoid = nn.Sigmoid()
def forward(self, input_0):
primals_1 = self.final_conv.weight
primals_2 = self.final_conv.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
JXQI/ModelsGenesis
|
OutputTransition
| false
| 2,394
|
[
"MIT"
] | 0
|
f961288313a78f03bd3045ac27722f791f365bd8
|
https://github.com/JXQI/ModelsGenesis/tree/f961288313a78f03bd3045ac27722f791f365bd8
|
ZeroPad1d
|
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.optim.lr_scheduler
import torch.utils.data
import torch.onnx.operators
import torch.optim
class ZeroPad1d(nn.Module):
def __init__(self, pad_left, pad_right):
super().__init__()
self.pad_left = pad_left
self.pad_right = pad_right
def forward(self, x):
return F.pad(x, (self.pad_left, self.pad_right))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'pad_left': 4, 'pad_right': 4}]
|
import torch
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
import torch.nn as nn
import torch.optim.lr_scheduler
import torch.utils.data
import torch.onnx.operators
import torch.optim
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda
@triton.jit
def triton_poi_fused_constant_pad_nd_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 768
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 12
x1 = xindex // 12
x2 = xindex
tmp0 = -4 + x0
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = tl.load(in_ptr0 + (-4 + x0 + 4 * x1), tmp5 & xmask, other=0.0)
tl.store(out_ptr0 + x2, tmp6, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 12), (192, 48, 12, 1), torch.
float32)
get_raw_stream(0)
triton_poi_fused_constant_pad_nd_0[grid(768)](arg0_1, buf0, 768,
XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class ZeroPad1dNew(nn.Module):
def __init__(self, pad_left, pad_right):
super().__init__()
self.pad_left = pad_left
self.pad_right = pad_right
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
Fei00Wu/espresso
|
ZeroPad1d
| false
| 2,395
|
[
"MIT"
] | 0
|
4e8e6e2f9151a87448845c5142611c103dd4580c
|
https://github.com/Fei00Wu/espresso/tree/4e8e6e2f9151a87448845c5142611c103dd4580c
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.