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
|
|---|---|---|---|---|---|---|---|---|---|---|
PitchShift
|
import torch
from torch import nn
import torch.nn.functional as F
class PitchShift(nn.Module):
def __init__(self, shift):
super(PitchShift, self).__init__()
self.shift = shift
def forward(self, x):
if len(x.shape) == 2:
x = x.unsqueeze(0)
x = x.squeeze()
mel_size = x.shape[1]
shift_scale = (mel_size + self.shift) / mel_size
x = F.interpolate(x.unsqueeze(1), scale_factor=(shift_scale, 1.0),
align_corners=False, recompute_scale_factor=True, mode='bilinear'
).squeeze(1)
x = x[:, :mel_size]
if x.size(1) < mel_size:
pad_size = mel_size - x.size(1)
x = torch.cat([x, torch.zeros(x.size(0), pad_size, x.size(2))],
dim=1)
x = x.squeeze()
return x.unsqueeze(1)
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'shift': 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 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__to_copy__unsafe_index_add_arange_clamp_mul_sub_0(
in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 8
x0 = xindex % 4
x2 = xindex // 32
x4 = xindex
tmp0 = x1
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 + tmp2
tmp4 = tmp3 * tmp2
tmp5 = tmp4 - tmp2
tmp6 = 0.0
tmp7 = triton_helpers.maximum(tmp5, tmp6)
tmp8 = tmp7.to(tl.int32)
tmp9 = tl.full([1], 1, tl.int64)
tmp10 = tmp8 + tmp9
tmp11 = tl.full([1], 3, tl.int64)
tmp12 = triton_helpers.minimum(tmp10, tmp11)
tmp13 = x0
tmp14 = tmp13.to(tl.float32)
tmp15 = tmp14 + tmp2
tmp16 = 1.0
tmp17 = tmp15 * tmp16
tmp18 = tmp17 - tmp2
tmp19 = triton_helpers.maximum(tmp18, tmp6)
tmp20 = tmp19.to(tl.int32)
tmp21 = tmp20 + tmp9
tmp22 = triton_helpers.minimum(tmp21, tmp11)
tmp23 = tl.load(in_ptr0 + (tmp22 + 4 * tmp12 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp24 = tl.load(in_ptr0 + (tmp20 + 4 * tmp12 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp25 = tmp23 - tmp24
tmp26 = tmp20.to(tl.float32)
tmp27 = tmp19 - tmp26
tmp28 = triton_helpers.maximum(tmp27, tmp6)
tmp29 = triton_helpers.minimum(tmp28, tmp16)
tmp30 = tmp25 * tmp29
tmp31 = tmp24 + tmp30
tmp32 = tl.load(in_ptr0 + (tmp20 + 4 * tmp8 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp33 = tl.load(in_ptr0 + (tmp22 + 4 * tmp8 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp34 = tmp33 - tmp32
tmp35 = tmp34 * tmp29
tmp36 = tmp32 + tmp35
tmp37 = tmp31 - tmp36
tmp38 = tmp8.to(tl.float32)
tmp39 = tmp7 - tmp38
tmp40 = triton_helpers.maximum(tmp39, tmp6)
tmp41 = triton_helpers.minimum(tmp40, tmp16)
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), (16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 8, 4), (32, 128, 4, 1), torch.float32)
buf1 = buf0
del buf0
buf2 = reinterpret_tensor(buf1, (4, 1, 8, 4), (32, 32, 4, 1), 0)
del buf1
get_raw_stream(0)
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_0[grid
(128)](buf2, arg0_1, 128, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf2, (4, 1, 4, 4), (32, 16, 4, 1), 0),
class PitchShiftNew(nn.Module):
def __init__(self, shift):
super(PitchShiftNew, self).__init__()
self.shift = shift
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
shaun95/StarGANv2-VC
|
PitchShift
| false
| 16,402
|
[
"MIT"
] | 116
|
ed20538971a03d699351a349a3631767333baeb7
|
https://github.com/shaun95/StarGANv2-VC/tree/ed20538971a03d699351a349a3631767333baeb7
|
InjectNoise
|
import torch
from torch import nn
import torch.utils.data
import torch.nn
class InjectNoise(nn.Module):
def __init__(self, channels):
super().__init__()
self.weight = nn.Parameter(torch.zeros(1, channels, 1, 1))
def forward(self, x):
noise = torch.randn((x.shape[0], 1, x.shape[2], x.shape[3]), device
=x.device)
return x + self.weight * noise
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channels': 4}]
|
import torch
from torch import device
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
import torch.utils.data
import torch.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_mul_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
x3 = xindex
x1 = xindex // 16 % 4
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tl.store(out_ptr0 + x3, 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, 4, 1, 1), (4, 1, 1, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = torch.ops.aten.randn.default([4, 1, 4, 4], device=device(
type='cuda', index=0), pin_memory=False)
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_add_mul_0[grid(256)](primals_1, primals_2, buf1,
buf2, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_2
return buf2, buf1
class InjectNoiseNew(nn.Module):
def __init__(self, channels):
super().__init__()
self.weight = nn.Parameter(torch.zeros(1, channels, 1, 1))
def forward(self, input_0):
primals_2 = self.weight
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
shimon-c/Machine-Learning-Collection
|
InjectNoise
| false
| 16,403
|
[
"MIT"
] | 3,094
|
ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
https://github.com/shimon-c/Machine-Learning-Collection/tree/ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
ResBlk
|
import math
import torch
from torch import nn
import torch.nn.functional as F
class DownSample(nn.Module):
def __init__(self, layer_type):
super().__init__()
self.layer_type = layer_type
def forward(self, x):
if self.layer_type == 'none':
return x
elif self.layer_type == 'timepreserve':
return F.avg_pool2d(x, (2, 1))
elif self.layer_type == 'half':
return F.avg_pool2d(x, 2)
else:
raise RuntimeError(
'Got unexpected donwsampletype %s, expected is [none, timepreserve, half]'
% self.layer_type)
class ResBlk(nn.Module):
def __init__(self, dim_in, dim_out, actv=nn.LeakyReLU(0.2), normalize=
False, downsample='none'):
super().__init__()
self.actv = actv
self.normalize = normalize
self.downsample = DownSample(downsample)
self.learned_sc = dim_in != dim_out
self._build_weights(dim_in, dim_out)
def _build_weights(self, dim_in, dim_out):
self.conv1 = nn.Conv2d(dim_in, dim_in, 3, 1, 1)
self.conv2 = nn.Conv2d(dim_in, dim_out, 3, 1, 1)
if self.normalize:
self.norm1 = nn.InstanceNorm2d(dim_in, affine=True)
self.norm2 = nn.InstanceNorm2d(dim_in, affine=True)
if self.learned_sc:
self.conv1x1 = nn.Conv2d(dim_in, dim_out, 1, 1, 0, bias=False)
def _shortcut(self, x):
if self.learned_sc:
x = self.conv1x1(x)
if self.downsample:
x = self.downsample(x)
return x
def _residual(self, x):
if self.normalize:
x = self.norm1(x)
x = self.actv(x)
x = self.conv1(x)
x = self.downsample(x)
if self.normalize:
x = self.norm2(x)
x = self.actv(x)
x = self.conv2(x)
return x
def forward(self, x):
x = self._shortcut(x) + self._residual(x)
return x / math.sqrt(2)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim_in': 4, 'dim_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 import 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_leaky_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 = 0.0
tmp2 = tmp0 > tmp1
tmp3 = 0.2
tmp4 = tmp0 * tmp3
tmp5 = tl.where(tmp2, tmp0, tmp4)
tl.store(out_ptr0 + x0, tmp5, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_1(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.2
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp7, xmask)
@triton.jit
def triton_poi_fused_add_convolution_div_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
x3 = xindex
x1 = xindex // 16 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_out_ptr0 + x3, xmask)
tmp2 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tmp0 + tmp3
tmp5 = 0.7071067811865475
tmp6 = tmp4 * tmp5
tl.store(in_out_ptr0 + x3, 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, 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_leaky_relu_0[grid(256)](primals_1, buf0, 256,
XBLOCK=256, 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 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_convolution_leaky_relu_1[grid(256)](buf1,
primals_3, buf2, buf3, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf1
del primals_3
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1))
buf5 = buf4
del buf4
triton_poi_fused_add_convolution_div_2[grid(256)](buf5, primals_1,
primals_5, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
del primals_5
return buf5, primals_2, primals_4, buf0, buf2, buf3
class DownSample(nn.Module):
def __init__(self, layer_type):
super().__init__()
self.layer_type = layer_type
def forward(self, x):
if self.layer_type == 'none':
return x
elif self.layer_type == 'timepreserve':
return F.avg_pool2d(x, (2, 1))
elif self.layer_type == 'half':
return F.avg_pool2d(x, 2)
else:
raise RuntimeError(
'Got unexpected donwsampletype %s, expected is [none, timepreserve, half]'
% self.layer_type)
class ResBlkNew(nn.Module):
def __init__(self, dim_in, dim_out, actv=nn.LeakyReLU(0.2), normalize=
False, downsample='none'):
super().__init__()
self.actv = actv
self.normalize = normalize
self.downsample = DownSample(downsample)
self.learned_sc = dim_in != dim_out
self._build_weights(dim_in, dim_out)
def _build_weights(self, dim_in, dim_out):
self.conv1 = nn.Conv2d(dim_in, dim_in, 3, 1, 1)
self.conv2 = nn.Conv2d(dim_in, dim_out, 3, 1, 1)
if self.normalize:
self.norm1 = nn.InstanceNorm2d(dim_in, affine=True)
self.norm2 = nn.InstanceNorm2d(dim_in, affine=True)
if self.learned_sc:
self.conv1x1 = nn.Conv2d(dim_in, dim_out, 1, 1, 0, bias=False)
def _shortcut(self, x):
if self.learned_sc:
x = self.conv1x1(x)
if self.downsample:
x = self.downsample(x)
return x
def _residual(self, x):
if self.normalize:
x = self.norm1(x)
x = self.actv(x)
x = self.conv1(x)
x = self.downsample(x)
if self.normalize:
x = self.norm2(x)
x = self.actv(x)
x = self.conv2(x)
return x
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]
|
shaun95/StarGANv2-VC
|
ResBlk
| false
| 16,404
|
[
"MIT"
] | 116
|
ed20538971a03d699351a349a3631767333baeb7
|
https://github.com/shaun95/StarGANv2-VC/tree/ed20538971a03d699351a349a3631767333baeb7
|
LayerNorm
|
import torch
import torch.nn as nn
class LayerNorm(nn.Module):
"""Norm to 0-mean 1-std , then do a learned diagonal affine transform."""
def __init__(self, features, eps=1e-05):
super(LayerNorm, self).__init__()
self.scale = nn.Parameter(torch.ones(features))
self.shift = nn.Parameter(torch.zeros(features))
self.eps = eps
def forward(self, x):
mean = x.mean(-1, keepdim=True)
s = (x - mean).pow(2).mean(-1, keepdim=True)
x = (x - mean) * torch.rsqrt(s + self.eps)
return self.scale * x + self.shift
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'features': 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_mean_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
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 = 4.0
tmp9 = tmp7 / tmp8
tmp10 = tmp0 - tmp9
tl.store(out_ptr0 + x2, tmp10, xmask)
@triton.jit
def triton_poi_fused_add_mean_mul_pow_rsqrt_1(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')
tmp4 = tl.load(in_ptr1 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr1 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr1 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp20 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp3 = tmp2 * tmp2
tmp5 = tmp4 * tmp4
tmp6 = tmp3 + tmp5
tmp8 = tmp7 * tmp7
tmp9 = tmp6 + tmp8
tmp11 = tmp10 * tmp10
tmp12 = tmp9 + tmp11
tmp13 = 4.0
tmp14 = tmp12 / tmp13
tmp15 = 1e-05
tmp16 = tmp14 + tmp15
tmp17 = libdevice.rsqrt(tmp16)
tmp18 = tmp1 * tmp17
tmp19 = tmp0 * tmp18
tmp21 = tmp19 + tmp20
tl.store(out_ptr0 + x2, tmp21, 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,), (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_mean_sub_0[grid(256)](primals_1, buf0, 256, XBLOCK
=128, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mean_mul_pow_rsqrt_1[grid(256)](primals_2,
buf0, primals_3, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del primals_2
del primals_3
return buf1, primals_1
class LayerNormNew(nn.Module):
"""Norm to 0-mean 1-std , then do a learned diagonal affine transform."""
def __init__(self, features, eps=1e-05):
super(LayerNormNew, self).__init__()
self.scale = nn.Parameter(torch.ones(features))
self.shift = nn.Parameter(torch.zeros(features))
self.eps = eps
def forward(self, input_0):
primals_2 = self.scale
primals_3 = self.shift
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
shenyunlong/naru
|
LayerNorm
| false
| 16,405
|
[
"Apache-2.0"
] | 70
|
264cf4e9c96c9e34422f9eebc455a714aeef0b57
|
https://github.com/shenyunlong/naru/tree/264cf4e9c96c9e34422f9eebc455a714aeef0b57
|
AdaIN
|
import torch
from torch import nn
class AdaIN(nn.Module):
def __init__(self, style_dim, num_features):
super().__init__()
self.norm = nn.InstanceNorm2d(num_features, affine=False)
self.fc = nn.Linear(style_dim, num_features * 2)
def forward(self, x, s):
h = self.fc(s)
h = h.view(h.size(0), h.size(1), 1, 1)
gamma, beta = torch.chunk(h, chunks=2, dim=1)
return (1 + gamma) * self.norm(x) + beta
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'style_dim': 4, 'num_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_per_fused__native_batch_norm_legit_add_mul_0(in_out_ptr0,
in_ptr0, in_ptr1, in_ptr2, out_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
x2 = xindex % 4
x3 = xindex // 4
tmp0 = tl.load(in_ptr0 + (r1 + 16 * x0), xmask, other=0.0)
tmp22 = tl.load(in_ptr1 + (x2 + 8 * x3), xmask, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last')
tmp30 = tl.load(in_ptr1 + (4 + x2 + 8 * x3), xmask, eviction_policy=
'evict_last')
tmp31 = tl.load(in_ptr2 + (4 + x2), xmask, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = 16.0
tmp18 = tmp16 / tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.rsqrt(tmp20)
tmp24 = tmp22 + tmp23
tmp25 = 1.0
tmp26 = tmp24 + tmp25
tmp27 = tmp0 - tmp10
tmp28 = tmp27 * tmp21
tmp29 = tmp26 * tmp28
tmp32 = tmp30 + tmp31
tmp33 = tmp29 + tmp32
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp21, xmask)
tl.store(out_ptr1 + (r1 + 16 * x0), tmp33, xmask)
tl.store(out_ptr0 + x0, tmp10, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (8, 4), (4, 1))
assert_size_stride(primals_2, (8,), (1,))
assert_size_stride(primals_3, (4, 4), (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)
buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 8),
(1, 4), 0), out=buf0)
del primals_1
buf1 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32)
buf2 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32
)
buf4 = reinterpret_tensor(buf2, (1, 16, 1, 1), (16, 1, 1, 1), 0)
del buf2
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused__native_batch_norm_legit_add_mul_0[grid(16)](buf4,
primals_4, buf0, primals_2, buf1, buf5, 16, 16, XBLOCK=8,
num_warps=2, num_stages=1)
del buf0
del primals_2
return buf5, primals_3, primals_4, buf1, buf4
class AdaINNew(nn.Module):
def __init__(self, style_dim, num_features):
super().__init__()
self.norm = nn.InstanceNorm2d(num_features, affine=False)
self.fc = nn.Linear(style_dim, num_features * 2)
def forward(self, input_0, input_1):
primals_1 = self.fc.weight
primals_2 = self.fc.bias
primals_4 = input_0
primals_3 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
shaun95/StarGANv2-VC
|
AdaIN
| false
| 16,406
|
[
"MIT"
] | 116
|
ed20538971a03d699351a349a3631767333baeb7
|
https://github.com/shaun95/StarGANv2-VC/tree/ed20538971a03d699351a349a3631767333baeb7
|
WSConv2d
|
import torch
from torch import nn
import torch.utils.data
import torch.nn
class WSConv2d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
padding=1, gain=2):
super(WSConv2d, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding)
self.scale = (gain / (in_channels * kernel_size ** 2)) ** 0.5
self.bias = self.conv.bias
self.conv.bias = None
nn.init.normal_(self.conv.weight)
nn.init.zeros_(self.bias)
def forward(self, x):
return self.conv(x * self.scale) + self.bias.view(1, self.bias.
shape[0], 1, 1)
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 import nn
import torch.utils.data
import torch.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_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 = 0.23570226039551584
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_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
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, 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,))
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_mul_0[grid(256)](primals_1, buf0, 256, XBLOCK=256,
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, 4, 4), (64, 16, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_add_1[grid(256)](buf2, primals_3, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_3
return buf2, primals_2, buf0
class WSConv2dNew(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
padding=1, gain=2):
super(WSConv2dNew, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding)
self.scale = (gain / (in_channels * kernel_size ** 2)) ** 0.5
self.bias = self.conv.bias
self.conv.bias = None
nn.init.normal_(self.conv.weight)
nn.init.zeros_(self.bias)
def forward(self, input_0):
primals_3 = self.bias
primals_2 = self.conv.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
shimon-c/Machine-Learning-Collection
|
WSConv2d
| false
| 16,407
|
[
"MIT"
] | 3,094
|
ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
https://github.com/shimon-c/Machine-Learning-Collection/tree/ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
WSLinear
|
import torch
from torch import nn
import torch.utils.data
import torch.nn
class WSLinear(nn.Module):
def __init__(self, in_features, out_features, gain=2):
super(WSLinear, self).__init__()
self.linear = nn.Linear(in_features, out_features)
self.scale = (gain / in_features) ** 0.5
self.bias = self.linear.bias
self.linear.bias = None
nn.init.normal_(self.linear.weight)
nn.init.zeros_(self.bias)
def forward(self, x):
return self.linear(x * self.scale) + 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 import nn
import torch.utils.data
import torch.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_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.7071067811865476
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_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
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, 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_mul_0[grid(256)](primals_1, buf0, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf1)
del primals_2
buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
triton_poi_fused_add_1[grid(256)](buf2, primals_3, 256, XBLOCK=128,
num_warps=4, num_stages=1)
del primals_3
return buf2, reinterpret_tensor(buf0, (64, 4), (4, 1), 0)
class WSLinearNew(nn.Module):
def __init__(self, in_features, out_features, gain=2):
super(WSLinearNew, self).__init__()
self.linear = nn.Linear(in_features, out_features)
self.scale = (gain / in_features) ** 0.5
self.bias = self.linear.bias
self.linear.bias = None
nn.init.normal_(self.linear.weight)
nn.init.zeros_(self.bias)
def forward(self, input_0):
primals_3 = self.bias
primals_2 = self.linear.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
shimon-c/Machine-Learning-Collection
|
WSLinear
| false
| 16,408
|
[
"MIT"
] | 3,094
|
ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
https://github.com/shimon-c/Machine-Learning-Collection/tree/ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
WSConv2d
|
import torch
from torchvision.transforms import functional as F
from torch import nn
from torch.nn import functional as F
class WSConv2d(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, bias=True, eps=1e-05):
super().__init__(in_channels, out_channels, kernel_size, stride,
padding, dilation, groups, bias)
self.gain = nn.Parameter(torch.ones(out_channels))
self.eps = eps ** 2
fan_in = torch.numel(self.weight[0])
self.scale = fan_in ** -0.5
nn.init.kaiming_normal_(self.weight, nonlinearity='linear')
def forward(self, input):
weight = F.layer_norm(self.weight, self.weight.shape[1:], eps=self.eps)
gain = self.gain.view([-1] + [1] * (weight.ndim - 1))
weight = gain * self.scale * weight
return F.conv2d(input, weight, self.bias, self.stride, self.padding,
self.dilation, self.groups)
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_per_fused_mul_native_layer_norm_0(in_out_ptr0, in_ptr0, in_ptr1,
out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
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)
tmp22 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = 64.0
tmp18 = tmp16 / tmp17
tmp19 = 1.0000000000000002e-10
tmp20 = tmp18 + tmp19
tmp21 = libdevice.rsqrt(tmp20)
tmp23 = 0.125
tmp24 = tmp22 * tmp23
tmp25 = tmp0 - tmp10
tmp26 = tmp25 * tmp21
tmp27 = tmp24 * tmp26
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp21, xmask)
tl.store(out_ptr1 + (r1 + 64 * x0), tmp27, xmask)
tl.store(out_ptr0 + x0, tmp10, xmask)
@triton.jit
def triton_poi_fused_convolution_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
tl.store(in_out_ptr0 + x2, tmp2, 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, (4,), (1,))
assert_size_stride(primals_3, (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)
buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32)
buf1 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
buf3 = reinterpret_tensor(buf1, (4, 1, 1, 1), (1, 1, 1, 1), 0)
del buf1
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_mul_native_layer_norm_0[grid(4)](buf3, primals_1,
primals_2, buf0, buf4, 4, 64, XBLOCK=1, num_warps=2, num_stages=1)
buf5 = extern_kernels.convolution(primals_4, buf4, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf5, (4, 4, 1, 1), (4, 1, 1, 1))
buf6 = buf5
del buf5
triton_poi_fused_convolution_1[grid(16)](buf6, primals_3, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
return buf6, primals_1, primals_2, primals_4, buf0, buf3, buf4
class WSConv2dNew(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, bias=True, eps=1e-05):
super().__init__(in_channels, out_channels, kernel_size, stride,
padding, dilation, groups, bias)
self.gain = nn.Parameter(torch.ones(out_channels))
self.eps = eps ** 2
fan_in = torch.numel(self.weight[0])
self.scale = fan_in ** -0.5
nn.init.kaiming_normal_(self.weight, nonlinearity='linear')
def forward(self, input_0):
primals_1 = self.weight
primals_2 = self.bias
primals_3 = self.gain
primals_4 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
rosinality/vision-transformers-pytorch
|
WSConv2d
| false
| 16,409
|
[
"MIT"
] | 77
|
b884b5da79900c96e4ce17fbb575cf1c5cb3cd5f
|
https://github.com/rosinality/vision-transformers-pytorch/tree/b884b5da79900c96e4ce17fbb575cf1c5cb3cd5f
|
DQN
|
import random
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
class DQN(nn.Module):
def __init__(self, state_dim, out_dim, capacity, bsz, epsilon):
super().__init__()
self.steps_done = 0
self.position = 0
self.pool = []
self.capacity = capacity
self.bsz = bsz
self.epsilon = epsilon
self.fc1 = nn.Linear(state_dim, 32)
self.fc2 = nn.Linear(32, out_dim)
self.fc1.weight.data.uniform_(-0.1, 0.1)
self.fc2.weight.data.uniform_(-0.1, 0.1)
def forward(self, x):
x = F.relu(self.fc1(x))
return self.fc2(x)
def action(self, state):
self.epsilon -= (INITIAL_EPSILON - FINAL_EPSILON) / 10000
if random.random() > self.epsilon:
return self(Variable(state, volatile=True)).data.max(1)[1].view(
1, 1)
else:
return longTensor([[random.randrange(2)]])
def push(self, *args):
if len(self) < self.capacity:
self.pool.append(None)
self.pool[self.position] = Transition(*args)
self.position = (self.position + 1) % self.capacity
def sample(self):
return random.sample(self.pool, self.bsz)
def __len__(self):
return len(self.pool)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'state_dim': 4, 'out_dim': 4, 'capacity': 4, 'bsz': 4,
'epsilon': 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 random
import torch.nn as nn
from torch.autograd import Variable
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):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x2 = xindex
x0 = xindex % 32
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)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (32, 4), (4, 1))
assert_size_stride(primals_2, (32,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (4, 32), (32, 1))
assert_size_stride(primals_5, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 32), (32, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 32), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 32), (512, 128, 32, 1), 0)
del buf0
buf3 = empty_strided_cuda((4, 4, 4, 32), (512, 128, 32, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(2048)](buf1,
primals_2, buf3, 2048, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 32),
(32, 1), 0), reinterpret_tensor(primals_4, (32, 4), (1, 32), 0),
alpha=1, beta=1, out=buf2)
del primals_5
return reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 32), (32, 1), 0), primals_4, buf3
class DQNNew(nn.Module):
def __init__(self, state_dim, out_dim, capacity, bsz, epsilon):
super().__init__()
self.steps_done = 0
self.position = 0
self.pool = []
self.capacity = capacity
self.bsz = bsz
self.epsilon = epsilon
self.fc1 = nn.Linear(state_dim, 32)
self.fc2 = nn.Linear(32, out_dim)
self.fc1.weight.data.uniform_(-0.1, 0.1)
self.fc2.weight.data.uniform_(-0.1, 0.1)
def action(self, state):
self.epsilon -= (INITIAL_EPSILON - FINAL_EPSILON) / 10000
if random.random() > self.epsilon:
return self(Variable(state, volatile=True)).data.max(1)[1].view(
1, 1)
else:
return longTensor([[random.randrange(2)]])
def push(self, *args):
if len(self) < self.capacity:
self.pool.append(None)
self.pool[self.position] = Transition(*args)
self.position = (self.position + 1) % self.capacity
def sample(self):
return random.sample(self.pool, self.bsz)
def __len__(self):
return len(self.pool)
def forward(self, input_0):
primals_1 = self.fc1.weight
primals_2 = self.fc1.bias
primals_4 = self.fc2.weight
primals_5 = self.fc2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
shinoyuki222/torch-light
|
DQN
| false
| 16,410
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
Attention
|
import torch
import torch.nn as nn
class Attention(nn.Module):
def __init__(self, dim, heads, dropout):
super().__init__()
self.heads = heads
head_dim = dim // heads
self.scale = head_dim ** -0.5
self.attn = None
self.qkv = nn.Linear(dim, dim * 3)
self.attn_drop = nn.Dropout(dropout)
self.proj = nn.Linear(dim, dim)
self.proj_drop = nn.Dropout(dropout)
@property
def unwrapped(self):
return self
def forward(self, x, mask=None):
B, N, C = x.shape
qkv = self.qkv(x).reshape(B, N, 3, self.heads, C // self.heads
).permute(2, 0, 3, 1, 4)
q, k, v = qkv[0], qkv[1], qkv[2]
attn = q @ k.transpose(-2, -1) * self.scale
attn = attn.softmax(dim=-1)
attn = self.attn_drop(attn)
x = (attn @ v).transpose(1, 2).reshape(B, N, C)
x = self.proj(x)
x = self.proj_drop(x)
return x, attn
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4, 'heads': 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 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 = 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 + 12 * x2 + 48 * 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_clone_1(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 + (4 + y0 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (4 + 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__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)
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 = tmp14 * tmp1
tmp16 = tl_math.exp(tmp15)
tl.store(out_ptr0 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused__softmax_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
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_4(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 + (8 + y0 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (8 + 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_clone_5(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_add_6(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 % 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 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (12, 4), (4, 1))
assert_size_stride(primals_3, (12,), (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((16, 12), (12, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_2, (4, 12), (1, 4), 0), out=buf0)
del primals_2
buf1 = 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, buf1, 16, 4,
XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32)
triton_poi_fused_clone_1[grid(16, 4)](buf0, primals_3, buf2, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (16, 4, 1), (4, 1, 0),
0), reinterpret_tensor(buf2, (16, 1, 4), (4, 0, 1), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__softmax_2[grid(256)](buf3, buf4, 256, XBLOCK=128,
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_3[grid(256)](buf4, buf5, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf4
buf6 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
triton_poi_fused_clone_4[grid(16, 4)](buf0, primals_3, buf6, 16, 4,
XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
del buf0
del primals_3
buf7 = empty_strided_cuda((16, 4, 1), (4, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf5, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf6, (16, 4, 1), (4, 1, 0), 0), out=buf7)
buf8 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_clone_5[grid(16, 4)](buf7, buf8, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf9 = reinterpret_tensor(buf7, (16, 4), (4, 1), 0)
del buf7
extern_kernels.mm(reinterpret_tensor(buf8, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), out=buf9)
buf10 = reinterpret_tensor(buf9, (4, 4, 4), (16, 4, 1), 0)
del buf9
triton_poi_fused_add_6[grid(64)](buf10, primals_5, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_5
return buf10, buf5, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), buf5, reinterpret_tensor(buf8, (16, 4), (4, 1), 0
), primals_4, reinterpret_tensor(buf6, (16, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf1, (16, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 4), 0)
class AttentionNew(nn.Module):
def __init__(self, dim, heads, dropout):
super().__init__()
self.heads = heads
head_dim = dim // heads
self.scale = head_dim ** -0.5
self.attn = None
self.qkv = nn.Linear(dim, dim * 3)
self.attn_drop = nn.Dropout(dropout)
self.proj = nn.Linear(dim, dim)
self.proj_drop = nn.Dropout(dropout)
@property
def unwrapped(self):
return self
def forward(self, input_0):
primals_2 = self.qkv.weight
primals_3 = self.qkv.bias
primals_4 = self.proj.weight
primals_5 = self.proj.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0], output[1]
|
shampooma/segmenter
|
Attention
| false
| 16,411
|
[
"MIT"
] | 418
|
b08fd481da6758e37d108ba28676229b62f757aa
|
https://github.com/shampooma/segmenter/tree/b08fd481da6758e37d108ba28676229b62f757aa
|
Early_StyleConv_Block
|
import math
import torch
import torch.nn as nn
def quick_scale(module, name='weight'):
ScaleW.apply(module, name)
return module
class ScaleW:
"""
Constructor: name - name of attribute to be scaled
"""
def __init__(self, name):
self.name = name
def scale(self, module):
weight = getattr(module, self.name + '_orig')
fan_in = weight.data.size(1) * weight.data[0][0].numel()
return weight * math.sqrt(2 / fan_in)
@staticmethod
def apply(module, name):
"""
Apply runtime scaling to specific module
"""
hook = ScaleW(name)
weight = getattr(module, name)
module.register_parameter(name + '_orig', nn.Parameter(weight.data))
del module._parameters[name]
module.register_forward_pre_hook(hook)
def __call__(self, module, whatever):
weight = self.scale(module)
setattr(module, self.name, weight)
class SLinear(nn.Module):
def __init__(self, dim_in, dim_out):
super().__init__()
linear = nn.Linear(dim_in, dim_out)
linear.weight.data.normal_()
linear.bias.data.zero_()
self.linear = quick_scale(linear)
def forward(self, x):
return self.linear(x)
class SConv2d(nn.Module):
def __init__(self, *args, **kwargs):
super().__init__()
conv = nn.Conv2d(*args, **kwargs)
conv.weight.data.normal_()
conv.bias.data.zero_()
self.conv = quick_scale(conv)
def forward(self, x):
return self.conv(x)
class FC_A(nn.Module):
"""
Learned affine transform A, this module is used to transform
midiate vector w into a style vector
"""
def __init__(self, dim_latent, n_channel):
super().__init__()
self.transform = SLinear(dim_latent, n_channel * 2)
self.transform.linear.bias.data[:n_channel] = 1
self.transform.linear.bias.data[n_channel:] = 0
def forward(self, w):
style = self.transform(w).unsqueeze(2).unsqueeze(3)
return style
class AdaIn(nn.Module):
"""
adaptive instance normalization
"""
def __init__(self, n_channel):
super().__init__()
self.norm = nn.InstanceNorm2d(n_channel)
def forward(self, image, style):
factor, bias = style.chunk(2, 1)
result = self.norm(image)
result = result * factor + bias
return result
class Scale_B(nn.Module):
"""
Learned per-channel scale factor, used to scale the noise
"""
def __init__(self, n_channel):
super().__init__()
self.weight = nn.Parameter(torch.zeros((1, n_channel, 1, 1)))
def forward(self, noise):
result = noise * self.weight
return result
class Early_StyleConv_Block(nn.Module):
"""
This is the very first block of generator that get the constant value as input
"""
def __init__(self, n_channel, dim_latent, dim_input):
super().__init__()
self.constant = nn.Parameter(torch.randn(1, n_channel, dim_input,
dim_input))
self.style1 = FC_A(dim_latent, n_channel)
self.style2 = FC_A(dim_latent, n_channel)
self.noise1 = quick_scale(Scale_B(n_channel))
self.noise2 = quick_scale(Scale_B(n_channel))
self.adain = AdaIn(n_channel)
self.lrelu = nn.LeakyReLU(0.2)
self.conv = SConv2d(n_channel, n_channel, 3, padding=1)
def forward(self, latent_w, noise):
result = self.constant.repeat(noise.shape[0], 1, 1, 1)
result = result + self.noise1(noise)
result = self.adain(result, self.style1(latent_w))
result = self.lrelu(result)
result = self.conv(result)
result = result + self.noise2(noise)
result = self.adain(result, self.style2(latent_w))
result = self.lrelu(result)
return result
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'n_channel': 4, 'dim_latent': 4, 'dim_input': 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.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_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 + x0, xmask)
tmp1 = 0.7071067811865476
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_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
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.7071067811865476
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_per_fused__native_batch_norm_legit_add_leaky_relu_mul_repeat_2(
in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, out_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)
r2 = rindex
x0 = xindex % 4
x3 = xindex
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0), xmask, eviction_policy=
'evict_last', other=0.0)
tmp1 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + x3 % 4, xmask, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp31 = tl.load(in_ptr3 + (x0 + 8 * x1), xmask, eviction_policy=
'evict_last')
tmp33 = tl.load(in_ptr3 + (4 + x0 + 8 * x1), xmask, eviction_policy=
'evict_last')
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
tl.where(xmask, tmp5, 0)
tmp8 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
tmp10 = tl.where(xmask, tmp8, 0)
tmp11 = tl.sum(tmp10, 1)[:, None]
tmp12 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp13 = tmp12.to(tl.float32)
tmp14 = tmp11 / tmp13
tmp15 = tmp5 - tmp14
tmp16 = tmp15 * tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp19 = tl.where(xmask, tmp17, 0)
tmp20 = tl.sum(tmp19, 1)[:, None]
tmp21 = 16.0
tmp22 = tmp20 / tmp21
tmp23 = 1e-05
tmp24 = tmp22 + tmp23
tmp25 = libdevice.rsqrt(tmp24)
tmp27 = tmp1 * tmp26
tmp28 = tmp0 + tmp27
tmp29 = tmp28 - tmp14
tmp30 = tmp29 * tmp25
tmp32 = tmp30 * tmp31
tmp34 = tmp32 + tmp33
tmp35 = 0.0
tmp36 = tmp34 > tmp35
tmp37 = 0.2
tmp38 = tmp34 * tmp37
tmp39 = tl.where(tmp36, tmp34, tmp38)
tl.store(out_ptr0 + (r2 + 16 * x3), tmp0, xmask)
tl.debug_barrier()
tl.store(in_out_ptr0 + x3, tmp25, xmask)
tl.store(in_out_ptr1 + (r2 + 16 * x3), tmp39, xmask)
tl.store(out_ptr1 + x3, tmp14, xmask)
@triton.jit
def triton_poi_fused_mul_3(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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.23570226039551584
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_per_fused__native_batch_norm_legit_add_convolution_leaky_relu_mul_4(
in_out_ptr0, in_out_ptr1, in_out_ptr2, in_ptr0, in_ptr1, in_ptr2,
in_ptr3, out_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)
r2 = rindex
x3 = xindex
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + r2, None, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr2 + x3 % 4, xmask, eviction_policy='evict_last')
tmp28 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp33 = tl.load(in_ptr3 + (x0 + 8 * x1), xmask, eviction_policy=
'evict_last')
tmp35 = tl.load(in_ptr3 + (4 + x0 + 8 * x1), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 * tmp4
tmp6 = tmp2 + tmp5
tmp7 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tl.where(xmask, tmp7, 0)
tmp10 = tl.broadcast_to(tmp7, [XBLOCK, RBLOCK])
tmp12 = tl.where(xmask, tmp10, 0)
tmp13 = tl.sum(tmp12, 1)[:, None]
tmp14 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp15 = tmp14.to(tl.float32)
tmp16 = tmp13 / tmp15
tmp17 = tmp7 - tmp16
tmp18 = tmp17 * tmp17
tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK])
tmp21 = tl.where(xmask, tmp19, 0)
tmp22 = tl.sum(tmp21, 1)[:, None]
tmp23 = 16.0
tmp24 = tmp22 / tmp23
tmp25 = 1e-05
tmp26 = tmp24 + tmp25
tmp27 = libdevice.rsqrt(tmp26)
tmp29 = tmp3 * tmp28
tmp30 = tmp2 + tmp29
tmp31 = tmp30 - tmp16
tmp32 = tmp31 * tmp27
tmp34 = tmp32 * tmp33
tmp36 = tmp34 + tmp35
tmp37 = 0.0
tmp38 = tmp36 > tmp37
tmp39 = 0.2
tmp40 = tmp36 * tmp39
tmp41 = tl.where(tmp38, tmp36, tmp40)
tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask)
tl.debug_barrier()
tl.store(in_out_ptr1 + x3, tmp27, xmask)
tl.store(in_out_ptr2 + (r2 + 16 * x3), tmp41, xmask)
tl.store(out_ptr0 + x3, tmp16, 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) = args
args.clear()
assert_size_stride(primals_1, (1, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4), (4, 1))
assert_size_stride(primals_3, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_4, (8, 4), (4, 1))
assert_size_stride(primals_5, (8,), (1,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_8, (4,), (1,))
assert_size_stride(primals_9, (1, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_10, (8, 4), (4, 1))
assert_size_stride(primals_11, (8,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf1 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_0[grid(4)](primals_3, buf1, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
triton_poi_fused_mul_1[grid(32)](primals_4, buf2, 32, XBLOCK=32,
num_warps=1, num_stages=1)
del primals_4
buf3 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
extern_kernels.addmm(primals_5, primals_6, reinterpret_tensor(buf2,
(4, 8), (1, 4), 0), alpha=1, beta=1, out=buf3)
del primals_5
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf4 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32)
buf5 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32
)
buf7 = reinterpret_tensor(buf5, (1, 16, 1, 1), (16, 1, 1, 1), 0)
del buf5
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf9 = buf8
del buf8
triton_per_fused__native_batch_norm_legit_add_leaky_relu_mul_repeat_2[
grid(16)](buf7, buf9, primals_1, primals_2, buf1, buf3, buf0,
buf4, 16, 16, XBLOCK=8, num_warps=2, num_stages=1)
del primals_1
buf10 = empty_strided_cuda((4, 4, 3, 3), (36, 9, 3, 1), torch.float32)
triton_poi_fused_mul_3[grid(144)](primals_7, buf10, 144, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_7
buf11 = extern_kernels.convolution(buf9, buf10, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf11, (4, 4, 4, 4), (64, 16, 4, 1))
buf13 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused_mul_0[grid(4)](primals_9, buf13, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del primals_9
buf14 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
triton_poi_fused_mul_1[grid(32)](primals_10, buf14, 32, XBLOCK=32,
num_warps=1, num_stages=1)
del primals_10
buf15 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
extern_kernels.addmm(primals_11, primals_6, reinterpret_tensor(
buf14, (4, 8), (1, 4), 0), alpha=1, beta=1, out=buf15)
del primals_11
buf12 = buf11
del buf11
buf16 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32)
buf17 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.
float32)
buf19 = reinterpret_tensor(buf17, (1, 16, 1, 1), (16, 1, 1, 1), 0)
del buf17
buf20 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf21 = buf20
del buf20
triton_per_fused__native_batch_norm_legit_add_convolution_leaky_relu_mul_4[
grid(16)](buf12, buf19, buf21, primals_8, primals_2, buf13,
buf15, buf16, 16, 16, XBLOCK=1, num_warps=2, num_stages=1)
del primals_8
return (buf21, buf1, buf2, buf10, buf13, buf14, primals_2, primals_6,
buf0, buf1, reinterpret_tensor(buf3, (4, 4, 1, 1), (8, 1, 1, 1), 0),
reinterpret_tensor(buf3, (4, 4, 1, 1), (8, 1, 1, 1), 4), buf4, buf7,
buf9, buf10, buf12, buf13, reinterpret_tensor(buf15, (4, 4, 1, 1),
(8, 1, 1, 1), 0), reinterpret_tensor(buf15, (4, 4, 1, 1), (8, 1, 1,
1), 4), buf16, buf19)
def quick_scale(module, name='weight'):
ScaleW.apply(module, name)
return module
class ScaleW:
"""
Constructor: name - name of attribute to be scaled
"""
def __init__(self, name):
self.name = name
def scale(self, module):
weight = getattr(module, self.name + '_orig')
fan_in = weight.data.size(1) * weight.data[0][0].numel()
return weight * math.sqrt(2 / fan_in)
@staticmethod
def apply(module, name):
"""
Apply runtime scaling to specific module
"""
hook = ScaleW(name)
weight = getattr(module, name)
module.register_parameter(name + '_orig', nn.Parameter(weight.data))
del module._parameters[name]
module.register_forward_pre_hook(hook)
def __call__(self, module, whatever):
weight = self.scale(module)
setattr(module, self.name, weight)
class SLinear(nn.Module):
def __init__(self, dim_in, dim_out):
super().__init__()
linear = nn.Linear(dim_in, dim_out)
linear.weight.data.normal_()
linear.bias.data.zero_()
self.linear = quick_scale(linear)
def forward(self, x):
return self.linear(x)
class SConv2d(nn.Module):
def __init__(self, *args, **kwargs):
super().__init__()
conv = nn.Conv2d(*args, **kwargs)
conv.weight.data.normal_()
conv.bias.data.zero_()
self.conv = quick_scale(conv)
def forward(self, x):
return self.conv(x)
class FC_A(nn.Module):
"""
Learned affine transform A, this module is used to transform
midiate vector w into a style vector
"""
def __init__(self, dim_latent, n_channel):
super().__init__()
self.transform = SLinear(dim_latent, n_channel * 2)
self.transform.linear.bias.data[:n_channel] = 1
self.transform.linear.bias.data[n_channel:] = 0
def forward(self, w):
style = self.transform(w).unsqueeze(2).unsqueeze(3)
return style
class AdaIn(nn.Module):
"""
adaptive instance normalization
"""
def __init__(self, n_channel):
super().__init__()
self.norm = nn.InstanceNorm2d(n_channel)
def forward(self, image, style):
factor, bias = style.chunk(2, 1)
result = self.norm(image)
result = result * factor + bias
return result
class Scale_B(nn.Module):
"""
Learned per-channel scale factor, used to scale the noise
"""
def __init__(self, n_channel):
super().__init__()
self.weight = nn.Parameter(torch.zeros((1, n_channel, 1, 1)))
def forward(self, noise):
result = noise * self.weight
return result
class Early_StyleConv_BlockNew(nn.Module):
"""
This is the very first block of generator that get the constant value as input
"""
def __init__(self, n_channel, dim_latent, dim_input):
super().__init__()
self.constant = nn.Parameter(torch.randn(1, n_channel, dim_input,
dim_input))
self.style1 = FC_A(dim_latent, n_channel)
self.style2 = FC_A(dim_latent, n_channel)
self.noise1 = quick_scale(Scale_B(n_channel))
self.noise2 = quick_scale(Scale_B(n_channel))
self.adain = AdaIn(n_channel)
self.lrelu = nn.LeakyReLU(0.2)
self.conv = SConv2d(n_channel, n_channel, 3, padding=1)
def forward(self, input_0, input_1):
primals_1 = self.constant
primals_5 = self.style1.transform.linear.bias
primals_4 = self.style1.transform.linear.weight_orig
primals_11 = self.style2.transform.linear.bias
primals_10 = self.style2.transform.linear.weight_orig
primals_3 = self.noise1.weight_orig
primals_9 = self.noise2.weight_orig
primals_8 = self.conv.conv.bias
primals_7 = self.conv.conv.weight_orig
primals_2 = input_0
primals_6 = 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])
return output[0]
|
sergkuzn148/stg
|
Early_StyleConv_Block
| false
| 16,412
|
[
"MIT"
] | 96
|
84d9f53ae3665c423836a4d0176dc3b22de62b19
|
https://github.com/sergkuzn148/stg/tree/84d9f53ae3665c423836a4d0176dc3b22de62b19
|
ConvBlock
|
import torch
from torch import nn
import torch.utils.data
import torch.nn
class WSConv2d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
padding=1, gain=2):
super(WSConv2d, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding)
self.scale = (gain / (in_channels * kernel_size ** 2)) ** 0.5
self.bias = self.conv.bias
self.conv.bias = None
nn.init.normal_(self.conv.weight)
nn.init.zeros_(self.bias)
def forward(self, x):
return self.conv(x * self.scale) + self.bias.view(1, self.bias.
shape[0], 1, 1)
class ConvBlock(nn.Module):
def __init__(self, in_channels, out_channels):
super(ConvBlock, self).__init__()
self.conv1 = WSConv2d(in_channels, out_channels)
self.conv2 = WSConv2d(out_channels, out_channels)
self.leaky = nn.LeakyReLU(0.2)
def forward(self, x):
x = self.leaky(self.conv1(x))
x = self.leaky(self.conv2(x))
return 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
from torch import nn
import torch.utils.data
import torch.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_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 = 0.23570226039551584
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_leaky_relu_mul_1(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.2
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tmp8 = 0.23570226039551584
tmp9 = tmp7 * tmp8
tl.store(out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr1 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_leaky_relu_2(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.2
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, 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_mul_0[grid(256)](primals_1, buf0, 256, XBLOCK=256,
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, 4, 4), (64, 16, 4, 1))
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_leaky_relu_mul_1[grid(256)](buf1, primals_3,
buf2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
buf4 = extern_kernels.convolution(buf3, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 4, 4, 4), (64, 16, 4, 1))
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
buf6 = buf1
del buf1
triton_poi_fused_add_leaky_relu_2[grid(256)](buf4, primals_5, buf5,
buf6, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf4
del primals_5
return buf6, primals_2, primals_4, buf0, buf2, buf3, buf5
class WSConv2d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size=3, stride=1,
padding=1, gain=2):
super(WSConv2d, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size,
stride, padding)
self.scale = (gain / (in_channels * kernel_size ** 2)) ** 0.5
self.bias = self.conv.bias
self.conv.bias = None
nn.init.normal_(self.conv.weight)
nn.init.zeros_(self.bias)
def forward(self, x):
return self.conv(x * self.scale) + self.bias.view(1, self.bias.
shape[0], 1, 1)
class ConvBlockNew(nn.Module):
def __init__(self, in_channels, out_channels):
super(ConvBlockNew, self).__init__()
self.conv1 = WSConv2d(in_channels, out_channels)
self.conv2 = WSConv2d(out_channels, out_channels)
self.leaky = nn.LeakyReLU(0.2)
def forward(self, input_0):
primals_3 = self.conv1.bias
primals_2 = self.conv1.conv.weight
primals_5 = self.conv2.bias
primals_4 = self.conv2.conv.weight
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
shimon-c/Machine-Learning-Collection
|
ConvBlock
| false
| 16,413
|
[
"MIT"
] | 3,094
|
ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
https://github.com/shimon-c/Machine-Learning-Collection/tree/ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
PaddedInstanceNorm1d
|
import torch
import torch.nn as nn
class PaddedInstanceNorm1d(nn.Module):
def __init__(self, num_features, eps=1e-05, momentum=0.1, affine=False,
track_running_stats=False):
super().__init__()
self.num_features = num_features
self.eps = eps
self.momentum = momentum
if affine is True:
raise NotImplementedError
if track_running_stats is True:
raise NotImplementedError
def forward(self, x, lengths):
lengths = lengths.view(-1, 1, 1).float()
sum_ = torch.sum(x, dim=2, keepdim=True)
mean = sum_ / lengths
sqsum = torch.sum(torch.pow(x, 2.0), dim=2, keepdim=True)
sqmean = sqsum / lengths
var = sqmean - torch.pow(mean, 2.0)
return (x - mean) / torch.pow(var + self.eps, 0.5)
def get_inputs():
return [torch.rand([4, 16384, 4, 4]), torch.rand([4, 256, 4, 4])]
def get_init_inputs():
return [[], {'num_features': 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_pow_sub_sum_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 4
x3 = xindex // 4
x1 = xindex // 4 % 16384
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x3), None)
tmp1 = tl.load(in_ptr0 + (4 + x0 + 16 * x3), None)
tmp3 = tl.load(in_ptr0 + (8 + x0 + 16 * x3), None)
tmp5 = tl.load(in_ptr0 + (12 + x0 + 16 * x3), None)
tmp7 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp8 = tmp6 / tmp7
tmp9 = tmp0 * tmp0
tmp10 = tmp1 * tmp1
tmp11 = tmp9 + tmp10
tmp12 = tmp3 * tmp3
tmp13 = tmp11 + tmp12
tmp14 = tmp5 * tmp5
tmp15 = tmp13 + tmp14
tmp16 = tmp15 / tmp7
tmp17 = tmp8 * tmp8
tmp18 = tmp16 - tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.sqrt(tmp20)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp21, None)
@triton.jit
def triton_poi_fused_add_div_pow_sub_sum_1(in_ptr0, in_ptr1, in_ptr2,
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 % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + (x0 + 4 * x2), None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 / tmp3
tl.store(out_ptr0 + x3, tmp4, None)
def call(args):
arg0_1, arg1_1 = args
args.clear()
assert_size_stride(arg0_1, (4, 256, 4, 4), (4096, 16, 4, 1))
assert_size_stride(arg1_1, (4, 16384, 4, 4), (262144, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 16384, 1, 4), (65536, 4, 262144, 1),
torch.float32)
buf1 = empty_strided_cuda((4, 16384, 1, 4), (65536, 4, 262144, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_add_div_pow_sub_sum_0[grid(262144)](arg1_1, arg0_1,
buf0, buf1, 262144, XBLOCK=512, num_warps=8, num_stages=1)
del arg0_1
buf2 = empty_strided_cuda((4, 16384, 4, 4), (262144, 16, 4, 1),
torch.float32)
triton_poi_fused_add_div_pow_sub_sum_1[grid(1048576)](arg1_1, buf0,
buf1, buf2, 1048576, XBLOCK=1024, num_warps=4, num_stages=1)
del arg1_1
del buf0
del buf1
return buf2,
class PaddedInstanceNorm1dNew(nn.Module):
def __init__(self, num_features, eps=1e-05, momentum=0.1, affine=False,
track_running_stats=False):
super().__init__()
self.num_features = num_features
self.eps = eps
self.momentum = momentum
if affine is True:
raise NotImplementedError
if track_running_stats is True:
raise NotImplementedError
def forward(self, input_0, input_1):
arg1_1 = input_0
arg0_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
shaun95/cotatron
|
PaddedInstanceNorm1d
| false
| 16,414
|
[
"BSD-3-Clause"
] | 202
|
2d0254399a3063ba1d2f77bef535cc148041236e
|
https://github.com/shaun95/cotatron/tree/2d0254399a3063ba1d2f77bef535cc148041236e
|
AtteMatchLay
|
import torch
import torch.nn as nn
from torch.nn.functional import cosine_similarity
def multi_perspective_expand_for_2D(in_tensor, decompose_params):
"""
Return: [batch_size, decompse_dim, dim]
"""
in_tensor = in_tensor.unsqueeze(1)
decompose_params = decompose_params.unsqueeze(0)
return torch.mul(in_tensor, decompose_params)
class AtteMatchLay(nn.Module):
def __init__(self, mp_dim, cont_dim):
super(AtteMatchLay, self).__init__()
self.cont_dim = cont_dim
self.mp_dim = mp_dim
self.register_parameter('weight', nn.Parameter(torch.Tensor(mp_dim,
cont_dim)))
self.weight.data.uniform_(-1.0, 1.0)
def forward(self, repres, max_att):
"""
Args:
repres - [bsz, a_len|q_len, cont_dim]
max_att - [bsz, q_len|a_len, cont_dim]
Return:
size - [bsz, sentence_len, mp_dim]
"""
bsz = repres.size(0)
sent_len = repres.size(1)
repres = repres.view(-1, self.cont_dim)
max_att = max_att.view(-1, self.cont_dim)
repres = multi_perspective_expand_for_2D(repres, self.weight)
max_att = multi_perspective_expand_for_2D(max_att, self.weight)
temp = cosine_similarity(repres, max_att, repres.dim() - 1)
return temp.view(bsz, sent_len, self.mp_dim)
def get_inputs():
return [torch.rand([16, 4, 4]), torch.rand([64, 4])]
def get_init_inputs():
return [[], {'mp_dim': 4, 'cont_dim': 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
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_sum_0(in_out_ptr0,
in_ptr0, in_ptr1, in_ptr2, xnumel, XBLOCK: tl.constexpr):
xnumel = 256
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 + 4 * x1, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x0, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr0 + (1 + 4 * x1), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + (1 + 4 * x0), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr0 + (2 + 4 * x1), xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr1 + (2 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp14 = tl.load(in_ptr0 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp15 = tl.load(in_ptr1 + (3 + 4 * x0), xmask, eviction_policy='evict_last'
)
tmp22 = tl.load(in_ptr2 + 4 * x1, xmask, eviction_policy='evict_last')
tmp25 = tl.load(in_ptr2 + (1 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp29 = tl.load(in_ptr2 + (2 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp33 = tl.load(in_ptr2 + (3 + 4 * x1), xmask, eviction_policy='evict_last'
)
tmp2 = tmp0 * tmp1
tmp3 = tmp2 * tmp2
tmp6 = tmp4 * tmp5
tmp7 = tmp6 * tmp6
tmp8 = tmp3 + tmp7
tmp11 = tmp9 * tmp10
tmp12 = tmp11 * tmp11
tmp13 = tmp8 + tmp12
tmp16 = tmp14 * tmp15
tmp17 = tmp16 * tmp16
tmp18 = tmp13 + tmp17
tmp19 = libdevice.sqrt(tmp18)
tmp20 = 1e-08
tmp21 = triton_helpers.maximum(tmp19, tmp20)
tmp23 = tmp22 * tmp1
tmp24 = tmp23 * tmp23
tmp26 = tmp25 * tmp5
tmp27 = tmp26 * tmp26
tmp28 = tmp24 + tmp27
tmp30 = tmp29 * tmp10
tmp31 = tmp30 * tmp30
tmp32 = tmp28 + tmp31
tmp34 = tmp33 * tmp15
tmp35 = tmp34 * tmp34
tmp36 = tmp32 + tmp35
tmp37 = libdevice.sqrt(tmp36)
tmp38 = triton_helpers.maximum(tmp37, tmp20)
tmp39 = tmp23 / tmp38
tmp40 = tmp2 / tmp21
tmp41 = tmp39 * tmp40
tmp42 = tmp26 / tmp38
tmp43 = tmp6 / tmp21
tmp44 = tmp42 * tmp43
tmp45 = tmp41 + tmp44
tmp46 = tmp30 / tmp38
tmp47 = tmp11 / tmp21
tmp48 = tmp46 * tmp47
tmp49 = tmp45 + tmp48
tmp50 = tmp34 / tmp38
tmp51 = tmp16 / tmp21
tmp52 = tmp50 * tmp51
tmp53 = tmp49 + tmp52
tl.store(in_out_ptr0 + x2, tmp53, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (16, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (64, 4), (4, 1))
assert_size_stride(primals_3, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 4, 1), (4, 1, 256), torch.float32)
buf2 = reinterpret_tensor(buf0, (64, 4), (4, 1), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_clamp_min_div_linalg_vector_norm_mul_sum_0[grid(256)](
buf2, primals_2, primals_3, primals_1, 256, XBLOCK=256,
num_warps=4, num_stages=1)
return reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0
), primals_1, primals_2, primals_3
def multi_perspective_expand_for_2D(in_tensor, decompose_params):
"""
Return: [batch_size, decompse_dim, dim]
"""
in_tensor = in_tensor.unsqueeze(1)
decompose_params = decompose_params.unsqueeze(0)
return torch.mul(in_tensor, decompose_params)
class AtteMatchLayNew(nn.Module):
def __init__(self, mp_dim, cont_dim):
super(AtteMatchLayNew, self).__init__()
self.cont_dim = cont_dim
self.mp_dim = mp_dim
self.register_parameter('weight', nn.Parameter(torch.Tensor(mp_dim,
cont_dim)))
self.weight.data.uniform_(-1.0, 1.0)
def forward(self, input_0, input_1):
primals_3 = self.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3])
return output[0]
|
shinoyuki222/torch-light
|
AtteMatchLay
| false
| 16,415
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
InnerProductDecoder
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class InnerProductDecoder(nn.Module):
def __init__(self, activation=torch.sigmoid, dropout=0.1):
super(InnerProductDecoder, self).__init__()
self.dropout = dropout
self.activation = activation
def forward(self, z):
z = F.dropout(z, self.dropout)
adj = self.activation(torch.mm(z, z.t()))
return adj
def get_inputs():
return [torch.rand([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
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_sigmoid_0(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 = tl.sigmoid(tmp0)
tl.store(in_out_ptr0 + x0, tmp1, xmask)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4), (4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = torch.ops.aten.native_dropout.default(arg0_1, 0.1, True)
del arg0_1
buf1 = buf0[0]
del buf0
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf1, reinterpret_tensor(buf1, (4, 4), (1, 4), 0),
out=buf3)
del buf1
buf4 = buf3
del buf3
get_raw_stream(0)
triton_poi_fused_sigmoid_0[grid(16)](buf4, 16, XBLOCK=16, num_warps
=1, num_stages=1)
return buf4,
class InnerProductDecoderNew(nn.Module):
def __init__(self, activation=torch.sigmoid, dropout=0.1):
super(InnerProductDecoderNew, self).__init__()
self.dropout = dropout
self.activation = activation
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
shionhonda/graph_ae
|
InnerProductDecoder
| false
| 16,416
|
[
"MIT"
] | 48
|
b8284a85286eee1b16cb90c0dd139d8927e83648
|
https://github.com/shionhonda/graph_ae/tree/b8284a85286eee1b16cb90c0dd139d8927e83648
|
HyperpriorSynthesisDLMM
|
import torch
import torch.nn as nn
import torch.nn.functional as F
def get_num_DLMM_channels(C, K=4, params=['mu', 'scale', 'mix']):
"""
C: Channels of latent representation (L3C uses 5).
K: Number of mixture coefficients.
"""
return C * K * len(params)
class HyperpriorSynthesisDLMM(nn.Module):
"""
Outputs distribution parameters of input latents, conditional on
hyperlatents, assuming a discrete logistic mixture model.
C: Number of output channels
"""
def __init__(self, C=64, N=320, activation='relu', final_activation=None):
super(HyperpriorSynthesisDLMM, self).__init__()
cnn_kwargs = dict(kernel_size=5, stride=2, padding=2, output_padding=1)
self.activation = getattr(F, activation)
self.final_activation = final_activation
self.conv1 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv2 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv3 = nn.ConvTranspose2d(N, C, kernel_size=3, stride=1,
padding=1)
self.conv_out = nn.Conv2d(C, get_num_DLMM_channels(C), kernel_size=
1, stride=1)
if self.final_activation is not None:
self.final_activation = getattr(F, final_activation)
def forward(self, x):
x = self.activation(self.conv1(x))
x = self.activation(self.conv2(x))
x = self.conv3(x)
x = self.conv_out(x)
if self.final_activation is not None:
x = self.final_activation(x)
return x
def get_inputs():
return [torch.rand([4, 320, 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.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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 25
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 320
y1 = yindex // 320
tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 320 * x2 + 8000 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 1280
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
y0 = yindex % 320
y1 = yindex // 320
tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (y0 + 320 * x2 + 5120 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 64
y1 = yindex // 64
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 64 * x2 + 576 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_3(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)
x2 = xindex
x0 = xindex % 320
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_relu_4(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)
x2 = xindex
x0 = xindex % 320
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_5(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)
x2 = xindex
x0 = xindex % 64
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, None)
@triton.jit
def triton_poi_fused_convolution_6(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
xnumel = 256
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 768
y1 = yindex // 768
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 768 * x2 + 196608 * y1), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 256 * y3), tmp2, 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, (320, 320, 5, 5), (8000, 25, 5, 1))
assert_size_stride(primals_2, (320,), (1,))
assert_size_stride(primals_3, (4, 320, 4, 4), (5120, 16, 4, 1))
assert_size_stride(primals_4, (320, 320, 5, 5), (8000, 25, 5, 1))
assert_size_stride(primals_5, (320,), (1,))
assert_size_stride(primals_6, (320, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_7, (64,), (1,))
assert_size_stride(primals_8, (768, 64, 1, 1), (64, 1, 1, 1))
assert_size_stride(primals_9, (768,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((320, 320, 5, 5), (8000, 1, 1600, 320),
torch.float32)
get_raw_stream(0)
triton_poi_fused_0[grid(102400, 25)](primals_1, buf0, 102400, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 320, 4, 4), (5120, 1, 1280, 320),
torch.float32)
triton_poi_fused_1[grid(1280, 16)](primals_3, buf1, 1280, 16,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((320, 320, 5, 5), (8000, 1, 1600, 320),
torch.float32)
triton_poi_fused_0[grid(102400, 25)](primals_4, buf2, 102400, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_4
buf3 = empty_strided_cuda((320, 64, 3, 3), (576, 1, 192, 64), torch
.float32)
triton_poi_fused_2[grid(20480, 9)](primals_6, buf3, 20480, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_6
buf4 = extern_kernels.convolution(buf1, buf0, stride=(2, 2),
padding=(2, 2), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf4, (4, 320, 8, 8), (20480, 1, 2560, 320))
buf5 = buf4
del buf4
triton_poi_fused_convolution_relu_3[grid(81920)](buf5, primals_2,
81920, XBLOCK=512, num_warps=8, num_stages=1)
del primals_2
buf6 = extern_kernels.convolution(buf5, buf2, stride=(2, 2),
padding=(2, 2), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf6, (4, 320, 16, 16), (81920, 1, 5120, 320))
buf7 = buf6
del buf6
triton_poi_fused_convolution_relu_4[grid(327680)](buf7, primals_5,
327680, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_5
buf8 = extern_kernels.convolution(buf7, buf3, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 64, 16, 16), (16384, 1, 1024, 64))
buf9 = buf8
del buf8
triton_poi_fused_convolution_5[grid(65536)](buf9, primals_7, 65536,
XBLOCK=512, num_warps=4, num_stages=1)
del primals_7
buf10 = extern_kernels.convolution(buf9, primals_8, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf10, (4, 768, 16, 16), (196608, 1, 12288, 768))
buf11 = empty_strided_cuda((4, 768, 16, 16), (196608, 256, 16, 1),
torch.float32)
triton_poi_fused_convolution_6[grid(3072, 256)](buf10, primals_9,
buf11, 3072, 256, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del buf10
del primals_9
return buf11, buf0, buf1, buf2, buf3, primals_8, buf5, buf7, buf9
def get_num_DLMM_channels(C, K=4, params=['mu', 'scale', 'mix']):
"""
C: Channels of latent representation (L3C uses 5).
K: Number of mixture coefficients.
"""
return C * K * len(params)
class HyperpriorSynthesisDLMMNew(nn.Module):
"""
Outputs distribution parameters of input latents, conditional on
hyperlatents, assuming a discrete logistic mixture model.
C: Number of output channels
"""
def __init__(self, C=64, N=320, activation='relu', final_activation=None):
super(HyperpriorSynthesisDLMMNew, self).__init__()
cnn_kwargs = dict(kernel_size=5, stride=2, padding=2, output_padding=1)
self.activation = getattr(F, activation)
self.final_activation = final_activation
self.conv1 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv2 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv3 = nn.ConvTranspose2d(N, C, kernel_size=3, stride=1,
padding=1)
self.conv_out = nn.Conv2d(C, get_num_DLMM_channels(C), kernel_size=
1, stride=1)
if self.final_activation is not None:
self.final_activation = getattr(F, final_activation)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_8 = self.conv_out.weight
primals_9 = self.conv_out.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]
|
sedrickkeh/high-fidelity-dual-image
|
HyperpriorSynthesisDLMM
| false
| 16,417
|
[
"Apache-2.0"
] | 266
|
9cefd378467826b91596653df38666e469bb23e0
|
https://github.com/sedrickkeh/high-fidelity-dual-image/tree/9cefd378467826b91596653df38666e469bb23e0
|
CrossEntropy
|
import torch
import torch.nn as nn
class CrossEntropy(nn.Module):
def __init__(self):
super().__init__()
def forward(self, props, tgt):
tgt_props = props.gather(2, tgt.unsqueeze(2)).squeeze()
mask = (tgt > 0).float()
return -(tgt_props * mask).sum() / mask.sum()
def get_inputs():
return [torch.ones([4, 4, 4], dtype=torch.int64), torch.ones([4, 4],
dtype=torch.int64)]
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__to_copy_div_gt_mul_neg_sum_0(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)
r0 = rindex
tmp0 = tl.load(in_ptr0 + r0, None)
tmp1 = tl.full([XBLOCK, RBLOCK], 4, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tl.device_assert((0 <= tmp4) & (tmp4 < 4),
'index out of bounds: 0 <= tmp4 < 4')
tmp6 = tl.load(in_ptr1 + (tmp4 + 4 * r0), None, eviction_policy=
'evict_last')
tmp7 = tmp6.to(tl.float32)
tmp8 = tl.full([1, 1], 0, tl.int64)
tmp9 = tmp0 > tmp8
tmp10 = tmp9.to(tl.float32)
tmp11 = tmp7 * tmp10
tmp12 = tl.broadcast_to(tmp11, [XBLOCK, RBLOCK])
tmp14 = tl.sum(tmp12, 1)[:, None]
tmp15 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp17 = tl.sum(tmp15, 1)[:, None]
tmp18 = -tmp14
tmp19 = tmp18 / tmp17
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp19, None)
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, 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__to_copy_div_gt_mul_neg_sum_0[grid(1)](buf2,
arg1_1, arg0_1, 1, 16, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf2,
class CrossEntropyNew(nn.Module):
def __init__(self):
super().__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]
|
shinoyuki222/torch-light
|
CrossEntropy
| false
| 16,418
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
HyperpriorSynthesis
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class HyperpriorSynthesis(nn.Module):
"""
Hyperprior 'synthesis model' as proposed in [1]. Outputs
distribution parameters of input latents.
[1] Ballé et. al., "Variational image compression with a scale hyperprior",
arXiv:1802.01436 (2018).
C: Number of output channels
"""
def __init__(self, C=220, N=320, activation='relu', final_activation=None):
super(HyperpriorSynthesis, self).__init__()
cnn_kwargs = dict(kernel_size=5, stride=2, padding=2, output_padding=1)
self.activation = getattr(F, activation)
self.final_activation = final_activation
self.conv1 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv2 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv3 = nn.ConvTranspose2d(N, C, kernel_size=3, stride=1,
padding=1)
if self.final_activation is not None:
self.final_activation = getattr(F, final_activation)
def forward(self, x):
x = self.activation(self.conv1(x))
x = self.activation(self.conv2(x))
x = self.conv3(x)
if self.final_activation is not None:
x = self.final_activation(x)
return x
def get_inputs():
return [torch.rand([4, 320, 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.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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 25
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 320
y1 = yindex // 320
tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 320 * x2 + 8000 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 1280
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
y0 = yindex % 320
y1 = yindex // 320
tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (y0 + 320 * x2 + 5120 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 70400
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(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
y0 = yindex % 220
y1 = yindex // 220
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 220 * x2 + 1980 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_relu_3(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)
x2 = xindex
x0 = xindex % 320
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_relu_4(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)
x2 = xindex
x0 = xindex % 320
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_5(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 880
xnumel = 256
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 % 220
y1 = yindex // 220
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 220 * x2 + 56320 * 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 + 256 * y3), tmp2, xmask & ymask)
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, (320, 320, 5, 5), (8000, 25, 5, 1))
assert_size_stride(primals_2, (320,), (1,))
assert_size_stride(primals_3, (4, 320, 4, 4), (5120, 16, 4, 1))
assert_size_stride(primals_4, (320, 320, 5, 5), (8000, 25, 5, 1))
assert_size_stride(primals_5, (320,), (1,))
assert_size_stride(primals_6, (320, 220, 3, 3), (1980, 9, 3, 1))
assert_size_stride(primals_7, (220,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((320, 320, 5, 5), (8000, 1, 1600, 320),
torch.float32)
get_raw_stream(0)
triton_poi_fused_0[grid(102400, 25)](primals_1, buf0, 102400, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 320, 4, 4), (5120, 1, 1280, 320),
torch.float32)
triton_poi_fused_1[grid(1280, 16)](primals_3, buf1, 1280, 16,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((320, 320, 5, 5), (8000, 1, 1600, 320),
torch.float32)
triton_poi_fused_0[grid(102400, 25)](primals_4, buf2, 102400, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_4
buf3 = empty_strided_cuda((320, 220, 3, 3), (1980, 1, 660, 220),
torch.float32)
triton_poi_fused_2[grid(70400, 9)](primals_6, buf3, 70400, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_6
buf4 = extern_kernels.convolution(buf1, buf0, stride=(2, 2),
padding=(2, 2), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf4, (4, 320, 8, 8), (20480, 1, 2560, 320))
buf5 = buf4
del buf4
triton_poi_fused_convolution_relu_3[grid(81920)](buf5, primals_2,
81920, XBLOCK=512, num_warps=8, num_stages=1)
del primals_2
buf6 = extern_kernels.convolution(buf5, buf2, stride=(2, 2),
padding=(2, 2), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf6, (4, 320, 16, 16), (81920, 1, 5120, 320))
buf7 = buf6
del buf6
triton_poi_fused_convolution_relu_4[grid(327680)](buf7, primals_5,
327680, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_5
buf8 = extern_kernels.convolution(buf7, buf3, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=True,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 220, 16, 16), (56320, 1, 3520, 220))
buf9 = empty_strided_cuda((4, 220, 16, 16), (56320, 256, 16, 1),
torch.float32)
triton_poi_fused_convolution_5[grid(880, 256)](buf8, primals_7,
buf9, 880, 256, XBLOCK=256, YBLOCK=4, num_warps=4, num_stages=1)
del buf8
del primals_7
return buf9, buf0, buf1, buf2, buf3, buf5, buf7
class HyperpriorSynthesisNew(nn.Module):
"""
Hyperprior 'synthesis model' as proposed in [1]. Outputs
distribution parameters of input latents.
[1] Ballé et. al., "Variational image compression with a scale hyperprior",
arXiv:1802.01436 (2018).
C: Number of output channels
"""
def __init__(self, C=220, N=320, activation='relu', final_activation=None):
super(HyperpriorSynthesisNew, self).__init__()
cnn_kwargs = dict(kernel_size=5, stride=2, padding=2, output_padding=1)
self.activation = getattr(F, activation)
self.final_activation = final_activation
self.conv1 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv2 = nn.ConvTranspose2d(N, N, **cnn_kwargs)
self.conv3 = nn.ConvTranspose2d(N, C, kernel_size=3, stride=1,
padding=1)
if self.final_activation is not None:
self.final_activation = getattr(F, final_activation)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
sedrickkeh/high-fidelity-dual-image
|
HyperpriorSynthesis
| false
| 16,419
|
[
"Apache-2.0"
] | 266
|
9cefd378467826b91596653df38666e469bb23e0
|
https://github.com/sedrickkeh/high-fidelity-dual-image/tree/9cefd378467826b91596653df38666e469bb23e0
|
BasicUNet
|
import torch
from torch import nn
import torch.nn.functional as F
class BasicConvBlock(nn.Module):
def __init__(self, in_channels, out_channels):
super(BasicConvBlock, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3,
padding=1)
self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3,
padding=1)
self.norm = nn.InstanceNorm2d(out_channels)
def forward(self, x):
x = F.leaky_relu(self.norm(self.conv2(self.conv1(x))),
negative_slope=0.001, inplace=True)
return x
class BasicUNet(nn.Module):
def __init__(self, n_input_channel=1, n_output_channel=1, nic=8,
residual=True):
super().__init__()
self.residual = residual
self.down1 = nn.MaxPool2d(kernel_size=2)
self.down2 = nn.MaxPool2d(kernel_size=2)
self.down3 = nn.MaxPool2d(kernel_size=2)
self.down4 = nn.MaxPool2d(kernel_size=2)
self.up1 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.up2 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.up3 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.up4 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.conv1 = BasicConvBlock(n_input_channel, nic)
self.conv2 = BasicConvBlock(nic, nic * 2)
self.conv3 = BasicConvBlock(nic * 2, nic * 4)
self.conv4 = BasicConvBlock(nic * 4, nic * 8)
self.conv5 = BasicConvBlock(nic * 8, nic * 16)
self.conv6 = BasicConvBlock(nic * 3 * 8, nic * 8)
self.conv7 = BasicConvBlock(nic * 3 * 4, nic * 4)
self.conv8 = BasicConvBlock(nic * 3 * 2, nic * 2)
self.conv9 = BasicConvBlock(nic * 3, nic)
self.conv10 = BasicConvBlock(nic, n_output_channel)
if self.residual:
self.conv11 = BasicConvBlock(n_input_channel, n_output_channel)
def forward(self, x):
c0 = x
c1 = self.conv1(x)
x = self.down1(c1)
c2 = self.conv2(x)
x = self.down2(c2)
c3 = self.conv3(x)
x = self.down3(c3)
c4 = self.conv4(x)
x = self.down4(c4)
x = self.conv5(x)
x = self.up1(x)
x = torch.cat([x, c4], 1)
x = self.conv6(x)
x = self.up2(x)
x = torch.cat([x, c3], 1)
x = self.conv7(x)
x = self.up3(x)
x = torch.cat([x, c2], 1)
x = self.conv8(x)
x = self.up4(x)
x = torch.cat([x, c1], 1)
x = self.conv9(x)
x = self.conv10(x)
if self.residual:
x = torch.add(x, self.conv11(c0))
return x
def get_inputs():
return [torch.rand([4, 1, 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
from torch import 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_convolution_0(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 // 4096 % 8
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_red_fused__native_batch_norm_legit_cat_convolution_leaky_relu_1(
in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, out_ptr4, xnumel,
rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 32
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x3 = xindex
x0 = xindex % 8
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp4_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp4_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp4_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp0 = tl.load(in_out_ptr0 + (r2 + 4096 * x3), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp4_mean_next, tmp4_m2_next, tmp4_weight_next = (triton_helpers.
welford_reduce(tmp3, tmp4_mean, tmp4_m2, tmp4_weight, roffset == 0)
)
tmp4_mean = tl.where(rmask & xmask, tmp4_mean_next, tmp4_mean)
tmp4_m2 = tl.where(rmask & xmask, tmp4_m2_next, tmp4_m2)
tmp4_weight = tl.where(rmask & xmask, tmp4_weight_next, tmp4_weight)
tl.store(in_out_ptr0 + (r2 + 4096 * x3), tmp2, rmask & xmask)
tmp4_tmp, tmp5_tmp, tmp6_tmp = triton_helpers.welford(tmp4_mean,
tmp4_m2, tmp4_weight, 1)
tmp4 = tmp4_tmp[:, None]
tmp5 = tmp5_tmp[:, None]
tmp6_tmp[:, None]
tl.store(out_ptr0 + x3, tmp4, xmask)
x1 = xindex // 8
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp7 = tl.load(in_out_ptr0 + (r2 + 4096 * x3), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp8 = tmp7 - tmp4
tmp9 = 4096.0
tmp10 = tmp5 / tmp9
tmp11 = 1e-05
tmp12 = tmp10 + tmp11
tmp13 = libdevice.rsqrt(tmp12)
tmp14 = tmp8 * tmp13
tmp15 = 0.0
tmp16 = tmp14 > tmp15
tmp17 = 0.001
tmp18 = tmp14 * tmp17
tmp19 = tl.where(tmp16, tmp14, tmp18)
tl.store(out_ptr2 + (r2 + 4096 * x3), tmp19, rmask & xmask)
tl.store(out_ptr3 + (r2 + 4096 * x0 + 98304 * x1), tmp19, rmask & xmask
)
tmp20 = 4096.0
tmp21 = tmp5 / tmp20
tmp22 = 1e-05
tmp23 = tmp21 + tmp22
tmp24 = libdevice.rsqrt(tmp23)
tl.store(out_ptr4 + x3, tmp24, xmask)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 32
x1 = xindex // 32
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy
='evict_last')
tmp3 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x1), None,
eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x1), None,
eviction_policy='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_3(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 // 1024 % 16
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_per_fused__native_batch_norm_legit_cat_convolution_leaky_relu_4(
in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, out_ptr4, xnumel,
rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
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)
r2 = rindex
x3 = xindex
x0 = xindex % 16
x1 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + (r2 + 1024 * x3), None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
tmp5 = tl.broadcast_to(tmp3, [RBLOCK])
tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0))
tmp8 = tl.full([1], 1024, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp3 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
tmp16 = tmp2 - tmp10
tmp17 = 1024.0
tmp18 = tmp15 / tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.rsqrt(tmp20)
tmp22 = tmp16 * tmp21
tmp23 = 0.0
tmp24 = tmp22 > tmp23
tmp25 = 0.001
tmp26 = tmp22 * tmp25
tmp27 = tl.where(tmp24, tmp22, tmp26)
tl.store(in_out_ptr0 + (r2 + 1024 * x3), tmp2, None)
tl.store(out_ptr2 + (r2 + 1024 * x3), tmp27, None)
tl.store(out_ptr3 + (r2 + 1024 * x0 + 49152 * x1), tmp27, None)
tl.store(out_ptr4 + x3, tmp21, None)
tl.store(out_ptr0 + x3, tmp10, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 64 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 64 * x1), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (32 + 2 * x0 + 64 * x1), None, eviction_policy
='evict_last')
tmp5 = tl.load(in_ptr0 + (33 + 2 * x0 + 64 * x1), None, eviction_policy
='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_6(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 // 256 % 32
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_per_fused__native_batch_norm_legit_cat_convolution_leaky_relu_7(
in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, out_ptr4, 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)
r2 = rindex
x3 = xindex
x0 = xindex % 32
x1 = xindex // 32
tmp0 = tl.load(in_out_ptr0 + (r2 + 256 * x3), None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
tmp5 = tl.broadcast_to(tmp3, [RBLOCK])
tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0))
tmp8 = tl.full([1], 256, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp3 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
tmp16 = tmp2 - tmp10
tmp17 = 256.0
tmp18 = tmp15 / tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.rsqrt(tmp20)
tmp22 = tmp16 * tmp21
tmp23 = 0.0
tmp24 = tmp22 > tmp23
tmp25 = 0.001
tmp26 = tmp22 * tmp25
tmp27 = tl.where(tmp24, tmp22, tmp26)
tl.store(in_out_ptr0 + (r2 + 256 * x3), tmp2, None)
tl.store(out_ptr2 + (r2 + 256 * x3), tmp27, None)
tl.store(out_ptr3 + (r2 + 256 * x0 + 24576 * x1), tmp27, None)
tl.store(out_ptr4 + x3, tmp21, None)
tl.store(out_ptr0 + x3, tmp10, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 8
x1 = xindex // 8
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 32 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 32 * x1), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + 2 * x0 + 32 * x1), None, eviction_policy
='evict_last')
tmp5 = tl.load(in_ptr0 + (17 + 2 * x0 + 32 * x1), None, eviction_policy
='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_9(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 // 64 % 64
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_per_fused__native_batch_norm_legit_cat_convolution_leaky_relu_10(
in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, out_ptr4, xnumel,
rnumel, XBLOCK: tl.constexpr):
xnumel = 256
RBLOCK: tl.constexpr = 64
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)
r2 = rindex
x3 = xindex
x0 = xindex % 64
x1 = xindex // 64
tmp0 = tl.load(in_out_ptr0 + (r2 + 64 * x3), xmask, other=0.0)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tl.where(xmask, tmp3, 0)
tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp8 = tl.where(xmask, tmp6, 0)
tmp9 = tl.sum(tmp8, 1)[:, None]
tmp10 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp11 = tmp10.to(tl.float32)
tmp12 = tmp9 / tmp11
tmp13 = tmp3 - tmp12
tmp14 = tmp13 * tmp13
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp17 = tl.where(xmask, tmp15, 0)
tmp18 = tl.sum(tmp17, 1)[:, None]
tmp19 = tmp2 - tmp12
tmp20 = 64.0
tmp21 = tmp18 / tmp20
tmp22 = 1e-05
tmp23 = tmp21 + tmp22
tmp24 = libdevice.rsqrt(tmp23)
tmp25 = tmp19 * tmp24
tmp26 = 0.0
tmp27 = tmp25 > tmp26
tmp28 = 0.001
tmp29 = tmp25 * tmp28
tmp30 = tl.where(tmp27, tmp25, tmp29)
tl.store(in_out_ptr0 + (r2 + 64 * x3), tmp2, xmask)
tl.store(out_ptr2 + (r2 + 64 * x3), tmp30, xmask)
tl.store(out_ptr3 + (r2 + 64 * x0 + 12288 * x1), tmp30, xmask)
tl.store(out_ptr4 + x3, tmp24, xmask)
tl.store(out_ptr0 + x3, tmp12, xmask)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_11(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 16 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 16 * x1), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (8 + 2 * x0 + 16 * x1), None, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (9 + 2 * x0 + 16 * x1), None, eviction_policy=
'evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_12(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_per_fused__native_batch_norm_legit_convolution_13(in_out_ptr0,
in_out_ptr1, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 512
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)
r2 = rindex
x3 = xindex
x0 = xindex % 128
tmp0 = tl.load(in_out_ptr0 + (r2 + 16 * x3), xmask, other=0.0)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tl.where(xmask, tmp3, 0)
tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp8 = tl.where(xmask, tmp6, 0)
tmp9 = tl.sum(tmp8, 1)[:, None]
tmp10 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp11 = tmp10.to(tl.float32)
tmp12 = tmp9 / tmp11
tmp13 = tmp3 - tmp12
tmp14 = tmp13 * tmp13
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp17 = tl.where(xmask, tmp15, 0)
tmp18 = tl.sum(tmp17, 1)[:, None]
tmp19 = 16.0
tmp20 = tmp18 / tmp19
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(in_out_ptr0 + (r2 + 16 * x3), tmp2, xmask)
tl.debug_barrier()
tl.store(in_out_ptr1 + x3, tmp23, xmask)
tl.store(out_ptr0 + x3, tmp12, xmask)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_14(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
tmp0 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_15(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 // 8 % 8
x0 = xindex % 8
x5 = xindex // 64
x3 = xindex // 8192
x6 = xindex % 8192
tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x5, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr3 + x5, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 4, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 4 * tmp4 + 16 * x5), None,
eviction_policy='evict_last')
tmp11 = tmp9 - tmp10
tmp13 = tmp11 * tmp12
tmp14 = 0.0
tmp15 = tmp13 > tmp14
tmp16 = 0.001
tmp17 = tmp13 * tmp16
tmp18 = tl.where(tmp15, tmp13, tmp17)
tl.store(out_ptr0 + (x6 + 12288 * x3), tmp18, None)
@triton.jit
def triton_per_fused__native_batch_norm_legit_convolution_16(in_out_ptr0,
in_out_ptr1, in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 256
RBLOCK: tl.constexpr = 64
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)
r2 = rindex
x3 = xindex
x0 = xindex % 64
tmp0 = tl.load(in_out_ptr0 + (r2 + 64 * x3), xmask, other=0.0)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tl.where(xmask, tmp3, 0)
tmp6 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp8 = tl.where(xmask, tmp6, 0)
tmp9 = tl.sum(tmp8, 1)[:, None]
tmp10 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp11 = tmp10.to(tl.float32)
tmp12 = tmp9 / tmp11
tmp13 = tmp3 - tmp12
tmp14 = tmp13 * tmp13
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp17 = tl.where(xmask, tmp15, 0)
tmp18 = tl.sum(tmp17, 1)[:, None]
tmp19 = 64.0
tmp20 = tmp18 / tmp19
tmp21 = 1e-05
tmp22 = tmp20 + tmp21
tmp23 = libdevice.rsqrt(tmp22)
tl.store(in_out_ptr0 + (r2 + 64 * x3), tmp2, xmask)
tl.debug_barrier()
tl.store(in_out_ptr1 + x3, tmp23, xmask)
tl.store(out_ptr0 + x3, tmp12, xmask)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_17(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 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_18(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 % 16
x0 = xindex % 16
x5 = xindex // 256
x3 = xindex // 16384
x6 = xindex % 16384
tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x5, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr3 + x5, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 8, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 8 * tmp4 + 64 * x5), None,
eviction_policy='evict_last')
tmp11 = tmp9 - tmp10
tmp13 = tmp11 * tmp12
tmp14 = 0.0
tmp15 = tmp13 > tmp14
tmp16 = 0.001
tmp17 = tmp13 * tmp16
tmp18 = tl.where(tmp15, tmp13, tmp17)
tl.store(out_ptr0 + (x6 + 24576 * x3), tmp18, None)
@triton.jit
def triton_per_fused__native_batch_norm_legit_convolution_19(in_out_ptr0,
in_out_ptr1, in_ptr0, out_ptr0, 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)
r2 = rindex
x3 = xindex
x0 = xindex % 32
tmp0 = tl.load(in_out_ptr0 + (r2 + 256 * x3), None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
tmp5 = tl.broadcast_to(tmp3, [RBLOCK])
tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0))
tmp8 = tl.full([1], 256, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp3 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
tmp16 = 256.0
tmp17 = tmp15 / tmp16
tmp18 = 1e-05
tmp19 = tmp17 + tmp18
tmp20 = libdevice.rsqrt(tmp19)
tl.store(in_out_ptr0 + (r2 + 256 * x3), tmp2, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + x3, tmp20, None)
tl.store(out_ptr0 + x3, tmp10, None)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_20(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 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_21(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 // 32 % 32
x0 = xindex % 32
x5 = xindex // 1024
x3 = xindex // 32768
x6 = xindex % 32768
tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x5, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr3 + x5, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 16, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 16 * tmp4 + 256 * x5), None,
eviction_policy='evict_last')
tmp11 = tmp9 - tmp10
tmp13 = tmp11 * tmp12
tmp14 = 0.0
tmp15 = tmp13 > tmp14
tmp16 = 0.001
tmp17 = tmp13 * tmp16
tmp18 = tl.where(tmp15, tmp13, tmp17)
tl.store(out_ptr0 + (x6 + 49152 * x3), tmp18, None)
@triton.jit
def triton_per_fused__native_batch_norm_legit_convolution_22(in_out_ptr0,
in_out_ptr1, in_ptr0, out_ptr0, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
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)
r2 = rindex
x3 = xindex
x0 = xindex % 16
tmp0 = tl.load(in_out_ptr0 + (r2 + 1024 * x3), None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [RBLOCK])
tmp5 = tl.broadcast_to(tmp3, [RBLOCK])
tmp7 = triton_helpers.promote_to_tensor(tl.sum(tmp5, 0))
tmp8 = tl.full([1], 1024, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp3 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [RBLOCK])
tmp15 = triton_helpers.promote_to_tensor(tl.sum(tmp13, 0))
tmp16 = 1024.0
tmp17 = tmp15 / tmp16
tmp18 = 1e-05
tmp19 = tmp17 + tmp18
tmp20 = libdevice.rsqrt(tmp19)
tl.store(in_out_ptr0 + (r2 + 1024 * x3), tmp2, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + x3, tmp20, None)
tl.store(out_ptr0 + x3, tmp10, None)
@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_23(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 = x0
tmp1 = tmp0.to(tl.float32)
tmp2 = 0.5
tmp3 = tmp1 * tmp2
tmp4 = tmp3.to(tl.int32)
tl.store(out_ptr0 + x0, tmp4, xmask)
@triton.jit
def triton_poi_fused__unsafe_index_24(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 // 64 % 64
x0 = xindex % 64
x5 = xindex // 4096
x3 = xindex // 65536
x6 = xindex % 65536
tmp0 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp10 = tl.load(in_ptr2 + x5, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr3 + x5, None, eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 32, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tmp6 = tmp5 + tmp1
tmp7 = tmp5 < 0
tmp8 = tl.where(tmp7, tmp6, tmp5)
tmp9 = tl.load(in_ptr1 + (tmp8 + 32 * tmp4 + 1024 * x5), None,
eviction_policy='evict_last')
tmp11 = tmp9 - tmp10
tmp13 = tmp11 * tmp12
tmp14 = 0.0
tmp15 = tmp13 > tmp14
tmp16 = 0.001
tmp17 = tmp13 * tmp16
tmp18 = tl.where(tmp15, tmp13, tmp17)
tl.store(out_ptr0 + (x6 + 98304 * x3), tmp18, None)
@triton.jit
def triton_red_fused__native_batch_norm_legit_convolution_leaky_relu_25(
in_out_ptr0, in_ptr0, out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel,
XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 32
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x3 = xindex
x0 = xindex % 8
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp4_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp4_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp4_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp0 = tl.load(in_out_ptr0 + (r2 + 4096 * x3), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp2 = tmp0 + tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp4_mean_next, tmp4_m2_next, tmp4_weight_next = (triton_helpers.
welford_reduce(tmp3, tmp4_mean, tmp4_m2, tmp4_weight, roffset == 0)
)
tmp4_mean = tl.where(rmask & xmask, tmp4_mean_next, tmp4_mean)
tmp4_m2 = tl.where(rmask & xmask, tmp4_m2_next, tmp4_m2)
tmp4_weight = tl.where(rmask & xmask, tmp4_weight_next, tmp4_weight)
tl.store(in_out_ptr0 + (r2 + 4096 * x3), tmp2, rmask & xmask)
tmp4_tmp, tmp5_tmp, tmp6_tmp = triton_helpers.welford(tmp4_mean,
tmp4_m2, tmp4_weight, 1)
tmp4 = tmp4_tmp[:, None]
tmp5 = tmp5_tmp[:, None]
tmp6_tmp[:, None]
tl.store(out_ptr0 + x3, tmp4, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex
tmp7 = tl.load(in_out_ptr0 + (r2 + 4096 * x3), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp8 = tmp7 - tmp4
tmp9 = 4096.0
tmp10 = tmp5 / tmp9
tmp11 = 1e-05
tmp12 = tmp10 + tmp11
tmp13 = libdevice.rsqrt(tmp12)
tmp14 = tmp8 * tmp13
tmp15 = 0.0
tmp16 = tmp14 > tmp15
tmp17 = 0.001
tmp18 = tmp14 * tmp17
tmp19 = tl.where(tmp16, tmp14, tmp18)
tl.store(out_ptr2 + (r2 + 4096 * x3), tmp19, rmask & xmask)
tmp20 = 4096.0
tmp21 = tmp5 / tmp20
tmp22 = 1e-05
tmp23 = tmp21 + tmp22
tmp24 = libdevice.rsqrt(tmp23)
tl.store(out_ptr3 + x3, tmp24, xmask)
@triton.jit
def triton_poi_fused_convolution_26(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)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tl.store(in_out_ptr0 + x0, tmp3, None)
@triton.jit
def triton_red_fused__native_batch_norm_legit_add_convolution_27(in_out_ptr0,
in_out_ptr1, in_out_ptr2, in_out_ptr3, in_ptr0, in_ptr1, out_ptr0,
out_ptr1, out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.
constexpr):
xnumel = 4
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp5_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp5_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp5_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_out_ptr0 + (r1 + 4096 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp3 = tmp0 + tmp2
tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp5_mean_next, tmp5_m2_next, tmp5_weight_next = (triton_helpers.
welford_reduce(tmp4, tmp5_mean, tmp5_m2, tmp5_weight, roffset == 0)
)
tmp5_mean = tl.where(rmask & xmask, tmp5_mean_next, tmp5_mean)
tmp5_m2 = tl.where(rmask & xmask, tmp5_m2_next, tmp5_m2)
tmp5_weight = tl.where(rmask & xmask, tmp5_weight_next, tmp5_weight)
tl.store(in_out_ptr0 + (r1 + 4096 * x0), tmp3, rmask & xmask)
tmp5_tmp, tmp6_tmp, tmp7_tmp = triton_helpers.welford(tmp5_mean,
tmp5_m2, tmp5_weight, 1)
tmp5 = tmp5_tmp[:, None]
tmp6 = tmp6_tmp[:, None]
tmp7_tmp[:, None]
tl.store(out_ptr0 + x0, tmp5, xmask)
tmp8 = 4096.0
tmp9 = tmp6 / tmp8
tmp10 = 1e-05
tmp11 = tmp9 + tmp10
tmp12 = libdevice.rsqrt(tmp11)
tl.debug_barrier()
tl.store(in_out_ptr1 + x0, tmp12, xmask)
tmp14 = tl.load(in_ptr1 + 0)
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp18_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp18_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp18_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp13 = tl.load(in_out_ptr2 + (r1 + 4096 * x0), rmask & xmask,
eviction_policy='evict_last', other=0.0)
tmp16 = tmp13 + tmp15
tmp17 = tl.broadcast_to(tmp16, [XBLOCK, RBLOCK])
tmp18_mean_next, tmp18_m2_next, tmp18_weight_next = (triton_helpers
.welford_reduce(tmp17, tmp18_mean, tmp18_m2, tmp18_weight,
roffset == 0))
tmp18_mean = tl.where(rmask & xmask, tmp18_mean_next, tmp18_mean)
tmp18_m2 = tl.where(rmask & xmask, tmp18_m2_next, tmp18_m2)
tmp18_weight = tl.where(rmask & xmask, tmp18_weight_next, tmp18_weight)
tl.store(in_out_ptr2 + (r1 + 4096 * x0), tmp16, rmask & xmask)
tmp18_tmp, tmp19_tmp, tmp20_tmp = triton_helpers.welford(tmp18_mean,
tmp18_m2, tmp18_weight, 1)
tmp18 = tmp18_tmp[:, None]
tmp19 = tmp19_tmp[:, None]
tmp20_tmp[:, None]
tl.store(out_ptr1 + x0, tmp18, xmask)
tmp21 = 4096.0
tmp22 = tmp19 / tmp21
tmp23 = 1e-05
tmp24 = tmp22 + tmp23
tmp25 = libdevice.rsqrt(tmp24)
tl.debug_barrier()
tl.store(in_out_ptr3 + x0, tmp25, xmask)
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r1 = rindex
tmp26 = tl.load(in_out_ptr0 + (r1 + 4096 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp34 = tl.load(in_out_ptr2 + (r1 + 4096 * x0), rmask & xmask,
eviction_policy='evict_first', other=0.0)
tmp27 = tmp26 - tmp5
tmp28 = tmp27 * tmp12
tmp29 = 0.0
tmp30 = tmp28 > tmp29
tmp31 = 0.001
tmp32 = tmp28 * tmp31
tmp33 = tl.where(tmp30, tmp28, tmp32)
tmp35 = tmp34 - tmp18
tmp36 = tmp35 * tmp25
tmp37 = tmp36 > tmp29
tmp38 = tmp36 * tmp31
tmp39 = tl.where(tmp37, tmp36, tmp38)
tmp40 = tmp33 + tmp39
tl.store(out_ptr2 + (r1 + 4096 * x0), tmp40, rmask & 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) = args
args.clear()
assert_size_stride(primals_1, (4, 1, 64, 64), (4096, 4096, 64, 1))
assert_size_stride(primals_2, (8, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_3, (8,), (1,))
assert_size_stride(primals_4, (8, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_5, (8,), (1,))
assert_size_stride(primals_6, (16, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_7, (16,), (1,))
assert_size_stride(primals_8, (16, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_9, (16,), (1,))
assert_size_stride(primals_10, (32, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_11, (32,), (1,))
assert_size_stride(primals_12, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_13, (32,), (1,))
assert_size_stride(primals_14, (64, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_15, (64,), (1,))
assert_size_stride(primals_16, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_17, (64,), (1,))
assert_size_stride(primals_18, (128, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_19, (128,), (1,))
assert_size_stride(primals_20, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_21, (128,), (1,))
assert_size_stride(primals_22, (64, 192, 3, 3), (1728, 9, 3, 1))
assert_size_stride(primals_23, (64,), (1,))
assert_size_stride(primals_24, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_25, (64,), (1,))
assert_size_stride(primals_26, (32, 96, 3, 3), (864, 9, 3, 1))
assert_size_stride(primals_27, (32,), (1,))
assert_size_stride(primals_28, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_29, (32,), (1,))
assert_size_stride(primals_30, (16, 48, 3, 3), (432, 9, 3, 1))
assert_size_stride(primals_31, (16,), (1,))
assert_size_stride(primals_32, (16, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_33, (16,), (1,))
assert_size_stride(primals_34, (8, 24, 3, 3), (216, 9, 3, 1))
assert_size_stride(primals_35, (8,), (1,))
assert_size_stride(primals_36, (8, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_37, (8,), (1,))
assert_size_stride(primals_38, (1, 8, 3, 3), (72, 9, 3, 1))
assert_size_stride(primals_39, (1,), (1,))
assert_size_stride(primals_40, (1, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_41, (1,), (1,))
assert_size_stride(primals_42, (1, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_43, (1,), (1,))
assert_size_stride(primals_44, (1, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_45, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 8, 64, 64), (32768, 4096, 64, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(131072)](buf1, primals_3,
131072, XBLOCK=512, num_warps=8, num_stages=1)
del primals_3
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, 8, 64, 64), (32768, 4096, 64, 1))
buf3 = buf2
del buf2
buf4 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch.float32
)
buf8 = empty_strided_cuda((4, 8, 64, 64), (32768, 4096, 64, 1),
torch.float32)
buf91 = empty_strided_cuda((4, 24, 64, 64), (98304, 4096, 64, 1),
torch.float32)
buf90 = reinterpret_tensor(buf91, (4, 8, 64, 64), (98304, 4096, 64,
1), 65536)
buf7 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch.float32
)
triton_red_fused__native_batch_norm_legit_cat_convolution_leaky_relu_1[
grid(32)](buf3, primals_5, buf4, buf8, buf90, buf7, 32, 4096,
XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1)
del primals_5
buf9 = empty_strided_cuda((4, 8, 32, 32), (8192, 1024, 32, 1),
torch.float32)
buf10 = empty_strided_cuda((4, 8, 32, 32), (8192, 1024, 32, 1),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_2[grid(32768)](buf8, buf9,
buf10, 32768, XBLOCK=256, num_warps=4, num_stages=1)
buf11 = extern_kernels.convolution(buf9, primals_6, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf11, (4, 16, 32, 32), (16384, 1024, 32, 1))
buf12 = buf11
del buf11
triton_poi_fused_convolution_3[grid(65536)](buf12, primals_7, 65536,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_7
buf13 = extern_kernels.convolution(buf12, primals_8, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf13, (4, 16, 32, 32), (16384, 1024, 32, 1))
buf14 = buf13
del buf13
buf15 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch.
float32)
buf19 = empty_strided_cuda((4, 16, 32, 32), (16384, 1024, 32, 1),
torch.float32)
buf79 = empty_strided_cuda((4, 48, 32, 32), (49152, 1024, 32, 1),
torch.float32)
buf78 = reinterpret_tensor(buf79, (4, 16, 32, 32), (49152, 1024, 32,
1), 32768)
buf18 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch.
float32)
triton_per_fused__native_batch_norm_legit_cat_convolution_leaky_relu_4[
grid(64)](buf14, primals_9, buf15, buf19, buf78, buf18, 64,
1024, num_warps=8, num_stages=1)
del primals_9
buf20 = empty_strided_cuda((4, 16, 16, 16), (4096, 256, 16, 1),
torch.float32)
buf21 = empty_strided_cuda((4, 16, 16, 16), (4096, 256, 16, 1),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_5[grid(16384)](buf19,
buf20, buf21, 16384, XBLOCK=256, num_warps=4, num_stages=1)
buf22 = extern_kernels.convolution(buf20, primals_10, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf22, (4, 32, 16, 16), (8192, 256, 16, 1))
buf23 = buf22
del buf22
triton_poi_fused_convolution_6[grid(32768)](buf23, primals_11,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_11
buf24 = extern_kernels.convolution(buf23, primals_12, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf24, (4, 32, 16, 16), (8192, 256, 16, 1))
buf25 = buf24
del buf24
buf26 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128),
torch.float32)
buf30 = empty_strided_cuda((4, 32, 16, 16), (8192, 256, 16, 1),
torch.float32)
buf67 = empty_strided_cuda((4, 96, 16, 16), (24576, 256, 16, 1),
torch.float32)
buf66 = reinterpret_tensor(buf67, (4, 32, 16, 16), (24576, 256, 16,
1), 16384)
buf29 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128),
torch.float32)
triton_per_fused__native_batch_norm_legit_cat_convolution_leaky_relu_7[
grid(128)](buf25, primals_13, buf26, buf30, buf66, buf29, 128,
256, num_warps=2, num_stages=1)
del primals_13
buf31 = empty_strided_cuda((4, 32, 8, 8), (2048, 64, 8, 1), torch.
float32)
buf32 = empty_strided_cuda((4, 32, 8, 8), (2048, 64, 8, 1), torch.int8)
triton_poi_fused_max_pool2d_with_indices_8[grid(8192)](buf30, buf31,
buf32, 8192, XBLOCK=128, num_warps=4, num_stages=1)
buf33 = extern_kernels.convolution(buf31, primals_14, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf33, (4, 64, 8, 8), (4096, 64, 8, 1))
buf34 = buf33
del buf33
triton_poi_fused_convolution_9[grid(16384)](buf34, primals_15,
16384, XBLOCK=256, num_warps=4, num_stages=1)
del primals_15
buf35 = extern_kernels.convolution(buf34, primals_16, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf35, (4, 64, 8, 8), (4096, 64, 8, 1))
buf36 = buf35
del buf35
buf37 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
buf41 = empty_strided_cuda((4, 64, 8, 8), (4096, 64, 8, 1), torch.
float32)
buf55 = empty_strided_cuda((4, 192, 8, 8), (12288, 64, 8, 1), torch
.float32)
buf54 = reinterpret_tensor(buf55, (4, 64, 8, 8), (12288, 64, 8, 1),
8192)
buf40 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
triton_per_fused__native_batch_norm_legit_cat_convolution_leaky_relu_10[
grid(256)](buf36, primals_17, buf37, buf41, buf54, buf40, 256,
64, XBLOCK=8, num_warps=4, num_stages=1)
del primals_17
buf42 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.
float32)
buf43 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.int8)
triton_poi_fused_max_pool2d_with_indices_11[grid(4096)](buf41,
buf42, buf43, 4096, XBLOCK=128, num_warps=4, num_stages=1)
buf44 = extern_kernels.convolution(buf42, primals_18, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf44, (4, 128, 4, 4), (2048, 16, 4, 1))
buf45 = buf44
del buf44
triton_poi_fused_convolution_12[grid(8192)](buf45, primals_19, 8192,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_19
buf46 = extern_kernels.convolution(buf45, primals_20, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf46, (4, 128, 4, 4), (2048, 16, 4, 1))
buf47 = buf46
del buf46
buf48 = empty_strided_cuda((1, 512, 1, 1), (512, 1, 1, 1), torch.
float32)
buf49 = empty_strided_cuda((1, 512, 1, 1), (512, 1, 512, 512),
torch.float32)
buf51 = reinterpret_tensor(buf49, (1, 512, 1, 1), (512, 1, 1, 1), 0)
del buf49
triton_per_fused__native_batch_norm_legit_convolution_13[grid(512)](
buf47, buf51, primals_21, buf48, 512, 16, XBLOCK=32, num_warps=
4, num_stages=1)
del primals_21
buf52 = empty_strided_cuda((8,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_14[grid(8)](buf52, 8,
XBLOCK=8, num_warps=1, num_stages=1)
buf53 = reinterpret_tensor(buf55, (4, 128, 8, 8), (12288, 64, 8, 1), 0)
triton_poi_fused__unsafe_index_15[grid(32768)](buf52, buf47, buf48,
buf51, buf53, 32768, XBLOCK=256, num_warps=4, num_stages=1)
buf56 = extern_kernels.convolution(buf55, primals_22, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf56, (4, 64, 8, 8), (4096, 64, 8, 1))
buf57 = buf56
del buf56
triton_poi_fused_convolution_9[grid(16384)](buf57, primals_23,
16384, XBLOCK=256, num_warps=4, num_stages=1)
del primals_23
buf58 = extern_kernels.convolution(buf57, primals_24, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf58, (4, 64, 8, 8), (4096, 64, 8, 1))
buf59 = buf58
del buf58
buf60 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 1, 1), torch.
float32)
buf61 = empty_strided_cuda((1, 256, 1, 1), (256, 1, 256, 256),
torch.float32)
buf63 = reinterpret_tensor(buf61, (1, 256, 1, 1), (256, 1, 1, 1), 0)
del buf61
triton_per_fused__native_batch_norm_legit_convolution_16[grid(256)](
buf59, buf63, primals_25, buf60, 256, 64, XBLOCK=8, num_warps=4,
num_stages=1)
del primals_25
buf64 = empty_strided_cuda((16,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_17[grid(16)](buf64, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf65 = reinterpret_tensor(buf67, (4, 64, 16, 16), (24576, 256, 16,
1), 0)
triton_poi_fused__unsafe_index_18[grid(65536)](buf64, buf59, buf60,
buf63, buf65, 65536, XBLOCK=512, num_warps=4, num_stages=1)
buf68 = extern_kernels.convolution(buf67, primals_26, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf68, (4, 32, 16, 16), (8192, 256, 16, 1))
buf69 = buf68
del buf68
triton_poi_fused_convolution_6[grid(32768)](buf69, primals_27,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_27
buf70 = extern_kernels.convolution(buf69, primals_28, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf70, (4, 32, 16, 16), (8192, 256, 16, 1))
buf71 = buf70
del buf70
buf72 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 1, 1), torch.
float32)
buf73 = empty_strided_cuda((1, 128, 1, 1), (128, 1, 128, 128),
torch.float32)
buf75 = reinterpret_tensor(buf73, (1, 128, 1, 1), (128, 1, 1, 1), 0)
del buf73
triton_per_fused__native_batch_norm_legit_convolution_19[grid(128)](
buf71, buf75, primals_29, buf72, 128, 256, num_warps=2,
num_stages=1)
del primals_29
buf76 = empty_strided_cuda((32,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_20[grid(32)](buf76, 32,
XBLOCK=32, num_warps=1, num_stages=1)
buf77 = reinterpret_tensor(buf79, (4, 32, 32, 32), (49152, 1024, 32,
1), 0)
triton_poi_fused__unsafe_index_21[grid(131072)](buf76, buf71, buf72,
buf75, buf77, 131072, XBLOCK=512, num_warps=8, num_stages=1)
buf80 = extern_kernels.convolution(buf79, primals_30, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf80, (4, 16, 32, 32), (16384, 1024, 32, 1))
buf81 = buf80
del buf80
triton_poi_fused_convolution_3[grid(65536)](buf81, primals_31,
65536, XBLOCK=256, num_warps=4, num_stages=1)
del primals_31
buf82 = extern_kernels.convolution(buf81, primals_32, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf82, (4, 16, 32, 32), (16384, 1024, 32, 1))
buf83 = buf82
del buf82
buf84 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 1, 1), torch.float32)
buf85 = empty_strided_cuda((1, 64, 1, 1), (64, 1, 64, 64), torch.
float32)
buf87 = reinterpret_tensor(buf85, (1, 64, 1, 1), (64, 1, 1, 1), 0)
del buf85
triton_per_fused__native_batch_norm_legit_convolution_22[grid(64)](
buf83, buf87, primals_33, buf84, 64, 1024, num_warps=8,
num_stages=1)
del primals_33
buf88 = empty_strided_cuda((64,), (1,), torch.int64)
triton_poi_fused__to_copy_add_arange_mul_23[grid(64)](buf88, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf89 = reinterpret_tensor(buf91, (4, 16, 64, 64), (98304, 4096, 64,
1), 0)
triton_poi_fused__unsafe_index_24[grid(262144)](buf88, buf83, buf84,
buf87, buf89, 262144, XBLOCK=512, num_warps=8, num_stages=1)
buf92 = extern_kernels.convolution(buf91, primals_34, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf92, (4, 8, 64, 64), (32768, 4096, 64, 1))
buf93 = buf92
del buf92
triton_poi_fused_convolution_0[grid(131072)](buf93, primals_35,
131072, XBLOCK=512, num_warps=8, num_stages=1)
del primals_35
buf94 = extern_kernels.convolution(buf93, primals_36, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf94, (4, 8, 64, 64), (32768, 4096, 64, 1))
buf95 = buf94
del buf94
buf96 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch.
float32)
buf100 = empty_strided_cuda((4, 8, 64, 64), (32768, 4096, 64, 1),
torch.float32)
buf99 = empty_strided_cuda((1, 32, 1, 1), (32, 1, 32, 32), torch.
float32)
triton_red_fused__native_batch_norm_legit_convolution_leaky_relu_25[
grid(32)](buf95, primals_37, buf96, buf100, buf99, 32, 4096,
XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1)
del primals_37
buf101 = extern_kernels.convolution(buf100, primals_38, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf101, (4, 1, 64, 64), (4096, 4096, 64, 1))
buf102 = buf101
del buf101
triton_poi_fused_convolution_26[grid(16384)](buf102, primals_39,
16384, XBLOCK=256, num_warps=4, num_stages=1)
del primals_39
buf103 = extern_kernels.convolution(buf102, primals_40, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf103, (4, 1, 64, 64), (4096, 4096, 64, 1))
buf109 = extern_kernels.convolution(primals_1, primals_42, stride=(
1, 1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf109, (4, 1, 64, 64), (4096, 4096, 64, 1))
buf110 = buf109
del buf109
triton_poi_fused_convolution_26[grid(16384)](buf110, primals_43,
16384, XBLOCK=256, num_warps=4, num_stages=1)
del primals_43
buf111 = extern_kernels.convolution(buf110, primals_44, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf111, (4, 1, 64, 64), (4096, 4096, 64, 1))
buf104 = buf103
del buf103
buf105 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
buf106 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
buf108 = reinterpret_tensor(buf106, (1, 4, 1, 1), (4, 1, 1, 1), 0)
del buf106
buf112 = buf111
del buf111
buf113 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 1, 1), torch.float32)
buf114 = empty_strided_cuda((1, 4, 1, 1), (4, 1, 4, 4), torch.float32)
buf116 = reinterpret_tensor(buf114, (1, 4, 1, 1), (4, 1, 1, 1), 0)
del buf114
buf117 = empty_strided_cuda((4, 1, 64, 64), (4096, 4096, 64, 1),
torch.float32)
triton_red_fused__native_batch_norm_legit_add_convolution_27[grid(4)](
buf104, buf108, buf112, buf116, primals_41, primals_45, buf105,
buf113, buf117, 4, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
del primals_41
del primals_45
return (buf117, primals_1, primals_2, primals_4, primals_6, primals_8,
primals_10, primals_12, primals_14, primals_16, primals_18,
primals_20, primals_22, primals_24, primals_26, primals_28,
primals_30, primals_32, primals_34, primals_36, primals_38,
primals_40, primals_42, primals_44, buf1, buf3, reinterpret_tensor(
buf7, (32,), (1,), 0), buf8, buf9, buf10, buf12, buf14,
reinterpret_tensor(buf18, (64,), (1,), 0), buf19, buf20, buf21,
buf23, buf25, reinterpret_tensor(buf29, (128,), (1,), 0), buf30,
buf31, buf32, buf34, buf36, reinterpret_tensor(buf40, (256,), (1,),
0), buf41, buf42, buf43, buf45, buf47, buf48, buf51, buf52, buf55,
buf57, buf59, buf60, buf63, buf64, buf67, buf69, buf71, buf72,
buf75, buf76, buf79, buf81, buf83, buf84, buf87, buf88, buf91,
buf93, buf95, reinterpret_tensor(buf99, (32,), (1,), 0), buf100,
buf102, buf104, buf105, buf108, buf110, buf112, buf113, buf116,
reinterpret_tensor(buf96, (1, 32, 1, 1), (32, 1, 1, 1), 0),
reinterpret_tensor(buf37, (1, 256, 1, 1), (256, 1, 1, 1), 0),
reinterpret_tensor(buf26, (1, 128, 1, 1), (128, 1, 1, 1), 0),
reinterpret_tensor(buf15, (1, 64, 1, 1), (64, 1, 1, 1), 0),
reinterpret_tensor(buf4, (1, 32, 1, 1), (32, 1, 1, 1), 0))
class BasicConvBlock(nn.Module):
def __init__(self, in_channels, out_channels):
super(BasicConvBlock, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3,
padding=1)
self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=3,
padding=1)
self.norm = nn.InstanceNorm2d(out_channels)
def forward(self, x):
x = F.leaky_relu(self.norm(self.conv2(self.conv1(x))),
negative_slope=0.001, inplace=True)
return x
class BasicUNetNew(nn.Module):
def __init__(self, n_input_channel=1, n_output_channel=1, nic=8,
residual=True):
super().__init__()
self.residual = residual
self.down1 = nn.MaxPool2d(kernel_size=2)
self.down2 = nn.MaxPool2d(kernel_size=2)
self.down3 = nn.MaxPool2d(kernel_size=2)
self.down4 = nn.MaxPool2d(kernel_size=2)
self.up1 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.up2 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.up3 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.up4 = lambda x: nn.functional.interpolate(x, mode='nearest',
scale_factor=2)
self.conv1 = BasicConvBlock(n_input_channel, nic)
self.conv2 = BasicConvBlock(nic, nic * 2)
self.conv3 = BasicConvBlock(nic * 2, nic * 4)
self.conv4 = BasicConvBlock(nic * 4, nic * 8)
self.conv5 = BasicConvBlock(nic * 8, nic * 16)
self.conv6 = BasicConvBlock(nic * 3 * 8, nic * 8)
self.conv7 = BasicConvBlock(nic * 3 * 4, nic * 4)
self.conv8 = BasicConvBlock(nic * 3 * 2, nic * 2)
self.conv9 = BasicConvBlock(nic * 3, nic)
self.conv10 = BasicConvBlock(nic, n_output_channel)
if self.residual:
self.conv11 = BasicConvBlock(n_input_channel, n_output_channel)
def forward(self, input_0):
primals_2 = self.conv1.conv1.weight
primals_3 = self.conv1.conv1.bias
primals_4 = self.conv1.conv2.weight
primals_5 = self.conv1.conv2.bias
primals_6 = self.conv2.conv1.weight
primals_7 = self.conv2.conv1.bias
primals_8 = self.conv2.conv2.weight
primals_9 = self.conv2.conv2.bias
primals_10 = self.conv3.conv1.weight
primals_11 = self.conv3.conv1.bias
primals_12 = self.conv3.conv2.weight
primals_13 = self.conv3.conv2.bias
primals_14 = self.conv4.conv1.weight
primals_15 = self.conv4.conv1.bias
primals_16 = self.conv4.conv2.weight
primals_17 = self.conv4.conv2.bias
primals_18 = self.conv5.conv1.weight
primals_19 = self.conv5.conv1.bias
primals_20 = self.conv5.conv2.weight
primals_21 = self.conv5.conv2.bias
primals_22 = self.conv6.conv1.weight
primals_23 = self.conv6.conv1.bias
primals_24 = self.conv6.conv2.weight
primals_25 = self.conv6.conv2.bias
primals_26 = self.conv7.conv1.weight
primals_27 = self.conv7.conv1.bias
primals_28 = self.conv7.conv2.weight
primals_29 = self.conv7.conv2.bias
primals_30 = self.conv8.conv1.weight
primals_31 = self.conv8.conv1.bias
primals_32 = self.conv8.conv2.weight
primals_33 = self.conv8.conv2.bias
primals_34 = self.conv9.conv1.weight
primals_35 = self.conv9.conv1.bias
primals_36 = self.conv9.conv2.weight
primals_37 = self.conv9.conv2.bias
primals_38 = self.conv10.conv1.weight
primals_39 = self.conv10.conv1.bias
primals_40 = self.conv10.conv2.weight
primals_41 = self.conv10.conv2.bias
primals_42 = self.conv11.conv1.weight
primals_43 = self.conv11.conv1.bias
primals_44 = self.conv11.conv2.weight
primals_45 = self.conv11.conv2.bias
primals_1 = 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])
return output[0]
|
royerloic/aydin
|
BasicUNet
| false
| 16,420
|
[
"BSD-3-Clause"
] | 78
|
f9c61a24030891d008c318b250da5faec69fcd7d
|
https://github.com/royerloic/aydin/tree/f9c61a24030891d008c318b250da5faec69fcd7d
|
HSwish
|
import torch
from torch import nn
import torch.utils.data
class HSwish(nn.Module):
"""Hard Swish activation function.
See: https://arxiv.org/abs/1905.02244
"""
def forward(self, x):
return x * nn.functional.relu6(x + 3).div_(6)
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 import 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_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 = 0.16666666666666666
tmp8 = tmp6 * tmp7
tmp9 = tmp0 * 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):
"""Hard Swish activation function.
See: https://arxiv.org/abs/1905.02244
"""
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
shiyuann/determined
|
HSwish
| false
| 16,421
|
[
"Apache-2.0"
] | 1,729
|
856123ae112759de7bded9bc7bd0e07055f2174b
|
https://github.com/shiyuann/determined/tree/856123ae112759de7bded9bc7bd0e07055f2174b
|
StyledConv
|
import math
import torch
import warnings
import numpy as np
from torch import nn
from torch.nn import functional as F
import torch.utils.cpp_extension
def fused_leaky_relu(input, bias, negative_slope=0.2, scale=2 ** 0.5):
rest_dim = [1] * (input.ndim - bias.ndim - 1)
input = input
return F.leaky_relu(input + bias.view(1, bias.shape[0], *rest_dim),
negative_slope=negative_slope) * scale
def make_kernel(k):
k = torch.tensor(k, dtype=torch.float32)
if k.ndim == 1:
k = k[None, :] * k[:, None]
k /= k.sum()
return k
def _init():
global _inited, _plugin
if not _inited:
sources = ['upfirdn2d.cpp', 'upfirdn2d.cu']
sources = [os.path.join(os.path.dirname(__file__), s) for s in sources]
try:
_plugin = custom_ops.get_plugin('upfirdn2d_plugin', sources=
sources, extra_cuda_cflags=['--use_fast_math'])
except:
warnings.warn(
"""Failed to build CUDA kernels for upfirdn2d. Falling back to slow reference implementation. Details:
"""
+ traceback.format_exc())
return _plugin is not None
def _get_filter_size(f):
if f is None:
return 1, 1
assert isinstance(f, torch.Tensor) and f.ndim in [1, 2]
fw = f.shape[-1]
fh = f.shape[0]
with misc.suppress_tracer_warnings():
fw = int(fw)
fh = int(fh)
misc.assert_shape(f, [fh, fw][:f.ndim])
assert fw >= 1 and fh >= 1
return fw, fh
def _parse_padding(padding):
if isinstance(padding, int):
padding = [padding, padding]
assert isinstance(padding, (list, tuple))
assert all(isinstance(x, int) for x in padding)
if len(padding) == 2:
padx, pady = padding
padding = [padx, padx, pady, pady]
padx0, padx1, pady0, pady1 = padding
return padx0, padx1, pady0, pady1
def _parse_scaling(scaling):
if isinstance(scaling, int):
scaling = [scaling, scaling]
assert isinstance(scaling, (list, tuple))
assert all(isinstance(x, int) for x in scaling)
sx, sy = scaling
assert sx >= 1 and sy >= 1
return sx, sy
def _upfirdn2d_cuda(up=1, down=1, padding=0, flip_filter=False, gain=1):
"""Fast CUDA implementation of `upfirdn2d()` using custom ops.
"""
upx, upy = _parse_scaling(up)
downx, downy = _parse_scaling(down)
padx0, padx1, pady0, pady1 = _parse_padding(padding)
key = upx, upy, downx, downy, padx0, padx1, pady0, pady1, flip_filter, gain
if key in _upfirdn2d_cuda_cache:
return _upfirdn2d_cuda_cache[key]
class Upfirdn2dCuda(torch.autograd.Function):
@staticmethod
def forward(ctx, x, f):
assert isinstance(x, torch.Tensor) and x.ndim == 4
if f is None:
f = torch.ones([1, 1], dtype=torch.float32, device=x.device)
assert isinstance(f, torch.Tensor) and f.ndim in [1, 2]
y = x
if f.ndim == 2:
y = _plugin.upfirdn2d(y, f, upx, upy, downx, downy, padx0,
padx1, pady0, pady1, flip_filter, gain)
else:
y = _plugin.upfirdn2d(y, f.unsqueeze(0), upx, 1, downx, 1,
padx0, padx1, 0, 0, flip_filter, np.sqrt(gain))
y = _plugin.upfirdn2d(y, f.unsqueeze(1), 1, upy, 1, downy,
0, 0, pady0, pady1, flip_filter, np.sqrt(gain))
ctx.save_for_backward(f)
ctx.x_shape = x.shape
return y
@staticmethod
def backward(ctx, dy):
f, = ctx.saved_tensors
_, _, ih, iw = ctx.x_shape
_, _, oh, ow = dy.shape
fw, fh = _get_filter_size(f)
p = [fw - padx0 - 1, iw * upx - ow * downx + padx0 - upx + 1,
fh - pady0 - 1, ih * upy - oh * downy + pady0 - upy + 1]
dx = None
df = None
if ctx.needs_input_grad[0]:
dx = _upfirdn2d_cuda(up=down, down=up, padding=p,
flip_filter=not flip_filter, gain=gain).apply(dy, f)
assert not ctx.needs_input_grad[1]
return dx, df
_upfirdn2d_cuda_cache[key] = Upfirdn2dCuda
return Upfirdn2dCuda
def upfirdn2d(x, f, up=1, down=1, padding=0, flip_filter=False, gain=1,
impl='cuda'):
"""Pad, upsample, filter, and downsample a batch of 2D images.
Performs the following sequence of operations for each channel:
1. Upsample the image by inserting N-1 zeros after each pixel (`up`).
2. Pad the image with the specified number of zeros on each side (`padding`).
Negative padding corresponds to cropping the image.
3. Convolve the image with the specified 2D FIR filter (`f`), shrinking it
so that the footprint of all output pixels lies within the input image.
4. Downsample the image by keeping every Nth pixel (`down`).
This sequence of operations bears close resemblance to scipy.signal.upfirdn().
The fused op is considerably more efficient than performing the same calculation
using standard PyTorch ops. It supports gradients of arbitrary order.
Args:
x: Float32/float64/float16 input tensor of the shape
`[batch_size, num_channels, in_height, in_width]`.
f: Float32 FIR filter of the shape
`[filter_height, filter_width]` (non-separable),
`[filter_taps]` (separable), or
`None` (identity).
up: Integer upsampling factor. Can be a single int or a list/tuple
`[x, y]` (default: 1).
down: Integer downsampling factor. Can be a single int or a list/tuple
`[x, y]` (default: 1).
padding: Padding with respect to the upsampled image. Can be a single number
or a list/tuple `[x, y]` or `[x_before, x_after, y_before, y_after]`
(default: 0).
flip_filter: False = convolution, True = correlation (default: False).
gain: Overall scaling factor for signal magnitude (default: 1).
impl: Implementation to use. Can be `'ref'` or `'cuda'` (default: `'cuda'`).
Returns:
Tensor of the shape `[batch_size, num_channels, out_height, out_width]`.
"""
assert isinstance(x, torch.Tensor)
assert impl in ['ref', 'cuda']
if impl == 'cuda' and x.device.type == 'cuda' and _init():
return _upfirdn2d_cuda(up=up, down=down, padding=padding,
flip_filter=flip_filter, gain=gain).apply(x, f)
return _upfirdn2d_ref(x, f, up=up, down=down, padding=padding,
flip_filter=flip_filter, gain=gain)
class EqualLinear(nn.Module):
def __init__(self, in_dim, out_dim, bias=True, bias_init=0, lr_mul=1,
activation=None):
super().__init__()
self.weight = nn.Parameter(torch.randn(out_dim, in_dim).div_(lr_mul))
if bias:
self.bias = nn.Parameter(torch.zeros(out_dim).fill_(bias_init))
else:
self.bias = None
self.activation = activation
self.scale = 1 / math.sqrt(in_dim) * lr_mul
self.lr_mul = lr_mul
def forward(self, input):
if self.activation:
out = F.linear(input, self.weight * self.scale)
out = fused_leaky_relu(out, self.bias * self.lr_mul)
else:
out = F.linear(input, self.weight * self.scale, bias=self.bias *
self.lr_mul)
return out
def __repr__(self):
return (
f'{self.__class__.__name__}({self.weight.shape[1]}, {self.weight.shape[0]})'
)
class Blur(nn.Module):
def __init__(self, kernel, pad, upsample_factor=1):
super().__init__()
kernel = make_kernel(kernel)
if upsample_factor > 1:
kernel = kernel * upsample_factor ** 2
self.register_buffer('kernel', kernel)
self.pad = pad
def forward(self, input):
out = upfirdn2d(input, self.kernel, pad=self.pad)
return out
class ModulatedConv2d(nn.Module):
def __init__(self, in_channel, out_channel, kernel_size, style_dim,
demodulate=True, upsample=False, downsample=False, blur_kernel=[1,
3, 3, 1]):
super().__init__()
self.eps = 1e-08
self.kernel_size = kernel_size
self.in_channel = in_channel
self.out_channel = out_channel
self.upsample = upsample
self.downsample = downsample
if upsample:
factor = 2
p = len(blur_kernel) - factor - (kernel_size - 1)
pad0 = (p + 1) // 2 + factor - 1
pad1 = p // 2 + 1
self.blur = Blur(blur_kernel, pad=(pad0, pad1), upsample_factor
=factor)
if downsample:
factor = 2
p = len(blur_kernel) - factor + (kernel_size - 1)
pad0 = (p + 1) // 2
pad1 = p // 2
self.blur = Blur(blur_kernel, pad=(pad0, pad1))
fan_in = in_channel * kernel_size ** 2
self.scale = 1 / math.sqrt(fan_in)
self.padding = kernel_size // 2
self.weight = nn.Parameter(torch.randn(1, out_channel, in_channel,
kernel_size, kernel_size))
self.modulation = EqualLinear(style_dim, in_channel, bias_init=1)
self.demodulate = demodulate
def __repr__(self):
return (
f'{self.__class__.__name__}({self.in_channel}, {self.out_channel}, {self.kernel_size}, upsample={self.upsample}, downsample={self.downsample})'
)
def forward(self, input, style):
batch, in_channel, height, width = input.shape
style = self.modulation(style).view(batch, 1, in_channel, 1, 1)
weight = self.scale * self.weight * style
if self.demodulate:
demod = torch.rsqrt(weight.pow(2).sum([2, 3, 4]) + 1e-08)
weight = weight * demod.view(batch, self.out_channel, 1, 1, 1)
weight = weight.view(batch * self.out_channel, in_channel, self.
kernel_size, self.kernel_size)
if self.upsample:
input = input.view(1, batch * in_channel, height, width)
weight = weight.view(batch, self.out_channel, in_channel, self.
kernel_size, self.kernel_size)
weight = weight.transpose(1, 2).reshape(batch * in_channel,
self.out_channel, self.kernel_size, self.kernel_size)
out = F.conv_transpose2d(input, weight, padding=0, stride=2,
groups=batch)
_, _, height, width = out.shape
out = out.view(batch, self.out_channel, height, width)
out = self.blur(out)
elif self.downsample:
input = self.blur(input)
_, _, height, width = input.shape
input = input.view(1, batch * in_channel, height, width)
out = F.conv2d(input, weight, padding=0, stride=2, groups=batch)
_, _, height, width = out.shape
out = out.view(batch, self.out_channel, height, width)
else:
input = input.view(1, batch * in_channel, height, width)
out = F.conv2d(input, weight, padding=self.padding, groups=batch)
_, _, height, width = out.shape
out = out.view(batch, self.out_channel, height, width)
return out
class NoiseInjection(nn.Module):
def __init__(self):
super().__init__()
self.weight = nn.Parameter(torch.zeros(1))
def forward(self, image, noise=None):
if noise is None:
batch, _, height, width = image.shape
noise = image.new_empty(batch, 1, height, width).normal_()
return image + self.weight * noise
class FusedLeakyReLU(nn.Module):
def __init__(self, channel, negative_slope=0.2, scale=2 ** 0.5):
super().__init__()
self.bias = nn.Parameter(torch.zeros(channel))
self.negative_slope = negative_slope
self.scale = scale
def forward(self, input):
return fused_leaky_relu(input, self.bias, self.negative_slope, self
.scale)
class StyledConv(nn.Module):
def __init__(self, in_channel, out_channel, kernel_size, style_dim,
upsample=False, blur_kernel=[1, 3, 3, 1], demodulate=True):
super().__init__()
self.conv = ModulatedConv2d(in_channel, out_channel, kernel_size,
style_dim, upsample=upsample, blur_kernel=blur_kernel,
demodulate=demodulate)
self.noise = NoiseInjection()
self.activate = FusedLeakyReLU(out_channel)
def forward(self, input, style, noise=None):
out = self.conv(input, style)
out = self.noise(out, noise=noise)
out = self.activate(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'in_channel': 4, 'out_channel': 4, 'kernel_size': 4,
'style_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
import warnings
import numpy as np
from torch import nn
from torch.nn import functional as F
import torch.utils.cpp_extension
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_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 + x0, xmask)
tmp1 = 0.5
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_mul_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 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_per_fused_add_mul_pow_rsqrt_sum_2(in_out_ptr0, in_ptr0, in_ptr1,
out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 16
RBLOCK: tl.constexpr = 64
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)
r5 = rindex
x0 = xindex % 4
r3 = rindex // 16
x1 = xindex // 4
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r5 + 64 * x0), xmask, eviction_policy=
'evict_last', other=0.0)
tmp3 = tl.load(in_ptr1 + (r3 + 4 * x1), xmask, eviction_policy=
'evict_last', other=0.0)
tmp1 = 0.125
tmp2 = tmp0 * tmp1
tmp4 = tmp2 * tmp3
tmp5 = tmp4 * tmp4
tmp6 = tl.broadcast_to(tmp5, [XBLOCK, RBLOCK])
tmp8 = tl.where(xmask, tmp6, 0)
tmp9 = tl.sum(tmp8, 1)[:, None]
tmp10 = 1e-08
tmp11 = tmp9 + tmp10
tmp12 = libdevice.rsqrt(tmp11)
tmp13 = tmp4 * tmp12
tl.debug_barrier()
tl.store(in_out_ptr0 + x4, tmp12, xmask)
tl.store(out_ptr0 + (r5 + 64 * x4), tmp13, xmask)
@triton.jit
def triton_poi_fused_add_leaky_relu_mul_3(in_ptr0, in_ptr1, in_ptr2,
in_ptr3, out_ptr0, out_ptr1, xnumel, XBLOCK: tl.constexpr):
xnumel = 400
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x0 = xindex % 25
x2 = xindex // 100
x1 = xindex // 25 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tl.load(in_ptr2 + (x0 + 25 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp4 = tmp2 * tmp3
tmp5 = tmp0 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = 0.0
tmp9 = tmp7 > tmp8
tmp10 = 0.2
tmp11 = tmp7 * tmp10
tmp12 = tl.where(tmp9, tmp7, tmp11)
tmp13 = 1.4142135623730951
tmp14 = tmp12 * tmp13
tl.store(out_ptr0 + x3, tmp9, xmask)
tl.store(out_ptr1 + x3, tmp14, 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, (1, 4, 4, 4, 4), (256, 64, 16, 4, 1))
assert_size_stride(primals_6, (1,), (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)
get_raw_stream(0)
triton_poi_fused_mul_0[grid(16)](primals_2, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((4,), (1,), torch.float32)
triton_poi_fused_mul_1[grid(4)](primals_3, buf1, 4, XBLOCK=4,
num_warps=1, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(buf1, primals_4, reinterpret_tensor(buf0, (4,
4), (1, 4), 0), alpha=1, beta=1, out=buf2)
del buf1
buf3 = buf0
del buf0
buf4 = buf3
del buf3
buf5 = empty_strided_cuda((4, 4, 4, 4, 4), (256, 64, 16, 4, 1),
torch.float32)
triton_per_fused_add_mul_pow_rsqrt_sum_2[grid(16)](buf4, primals_5,
buf2, buf5, 16, 64, XBLOCK=8, num_warps=4, num_stages=1)
buf6 = extern_kernels.convolution(reinterpret_tensor(primals_1, (1,
16, 4, 4), (256, 16, 4, 1), 0), reinterpret_tensor(buf5, (16, 4,
4, 4), (64, 16, 4, 1), 0), stride=(1, 1), padding=(2, 2),
dilation=(1, 1), transposed=False, output_padding=(0, 0),
groups=4, bias=None)
assert_size_stride(buf6, (1, 16, 5, 5), (400, 25, 5, 1))
buf7 = empty_strided_cuda((4, 1, 5, 5), (25, 25, 5, 1), torch.float32)
buf8 = torch.ops.aten.normal_functional.default(buf7)
del buf7
buf9 = buf8
del buf8
buf10 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.bool)
buf11 = empty_strided_cuda((4, 4, 5, 5), (100, 25, 5, 1), torch.float32
)
triton_poi_fused_add_leaky_relu_mul_3[grid(400)](buf6, primals_6,
buf9, primals_7, buf10, buf11, 400, XBLOCK=256, num_warps=4,
num_stages=1)
del buf6
del primals_6
del primals_7
return buf11, primals_4, primals_5, buf2, buf4, reinterpret_tensor(buf5,
(16, 4, 4, 4), (64, 16, 4, 1), 0), reinterpret_tensor(primals_1, (1,
16, 4, 4), (256, 16, 4, 1), 0), buf9, buf10
def fused_leaky_relu(input, bias, negative_slope=0.2, scale=2 ** 0.5):
rest_dim = [1] * (input.ndim - bias.ndim - 1)
input = input
return F.leaky_relu(input + bias.view(1, bias.shape[0], *rest_dim),
negative_slope=negative_slope) * scale
def make_kernel(k):
k = torch.tensor(k, dtype=torch.float32)
if k.ndim == 1:
k = k[None, :] * k[:, None]
k /= k.sum()
return k
def _init():
global _inited, _plugin
if not _inited:
sources = ['upfirdn2d.cpp', 'upfirdn2d.cu']
sources = [os.path.join(os.path.dirname(__file__), s) for s in sources]
try:
_plugin = custom_ops.get_plugin('upfirdn2d_plugin', sources=
sources, extra_cuda_cflags=['--use_fast_math'])
except:
warnings.warn(
"""Failed to build CUDA kernels for upfirdn2d. Falling back to slow reference implementation. Details:
"""
+ traceback.format_exc())
return _plugin is not None
def _get_filter_size(f):
if f is None:
return 1, 1
assert isinstance(f, torch.Tensor) and f.ndim in [1, 2]
fw = f.shape[-1]
fh = f.shape[0]
with misc.suppress_tracer_warnings():
fw = int(fw)
fh = int(fh)
misc.assert_shape(f, [fh, fw][:f.ndim])
assert fw >= 1 and fh >= 1
return fw, fh
def _parse_padding(padding):
if isinstance(padding, int):
padding = [padding, padding]
assert isinstance(padding, (list, tuple))
assert all(isinstance(x, int) for x in padding)
if len(padding) == 2:
padx, pady = padding
padding = [padx, padx, pady, pady]
padx0, padx1, pady0, pady1 = padding
return padx0, padx1, pady0, pady1
def _parse_scaling(scaling):
if isinstance(scaling, int):
scaling = [scaling, scaling]
assert isinstance(scaling, (list, tuple))
assert all(isinstance(x, int) for x in scaling)
sx, sy = scaling
assert sx >= 1 and sy >= 1
return sx, sy
def _upfirdn2d_cuda(up=1, down=1, padding=0, flip_filter=False, gain=1):
"""Fast CUDA implementation of `upfirdn2d()` using custom ops.
"""
upx, upy = _parse_scaling(up)
downx, downy = _parse_scaling(down)
padx0, padx1, pady0, pady1 = _parse_padding(padding)
key = upx, upy, downx, downy, padx0, padx1, pady0, pady1, flip_filter, gain
if key in _upfirdn2d_cuda_cache:
return _upfirdn2d_cuda_cache[key]
class Upfirdn2dCuda(torch.autograd.Function):
@staticmethod
def forward(ctx, x, f):
assert isinstance(x, torch.Tensor) and x.ndim == 4
if f is None:
f = torch.ones([1, 1], dtype=torch.float32, device=x.device)
assert isinstance(f, torch.Tensor) and f.ndim in [1, 2]
y = x
if f.ndim == 2:
y = _plugin.upfirdn2d(y, f, upx, upy, downx, downy, padx0,
padx1, pady0, pady1, flip_filter, gain)
else:
y = _plugin.upfirdn2d(y, f.unsqueeze(0), upx, 1, downx, 1,
padx0, padx1, 0, 0, flip_filter, np.sqrt(gain))
y = _plugin.upfirdn2d(y, f.unsqueeze(1), 1, upy, 1, downy,
0, 0, pady0, pady1, flip_filter, np.sqrt(gain))
ctx.save_for_backward(f)
ctx.x_shape = x.shape
return y
@staticmethod
def backward(ctx, dy):
f, = ctx.saved_tensors
_, _, ih, iw = ctx.x_shape
_, _, oh, ow = dy.shape
fw, fh = _get_filter_size(f)
p = [fw - padx0 - 1, iw * upx - ow * downx + padx0 - upx + 1,
fh - pady0 - 1, ih * upy - oh * downy + pady0 - upy + 1]
dx = None
df = None
if ctx.needs_input_grad[0]:
dx = _upfirdn2d_cuda(up=down, down=up, padding=p,
flip_filter=not flip_filter, gain=gain).apply(dy, f)
assert not ctx.needs_input_grad[1]
return dx, df
_upfirdn2d_cuda_cache[key] = Upfirdn2dCuda
return Upfirdn2dCuda
def upfirdn2d(x, f, up=1, down=1, padding=0, flip_filter=False, gain=1,
impl='cuda'):
"""Pad, upsample, filter, and downsample a batch of 2D images.
Performs the following sequence of operations for each channel:
1. Upsample the image by inserting N-1 zeros after each pixel (`up`).
2. Pad the image with the specified number of zeros on each side (`padding`).
Negative padding corresponds to cropping the image.
3. Convolve the image with the specified 2D FIR filter (`f`), shrinking it
so that the footprint of all output pixels lies within the input image.
4. Downsample the image by keeping every Nth pixel (`down`).
This sequence of operations bears close resemblance to scipy.signal.upfirdn().
The fused op is considerably more efficient than performing the same calculation
using standard PyTorch ops. It supports gradients of arbitrary order.
Args:
x: Float32/float64/float16 input tensor of the shape
`[batch_size, num_channels, in_height, in_width]`.
f: Float32 FIR filter of the shape
`[filter_height, filter_width]` (non-separable),
`[filter_taps]` (separable), or
`None` (identity).
up: Integer upsampling factor. Can be a single int or a list/tuple
`[x, y]` (default: 1).
down: Integer downsampling factor. Can be a single int or a list/tuple
`[x, y]` (default: 1).
padding: Padding with respect to the upsampled image. Can be a single number
or a list/tuple `[x, y]` or `[x_before, x_after, y_before, y_after]`
(default: 0).
flip_filter: False = convolution, True = correlation (default: False).
gain: Overall scaling factor for signal magnitude (default: 1).
impl: Implementation to use. Can be `'ref'` or `'cuda'` (default: `'cuda'`).
Returns:
Tensor of the shape `[batch_size, num_channels, out_height, out_width]`.
"""
assert isinstance(x, torch.Tensor)
assert impl in ['ref', 'cuda']
if impl == 'cuda' and x.device.type == 'cuda' and _init():
return _upfirdn2d_cuda(up=up, down=down, padding=padding,
flip_filter=flip_filter, gain=gain).apply(x, f)
return _upfirdn2d_ref(x, f, up=up, down=down, padding=padding,
flip_filter=flip_filter, gain=gain)
class EqualLinear(nn.Module):
def __init__(self, in_dim, out_dim, bias=True, bias_init=0, lr_mul=1,
activation=None):
super().__init__()
self.weight = nn.Parameter(torch.randn(out_dim, in_dim).div_(lr_mul))
if bias:
self.bias = nn.Parameter(torch.zeros(out_dim).fill_(bias_init))
else:
self.bias = None
self.activation = activation
self.scale = 1 / math.sqrt(in_dim) * lr_mul
self.lr_mul = lr_mul
def forward(self, input):
if self.activation:
out = F.linear(input, self.weight * self.scale)
out = fused_leaky_relu(out, self.bias * self.lr_mul)
else:
out = F.linear(input, self.weight * self.scale, bias=self.bias *
self.lr_mul)
return out
def __repr__(self):
return (
f'{self.__class__.__name__}({self.weight.shape[1]}, {self.weight.shape[0]})'
)
class Blur(nn.Module):
def __init__(self, kernel, pad, upsample_factor=1):
super().__init__()
kernel = make_kernel(kernel)
if upsample_factor > 1:
kernel = kernel * upsample_factor ** 2
self.register_buffer('kernel', kernel)
self.pad = pad
def forward(self, input):
out = upfirdn2d(input, self.kernel, pad=self.pad)
return out
class ModulatedConv2d(nn.Module):
def __init__(self, in_channel, out_channel, kernel_size, style_dim,
demodulate=True, upsample=False, downsample=False, blur_kernel=[1,
3, 3, 1]):
super().__init__()
self.eps = 1e-08
self.kernel_size = kernel_size
self.in_channel = in_channel
self.out_channel = out_channel
self.upsample = upsample
self.downsample = downsample
if upsample:
factor = 2
p = len(blur_kernel) - factor - (kernel_size - 1)
pad0 = (p + 1) // 2 + factor - 1
pad1 = p // 2 + 1
self.blur = Blur(blur_kernel, pad=(pad0, pad1), upsample_factor
=factor)
if downsample:
factor = 2
p = len(blur_kernel) - factor + (kernel_size - 1)
pad0 = (p + 1) // 2
pad1 = p // 2
self.blur = Blur(blur_kernel, pad=(pad0, pad1))
fan_in = in_channel * kernel_size ** 2
self.scale = 1 / math.sqrt(fan_in)
self.padding = kernel_size // 2
self.weight = nn.Parameter(torch.randn(1, out_channel, in_channel,
kernel_size, kernel_size))
self.modulation = EqualLinear(style_dim, in_channel, bias_init=1)
self.demodulate = demodulate
def __repr__(self):
return (
f'{self.__class__.__name__}({self.in_channel}, {self.out_channel}, {self.kernel_size}, upsample={self.upsample}, downsample={self.downsample})'
)
def forward(self, input, style):
batch, in_channel, height, width = input.shape
style = self.modulation(style).view(batch, 1, in_channel, 1, 1)
weight = self.scale * self.weight * style
if self.demodulate:
demod = torch.rsqrt(weight.pow(2).sum([2, 3, 4]) + 1e-08)
weight = weight * demod.view(batch, self.out_channel, 1, 1, 1)
weight = weight.view(batch * self.out_channel, in_channel, self.
kernel_size, self.kernel_size)
if self.upsample:
input = input.view(1, batch * in_channel, height, width)
weight = weight.view(batch, self.out_channel, in_channel, self.
kernel_size, self.kernel_size)
weight = weight.transpose(1, 2).reshape(batch * in_channel,
self.out_channel, self.kernel_size, self.kernel_size)
out = F.conv_transpose2d(input, weight, padding=0, stride=2,
groups=batch)
_, _, height, width = out.shape
out = out.view(batch, self.out_channel, height, width)
out = self.blur(out)
elif self.downsample:
input = self.blur(input)
_, _, height, width = input.shape
input = input.view(1, batch * in_channel, height, width)
out = F.conv2d(input, weight, padding=0, stride=2, groups=batch)
_, _, height, width = out.shape
out = out.view(batch, self.out_channel, height, width)
else:
input = input.view(1, batch * in_channel, height, width)
out = F.conv2d(input, weight, padding=self.padding, groups=batch)
_, _, height, width = out.shape
out = out.view(batch, self.out_channel, height, width)
return out
class NoiseInjection(nn.Module):
def __init__(self):
super().__init__()
self.weight = nn.Parameter(torch.zeros(1))
def forward(self, image, noise=None):
if noise is None:
batch, _, height, width = image.shape
noise = image.new_empty(batch, 1, height, width).normal_()
return image + self.weight * noise
class FusedLeakyReLU(nn.Module):
def __init__(self, channel, negative_slope=0.2, scale=2 ** 0.5):
super().__init__()
self.bias = nn.Parameter(torch.zeros(channel))
self.negative_slope = negative_slope
self.scale = scale
def forward(self, input):
return fused_leaky_relu(input, self.bias, self.negative_slope, self
.scale)
class StyledConvNew(nn.Module):
def __init__(self, in_channel, out_channel, kernel_size, style_dim,
upsample=False, blur_kernel=[1, 3, 3, 1], demodulate=True):
super().__init__()
self.conv = ModulatedConv2d(in_channel, out_channel, kernel_size,
style_dim, upsample=upsample, blur_kernel=blur_kernel,
demodulate=demodulate)
self.noise = NoiseInjection()
self.activate = FusedLeakyReLU(out_channel)
def forward(self, input_0, input_1):
primals_5 = self.conv.weight
primals_2 = self.conv.modulation.weight
primals_3 = self.conv.modulation.bias
primals_6 = self.noise.weight
primals_7 = self.activate.bias
primals_1 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
phygitalism/PTI
|
StyledConv
| false
| 16,422
|
[
"MIT"
] | 345
|
adab2eb1d0e36ac5714e663e1fec9f85a0d51fbf
|
https://github.com/phygitalism/PTI/tree/adab2eb1d0e36ac5714e663e1fec9f85a0d51fbf
|
AlphaEntropy
|
import torch
import torch.nn as nn
class AlphaEntropy(nn.Module):
def __init__(self):
super().__init__()
self.v_loss = nn.MSELoss()
def forward(self, props, v, pi, reward):
v_loss = self.v_loss(v, reward)
p_loss = -torch.mean(torch.sum(props * pi, 1))
return p_loss + v_loss
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, 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_mean_mul_sum_0(in_ptr0, in_ptr1, out_ptr0, 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 % 16
r1 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
tmp3 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
tmp4 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
tmp7 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
tmp8 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
tmp11 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
tmp12 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
tmp2 = tmp0 * tmp1
tmp5 = tmp3 * tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 * tmp8
tmp10 = tmp6 + tmp9
tmp13 = tmp11 * tmp12
tmp14 = tmp10 + tmp13
tmp15 = tl.broadcast_to(tmp14, [XBLOCK, RBLOCK])
tmp17 = tl.sum(tmp15, 1)[:, None]
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp17, None)
@triton.jit
def triton_per_fused_add_mean_mse_loss_mul_neg_sum_1(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)
tmp7 = tl.load(in_out_ptr0 + 0)
tmp8 = tl.broadcast_to(tmp7, [1])
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [RBLOCK])
tmp6 = triton_helpers.promote_to_tensor(tl.sum(tmp4, 0))
tmp9 = 64.0
tmp10 = tmp8 / tmp9
tmp11 = -tmp10
tmp12 = 256.0
tmp13 = tmp6 / tmp12
tmp14 = tmp11 + tmp13
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp14, None)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_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))
assert_size_stride(arg3_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)
get_raw_stream(0)
triton_per_fused_mean_mul_sum_0[grid(1)](arg2_1, arg3_1, buf0, 1,
64, XBLOCK=1, num_warps=2, num_stages=1)
del arg2_1
del arg3_1
buf2 = buf0
del buf0
triton_per_fused_add_mean_mse_loss_mul_neg_sum_1[grid(1)](buf2,
arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf2,
class AlphaEntropyNew(nn.Module):
def __init__(self):
super().__init__()
self.v_loss = nn.MSELoss()
def forward(self, input_0, input_1, input_2, input_3):
arg0_1 = input_0
arg1_1 = input_1
arg2_1 = input_2
arg3_1 = input_3
output = call([arg0_1, arg1_1, arg2_1, arg3_1])
return output[0]
|
shinoyuki222/torch-light
|
AlphaEntropy
| false
| 16,423
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
MLP
|
import math
import torch
from torch import nn
import torch.nn.functional as F
import torch.cuda
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
class Butterfly(nn.Module):
"""Product of log N butterfly factors, each is a block 2x2 of diagonal matrices.
Compatible with torch.nn.Linear.
Parameters:
in_size: size of input
out_size: size of output
bias: If set to False, the layer will not learn an additive bias.
Default: ``True``
complex: whether complex or real
increasing_stride: whether the first butterfly block will multiply with increasing stride
(e.g. 1, 2, ..., n/2) or decreasing stride (e.g., n/2, n/4, ..., 1).
init: 'randn', 'ortho', or 'identity'. Whether the weight matrix should be initialized to
from randn twiddle, or to be randomly orthogonal/unitary, or to be the identity matrix.
nblocks: number of B or B^T blocks. The B and B^T will alternate.
"""
def __init__(self, in_size, out_size, bias=True, complex=False,
increasing_stride=True, init='randn', nblocks=1):
super().__init__()
self.in_size = in_size
log_n = int(math.ceil(math.log2(in_size)))
self.log_n = log_n
size = self.in_size_extended = 1 << log_n
self.out_size = out_size
self.nstacks = int(math.ceil(out_size / self.in_size_extended))
self.complex = complex
self.increasing_stride = increasing_stride
assert nblocks >= 1
self.nblocks = nblocks
dtype = torch.get_default_dtype(
) if not self.complex else real_dtype_to_complex[torch.
get_default_dtype()]
twiddle_shape = self.nstacks, nblocks, log_n, size // 2, 2, 2
assert init in ['randn', 'ortho', 'identity']
self.init = init
self.twiddle = nn.Parameter(torch.empty(twiddle_shape, dtype=dtype))
if bias:
self.bias = nn.Parameter(torch.empty(out_size, dtype=dtype))
else:
self.register_parameter('bias', None)
self.twiddle._is_structured = True
if self.complex:
self.twiddle = nn.Parameter(view_as_real(self.twiddle))
if self.bias is not None:
self.bias = nn.Parameter(view_as_real(self.bias))
self.reset_parameters()
def reset_parameters(self):
"""Initialize bias the same way as torch.nn.Linear."""
twiddle = self.twiddle if not self.complex else view_as_complex(self
.twiddle)
if self.init == 'randn':
scaling = 1.0 / math.sqrt(2)
with torch.no_grad():
twiddle.copy_(torch.randn(twiddle.shape, dtype=twiddle.
dtype) * scaling)
elif self.init == 'ortho':
twiddle_core_shape = twiddle.shape[:-2]
if not self.complex:
theta = torch.rand(twiddle_core_shape) * math.pi * 2
c, s = torch.cos(theta), torch.sin(theta)
det = torch.randint(0, 2, twiddle_core_shape, dtype=c.dtype
) * 2 - 1
with torch.no_grad():
twiddle.copy_(torch.stack((torch.stack((det * c, -det *
s), dim=-1), torch.stack((s, c), dim=-1)), dim=-2))
else:
phi = torch.asin(torch.sqrt(torch.rand(twiddle_core_shape)))
c, s = torch.cos(phi), torch.sin(phi)
alpha, psi, chi = torch.rand((3,) + twiddle_core_shape
) * math.pi * 2
A = torch.exp(1.0j * (alpha + psi)) * c
B = torch.exp(1.0j * (alpha + chi)) * s
C = -torch.exp(1.0j * (alpha - chi)) * s
D = torch.exp(1.0j * (alpha - psi)) * c
with torch.no_grad():
twiddle.copy_(torch.stack((torch.stack((A, B), dim=-1),
torch.stack((C, D), dim=-1)), dim=-2))
elif self.init == 'identity':
twiddle_new = torch.eye(2, dtype=twiddle.dtype).reshape(1, 1, 1,
1, 2, 2)
twiddle_new = twiddle_new.expand(*twiddle.shape).contiguous()
with torch.no_grad():
twiddle.copy_(twiddle_new)
if self.bias is not None:
bound = 1 / math.sqrt(self.in_size)
nn.init.uniform_(self.bias, -bound, bound)
def forward(self, input, transpose=False, conjugate=False, subtwiddle=False
):
"""
Parameters:
input: (batch, *, in_size)
transpose: whether the butterfly matrix should be transposed.
conjugate: whether the butterfly matrix should be conjugated.
subtwiddle: allow using only part of the parameters for smaller input.
Could be useful for weight sharing.
out_size is set to self.nstacks * self.in_size_extended in this case
Return:
output: (batch, *, out_size)
"""
twiddle = self.twiddle if not self.complex else view_as_complex(self
.twiddle)
if not subtwiddle:
output = self.pre_process(input)
else:
log_n = int(math.ceil(math.log2(input.size(-1))))
n = 1 << log_n
output = self.pre_process(input, padded_size=n)
twiddle = twiddle[:, :, :log_n, :n // 2
] if self.increasing_stride else twiddle[:, :, -log_n:, :n // 2
]
if conjugate and self.complex:
twiddle = twiddle.conj()
if not transpose:
output = butterfly_multiply(twiddle, output, self.increasing_stride
)
else:
twiddle = twiddle.transpose(-1, -2).flip([1, 2])
last_increasing_stride = self.increasing_stride != ((self.
nblocks - 1) % 2 == 1)
output = butterfly_multiply(twiddle, output, not
last_increasing_stride)
if not subtwiddle:
return self.post_process(input, output)
else:
return self.post_process(input, output, out_size=output.size(-1))
def pre_process(self, input, padded_size=None):
if padded_size is None:
padded_size = self.in_size_extended
input_size = input.size(-1)
output = input.reshape(-1, input_size)
batch = output.shape[0]
if input_size != padded_size:
output = F.pad(output, (0, padded_size - input_size))
output = output.unsqueeze(1).expand(batch, self.nstacks, padded_size)
return output
def post_process(self, input, output, out_size=None):
if out_size is None:
out_size = self.out_size
batch = output.shape[0]
output = output.view(batch, self.nstacks * output.size(-1))
out_size_extended = 1 << int(math.ceil(math.log2(output.size(-1))))
if out_size != out_size_extended:
output = output[:, :out_size]
if self.bias is not None:
bias = self.bias if not self.complex else view_as_complex(self.bias
)
output = output + bias[:out_size]
return output.view(*input.size()[:-1], out_size)
def extra_repr(self):
s = (
'in_size={}, out_size={}, bias={}, complex={}, increasing_stride={}, init={}, nblocks={}'
.format(self.in_size, self.out_size, self.bias is not None,
self.complex, self.increasing_stride, self.init, self.nblocks))
return s
class MLP(nn.Module):
def __init__(self, method='linear', **kwargs):
super().__init__()
if method == 'linear':
def make_layer(name):
return self.add_module(name, nn.Linear(1024, 1024, bias=True))
elif method == 'butterfly':
def make_layer(name):
return self.add_module(name, Butterfly(1024, 1024, bias=
True, **kwargs))
elif method == 'low-rank':
def make_layer(name):
return self.add_module(name, nn.Sequential(nn.Linear(1024,
kwargs['rank'], bias=False), nn.Linear(kwargs['rank'],
1024, bias=True)))
elif method == 'toeplitz':
def make_layer(name):
return self.add_module(name, sl.ToeplitzLikeC(layer_size=
1024, bias=True, **kwargs))
else:
assert False, f'method {method} not supported'
make_layer('fc10')
make_layer('fc11')
make_layer('fc12')
make_layer('fc2')
make_layer('fc3')
self.logits = nn.Linear(1024, 10)
def forward(self, x):
x = x.view(-1, 3, 1024)
x = self.fc10(x[:, 0, :]) + self.fc11(x[:, 1, :]) + self.fc12(x[:,
2, :])
x = F.relu(x)
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
x = self.logits(x)
return x
def get_inputs():
return [torch.rand([4, 3, 1024])]
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 math
from torch import nn
import torch.nn.functional as F
import torch.cuda
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
reinterpret_tensor = torch._C._dynamo.guards._reinterpret_tensor
@triton.jit
def triton_poi_fused_add_relu_0(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2,
in_ptr3, in_ptr4, 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 % 1024
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr1 + x2, None)
tmp4 = tl.load(in_ptr2 + x0, None, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr3 + x2, None)
tmp8 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 + tmp8
tmp10 = tmp6 + tmp9
tmp11 = tl.full([1], 0, tl.int32)
tmp12 = triton_helpers.maximum(tmp11, tmp10)
tl.store(in_out_ptr0 + x2, tmp12, None)
@triton.jit
def triton_poi_fused_relu_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)
x2 = xindex
x0 = xindex % 1024
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
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, 3, 1024), (3072, 1024, 1))
assert_size_stride(primals_2, (1024, 1024), (1024, 1))
assert_size_stride(primals_3, (1024,), (1,))
assert_size_stride(primals_4, (1024, 1024), (1024, 1))
assert_size_stride(primals_5, (1024,), (1,))
assert_size_stride(primals_6, (1024, 1024), (1024, 1))
assert_size_stride(primals_7, (1024,), (1,))
assert_size_stride(primals_8, (1024, 1024), (1024, 1))
assert_size_stride(primals_9, (1024,), (1,))
assert_size_stride(primals_10, (1024, 1024), (1024, 1))
assert_size_stride(primals_11, (1024,), (1,))
assert_size_stride(primals_12, (10, 1024), (1024, 1))
assert_size_stride(primals_13, (10,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1024), (1024, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 1024), (3072, 1
), 0), reinterpret_tensor(primals_2, (1024, 1024), (1, 1024), 0
), out=buf0)
del primals_2
buf1 = empty_strided_cuda((4, 1024), (1024, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 1024), (3072, 1
), 1024), reinterpret_tensor(primals_4, (1024, 1024), (1, 1024),
0), out=buf1)
del primals_4
buf2 = empty_strided_cuda((4, 1024), (1024, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (4, 1024), (3072, 1
), 2048), reinterpret_tensor(primals_6, (1024, 1024), (1, 1024),
0), out=buf2)
del primals_6
buf3 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_add_relu_0[grid(4096)](buf3, primals_3, buf1,
primals_5, buf2, primals_7, 4096, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_3
del primals_5
del primals_7
buf4 = buf2
del buf2
extern_kernels.mm(buf3, reinterpret_tensor(primals_8, (1024, 1024),
(1, 1024), 0), out=buf4)
buf5 = buf4
del buf4
triton_poi_fused_relu_1[grid(4096)](buf5, primals_9, 4096, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_9
buf6 = buf1
del buf1
extern_kernels.mm(buf5, reinterpret_tensor(primals_10, (1024, 1024),
(1, 1024), 0), out=buf6)
buf7 = buf6
del buf6
triton_poi_fused_relu_1[grid(4096)](buf7, primals_11, 4096, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_11
buf8 = empty_strided_cuda((4, 10), (10, 1), torch.float32)
extern_kernels.addmm(primals_13, buf7, reinterpret_tensor(
primals_12, (1024, 10), (1, 1024), 0), alpha=1, beta=1, out=buf8)
del primals_13
return buf8, reinterpret_tensor(primals_1, (4, 1024), (3072, 1), 0
), reinterpret_tensor(primals_1, (4, 1024), (3072, 1), 1024
), reinterpret_tensor(primals_1, (4, 1024), (3072, 1), 2048
), buf3, buf5, buf7, primals_12, primals_10, primals_8
class Butterfly(nn.Module):
"""Product of log N butterfly factors, each is a block 2x2 of diagonal matrices.
Compatible with torch.nn.Linear.
Parameters:
in_size: size of input
out_size: size of output
bias: If set to False, the layer will not learn an additive bias.
Default: ``True``
complex: whether complex or real
increasing_stride: whether the first butterfly block will multiply with increasing stride
(e.g. 1, 2, ..., n/2) or decreasing stride (e.g., n/2, n/4, ..., 1).
init: 'randn', 'ortho', or 'identity'. Whether the weight matrix should be initialized to
from randn twiddle, or to be randomly orthogonal/unitary, or to be the identity matrix.
nblocks: number of B or B^T blocks. The B and B^T will alternate.
"""
def __init__(self, in_size, out_size, bias=True, complex=False,
increasing_stride=True, init='randn', nblocks=1):
super().__init__()
self.in_size = in_size
log_n = int(math.ceil(math.log2(in_size)))
self.log_n = log_n
size = self.in_size_extended = 1 << log_n
self.out_size = out_size
self.nstacks = int(math.ceil(out_size / self.in_size_extended))
self.complex = complex
self.increasing_stride = increasing_stride
assert nblocks >= 1
self.nblocks = nblocks
dtype = torch.get_default_dtype(
) if not self.complex else real_dtype_to_complex[torch.
get_default_dtype()]
twiddle_shape = self.nstacks, nblocks, log_n, size // 2, 2, 2
assert init in ['randn', 'ortho', 'identity']
self.init = init
self.twiddle = nn.Parameter(torch.empty(twiddle_shape, dtype=dtype))
if bias:
self.bias = nn.Parameter(torch.empty(out_size, dtype=dtype))
else:
self.register_parameter('bias', None)
self.twiddle._is_structured = True
if self.complex:
self.twiddle = nn.Parameter(view_as_real(self.twiddle))
if self.bias is not None:
self.bias = nn.Parameter(view_as_real(self.bias))
self.reset_parameters()
def reset_parameters(self):
"""Initialize bias the same way as torch.nn.Linear."""
twiddle = self.twiddle if not self.complex else view_as_complex(self
.twiddle)
if self.init == 'randn':
scaling = 1.0 / math.sqrt(2)
with torch.no_grad():
twiddle.copy_(torch.randn(twiddle.shape, dtype=twiddle.
dtype) * scaling)
elif self.init == 'ortho':
twiddle_core_shape = twiddle.shape[:-2]
if not self.complex:
theta = torch.rand(twiddle_core_shape) * math.pi * 2
c, s = torch.cos(theta), torch.sin(theta)
det = torch.randint(0, 2, twiddle_core_shape, dtype=c.dtype
) * 2 - 1
with torch.no_grad():
twiddle.copy_(torch.stack((torch.stack((det * c, -det *
s), dim=-1), torch.stack((s, c), dim=-1)), dim=-2))
else:
phi = torch.asin(torch.sqrt(torch.rand(twiddle_core_shape)))
c, s = torch.cos(phi), torch.sin(phi)
alpha, psi, chi = torch.rand((3,) + twiddle_core_shape
) * math.pi * 2
A = torch.exp(1.0j * (alpha + psi)) * c
B = torch.exp(1.0j * (alpha + chi)) * s
C = -torch.exp(1.0j * (alpha - chi)) * s
D = torch.exp(1.0j * (alpha - psi)) * c
with torch.no_grad():
twiddle.copy_(torch.stack((torch.stack((A, B), dim=-1),
torch.stack((C, D), dim=-1)), dim=-2))
elif self.init == 'identity':
twiddle_new = torch.eye(2, dtype=twiddle.dtype).reshape(1, 1, 1,
1, 2, 2)
twiddle_new = twiddle_new.expand(*twiddle.shape).contiguous()
with torch.no_grad():
twiddle.copy_(twiddle_new)
if self.bias is not None:
bound = 1 / math.sqrt(self.in_size)
nn.init.uniform_(self.bias, -bound, bound)
def forward(self, input, transpose=False, conjugate=False, subtwiddle=False
):
"""
Parameters:
input: (batch, *, in_size)
transpose: whether the butterfly matrix should be transposed.
conjugate: whether the butterfly matrix should be conjugated.
subtwiddle: allow using only part of the parameters for smaller input.
Could be useful for weight sharing.
out_size is set to self.nstacks * self.in_size_extended in this case
Return:
output: (batch, *, out_size)
"""
twiddle = self.twiddle if not self.complex else view_as_complex(self
.twiddle)
if not subtwiddle:
output = self.pre_process(input)
else:
log_n = int(math.ceil(math.log2(input.size(-1))))
n = 1 << log_n
output = self.pre_process(input, padded_size=n)
twiddle = twiddle[:, :, :log_n, :n // 2
] if self.increasing_stride else twiddle[:, :, -log_n:, :n // 2
]
if conjugate and self.complex:
twiddle = twiddle.conj()
if not transpose:
output = butterfly_multiply(twiddle, output, self.increasing_stride
)
else:
twiddle = twiddle.transpose(-1, -2).flip([1, 2])
last_increasing_stride = self.increasing_stride != ((self.
nblocks - 1) % 2 == 1)
output = butterfly_multiply(twiddle, output, not
last_increasing_stride)
if not subtwiddle:
return self.post_process(input, output)
else:
return self.post_process(input, output, out_size=output.size(-1))
def pre_process(self, input, padded_size=None):
if padded_size is None:
padded_size = self.in_size_extended
input_size = input.size(-1)
output = input.reshape(-1, input_size)
batch = output.shape[0]
if input_size != padded_size:
output = F.pad(output, (0, padded_size - input_size))
output = output.unsqueeze(1).expand(batch, self.nstacks, padded_size)
return output
def post_process(self, input, output, out_size=None):
if out_size is None:
out_size = self.out_size
batch = output.shape[0]
output = output.view(batch, self.nstacks * output.size(-1))
out_size_extended = 1 << int(math.ceil(math.log2(output.size(-1))))
if out_size != out_size_extended:
output = output[:, :out_size]
if self.bias is not None:
bias = self.bias if not self.complex else view_as_complex(self.bias
)
output = output + bias[:out_size]
return output.view(*input.size()[:-1], out_size)
def extra_repr(self):
s = (
'in_size={}, out_size={}, bias={}, complex={}, increasing_stride={}, init={}, nblocks={}'
.format(self.in_size, self.out_size, self.bias is not None,
self.complex, self.increasing_stride, self.init, self.nblocks))
return s
class MLPNew(nn.Module):
def __init__(self, method='linear', **kwargs):
super().__init__()
if method == 'linear':
def make_layer(name):
return self.add_module(name, nn.Linear(1024, 1024, bias=True))
elif method == 'butterfly':
def make_layer(name):
return self.add_module(name, Butterfly(1024, 1024, bias=
True, **kwargs))
elif method == 'low-rank':
def make_layer(name):
return self.add_module(name, nn.Sequential(nn.Linear(1024,
kwargs['rank'], bias=False), nn.Linear(kwargs['rank'],
1024, bias=True)))
elif method == 'toeplitz':
def make_layer(name):
return self.add_module(name, sl.ToeplitzLikeC(layer_size=
1024, bias=True, **kwargs))
else:
assert False, f'method {method} not supported'
make_layer('fc10')
make_layer('fc11')
make_layer('fc12')
make_layer('fc2')
make_layer('fc3')
self.logits = nn.Linear(1024, 10)
def forward(self, input_0):
primals_2 = self.fc10.weight
primals_3 = self.fc10.bias
primals_4 = self.fc11.weight
primals_5 = self.fc11.bias
primals_6 = self.fc12.weight
primals_7 = self.fc12.bias
primals_8 = self.fc2.weight
primals_9 = self.fc2.bias
primals_10 = self.fc3.weight
primals_11 = self.fc3.bias
primals_12 = self.logits.weight
primals_13 = self.logits.bias
primals_1 = 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])
return output[0]
|
sfox14/butterfly
|
MLP
| false
| 16,424
|
[
"Apache-2.0"
] | 52
|
13cc15cee5bdb7adaf376219aaf20fab0459e9ef
|
https://github.com/sfox14/butterfly/tree/13cc15cee5bdb7adaf376219aaf20fab0459e9ef
|
ActorCritic
|
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
from torch.distributions import Categorical
class ActorCritic(nn.Module):
def __init__(self):
super().__init__()
self.affine1 = nn.Linear(4, 128)
self.action_head = nn.Linear(128, 2)
self.value_head = nn.Linear(128, 1)
def forward(self, x):
x = F.relu(self.affine1(x))
action_scores = self.action_head(x)
state_values = self.value_head(x)
return F.softmax(action_scores, dim=-1), state_values
def select_action(self, state, values, select_props):
state = torch.from_numpy(state).float()
props, value = self(Variable(state))
dist = Categorical(props)
action = dist.sample()
log_props = dist.log_prob(action)
values.append(value)
select_props.append(log_props)
return action.data[0]
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._inductor.runtime.triton_helpers import math as tl_math
import torch.nn as nn
from torch.autograd import Variable
from torch.distributions import Categorical
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):
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__softmax_1(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
x2 = xindex
x1 = xindex // 2
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + 2 * x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr0 + (1 + 2 * x1), xmask, eviction_policy='evict_last')
tmp3 = triton_helpers.maximum(tmp1, tmp2)
tmp4 = tmp0 - tmp3
tmp5 = tl_math.exp(tmp4)
tmp6 = tmp1 - tmp3
tmp7 = tl_math.exp(tmp6)
tmp8 = tmp2 - tmp3
tmp9 = tl_math.exp(tmp8)
tmp10 = tmp7 + tmp9
tmp11 = tmp5 / tmp10
tl.store(out_ptr0 + x2, tmp11, 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, (128, 4), (4, 1))
assert_size_stride(primals_2, (128,), (1,))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (2, 128), (128, 1))
assert_size_stride(primals_5, (2,), (1,))
assert_size_stride(primals_6, (1, 128), (128, 1))
assert_size_stride(primals_7, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 128), (128, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 128), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 128), (2048, 512, 128, 1), 0)
del buf0
buf6 = empty_strided_cuda((4, 4, 4, 128), (2048, 512, 128, 1),
torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(8192)](buf1,
primals_2, buf6, 8192, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 128),
(128, 1), 0), reinterpret_tensor(primals_4, (128, 2), (1, 128),
0), alpha=1, beta=1, out=buf2)
del primals_5
buf4 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf1, (64, 128),
(128, 1), 0), reinterpret_tensor(primals_6, (128, 1), (1, 128),
0), alpha=1, beta=1, out=buf4)
del primals_7
buf5 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
triton_poi_fused__softmax_1[grid(128)](buf2, buf5, 128, XBLOCK=128,
num_warps=4, num_stages=1)
del buf2
return buf5, reinterpret_tensor(buf4, (4, 4, 4, 1), (16, 4, 1, 1), 0
), reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 128), (128, 1), 0
), buf5, primals_6, primals_4, buf6
class ActorCriticNew(nn.Module):
def __init__(self):
super().__init__()
self.affine1 = nn.Linear(4, 128)
self.action_head = nn.Linear(128, 2)
self.value_head = nn.Linear(128, 1)
def select_action(self, state, values, select_props):
state = torch.from_numpy(state).float()
props, value = self(Variable(state))
dist = Categorical(props)
action = dist.sample()
log_props = dist.log_prob(action)
values.append(value)
select_props.append(log_props)
return action.data[0]
def forward(self, input_0):
primals_1 = self.affine1.weight
primals_2 = self.affine1.bias
primals_4 = self.action_head.weight
primals_5 = self.action_head.bias
primals_6 = self.value_head.weight
primals_7 = self.value_head.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0], output[1]
|
shinoyuki222/torch-light
|
ActorCritic
| false
| 16,425
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
AdaIN
|
import torch
from torch import nn
import torch.utils.data
import torch.nn
class WSLinear(nn.Module):
def __init__(self, in_features, out_features, gain=2):
super(WSLinear, self).__init__()
self.linear = nn.Linear(in_features, out_features)
self.scale = (gain / in_features) ** 0.5
self.bias = self.linear.bias
self.linear.bias = None
nn.init.normal_(self.linear.weight)
nn.init.zeros_(self.bias)
def forward(self, x):
return self.linear(x * self.scale) + self.bias
class AdaIN(nn.Module):
def __init__(self, channels, w_dim):
super().__init__()
self.instance_norm = nn.InstanceNorm2d(channels)
self.style_scale = WSLinear(w_dim, channels)
self.style_bias = WSLinear(w_dim, channels)
def forward(self, x, w):
x = self.instance_norm(x)
style_scale = self.style_scale(w).unsqueeze(2).unsqueeze(3)
style_bias = self.style_bias(w).unsqueeze(2).unsqueeze(3)
return style_scale * x + style_bias
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'channels': 4, 'w_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
from torch import nn
import torch.utils.data
import torch.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_batch_norm_legit_0(in_out_ptr0, in_ptr0,
out_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])
tl.where(xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 16, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = 16.0
tmp18 = tmp16 / tmp17
tmp19 = 1e-05
tmp20 = tmp18 + tmp19
tmp21 = libdevice.rsqrt(tmp20)
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp21, xmask)
tl.store(out_ptr0 + x0, tmp10, xmask)
@triton.jit
def triton_poi_fused_mul_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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 0.7071067811865476
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_mul_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
in_ptr5, in_ptr6, 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 // 256
x4 = xindex % 16
x0 = xindex % 4
x5 = xindex % 256
x2 = xindex // 16 % 16
x6 = xindex
tmp0 = tl.load(in_ptr0 + (x4 + 16 * x3), None, eviction_policy='evict_last'
)
tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x5, None, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr3 + x2, None, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr4 + x2, None, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr5 + (x4 + 16 * x3), None, eviction_policy='evict_last'
)
tmp10 = tl.load(in_ptr6 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 - tmp4
tmp7 = tmp5 * tmp6
tmp8 = tmp2 * tmp7
tmp11 = tmp9 + tmp10
tmp12 = tmp8 + tmp11
tl.store(out_ptr0 + x6, tmp12, None)
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, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 4, 4, 4), (64, 16, 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,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 1, 1), torch.float32)
buf1 = empty_strided_cuda((1, 16, 1, 1), (16, 1, 16, 16), torch.float32
)
buf3 = reinterpret_tensor(buf1, (1, 16, 1, 1), (16, 1, 1, 1), 0)
del buf1
get_raw_stream(0)
triton_per_fused__native_batch_norm_legit_0[grid(16)](buf3,
primals_1, buf0, 16, 16, XBLOCK=8, num_warps=2, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_1[grid(256)](primals_2, buf4, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_2
buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf4, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 4), (1, 4), 0), out=buf5)
del primals_3
buf6 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf4, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf6)
del primals_5
buf7 = empty_strided_cuda((4, 4, 4, 4, 4, 4), (1024, 256, 64, 16, 4,
1), torch.float32)
triton_poi_fused_add_mul_2[grid(4096)](buf5, primals_4, primals_1,
buf0, buf3, buf6, primals_6, buf7, 4096, XBLOCK=128, num_warps=
4, num_stages=1)
del buf5
del buf6
del primals_4
del primals_6
return buf7, primals_1, buf0, buf3, reinterpret_tensor(buf4, (64, 4), (
4, 1), 0)
class WSLinear(nn.Module):
def __init__(self, in_features, out_features, gain=2):
super(WSLinear, self).__init__()
self.linear = nn.Linear(in_features, out_features)
self.scale = (gain / in_features) ** 0.5
self.bias = self.linear.bias
self.linear.bias = None
nn.init.normal_(self.linear.weight)
nn.init.zeros_(self.bias)
def forward(self, x):
return self.linear(x * self.scale) + self.bias
class AdaINNew(nn.Module):
def __init__(self, channels, w_dim):
super().__init__()
self.instance_norm = nn.InstanceNorm2d(channels)
self.style_scale = WSLinear(w_dim, channels)
self.style_bias = WSLinear(w_dim, channels)
def forward(self, input_0, input_1):
primals_4 = self.style_scale.bias
primals_3 = self.style_scale.linear.weight
primals_6 = self.style_bias.bias
primals_5 = self.style_bias.linear.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
shimon-c/Machine-Learning-Collection
|
AdaIN
| false
| 16,426
|
[
"MIT"
] | 3,094
|
ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
https://github.com/shimon-c/Machine-Learning-Collection/tree/ac5dcd03a40a08a8af7e1a67ade37f28cf88db43
|
BinaryFocalLossWithLogits
|
import torch
import torch.nn as nn
def binary_focal_loss_with_logits(input: 'torch.Tensor', target:
'torch.Tensor', alpha: 'float'=0.25, gamma: 'float'=2.0, reduction:
'str'='none', eps: 'float'=1e-08) ->torch.Tensor:
"""Function that computes Binary Focal loss.
.. math::
\\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t)
where:
- :math:`p_t` is the model's estimated probability for each class.
Args:
input: input data tensor of arbitrary shape.
target: the target tensor with shape matching input.
alpha: Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`.
gamma: Focusing parameter :math:`\\gamma >= 0`.
reduction: Specifies the reduction to apply to the
output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
will be applied, ``'mean'``: the sum of the output will be divided by
the number of elements in the output, ``'sum'``: the output will be
summed.
eps: for numerically stability when dividing.
Returns:
the computed loss.
Examples:
>>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'}
>>> logits = torch.tensor([[[6.325]],[[5.26]],[[87.49]]])
>>> labels = torch.tensor([[[1.]],[[1.]],[[0.]]])
>>> binary_focal_loss_with_logits(logits, labels, **kwargs)
tensor(4.6052)
"""
if not isinstance(input, torch.Tensor):
raise TypeError(f'Input type is not a torch.Tensor. Got {type(input)}')
if not len(input.shape) >= 2:
raise ValueError(
f'Invalid input shape, we expect BxCx*. Got: {input.shape}')
if input.size(0) != target.size(0):
raise ValueError(
f'Expected input batch_size ({input.size(0)}) to match target batch_size ({target.size(0)}).'
)
probs = torch.sigmoid(input)
loss_tmp = -alpha * torch.pow(1.0 - probs + eps, gamma
) * target * torch.log(probs + eps) - (1 - alpha) * torch.pow(probs +
eps, gamma) * (1.0 - target) * torch.log(1.0 - probs + eps)
if reduction == 'none':
loss = loss_tmp
elif reduction == 'mean':
loss = torch.mean(loss_tmp)
elif reduction == 'sum':
loss = torch.sum(loss_tmp)
else:
raise NotImplementedError(f'Invalid reduction mode: {reduction}')
return loss
class BinaryFocalLossWithLogits(nn.Module):
"""Criterion that computes Focal loss.
According to :cite:`lin2018focal`, the Focal loss is computed as follows:
.. math::
\\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t)
where:
- :math:`p_t` is the model's estimated probability for each class.
Args:
alpha): Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`.
gamma: Focusing parameter :math:`\\gamma >= 0`.
reduction: Specifies the reduction to apply to the
output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
will be applied, ``'mean'``: the sum of the output will be divided by
the number of elements in the output, ``'sum'``: the output will be
summed.
Shape:
- Input: :math:`(N, 1, *)`.
- Target: :math:`(N, 1, *)`.
Examples:
>>> N = 1 # num_classes
>>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'}
>>> loss = BinaryFocalLossWithLogits(**kwargs)
>>> input = torch.randn(1, N, 3, 5, requires_grad=True)
>>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)
>>> output = loss(input, target)
>>> output.backward()
"""
def __init__(self, alpha: 'float', gamma: 'float'=2.0, reduction: 'str'
='none') ->None:
super().__init__()
self.alpha: 'float' = alpha
self.gamma: 'float' = gamma
self.reduction: 'str' = reduction
self.eps: 'float' = 1e-08
def forward(self, input: 'torch.Tensor', target: 'torch.Tensor'
) ->torch.Tensor:
return binary_focal_loss_with_logits(input, target, self.alpha,
self.gamma, self.reduction, self.eps)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'alpha': 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 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_add_log_mul_pow_rsub_sigmoid_sub_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)
tmp9 = tl.load(in_ptr1 + x0, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp2 = 1.0
tmp3 = tmp2 - tmp1
tmp4 = 1e-08
tmp5 = tmp3 + tmp4
tmp6 = tmp5 * tmp5
tmp7 = -4.0
tmp8 = tmp6 * tmp7
tmp10 = tmp8 * tmp9
tmp11 = tmp1 + tmp4
tmp12 = tl_math.log(tmp11)
tmp13 = tmp10 * tmp12
tmp14 = tmp11 * tmp11
tmp15 = -3.0
tmp16 = tmp14 * tmp15
tmp17 = tmp2 - tmp9
tmp18 = tmp16 * tmp17
tmp19 = tl_math.log(tmp5)
tmp20 = tmp18 * tmp19
tmp21 = tmp13 - tmp20
tl.store(out_ptr0 + x0, tmp21, 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, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_log_mul_pow_rsub_sigmoid_sub_0[grid(256)](arg0_1,
arg1_1, buf0, 256, XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
return buf0,
def binary_focal_loss_with_logits(input: 'torch.Tensor', target:
'torch.Tensor', alpha: 'float'=0.25, gamma: 'float'=2.0, reduction:
'str'='none', eps: 'float'=1e-08) ->torch.Tensor:
"""Function that computes Binary Focal loss.
.. math::
\\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t)
where:
- :math:`p_t` is the model's estimated probability for each class.
Args:
input: input data tensor of arbitrary shape.
target: the target tensor with shape matching input.
alpha: Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`.
gamma: Focusing parameter :math:`\\gamma >= 0`.
reduction: Specifies the reduction to apply to the
output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
will be applied, ``'mean'``: the sum of the output will be divided by
the number of elements in the output, ``'sum'``: the output will be
summed.
eps: for numerically stability when dividing.
Returns:
the computed loss.
Examples:
>>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'}
>>> logits = torch.tensor([[[6.325]],[[5.26]],[[87.49]]])
>>> labels = torch.tensor([[[1.]],[[1.]],[[0.]]])
>>> binary_focal_loss_with_logits(logits, labels, **kwargs)
tensor(4.6052)
"""
if not isinstance(input, torch.Tensor):
raise TypeError(f'Input type is not a torch.Tensor. Got {type(input)}')
if not len(input.shape) >= 2:
raise ValueError(
f'Invalid input shape, we expect BxCx*. Got: {input.shape}')
if input.size(0) != target.size(0):
raise ValueError(
f'Expected input batch_size ({input.size(0)}) to match target batch_size ({target.size(0)}).'
)
probs = torch.sigmoid(input)
loss_tmp = -alpha * torch.pow(1.0 - probs + eps, gamma
) * target * torch.log(probs + eps) - (1 - alpha) * torch.pow(probs +
eps, gamma) * (1.0 - target) * torch.log(1.0 - probs + eps)
if reduction == 'none':
loss = loss_tmp
elif reduction == 'mean':
loss = torch.mean(loss_tmp)
elif reduction == 'sum':
loss = torch.sum(loss_tmp)
else:
raise NotImplementedError(f'Invalid reduction mode: {reduction}')
return loss
class BinaryFocalLossWithLogitsNew(nn.Module):
"""Criterion that computes Focal loss.
According to :cite:`lin2018focal`, the Focal loss is computed as follows:
.. math::
\\text{FL}(p_t) = -\\alpha_t (1 - p_t)^{\\gamma} \\, \\text{log}(p_t)
where:
- :math:`p_t` is the model's estimated probability for each class.
Args:
alpha): Weighting factor for the rare class :math:`\\alpha \\in [0, 1]`.
gamma: Focusing parameter :math:`\\gamma >= 0`.
reduction: Specifies the reduction to apply to the
output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
will be applied, ``'mean'``: the sum of the output will be divided by
the number of elements in the output, ``'sum'``: the output will be
summed.
Shape:
- Input: :math:`(N, 1, *)`.
- Target: :math:`(N, 1, *)`.
Examples:
>>> N = 1 # num_classes
>>> kwargs = {"alpha": 0.25, "gamma": 2.0, "reduction": 'mean'}
>>> loss = BinaryFocalLossWithLogits(**kwargs)
>>> input = torch.randn(1, N, 3, 5, requires_grad=True)
>>> target = torch.empty(1, 3, 5, dtype=torch.long).random_(N)
>>> output = loss(input, target)
>>> output.backward()
"""
def __init__(self, alpha: 'float', gamma: 'float'=2.0, reduction: 'str'
='none') ->None:
super().__init__()
self.alpha: 'float' = alpha
self.gamma: 'float' = gamma
self.reduction: 'str' = reduction
self.eps: 'float' = 1e-08
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
shiyangc-intusurg/kornia
|
BinaryFocalLossWithLogits
| false
| 16,427
|
[
"ECL-2.0",
"Apache-2.0"
] | 4,894
|
2e2512f8f20d300d8732e5873e16336b5a01f3bd
|
https://github.com/shiyangc-intusurg/kornia/tree/2e2512f8f20d300d8732e5873e16336b5a01f3bd
|
h_sigmoid
|
import torch
from torch import nn
class h_sigmoid(nn.Module):
def __init__(self, inplace=True, h_max=1):
super(h_sigmoid, self).__init__()
self.relu = nn.ReLU6(inplace=inplace)
self.h_max = h_max
def forward(self, x):
return self.relu(x + 3) * self.h_max / 6
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 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_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 = 1.0
tmp8 = tmp6 * tmp7
tmp9 = 0.16666666666666666
tmp10 = tmp8 * tmp9
tl.store(out_ptr0 + x0, 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, 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 h_sigmoidNew(nn.Module):
def __init__(self, inplace=True, h_max=1):
super(h_sigmoidNew, self).__init__()
self.relu = nn.ReLU6(inplace=inplace)
self.h_max = h_max
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
shivamsnaik/dynamic-head-microsoft-fork
|
h_sigmoid
| false
| 16,428
|
[
"MIT"
] | 494
|
0f337eec44d262df2517be8f5617477c0b092fcc
|
https://github.com/shivamsnaik/dynamic-head-microsoft-fork/tree/0f337eec44d262df2517be8f5617477c0b092fcc
|
DilatedGatedConv1D
|
import torch
import torch.nn as nn
class DilatedGatedConv1D(nn.Module):
def __init__(self, dilation_rate, dim):
super().__init__()
self.dim = dim
self.dropout = nn.Dropout(p=0.1)
self.cnn = nn.Conv1d(dim, dim * 2, 3, padding=dilation_rate,
dilation=dilation_rate)
def forward(self, x):
residual = x
x = self.cnn(x.transpose(1, 2)).transpose(1, 2)
x1, x2 = x[:, :, :self.dim], x[:, :, self.dim:]
x1 = torch.sigmoid(self.dropout(x1))
return residual * (1 - x1) + x2 * x1
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dilation_rate': 1, '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
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_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_1(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 4 % 8
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_add_clone_mul_rsub_sigmoid_2(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
tmp0 = tl.load(in_ptr0 + (y0 + 4 * x2 + 16 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x2 + 4 * y0 + 32 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp6 = tl.load(in_ptr1 + (16 + x2 + 4 * y0 + 32 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp2 = tl.sigmoid(tmp1)
tmp3 = 1.0
tmp4 = tmp3 - tmp2
tmp5 = tmp0 * tmp4
tmp7 = tmp6 * tmp2
tmp8 = tmp5 + tmp7
tl.store(out_ptr0 + (y0 + 4 * x2 + 16 * y1), tmp8, xmask & ymask)
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, (8, 4, 3), (12, 3, 1))
assert_size_stride(primals_3, (8,), (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=(1,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf1, (4, 8, 4), (32, 4, 1))
buf2 = buf1
del buf1
triton_poi_fused_convolution_1[grid(128)](buf2, primals_3, 128,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_3
buf3 = buf0
del buf0
triton_poi_fused_add_clone_mul_rsub_sigmoid_2[grid(16, 4)](primals_1,
buf2, buf3, 16, 4, XBLOCK=4, YBLOCK=16, num_warps=1, num_stages=1)
return buf3, primals_1, primals_2, buf2
class DilatedGatedConv1DNew(nn.Module):
def __init__(self, dilation_rate, dim):
super().__init__()
self.dim = dim
self.dropout = nn.Dropout(p=0.1)
self.cnn = nn.Conv1d(dim, dim * 2, 3, padding=dilation_rate,
dilation=dilation_rate)
def forward(self, input_0):
primals_2 = self.cnn.weight
primals_3 = self.cnn.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
shinoyuki222/torch-light
|
DilatedGatedConv1D
| false
| 16,429
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
MaskedMSELoss
|
import torch
import torch.nn as nn
class MaskedMSELoss(nn.Module):
def __init__(self):
super(MaskedMSELoss, self).__init__()
self.loss = nn.BCEWithLogitsLoss(reduction='sum')
def forward(self, pred, target, mask):
"""
pred -> batch*seq_len
target -> batch*seq_len
mask -> batch*seq_len
"""
loss = self.loss(pred * mask, target) / torch.sum(mask)
return loss
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
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_mul_sum_0(in_out_ptr0
, in_ptr0, in_ptr1, in_ptr2, 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)
tmp4 = tl.load(in_ptr2 + r0, None)
tmp1 = 1.0
tmp2 = tmp1 - tmp0
tmp5 = tmp3 * tmp4
tmp6 = tmp2 * tmp5
tmp7 = 0.0
tmp8 = triton_helpers.minimum(tmp7, tmp5)
tmp9 = tl_math.abs(tmp5)
tmp10 = -tmp9
tmp11 = tl_math.exp(tmp10)
tmp12 = libdevice.log1p(tmp11)
tmp13 = tmp8 - tmp12
tmp14 = tmp6 - tmp13
tmp15 = tl.broadcast_to(tmp14, [RBLOCK])
tmp17 = triton_helpers.promote_to_tensor(tl.sum(tmp15, 0))
tmp18 = tl.broadcast_to(tmp4, [RBLOCK])
tmp20 = triton_helpers.promote_to_tensor(tl.sum(tmp18, 0))
tmp21 = tmp17 / tmp20
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp21, None)
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((), (), torch.float32)
buf2 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_binary_cross_entropy_with_logits_div_mul_sum_0[grid(1)
](buf2, arg2_1, arg0_1, arg1_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
return buf2,
class MaskedMSELossNew(nn.Module):
def __init__(self):
super(MaskedMSELossNew, self).__init__()
self.loss = nn.BCEWithLogitsLoss(reduction='sum')
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]
|
shrx11/M2H2-dataset
|
MaskedMSELoss
| false
| 16,430
|
[
"MIT"
] | 206
|
8be80041fc0de04f2a6113e305f09f3b8d6279f4
|
https://github.com/shrx11/M2H2-dataset/tree/8be80041fc0de04f2a6113e305f09f3b8d6279f4
|
CombineTensorPatches
|
import torch
from typing import Optional
from typing import Tuple
import torch.nn as nn
from typing import Union
from torch.nn.modules.utils import _pair
def combine_tensor_patches(patches: 'torch.Tensor', window_size:
'Tuple[int, int]'=(4, 4), stride: 'Tuple[int, int]'=(4, 4), unpadding:
'Optional[Tuple[int, int, int, int]]'=None) ->torch.Tensor:
"""Restore input from patches.
Args:
patches: patched tensor.
window_size: the size of the sliding window and the output patch size.
stride: stride of the sliding window.
unpadding: remove the padding added to both side of the input.
Shape:
- Input: :math:`(B, N, C, H_{out}, W_{out})`
- Output: :math:`(B, C, H, W)`
Example:
>>> out = extract_tensor_patches(torch.arange(16).view(1, 1, 4, 4), window_size=(2, 2), stride=(2, 2))
>>> combine_tensor_patches(out, window_size=(2, 2), stride=(2, 2))
tensor([[[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]]]])
"""
if stride[0] != window_size[0] or stride[1] != window_size[1]:
raise NotImplementedError(
f'Only stride == window_size is supported. Got {stride} and {window_size}.Please feel free to drop a PR to Kornia Github.'
)
if unpadding is not None:
window_size = window_size[0] + (unpadding[0] + unpadding[1]
) // window_size[0], window_size[1] + (unpadding[2] + unpadding[3]
) // window_size[1]
patches_tensor = patches.view(-1, window_size[0], window_size[1], *
patches.shape[-3:])
restored_tensor = torch.cat(torch.chunk(patches_tensor, window_size[0],
dim=1), -2).squeeze(1)
restored_tensor = torch.cat(torch.chunk(restored_tensor, window_size[1],
dim=1), -1).squeeze(1)
if unpadding is not None:
restored_tensor = torch.nn.functional.pad(restored_tensor, [(-i) for
i in unpadding])
return restored_tensor
class CombineTensorPatches(nn.Module):
"""Module that combine patches from tensors.
In the simplest case, the output value of the operator with input size
:math:`(B, N, C, H_{out}, W_{out})` is :math:`(B, C, H, W)`.
where
- :math:`B` is the batch size.
- :math:`N` denotes the total number of extracted patches stacked in
- :math:`C` denotes the number of input channels.
- :math:`H`, :math:`W` the input height and width of the input in pixels.
- :math:`H_{out}`, :math:`W_{out}` denote to denote to the patch size
defined in the function signature.
left-right and top-bottom order.
* :attr:`window_size` is the size of the sliding window and controls the
shape of the output tensor and defines the shape of the output patch.
* :attr:`stride` controls the stride to apply to the sliding window and
regulates the overlapping between the extracted patches.
* :attr:`padding` controls the amount of implicit zeros-paddings on both
sizes at each dimension.
The parameters :attr:`window_size`, :attr:`stride` and :attr:`padding` can
be either:
- a single ``int`` -- in which case the same value is used for the
height and width dimension.
- a ``tuple`` of two ints -- in which case, the first `int` is used for
the height dimension, and the second `int` for the width dimension.
Args:
patches: patched tensor.
window_size: the size of the sliding window and the output patch size.
unpadding: remove the padding added to both side of the input.
Shape:
- Input: :math:`(B, N, C, H_{out}, W_{out})`
- Output: :math:`(B, C, H, W)`
Example:
>>> out = extract_tensor_patches(torch.arange(16).view(1, 1, 4, 4), window_size=(2, 2), stride=(2, 2))
>>> combine_tensor_patches(out, window_size=(2, 2), stride=(2, 2))
tensor([[[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]]]])
"""
def __init__(self, window_size: 'Union[int, Tuple[int, int]]',
unpadding: 'Union[int, Tuple[int, int]]'=0) ->None:
super().__init__()
self.window_size: 'Tuple[int, int]' = _pair(window_size)
pad: 'Tuple[int, int]' = _pair(unpadding)
self.unpadding: 'Tuple[int, int, int, int]' = (pad[0], pad[0], pad[
1], pad[1])
def forward(self, input: 'torch.Tensor') ->torch.Tensor:
return combine_tensor_patches(input, self.window_size, stride=self.
window_size, unpadding=self.unpadding)
def get_inputs():
return [torch.rand([4, 4, 4, 4, 4, 4])]
def get_init_inputs():
return [[], {'window_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 typing import Optional
from typing import Tuple
import torch.nn as nn
from typing import Union
from torch.nn.modules.utils import _pair
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)
x0 = xindex % 16
x1 = xindex // 16 % 16
x2 = xindex // 256 % 4
x3 = xindex // 1024
x4 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = x1
tmp7 = tmp5 < tmp3
tmp8 = tmp7 & tmp4
tmp9 = tl.load(in_ptr0 + (4 * x1 + 16 * x2 + 1024 * x3 + x0), tmp8,
eviction_policy='evict_last', other=0.0)
tmp10 = tmp5 >= tmp3
tmp11 = tl.full([1], 8, tl.int64)
tmp12 = tmp5 < tmp11
tmp13 = tmp10 & tmp12
tmp14 = tmp13 & tmp4
tmp15 = tl.load(in_ptr0 + (256 + 4 * (-4 + x1) + 16 * x2 + 1024 * x3 +
x0), tmp14, eviction_policy='evict_last', other=0.0)
tmp16 = tmp5 >= tmp11
tmp17 = tl.full([1], 12, tl.int64)
tmp18 = tmp5 < tmp17
tmp19 = tmp16 & tmp18
tmp20 = tmp19 & tmp4
tmp21 = tl.load(in_ptr0 + (512 + 4 * (-8 + x1) + 16 * x2 + 1024 * x3 +
x0), tmp20, eviction_policy='evict_last', other=0.0)
tmp22 = tmp5 >= tmp17
tl.full([1], 16, tl.int64)
tmp25 = tmp22 & tmp4
tmp26 = tl.load(in_ptr0 + (768 + 4 * (-12 + x1) + 16 * x2 + 1024 * x3 +
x0), tmp25, eviction_policy='evict_last', other=0.0)
tmp27 = tl.where(tmp19, tmp21, tmp26)
tmp28 = tl.where(tmp13, tmp15, tmp27)
tmp29 = tl.where(tmp7, tmp9, tmp28)
tmp30 = tl.full(tmp29.shape, 0.0, tmp29.dtype)
tmp31 = tl.where(tmp4, tmp29, tmp30)
tmp32 = tmp0 >= tmp3
tmp33 = tmp0 < tmp11
tmp34 = tmp32 & tmp33
tmp35 = tmp7 & tmp34
tmp36 = tl.load(in_ptr0 + (64 + 4 * x1 + 16 * x2 + 1024 * x3 + (-4 + x0
)), tmp35, eviction_policy='evict_last', other=0.0)
tmp37 = tmp13 & tmp34
tmp38 = tl.load(in_ptr0 + (320 + 4 * (-4 + x1) + 16 * x2 + 1024 * x3 +
(-4 + x0)), tmp37, eviction_policy='evict_last', other=0.0)
tmp39 = tmp19 & tmp34
tmp40 = tl.load(in_ptr0 + (576 + 4 * (-8 + x1) + 16 * x2 + 1024 * x3 +
(-4 + x0)), tmp39, eviction_policy='evict_last', other=0.0)
tmp41 = tmp22 & tmp34
tmp42 = tl.load(in_ptr0 + (832 + 4 * (-12 + x1) + 16 * x2 + 1024 * x3 +
(-4 + x0)), tmp41, eviction_policy='evict_last', other=0.0)
tmp43 = tl.where(tmp19, tmp40, tmp42)
tmp44 = tl.where(tmp13, tmp38, tmp43)
tmp45 = tl.where(tmp7, tmp36, tmp44)
tmp46 = tl.full(tmp45.shape, 0.0, tmp45.dtype)
tmp47 = tl.where(tmp34, tmp45, tmp46)
tmp48 = tmp0 >= tmp11
tmp49 = tmp0 < tmp17
tmp50 = tmp48 & tmp49
tmp51 = tmp7 & tmp50
tmp52 = tl.load(in_ptr0 + (128 + 4 * x1 + 16 * x2 + 1024 * x3 + (-8 +
x0)), tmp51, eviction_policy='evict_last', other=0.0)
tmp53 = tmp13 & tmp50
tmp54 = tl.load(in_ptr0 + (384 + 4 * (-4 + x1) + 16 * x2 + 1024 * x3 +
(-8 + x0)), tmp53, eviction_policy='evict_last', other=0.0)
tmp55 = tmp19 & tmp50
tmp56 = tl.load(in_ptr0 + (640 + 4 * (-8 + x1) + 16 * x2 + 1024 * x3 +
(-8 + x0)), tmp55, eviction_policy='evict_last', other=0.0)
tmp57 = tmp22 & tmp50
tmp58 = tl.load(in_ptr0 + (896 + 4 * (-12 + x1) + 16 * x2 + 1024 * x3 +
(-8 + x0)), tmp57, eviction_policy='evict_last', other=0.0)
tmp59 = tl.where(tmp19, tmp56, tmp58)
tmp60 = tl.where(tmp13, tmp54, tmp59)
tmp61 = tl.where(tmp7, tmp52, tmp60)
tmp62 = tl.full(tmp61.shape, 0.0, tmp61.dtype)
tmp63 = tl.where(tmp50, tmp61, tmp62)
tmp64 = tmp0 >= tmp17
tmp66 = tmp7 & tmp64
tmp67 = tl.load(in_ptr0 + (192 + 4 * x1 + 16 * x2 + 1024 * x3 + (-12 +
x0)), tmp66, eviction_policy='evict_last', other=0.0)
tmp68 = tmp13 & tmp64
tmp69 = tl.load(in_ptr0 + (448 + 4 * (-4 + x1) + 16 * x2 + 1024 * x3 +
(-12 + x0)), tmp68, eviction_policy='evict_last', other=0.0)
tmp70 = tmp19 & tmp64
tmp71 = tl.load(in_ptr0 + (704 + 4 * (-8 + x1) + 16 * x2 + 1024 * x3 +
(-12 + x0)), tmp70, eviction_policy='evict_last', other=0.0)
tmp72 = tmp22 & tmp64
tmp73 = tl.load(in_ptr0 + (960 + 4 * (-12 + x1) + 16 * x2 + 1024 * x3 +
(-12 + x0)), tmp72, eviction_policy='evict_last', other=0.0)
tmp74 = tl.where(tmp19, tmp71, tmp73)
tmp75 = tl.where(tmp13, tmp69, tmp74)
tmp76 = tl.where(tmp7, tmp67, tmp75)
tmp77 = tl.full(tmp76.shape, 0.0, tmp76.dtype)
tmp78 = tl.where(tmp64, tmp76, tmp77)
tmp79 = tl.where(tmp50, tmp63, tmp78)
tmp80 = tl.where(tmp34, tmp47, tmp79)
tmp81 = tl.where(tmp4, tmp31, tmp80)
tl.store(out_ptr0 + x4, tmp81, None)
def call(args):
arg0_1, = args
args.clear()
assert_size_stride(arg0_1, (4, 4, 4, 4, 4, 4), (1024, 256, 64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 4, 16, 16), (1024, 1024, 256, 16,
1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(4096)](arg0_1, buf0, 4096, XBLOCK=128,
num_warps=4, num_stages=1)
del arg0_1
return reinterpret_tensor(buf0, (4, 4, 16, 16), (1024, 256, 16, 1), 0),
def combine_tensor_patches(patches: 'torch.Tensor', window_size:
'Tuple[int, int]'=(4, 4), stride: 'Tuple[int, int]'=(4, 4), unpadding:
'Optional[Tuple[int, int, int, int]]'=None) ->torch.Tensor:
"""Restore input from patches.
Args:
patches: patched tensor.
window_size: the size of the sliding window and the output patch size.
stride: stride of the sliding window.
unpadding: remove the padding added to both side of the input.
Shape:
- Input: :math:`(B, N, C, H_{out}, W_{out})`
- Output: :math:`(B, C, H, W)`
Example:
>>> out = extract_tensor_patches(torch.arange(16).view(1, 1, 4, 4), window_size=(2, 2), stride=(2, 2))
>>> combine_tensor_patches(out, window_size=(2, 2), stride=(2, 2))
tensor([[[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]]]])
"""
if stride[0] != window_size[0] or stride[1] != window_size[1]:
raise NotImplementedError(
f'Only stride == window_size is supported. Got {stride} and {window_size}.Please feel free to drop a PR to Kornia Github.'
)
if unpadding is not None:
window_size = window_size[0] + (unpadding[0] + unpadding[1]
) // window_size[0], window_size[1] + (unpadding[2] + unpadding[3]
) // window_size[1]
patches_tensor = patches.view(-1, window_size[0], window_size[1], *
patches.shape[-3:])
restored_tensor = torch.cat(torch.chunk(patches_tensor, window_size[0],
dim=1), -2).squeeze(1)
restored_tensor = torch.cat(torch.chunk(restored_tensor, window_size[1],
dim=1), -1).squeeze(1)
if unpadding is not None:
restored_tensor = torch.nn.functional.pad(restored_tensor, [(-i) for
i in unpadding])
return restored_tensor
class CombineTensorPatchesNew(nn.Module):
"""Module that combine patches from tensors.
In the simplest case, the output value of the operator with input size
:math:`(B, N, C, H_{out}, W_{out})` is :math:`(B, C, H, W)`.
where
- :math:`B` is the batch size.
- :math:`N` denotes the total number of extracted patches stacked in
- :math:`C` denotes the number of input channels.
- :math:`H`, :math:`W` the input height and width of the input in pixels.
- :math:`H_{out}`, :math:`W_{out}` denote to denote to the patch size
defined in the function signature.
left-right and top-bottom order.
* :attr:`window_size` is the size of the sliding window and controls the
shape of the output tensor and defines the shape of the output patch.
* :attr:`stride` controls the stride to apply to the sliding window and
regulates the overlapping between the extracted patches.
* :attr:`padding` controls the amount of implicit zeros-paddings on both
sizes at each dimension.
The parameters :attr:`window_size`, :attr:`stride` and :attr:`padding` can
be either:
- a single ``int`` -- in which case the same value is used for the
height and width dimension.
- a ``tuple`` of two ints -- in which case, the first `int` is used for
the height dimension, and the second `int` for the width dimension.
Args:
patches: patched tensor.
window_size: the size of the sliding window and the output patch size.
unpadding: remove the padding added to both side of the input.
Shape:
- Input: :math:`(B, N, C, H_{out}, W_{out})`
- Output: :math:`(B, C, H, W)`
Example:
>>> out = extract_tensor_patches(torch.arange(16).view(1, 1, 4, 4), window_size=(2, 2), stride=(2, 2))
>>> combine_tensor_patches(out, window_size=(2, 2), stride=(2, 2))
tensor([[[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]]]])
"""
def __init__(self, window_size: 'Union[int, Tuple[int, int]]',
unpadding: 'Union[int, Tuple[int, int]]'=0) ->None:
super().__init__()
self.window_size: 'Tuple[int, int]' = _pair(window_size)
pad: 'Tuple[int, int]' = _pair(unpadding)
self.unpadding: 'Tuple[int, int, int, int]' = (pad[0], pad[0], pad[
1], pad[1])
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
shiyangc-intusurg/kornia
|
CombineTensorPatches
| false
| 16,431
|
[
"ECL-2.0",
"Apache-2.0"
] | 4,894
|
2e2512f8f20d300d8732e5873e16336b5a01f3bd
|
https://github.com/shiyangc-intusurg/kornia/tree/2e2512f8f20d300d8732e5873e16336b5a01f3bd
|
KLDivergence
|
import torch
import torch.nn.functional as F
import torch.nn as nn
import torch.optim
def kl_divergence(y, target, mask=None, reduce=True):
loss = (target * torch.log(target) - target * F.log_softmax(y, 1)).sum(1)
if mask is not None:
loss = mask * loss
if reduce:
return loss.mean()
else:
return loss
class KLDivergence(nn.Module):
def __init__(self, reduce):
super().__init__()
self.reduce = reduce
def forward(self, y, target, mask=None, *args, **kwargs):
return kl_divergence(y, target.detach(), mask, self.reduce)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'reduce': 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.functional as F
import torch.nn as nn
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__log_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
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_per_fused__log_softmax_log_mean_mul_sub_sum_1(in_out_ptr0,
in_ptr0, in_ptr1, 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 % 16
r1 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
tmp3 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
tmp5 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
tmp8 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
tmp11 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
tmp18 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
tmp25 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
tmp32 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
tmp1 = tl_math.log(tmp0)
tmp2 = tmp0 * tmp1
tmp4 = tl_math.exp(tmp3)
tmp6 = tl_math.exp(tmp5)
tmp7 = tmp4 + tmp6
tmp9 = tl_math.exp(tmp8)
tmp10 = tmp7 + tmp9
tmp12 = tl_math.exp(tmp11)
tmp13 = tmp10 + tmp12
tmp14 = tl_math.log(tmp13)
tmp15 = tmp3 - tmp14
tmp16 = tmp0 * tmp15
tmp17 = tmp2 - tmp16
tmp19 = tl_math.log(tmp18)
tmp20 = tmp18 * tmp19
tmp21 = tmp5 - tmp14
tmp22 = tmp18 * tmp21
tmp23 = tmp20 - tmp22
tmp24 = tmp17 + tmp23
tmp26 = tl_math.log(tmp25)
tmp27 = tmp25 * tmp26
tmp28 = tmp8 - tmp14
tmp29 = tmp25 * tmp28
tmp30 = tmp27 - tmp29
tmp31 = tmp24 + tmp30
tmp33 = tl_math.log(tmp32)
tmp34 = tmp32 * tmp33
tmp35 = tmp11 - tmp14
tmp36 = tmp32 * tmp35
tmp37 = tmp34 - tmp36
tmp38 = tmp31 + tmp37
tmp39 = tl.broadcast_to(tmp38, [XBLOCK, RBLOCK])
tmp41 = tl.sum(tmp39, 1)[:, None]
tmp42 = 64.0
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__log_softmax_0[grid(256)](arg1_1, buf0, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg1_1
buf2 = empty_strided_cuda((), (), torch.float32)
buf3 = buf2
del buf2
triton_per_fused__log_softmax_log_mean_mul_sub_sum_1[grid(1)](buf3,
arg0_1, buf0, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del buf0
return buf3,
def kl_divergence(y, target, mask=None, reduce=True):
loss = (target * torch.log(target) - target * F.log_softmax(y, 1)).sum(1)
if mask is not None:
loss = mask * loss
if reduce:
return loss.mean()
else:
return loss
class KLDivergenceNew(nn.Module):
def __init__(self, reduce):
super().__init__()
self.reduce = reduce
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
shrutimoy10/cords
|
KLDivergence
| false
| 16,432
|
[
"MIT"
] | 185
|
8f8d087098afafd352f793821911d80eb7b39a7d
|
https://github.com/shrutimoy10/cords/tree/8f8d087098afafd352f793821911d80eb7b39a7d
|
JointsMSELoss
|
import torch
import torch.nn as nn
import torch.utils.data
class JointsMSELoss(nn.Module):
def __init__(self):
super(JointsMSELoss, self).__init__()
self.criterion = nn.MSELoss(reduction='mean')
def forward(self, output, target, target_weight=None):
batch_size = output.size(0)
num_keypoints = output.size(1)
heatmaps_pred = output.reshape((batch_size, num_keypoints, -1)).split(
1, 1)
heatmaps_gt = target.reshape((batch_size, num_keypoints, -1)).split(
1, 1)
loss = 0
for idx in range(num_keypoints):
heatmap_pred = heatmaps_pred[idx].squeeze()
heatmap_gt = heatmaps_gt[idx].squeeze()
if target_weight is not None:
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_keypoints
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
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_per_fused_add_div_mse_loss_mul_0(in_out_ptr0, in_ptr0, in_ptr1,
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 % 16
r1 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r0 + 64 * r1), None)
tmp1 = tl.load(in_ptr1 + (r0 + 64 * r1), None)
tmp7 = tl.load(in_ptr0 + (16 + r0 + 64 * r1), None)
tmp8 = tl.load(in_ptr1 + (16 + r0 + 64 * r1), None)
tmp14 = tl.load(in_ptr0 + (32 + r0 + 64 * r1), None)
tmp15 = tl.load(in_ptr1 + (32 + r0 + 64 * r1), None)
tmp21 = tl.load(in_ptr0 + (48 + r0 + 64 * r1), None)
tmp22 = tl.load(in_ptr1 + (48 + r0 + 64 * r1), None)
tmp2 = tmp0 - tmp1
tmp3 = tmp2 * tmp2
tmp4 = tl.broadcast_to(tmp3, [XBLOCK, RBLOCK])
tmp6 = tl.sum(tmp4, 1)[:, None]
tmp9 = tmp7 - tmp8
tmp10 = tmp9 * tmp9
tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp13 = tl.sum(tmp11, 1)[:, None]
tmp16 = tmp14 - tmp15
tmp17 = tmp16 * tmp16
tmp18 = tl.broadcast_to(tmp17, [XBLOCK, RBLOCK])
tmp20 = tl.sum(tmp18, 1)[:, None]
tmp23 = tmp21 - tmp22
tmp24 = tmp23 * tmp23
tmp25 = tl.broadcast_to(tmp24, [XBLOCK, RBLOCK])
tmp27 = tl.sum(tmp25, 1)[:, None]
tmp28 = 64.0
tmp29 = tmp6 / tmp28
tmp30 = 0.5
tmp31 = tmp29 * tmp30
tmp32 = 0.0
tmp33 = tmp31 + tmp32
tmp34 = tmp13 / tmp28
tmp35 = tmp34 * tmp30
tmp36 = tmp33 + tmp35
tmp37 = tmp20 / tmp28
tmp38 = tmp37 * tmp30
tmp39 = tmp36 + tmp38
tmp40 = tmp27 / tmp28
tmp41 = tmp40 * tmp30
tmp42 = tmp39 + tmp41
tmp43 = 0.25
tmp44 = tmp42 * tmp43
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp44, 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)
buf4 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_add_div_mse_loss_mul_0[grid(1)](buf4, arg0_1,
arg1_1, 1, 64, XBLOCK=1, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf4,
class JointsMSELossNew(nn.Module):
def __init__(self):
super(JointsMSELossNew, self).__init__()
self.criterion = nn.MSELoss(reduction='mean')
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
shunya-toyokawa/qanet_human_parts_segmentatiom
|
JointsMSELoss
| false
| 16,433
|
[
"MIT"
] | 72
|
5527b247acd65534b455c26e3692a14b31669602
|
https://github.com/shunya-toyokawa/qanet_human_parts_segmentatiom/tree/5527b247acd65534b455c26e3692a14b31669602
|
BoundedIoULoss
|
import torch
import torch.nn as nn
import torch.utils.data
class BoundedIoULoss(nn.Module):
def __init__(self, beta=0.2, eps=0.001):
super(BoundedIoULoss, self).__init__()
self.beta = beta
self.eps = eps
def forward(self, pred, target, weight=None):
pred_ctr_2x = pred[:, :2] + pred[:, 2:]
pred_wh = pred[:, 2:] - pred[:, :2]
with torch.no_grad():
target_ctr_2x = target[:, :2] + target[:, 2:]
target_wh = target[:, 2:] - target[:, :2]
d_xy_2x = (target_ctr_2x - pred_ctr_2x).abs()
loss_xy = torch.clamp((target_wh - d_xy_2x) / (target_wh + d_xy_2x +
self.eps), min=0)
loss_wh = torch.min(target_wh / (pred_wh + self.eps), pred_wh / (
target_wh + self.eps))
loss = 1 - torch.cat([loss_xy, loss_wh], dim=-1)
if self.beta >= 1e-05:
loss = torch.where(loss < self.beta, 0.5 * loss ** 2 / self.
beta, loss - 0.5 * self.beta)
if weight is not None:
loss = loss * weight
return loss.sum()
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
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_per_fused_cat_div_lt_mul_pow_rsub_sub_sum_where_0(in_ptr0,
in_ptr1, out_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 % 8
r1 = rindex // 8 % 8
r2 = rindex // 64
tmp0 = r0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + tl.broadcast_to(32 + 4 * r1 + 64 * r2 + r0, [
RBLOCK]), tmp4, eviction_policy='evict_last', other=0.0)
tmp6 = tl.load(in_ptr0 + tl.broadcast_to(4 * r1 + 64 * r2 + r0, [RBLOCK
]), tmp4, eviction_policy='evict_last', other=0.0)
tmp7 = tmp5 - tmp6
tmp8 = tmp6 + tmp5
tmp9 = tl.load(in_ptr1 + tl.broadcast_to(4 * r1 + 64 * r2 + r0, [RBLOCK
]), tmp4, eviction_policy='evict_last', other=0.0)
tmp10 = tl.load(in_ptr1 + tl.broadcast_to(32 + 4 * r1 + 64 * r2 + r0, [
RBLOCK]), tmp4, eviction_policy='evict_last', other=0.0)
tmp11 = tmp9 + tmp10
tmp12 = tmp8 - tmp11
tmp13 = tl_math.abs(tmp12)
tmp14 = tmp7 - tmp13
tmp15 = tmp7 + tmp13
tmp16 = 0.001
tmp17 = tmp15 + tmp16
tmp18 = tmp14 / tmp17
tmp19 = 0.0
tmp20 = triton_helpers.maximum(tmp18, tmp19)
tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype)
tmp22 = tl.where(tmp4, tmp20, tmp21)
tmp23 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp26 = tl.load(in_ptr0 + tl.broadcast_to(32 + 4 * r1 + 64 * r2 + (-4 +
r0), [RBLOCK]), tmp23, eviction_policy='evict_last', other=0.0)
tmp27 = tl.load(in_ptr0 + tl.broadcast_to(4 * r1 + 64 * r2 + (-4 + r0),
[RBLOCK]), tmp23, eviction_policy='evict_last', other=0.0)
tmp28 = tmp26 - tmp27
tmp29 = tl.load(in_ptr1 + tl.broadcast_to(32 + 4 * r1 + 64 * r2 + (-4 +
r0), [RBLOCK]), tmp23, eviction_policy='evict_last', other=0.0)
tmp30 = tl.load(in_ptr1 + tl.broadcast_to(4 * r1 + 64 * r2 + (-4 + r0),
[RBLOCK]), tmp23, eviction_policy='evict_last', other=0.0)
tmp31 = tmp29 - tmp30
tmp32 = tmp31 + tmp16
tmp33 = tmp28 / tmp32
tmp34 = tmp28 + tmp16
tmp35 = tmp31 / tmp34
tmp36 = triton_helpers.minimum(tmp33, tmp35)
tmp37 = tl.full(tmp36.shape, 0.0, tmp36.dtype)
tmp38 = tl.where(tmp23, tmp36, tmp37)
tmp39 = tl.where(tmp4, tmp22, tmp38)
tmp40 = 1.0
tmp41 = tmp40 - tmp39
tmp42 = 0.2
tmp43 = tmp41 < tmp42
tmp44 = tmp41 * tmp41
tmp45 = 0.5
tmp46 = tmp44 * tmp45
tmp47 = 5.0
tmp48 = tmp46 * tmp47
tmp49 = 0.1
tmp50 = tmp41 - tmp49
tmp51 = tl.where(tmp43, tmp48, tmp50)
tmp52 = tl.broadcast_to(tmp51, [RBLOCK])
tmp54 = triton_helpers.promote_to_tensor(tl.sum(tmp52, 0))
tl.store(out_ptr1 + tl.full([1], 0, tl.int32), tmp54, 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)
buf1 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused_cat_div_lt_mul_pow_rsub_sub_sum_where_0[grid(1)](
arg1_1, arg0_1, buf1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf1,
class BoundedIoULossNew(nn.Module):
def __init__(self, beta=0.2, eps=0.001):
super(BoundedIoULossNew, self).__init__()
self.beta = beta
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]
|
shunya-toyokawa/qanet_human_parts_segmentatiom
|
BoundedIoULoss
| false
| 16,434
|
[
"MIT"
] | 72
|
5527b247acd65534b455c26e3692a14b31669602
|
https://github.com/shunya-toyokawa/qanet_human_parts_segmentatiom/tree/5527b247acd65534b455c26e3692a14b31669602
|
HyperpriorAnalysis
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class HyperpriorAnalysis(nn.Module):
"""
Hyperprior 'analysis model' as proposed in [1].
[1] Ballé et. al., "Variational image compression with a scale hyperprior",
arXiv:1802.01436 (2018).
C: Number of input channels
"""
def __init__(self, C=220, N=320, activation='relu'):
super(HyperpriorAnalysis, self).__init__()
cnn_kwargs = dict(kernel_size=5, stride=2, padding=2, padding_mode=
'reflect')
self.activation = getattr(F, activation)
self.n_downsampling_layers = 2
self.conv1 = nn.Conv2d(C, N, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(N, N, **cnn_kwargs)
self.conv3 = nn.Conv2d(N, N, **cnn_kwargs)
def forward(self, x):
x = self.activation(self.conv1(x))
x = self.activation(self.conv2(x))
x = self.conv3(x)
return x
def get_inputs():
return [torch.rand([4, 220, 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 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
@triton.jit
def triton_poi_fused_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 70400
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(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
y0 = yindex % 220
y1 = yindex // 220
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask & ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 220 * x2 + 1980 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 880
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]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 220
y1 = yindex // 220
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 220 * x2 + 901120 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 25
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 320
y1 = yindex // 320
tmp0 = tl.load(in_ptr0 + (x2 + 25 * y3), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 320 * x2 + 8000 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_convolution_reflection_pad2d_relu_3(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)
x0 = xindex % 320
x1 = xindex // 320 % 68
x2 = xindex // 21760 % 68
x3 = xindex // 1479680
x4 = xindex
tmp0 = tl.load(in_ptr0 + (1310400 + x0 + -20480 * tl_math.abs(-63 +
tl_math.abs(-2 + x2)) + -320 * tl_math.abs(-63 + tl_math.abs(-2 +
x1)) + 1310720 * x3), None)
tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(out_ptr0 + x4, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_reflection_pad2d_relu_4(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)
x0 = xindex % 320
x1 = xindex // 320 % 36
x2 = xindex // 11520 % 36
x3 = xindex // 414720
x4 = xindex
tmp0 = tl.load(in_ptr0 + (327360 + x0 + -10240 * tl_math.abs(-31 +
tl_math.abs(-2 + x2)) + -320 * tl_math.abs(-31 + tl_math.abs(-2 +
x1)) + 327680 * x3), None)
tmp1 = tl.load(in_ptr1 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.full([1], 0, tl.int32)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tl.store(out_ptr0 + x4, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_5(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 1280
xnumel = 256
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 % 320
y1 = yindex // 320
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 320 * x2 + 81920 * 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 + 256 * y3), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_6(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)
x2 = xindex
x0 = xindex % 320
tmp0 = tl.load(in_ptr0 + x2, None)
tmp1 = tl.load(in_ptr1 + 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(out_ptr0 + x2, tmp6, None)
@triton.jit
def triton_poi_fused_convolution_relu_threshold_backward_7(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)
x2 = xindex
x0 = xindex % 320
tmp0 = tl.load(in_ptr0 + x2, None)
tmp1 = tl.load(in_ptr1 + 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(out_ptr0 + x2, tmp6, None)
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, (320, 220, 3, 3), (1980, 9, 3, 1))
assert_size_stride(primals_2, (320,), (1,))
assert_size_stride(primals_3, (4, 220, 64, 64), (901120, 4096, 64, 1))
assert_size_stride(primals_4, (320, 320, 5, 5), (8000, 25, 5, 1))
assert_size_stride(primals_5, (320,), (1,))
assert_size_stride(primals_6, (320, 320, 5, 5), (8000, 25, 5, 1))
assert_size_stride(primals_7, (320,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((320, 220, 3, 3), (1980, 1, 660, 220),
torch.float32)
get_raw_stream(0)
triton_poi_fused_0[grid(70400, 9)](primals_1, buf0, 70400, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 220, 64, 64), (901120, 1, 14080, 220),
torch.float32)
triton_poi_fused_1[grid(880, 4096)](primals_3, buf1, 880, 4096,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_3
buf2 = empty_strided_cuda((320, 320, 5, 5), (8000, 1, 1600, 320),
torch.float32)
triton_poi_fused_2[grid(102400, 25)](primals_4, buf2, 102400, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_4
buf3 = empty_strided_cuda((320, 320, 5, 5), (8000, 1, 1600, 320),
torch.float32)
triton_poi_fused_2[grid(102400, 25)](primals_6, buf3, 102400, 25,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_6
buf4 = extern_kernels.convolution(buf1, buf0, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 320, 64, 64), (1310720, 1, 20480, 320))
buf5 = empty_strided_cuda((4, 320, 68, 68), (1479680, 1, 21760, 320
), torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_3[grid(5918720)](
buf4, primals_2, buf5, 5918720, XBLOCK=512, num_warps=8,
num_stages=1)
buf6 = extern_kernels.convolution(buf5, buf2, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 320, 32, 32), (327680, 1, 10240, 320))
buf7 = empty_strided_cuda((4, 320, 36, 36), (414720, 1, 11520, 320),
torch.float32)
triton_poi_fused_convolution_reflection_pad2d_relu_4[grid(1658880)](
buf6, primals_5, buf7, 1658880, XBLOCK=1024, num_warps=4,
num_stages=1)
buf8 = extern_kernels.convolution(buf7, buf3, stride=(2, 2),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 320, 16, 16), (81920, 1, 5120, 320))
buf9 = empty_strided_cuda((4, 320, 16, 16), (81920, 256, 16, 1),
torch.float32)
triton_poi_fused_convolution_5[grid(1280, 256)](buf8, primals_7,
buf9, 1280, 256, XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del buf8
del primals_7
buf10 = empty_strided_cuda((4, 320, 32, 32), (327680, 1, 10240, 320
), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_6[grid(1310720)](
buf6, primals_5, buf10, 1310720, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf6
del primals_5
buf11 = empty_strided_cuda((4, 320, 64, 64), (1310720, 1, 20480,
320), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_7[grid(5242880)](
buf4, primals_2, buf11, 5242880, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf4
del primals_2
return buf9, buf0, buf1, buf2, buf3, buf5, buf7, buf10, buf11
class HyperpriorAnalysisNew(nn.Module):
"""
Hyperprior 'analysis model' as proposed in [1].
[1] Ballé et. al., "Variational image compression with a scale hyperprior",
arXiv:1802.01436 (2018).
C: Number of input channels
"""
def __init__(self, C=220, N=320, activation='relu'):
super(HyperpriorAnalysisNew, self).__init__()
cnn_kwargs = dict(kernel_size=5, stride=2, padding=2, padding_mode=
'reflect')
self.activation = getattr(F, activation)
self.n_downsampling_layers = 2
self.conv1 = nn.Conv2d(C, N, kernel_size=3, stride=1, padding=1)
self.conv2 = nn.Conv2d(N, N, **cnn_kwargs)
self.conv3 = nn.Conv2d(N, N, **cnn_kwargs)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
sedrickkeh/high-fidelity-dual-image
|
HyperpriorAnalysis
| false
| 16,435
|
[
"Apache-2.0"
] | 266
|
9cefd378467826b91596653df38666e469bb23e0
|
https://github.com/sedrickkeh/high-fidelity-dual-image/tree/9cefd378467826b91596653df38666e469bb23e0
|
NormalizeScale
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class NormalizeScale(nn.Module):
def __init__(self, dim, init_norm=20):
super(NormalizeScale, self).__init__()
self.init_norm = init_norm
self.weight = nn.Parameter(torch.ones(1, dim) * init_norm)
def forward(self, bottom):
bottom_normalized = F.normalize(bottom, p=2, dim=1)
bottom_normalized_scaled = bottom_normalized * self.weight
return bottom_normalized_scaled
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 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
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_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
x4 = xindex
x3 = xindex // 64
x5 = xindex % 16
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + (x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (32 + x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (48 + x5 + 64 * x3), xmask, eviction_policy=
'evict_last')
tmp16 = tl.load(in_ptr1 + x0, 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-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tmp17 = tmp15 * tmp16
tl.store(out_ptr0 + x4, tmp17, 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, 4), (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=128, num_warps=4, num_stages=1)
del primals_2
return buf0, primals_1
class NormalizeScaleNew(nn.Module):
def __init__(self, dim, init_norm=20):
super(NormalizeScaleNew, self).__init__()
self.init_norm = init_norm
self.weight = nn.Parameter(torch.ones(1, dim) * init_norm)
def forward(self, input_0):
primals_2 = self.weight
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
sibeiyang/sgmn
|
NormalizeScale
| false
| 16,436
|
[
"MIT"
] | 130
|
00731b4f2202246d40a36d2a6727c599e6e649aa
|
https://github.com/sibeiyang/sgmn/tree/00731b4f2202246d40a36d2a6727c599e6e649aa
|
PrimaryCapsLayer
|
import torch
import torch.nn as nn
def squash(x):
lengths2 = x.pow(2).sum(dim=2)
lengths = lengths2.sqrt()
x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1)
return x
class PrimaryCapsLayer(nn.Module):
def __init__(self, input_channels, output_caps, output_dim, kernel_size,
stride):
super(PrimaryCapsLayer, self).__init__()
self.conv = nn.Conv2d(input_channels, output_caps * output_dim,
kernel_size=kernel_size, stride=stride)
self.input_channels = input_channels
self.output_caps = output_caps
self.output_dim = output_dim
def forward(self, input):
out = self.conv(input)
N, _C, H, W = out.size()
out = out.view(N, self.output_caps, self.output_dim, H, W)
out = out.permute(0, 1, 3, 4, 2).contiguous()
out = out.view(out.size(0), -1, out.size(4))
out = squash(out)
return out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_channels': 4, 'output_caps': 4, 'output_dim': 4,
'kernel_size': 4, 'stride': 1}]
|
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
@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
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_mul_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')
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 = 1.0
tmp13 = tmp11 + tmp12
tmp14 = tmp11 / tmp13
tmp15 = libdevice.sqrt(tmp11)
tmp16 = tmp14 / tmp15
tmp17 = tmp0 * tmp16
tl.store(out_ptr0 + x2, tmp17, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (16, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (16,), (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=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 16, 1, 1), (16, 1, 1, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(64)](buf1, primals_2, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_mul_1[grid(64)](buf1, buf2, 64, XBLOCK=64,
num_warps=1, num_stages=1)
return buf2, primals_1, primals_3, buf1
def squash(x):
lengths2 = x.pow(2).sum(dim=2)
lengths = lengths2.sqrt()
x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1)
return x
class PrimaryCapsLayerNew(nn.Module):
def __init__(self, input_channels, output_caps, output_dim, kernel_size,
stride):
super(PrimaryCapsLayerNew, self).__init__()
self.conv = nn.Conv2d(input_channels, output_caps * output_dim,
kernel_size=kernel_size, stride=stride)
self.input_channels = input_channels
self.output_caps = output_caps
self.output_dim = output_dim
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]
|
shwetasrsh/MNIST-baselines
|
PrimaryCapsLayer
| false
| 16,437
|
[
"MIT"
] | 61
|
aa888e201a1dddda13e7b278cab8f940d57538db
|
https://github.com/shwetasrsh/MNIST-baselines/tree/aa888e201a1dddda13e7b278cab8f940d57538db
|
NormAttnMap
|
import torch
import torch.nn as nn
class NormAttnMap(nn.Module):
def __init__(self, norm_type='cossim'):
super(NormAttnMap, self).__init__()
self.norm_type = norm_type
def forward(self, attn_map):
if self.norm_type != 'cosssim':
norm = torch.max(attn_map, dim=1, keepdim=True)[0].detach()
else:
norm = torch.max(torch.abs(attn_map), dim=1, keepdim=True)[0
].detach()
norm[norm <= 1] = 1
attn = attn_map / norm
return attn, norm
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_index_put_lift_fresh_max_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 = triton_helpers.maximum(tmp0, tmp1)
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp6 = triton_helpers.maximum(tmp4, tmp5)
tmp7 = 1.0
tmp8 = tmp6 <= tmp7
tmp9 = tl.where(tmp8, tmp7, tmp6)
tl.store(out_ptr0 + x2, tmp9, xmask)
@triton.jit
def triton_poi_fused_div_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 = tmp0 / tmp1
tl.store(out_ptr0 + x3, tmp2, 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_index_put_lift_fresh_max_0[grid(64)](arg0_1, buf0,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf1 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_div_1[grid(256)](arg0_1, buf0, buf1, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del arg0_1
return buf1, buf0
class NormAttnMapNew(nn.Module):
def __init__(self, norm_type='cossim'):
super(NormAttnMapNew, self).__init__()
self.norm_type = norm_type
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0], output[1]
|
sibeiyang/sgmn
|
NormAttnMap
| false
| 16,438
|
[
"MIT"
] | 130
|
00731b4f2202246d40a36d2a6727c599e6e649aa
|
https://github.com/sibeiyang/sgmn/tree/00731b4f2202246d40a36d2a6727c599e6e649aa
|
SwishX
|
import torch
import torch.nn as nn
import torch.utils.data
class SwishX(nn.Module):
def __init__(self, maxvalue=2.72):
super(SwishX, self).__init__()
self.maximal = nn.Parameter(torch.FloatTensor([maxvalue]))
def forward(self, x):
output = x * torch.sigmoid(x)
output = output.sub(self.maximal).clamp(max=0.0).add(self.maximal)
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
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
@triton.jit
def triton_poi_fused_add_clamp_le_mul_sigmoid_sub_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)
tmp3 = tl.load(in_ptr1 + 0)
tmp4 = tl.broadcast_to(tmp3, [XBLOCK])
tmp1 = tl.sigmoid(tmp0)
tmp2 = tmp0 * tmp1
tmp5 = tmp2 - tmp4
tmp6 = 0.0
tmp7 = triton_helpers.minimum(tmp5, tmp6)
tmp8 = tmp7 + tmp4
tmp9 = tmp5 <= tmp6
tl.store(out_ptr0 + x0, tmp8, xmask)
tl.store(out_ptr1 + x0, tmp9, 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.bool)
get_raw_stream(0)
triton_poi_fused_add_clamp_le_mul_sigmoid_sub_0[grid(256)](primals_1,
primals_2, buf0, buf1, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_1
del primals_2
return buf0, buf1
class SwishXNew(nn.Module):
def __init__(self, maxvalue=2.72):
super(SwishXNew, self).__init__()
self.maximal = nn.Parameter(torch.FloatTensor([maxvalue]))
def forward(self, input_0):
primals_2 = self.maximal
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
shunya-toyokawa/qanet_human_parts_segmentatiom
|
SwishX
| false
| 16,439
|
[
"MIT"
] | 72
|
5527b247acd65534b455c26e3692a14b31669602
|
https://github.com/shunya-toyokawa/qanet_human_parts_segmentatiom/tree/5527b247acd65534b455c26e3692a14b31669602
|
Anomaly
|
import torch
import torch.utils.data
from torch import nn
class Anomaly(nn.Module):
def __init__(self, window=1024):
self.window = window
super(Anomaly, self).__init__()
self.layer1 = nn.Conv1d(window, window, kernel_size=1, stride=1,
padding=0)
self.layer2 = nn.Conv1d(window, 2 * window, kernel_size=1, stride=1,
padding=0)
self.fc1 = nn.Linear(2 * window, 4 * window)
self.fc2 = nn.Linear(4 * window, window)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
x = x.view(x.size(0), self.window, 1)
x = self.layer1(x)
x = self.relu(x)
x = self.layer2(x)
x = x.view(x.size(0), -1)
x = self.relu(x)
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
return torch.sigmoid(x)
def get_inputs():
return [torch.rand([4, 1024, 1])]
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.utils.data
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_relu_0(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)
x2 = xindex
x0 = xindex % 1024
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_relu_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)
x2 = xindex
x0 = xindex % 2048
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_relu_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)
x2 = xindex
x0 = xindex % 4096
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)
tl.store(in_out_ptr0 + x2, tmp4, None)
@triton.jit
def triton_poi_fused_sigmoid_3(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)
x2 = xindex
x0 = xindex % 1024
tmp0 = tl.load(in_out_ptr0 + x2, None)
tmp1 = tl.load(in_ptr0 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tl.store(in_out_ptr0 + x2, tmp3, None)
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, (4, 1024, 1), (1024, 1, 1))
assert_size_stride(primals_2, (1024, 1024, 1), (1024, 1, 1))
assert_size_stride(primals_3, (1024,), (1,))
assert_size_stride(primals_4, (2048, 1024, 1), (1024, 1, 1))
assert_size_stride(primals_5, (2048,), (1,))
assert_size_stride(primals_6, (4096, 2048), (2048, 1))
assert_size_stride(primals_7, (4096,), (1,))
assert_size_stride(primals_8, (1024, 4096), (4096, 1))
assert_size_stride(primals_9, (1024,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_2, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf0, (4, 1024, 1), (1024, 1, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(4096)](buf1, primals_3,
4096, XBLOCK=256, num_warps=4, num_stages=1)
del primals_3
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1,),
padding=(0,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf2, (4, 2048, 1), (2048, 1, 1))
buf3 = reinterpret_tensor(buf2, (4, 2048), (2048, 1), 0)
del buf2
triton_poi_fused_relu_1[grid(8192)](buf3, primals_5, 8192, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((4, 4096), (4096, 1), torch.float32)
extern_kernels.mm(buf3, reinterpret_tensor(primals_6, (2048, 4096),
(1, 2048), 0), out=buf4)
buf5 = buf4
del buf4
triton_poi_fused_relu_2[grid(16384)](buf5, primals_7, 16384, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_7
buf6 = empty_strided_cuda((4, 1024), (1024, 1), torch.float32)
extern_kernels.mm(buf5, reinterpret_tensor(primals_8, (4096, 1024),
(1, 4096), 0), out=buf6)
buf7 = buf6
del buf6
triton_poi_fused_sigmoid_3[grid(4096)](buf7, primals_9, 4096,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_9
return (buf7, primals_1, primals_2, primals_4, buf1, buf3, buf5, buf7,
primals_8, primals_6)
class AnomalyNew(nn.Module):
def __init__(self, window=1024):
self.window = window
super(AnomalyNew, self).__init__()
self.layer1 = nn.Conv1d(window, window, kernel_size=1, stride=1,
padding=0)
self.layer2 = nn.Conv1d(window, 2 * window, kernel_size=1, stride=1,
padding=0)
self.fc1 = nn.Linear(2 * window, 4 * window)
self.fc2 = nn.Linear(4 * window, window)
self.relu = nn.ReLU(inplace=True)
def forward(self, input_0):
primals_2 = self.layer1.weight
primals_3 = self.layer1.bias
primals_4 = self.layer2.weight
primals_5 = self.layer2.bias
primals_6 = self.fc1.weight
primals_7 = self.fc1.bias
primals_8 = self.fc2.weight
primals_9 = self.fc2.bias
primals_1 = 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]
|
sccc19/anomalydetector
|
Anomaly
| false
| 16,440
|
[
"MIT"
] | 180
|
a963ef8d7f30971e99d21a748d059e26f2163b09
|
https://github.com/sccc19/anomalydetector/tree/a963ef8d7f30971e99d21a748d059e26f2163b09
|
Log10Loss
|
import torch
import numpy as np
import torch.nn as nn
import torch.nn.init
from math import log
def _mask_input(input, mask=None):
if mask is not None:
input = input * mask
count = torch.sum(mask).data[0]
else:
count = np.prod(input.size(), dtype=np.float32).item()
return input, count
class Log10Loss(nn.Module):
def forward(self, input, target, mask=None):
loss = torch.abs((torch.log(target) - torch.log(input)) / log(10))
loss, count = _mask_input(loss, mask)
return torch.sum(loss) / count
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.triton_helpers import math as tl_math
import numpy as np
import torch.nn as nn
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_abs_div_log_sub_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_math.log(tmp0)
tmp3 = tl_math.log(tmp2)
tmp4 = tmp1 - tmp3
tmp5 = 0.43429448190325176
tmp6 = tmp4 * tmp5
tmp7 = tl_math.abs(tmp6)
tl.store(out_ptr0 + x0, tmp7, 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, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_abs_div_log_sub_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,
def _mask_input(input, mask=None):
if mask is not None:
input = input * mask
count = torch.sum(mask).data[0]
else:
count = np.prod(input.size(), dtype=np.float32).item()
return input, count
class Log10LossNew(nn.Module):
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
simonmeister/pytorch-mono-depth
|
Log10Loss
| false
| 16,441
|
[
"MIT"
] | 56
|
713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
https://github.com/simonmeister/pytorch-mono-depth/tree/713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
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]
|
sidphbot/jina-hub
|
NormalizationLayer
| false
| 16,442
|
[
"Apache-2.0"
] | 106
|
ab195030b72353c9b803874e2c99829fb75e1b17
|
https://github.com/sidphbot/jina-hub/tree/ab195030b72353c9b803874e2c99829fb75e1b17
|
MaskIOULoss
|
import torch
import torch.nn as nn
import torch.utils.data
class MaskIOULoss(nn.Module):
def __init__(self):
super(MaskIOULoss, self).__init__()
def forward(self, pred, target, weight):
total = torch.stack([pred, target], -1)
l_max = total.max(dim=2)[0]
l_min = total.min(dim=2)[0]
loss = (l_max.sum(dim=1) / l_min.sum(dim=1)).log()
loss = loss * weight
return loss.sum()
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4]), torch.rand(
[4, 4, 4, 2])]
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
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_max_min_stack_0(in_ptr0, in_ptr1, out_ptr0, out_ptr1,
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 % 4
x2 = xindex // 8
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 + (x1 + 16 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 2, tl.int64)
tmp9 = tl.load(in_ptr1 + (x1 + 16 * x2), tmp6 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tmp11 = tl.load(in_ptr0 + (4 + x1 + 16 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp12 = tl.load(in_ptr1 + (4 + x1 + 16 * x2), tmp6 & xmask,
eviction_policy='evict_last', other=0.0)
tmp13 = tl.where(tmp4, tmp11, tmp12)
tmp14 = triton_helpers.maximum(tmp10, tmp13)
tmp15 = tl.load(in_ptr0 + (8 + x1 + 16 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp16 = tl.load(in_ptr1 + (8 + x1 + 16 * x2), tmp6 & xmask,
eviction_policy='evict_last', other=0.0)
tmp17 = tl.where(tmp4, tmp15, tmp16)
tmp18 = triton_helpers.maximum(tmp14, tmp17)
tmp19 = tl.load(in_ptr0 + (12 + x1 + 16 * x2), tmp4 & xmask,
eviction_policy='evict_last', other=0.0)
tmp20 = tl.load(in_ptr1 + (12 + x1 + 16 * x2), tmp6 & xmask,
eviction_policy='evict_last', other=0.0)
tmp21 = tl.where(tmp4, tmp19, tmp20)
tmp22 = triton_helpers.maximum(tmp18, tmp21)
tmp23 = triton_helpers.minimum(tmp10, tmp13)
tmp24 = triton_helpers.minimum(tmp23, tmp17)
tmp25 = triton_helpers.minimum(tmp24, tmp21)
tl.store(out_ptr0 + x3, tmp22, xmask)
tl.store(out_ptr1 + x3, tmp25, xmask)
@triton.jit
def triton_poi_fused_div_log_sum_1(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 % 8
x1 = xindex // 8
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 32 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (8 + x0 + 32 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (16 + x0 + 32 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (24 + x0 + 32 * x1), xmask)
tmp7 = tl.load(in_ptr1 + (x0 + 32 * x1), xmask)
tmp8 = tl.load(in_ptr1 + (8 + x0 + 32 * x1), xmask)
tmp10 = tl.load(in_ptr1 + (16 + x0 + 32 * x1), xmask)
tmp12 = tl.load(in_ptr1 + (24 + x0 + 32 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp4 = tmp2 + tmp3
tmp6 = tmp4 + tmp5
tmp9 = tmp7 + tmp8
tmp11 = tmp9 + tmp10
tmp13 = tmp11 + tmp12
tmp14 = tmp6 / tmp13
tmp15 = tl_math.log(tmp14)
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_per_fused_div_log_mul_sum_2(in_ptr0, in_ptr1, out_ptr0, xnumel,
rnumel, XBLOCK: tl.constexpr):
RBLOCK: tl.constexpr = 128
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 % 32
r2 = rindex
tmp0 = tl.load(in_ptr0 + r0, None, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + r2, None)
tmp2 = tmp0 * tmp1
tmp3 = tl.broadcast_to(tmp2, [XBLOCK, RBLOCK])
tmp5 = tl.sum(tmp3, 1)[:, None]
tl.store(out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp5, None)
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, 2), (32, 8, 2, 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)
buf1 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_max_min_stack_0[grid(128)](arg0_1, arg1_1, buf0,
buf1, 128, XBLOCK=128, num_warps=4, num_stages=1)
del arg0_1
del arg1_1
buf2 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.float32)
triton_poi_fused_div_log_sum_1[grid(32)](buf0, buf1, buf2, 32,
XBLOCK=32, num_warps=1, num_stages=1)
del buf0
del buf1
buf3 = empty_strided_cuda((), (), torch.float32)
triton_per_fused_div_log_mul_sum_2[grid(1)](buf2, arg2_1, buf3, 1,
128, XBLOCK=1, num_warps=2, num_stages=1)
del arg2_1
del buf2
return buf3,
class MaskIOULossNew(nn.Module):
def __init__(self):
super(MaskIOULossNew, 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]
|
shunya-toyokawa/qanet_human_parts_segmentatiom
|
MaskIOULoss
| false
| 16,443
|
[
"MIT"
] | 72
|
5527b247acd65534b455c26e3692a14b31669602
|
https://github.com/shunya-toyokawa/qanet_human_parts_segmentatiom/tree/5527b247acd65534b455c26e3692a14b31669602
|
LocationEncoder
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class NormalizeScale(nn.Module):
def __init__(self, dim, init_norm=20):
super(NormalizeScale, self).__init__()
self.init_norm = init_norm
self.weight = nn.Parameter(torch.ones(1, dim) * init_norm)
def forward(self, bottom):
bottom_normalized = F.normalize(bottom, p=2, dim=1)
bottom_normalized_scaled = bottom_normalized * self.weight
return bottom_normalized_scaled
class LocationEncoder(nn.Module):
def __init__(self, init_norm, dim):
super(LocationEncoder, self).__init__()
self.lfeat_normalizer = NormalizeScale(5, init_norm)
self.fc = nn.Linear(5, dim)
def forward(self, lfeats):
loc_feat = self.lfeat_normalizer(lfeats)
output = self.fc(loc_feat)
return output
def get_inputs():
return [torch.rand([4, 4, 4, 5])]
def get_init_inputs():
return [[], {'init_norm': 4, '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
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_div_mul_0(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 320
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x3 = xindex // 80
x5 = xindex % 20
x0 = xindex % 5
tmp0 = tl.load(in_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + (x5 + 80 * x3), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (20 + x5 + 80 * x3), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (40 + x5 + 80 * x3), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (60 + x5 + 80 * x3), xmask, eviction_policy=
'evict_last')
tmp16 = tl.load(in_ptr1 + x0, 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-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tmp17 = tmp15 * tmp16
tl.store(out_ptr0 + x4, tmp17, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 5), (80, 20, 5, 1))
assert_size_stride(primals_2, (1, 5), (5, 1))
assert_size_stride(primals_3, (4, 5), (5, 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, 5), (80, 20, 5, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_div_mul_0[grid(320)](primals_1, primals_2, buf0,
320, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_4, reinterpret_tensor(buf0, (64, 5), (
5, 1), 0), reinterpret_tensor(primals_3, (5, 4), (1, 5), 0),
alpha=1, beta=1, out=buf1)
del primals_4
return reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_1, reinterpret_tensor(buf0, (64, 5), (5, 1), 0), primals_3
class NormalizeScale(nn.Module):
def __init__(self, dim, init_norm=20):
super(NormalizeScale, self).__init__()
self.init_norm = init_norm
self.weight = nn.Parameter(torch.ones(1, dim) * init_norm)
def forward(self, bottom):
bottom_normalized = F.normalize(bottom, p=2, dim=1)
bottom_normalized_scaled = bottom_normalized * self.weight
return bottom_normalized_scaled
class LocationEncoderNew(nn.Module):
def __init__(self, init_norm, dim):
super(LocationEncoderNew, self).__init__()
self.lfeat_normalizer = NormalizeScale(5, init_norm)
self.fc = nn.Linear(5, dim)
def forward(self, input_0):
primals_2 = self.lfeat_normalizer.weight
primals_3 = self.fc.weight
primals_4 = self.fc.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
sibeiyang/sgmn
|
LocationEncoder
| false
| 16,444
|
[
"MIT"
] | 130
|
00731b4f2202246d40a36d2a6727c599e6e649aa
|
https://github.com/sibeiyang/sgmn/tree/00731b4f2202246d40a36d2a6727c599e6e649aa
|
ConvUnit
|
import torch
import torch.nn as nn
class ConvUnit(nn.Module):
def __init__(self):
super(ConvUnit, self).__init__()
self.conv = nn.Conv2d(in_channels=256, out_channels=32, kernel_size
=5, stride=1)
def forward(self, x):
return self.conv(x)
def get_inputs():
return [torch.rand([4, 256, 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
import torch.nn as nn
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):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x3 = xindex
x1 = xindex // 3600 % 32
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)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (32, 256, 5, 5), (6400, 25, 5, 1))
assert_size_stride(primals_2, (32,), (1,))
assert_size_stride(primals_3, (4, 256, 64, 64), (1048576, 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, 32, 60, 60), (115200, 3600, 60, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(460800)](buf1, primals_2,
460800, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_2
return buf1, primals_1, primals_3
class ConvUnitNew(nn.Module):
def __init__(self):
super(ConvUnitNew, self).__init__()
self.conv = nn.Conv2d(in_channels=256, out_channels=32, kernel_size
=5, stride=1)
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]
|
shinoyuki222/torch-light
|
ConvUnit
| false
| 16,445
|
[
"MIT"
] | 310
|
4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
https://github.com/shinoyuki222/torch-light/tree/4799805d9bcae82a9f12a574dcf9fdd838c92ee9
|
RelLoss
|
import torch
import numpy as np
import torch.nn as nn
import torch.nn.init
def _mask_input(input, mask=None):
if mask is not None:
input = input * mask
count = torch.sum(mask).data[0]
else:
count = np.prod(input.size(), dtype=np.float32).item()
return input, count
class RelLoss(nn.Module):
def forward(self, input, target, mask=None):
loss = torch.abs(input - target) / target
loss, count = _mask_input(loss, mask)
return torch.sum(loss) / count
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.triton_helpers import math as tl_math
import numpy as np
import torch.nn as nn
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_abs_div_sub_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)
tmp1 = tl.load(in_ptr1 + x0, xmask)
tmp2 = tmp0 - tmp1
tmp3 = tl_math.abs(tmp2)
tmp4 = tmp3 / tmp1
tl.store(out_ptr0 + x0, tmp4, 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, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_abs_div_sub_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,
def _mask_input(input, mask=None):
if mask is not None:
input = input * mask
count = torch.sum(mask).data[0]
else:
count = np.prod(input.size(), dtype=np.float32).item()
return input, count
class RelLossNew(nn.Module):
def forward(self, input_0, input_1):
arg0_1 = input_0
arg1_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
simonmeister/pytorch-mono-depth
|
RelLoss
| false
| 16,446
|
[
"MIT"
] | 56
|
713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
https://github.com/simonmeister/pytorch-mono-depth/tree/713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
MergeModule
|
import torch
import torch.nn as nn
class NormAttnMap(nn.Module):
def __init__(self, norm_type='cossim'):
super(NormAttnMap, self).__init__()
self.norm_type = norm_type
def forward(self, attn_map):
if self.norm_type != 'cosssim':
norm = torch.max(attn_map, dim=1, keepdim=True)[0].detach()
else:
norm = torch.max(torch.abs(attn_map), dim=1, keepdim=True)[0
].detach()
norm[norm <= 1] = 1
attn = attn_map / norm
return attn, norm
class MergeModule(nn.Module):
def __init__(self, norm_type='cossim', need_norm=True):
super(MergeModule, self).__init__()
self.norm_type = norm_type
self.need_norm = need_norm
self.norm_fun = NormAttnMap(norm_type)
def forward(self, attn_map, global_sub_attn_maps, global_obj_attn_maps,
mask_sub, mask_obj):
bs, num_seq, n = global_sub_attn_maps.size(0
), global_sub_attn_maps.size(1), global_sub_attn_maps.size(2)
mask_sub_expand = (mask_sub == 1).float().unsqueeze(2).expand(bs,
num_seq, n)
sub_attn_map_sum = torch.sum(mask_sub_expand * global_sub_attn_maps,
dim=1)
mask_obj_expand = (mask_obj == 1).float().unsqueeze(2).expand(bs,
num_seq, n)
obj_attn_map_sum = torch.sum(mask_obj_expand * global_obj_attn_maps,
dim=1)
attn_map_sum = sub_attn_map_sum + obj_attn_map_sum + attn_map
if self.need_norm:
attn, _norm = self.norm_fun(attn_map_sum)
else:
attn = attn_map_sum
return attn
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]), 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
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_mul_sum_0(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
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 // 4 % 4
x2 = xindex // 16
x3 = xindex % 16
x4 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr1 + (x3 + 64 * x2), xmask)
tmp6 = tl.load(in_ptr0 + (4 + x1), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr1 + (16 + x3 + 64 * x2), xmask)
tmp12 = tl.load(in_ptr0 + (8 + x1), xmask, eviction_policy='evict_last')
tmp15 = tl.load(in_ptr1 + (32 + x3 + 64 * x2), xmask)
tmp18 = tl.load(in_ptr0 + (12 + x1), xmask, eviction_policy='evict_last')
tmp21 = tl.load(in_ptr1 + (48 + x3 + 64 * x2), xmask)
tmp24 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp27 = tl.load(in_ptr3 + (x3 + 64 * x2), xmask)
tmp29 = tl.load(in_ptr2 + (4 + x1), xmask, eviction_policy='evict_last')
tmp32 = tl.load(in_ptr3 + (16 + x3 + 64 * x2), xmask)
tmp35 = tl.load(in_ptr2 + (8 + x1), xmask, eviction_policy='evict_last')
tmp38 = tl.load(in_ptr3 + (32 + x3 + 64 * x2), xmask)
tmp41 = tl.load(in_ptr2 + (12 + x1), xmask, eviction_policy='evict_last')
tmp44 = tl.load(in_ptr3 + (48 + x3 + 64 * x2), xmask)
tmp1 = 1.0
tmp2 = tmp0 == tmp1
tmp3 = tmp2.to(tl.float32)
tmp5 = tmp3 * tmp4
tmp7 = tmp6 == tmp1
tmp8 = tmp7.to(tl.float32)
tmp10 = tmp8 * tmp9
tmp11 = tmp5 + tmp10
tmp13 = tmp12 == tmp1
tmp14 = tmp13.to(tl.float32)
tmp16 = tmp14 * tmp15
tmp17 = tmp11 + tmp16
tmp19 = tmp18 == tmp1
tmp20 = tmp19.to(tl.float32)
tmp22 = tmp20 * tmp21
tmp23 = tmp17 + tmp22
tmp25 = tmp24 == tmp1
tmp26 = tmp25.to(tl.float32)
tmp28 = tmp26 * tmp27
tmp30 = tmp29 == tmp1
tmp31 = tmp30.to(tl.float32)
tmp33 = tmp31 * tmp32
tmp34 = tmp28 + tmp33
tmp36 = tmp35 == tmp1
tmp37 = tmp36.to(tl.float32)
tmp39 = tmp37 * tmp38
tmp40 = tmp34 + tmp39
tmp42 = tmp41 == tmp1
tmp43 = tmp42.to(tl.float32)
tmp45 = tmp43 * tmp44
tmp46 = tmp40 + tmp45
tmp47 = tmp23 + tmp46
tl.store(out_ptr0 + x4, tmp47, xmask)
@triton.jit
def triton_poi_fused_add_index_put_lift_fresh_max_1(in_out_ptr0, in_ptr0,
in_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, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x0 + 64 * x1), xmask)
tmp3 = tl.load(in_ptr0 + (16 + x0), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr1 + (16 + x0 + 64 * x1), xmask)
tmp7 = tl.load(in_ptr0 + (32 + x0), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr1 + (32 + x0 + 64 * x1), xmask)
tmp11 = tl.load(in_ptr0 + (48 + x0), xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr1 + (48 + x0 + 64 * x1), xmask)
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = triton_helpers.maximum(tmp2, tmp5)
tmp9 = tmp7 + tmp8
tmp10 = triton_helpers.maximum(tmp6, tmp9)
tmp13 = tmp11 + tmp12
tmp14 = triton_helpers.maximum(tmp10, tmp13)
tmp15 = 1.0
tmp16 = tmp14 <= tmp15
tmp17 = tl.where(tmp16, tmp15, tmp14)
tl.store(in_out_ptr0 + x2, tmp17, xmask)
@triton.jit
def triton_poi_fused_add_div_2(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 % 64
x4 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + x4, xmask)
tmp3 = tl.load(in_ptr2 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tmp0 + tmp1
tmp4 = tmp2 / tmp3
tl.store(out_ptr0 + x4, tmp4, xmask)
def call(args):
arg0_1, arg1_1, arg2_1, arg3_1, arg4_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, 1))
assert_size_stride(arg2_1, (4, 4), (4, 1))
assert_size_stride(arg3_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(arg4_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)
get_raw_stream(0)
triton_poi_fused_add_mul_sum_0[grid(64)](arg1_1, arg0_1, arg2_1,
arg3_1, buf0, 64, XBLOCK=64, num_warps=1, num_stages=1)
del arg0_1
del arg1_1
del arg2_1
del arg3_1
buf1 = empty_strided_cuda((4, 1, 4, 4), (16, 64, 4, 1), torch.float32)
buf2 = buf1
del buf1
triton_poi_fused_add_index_put_lift_fresh_max_1[grid(64)](buf2,
buf0, arg4_1, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_div_2[grid(256)](buf0, arg4_1, buf2, buf3, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del arg4_1
del buf0
del buf2
return buf3,
class NormAttnMap(nn.Module):
def __init__(self, norm_type='cossim'):
super(NormAttnMap, self).__init__()
self.norm_type = norm_type
def forward(self, attn_map):
if self.norm_type != 'cosssim':
norm = torch.max(attn_map, dim=1, keepdim=True)[0].detach()
else:
norm = torch.max(torch.abs(attn_map), dim=1, keepdim=True)[0
].detach()
norm[norm <= 1] = 1
attn = attn_map / norm
return attn, norm
class MergeModuleNew(nn.Module):
def __init__(self, norm_type='cossim', need_norm=True):
super(MergeModuleNew, self).__init__()
self.norm_type = norm_type
self.need_norm = need_norm
self.norm_fun = NormAttnMap(norm_type)
def forward(self, input_0, input_1, input_2, input_3, input_4):
arg0_1 = input_0
arg3_1 = input_1
arg4_1 = input_2
arg1_1 = input_3
arg2_1 = input_4
output = call([arg0_1, arg1_1, arg2_1, arg3_1, arg4_1])
return output[0]
|
sibeiyang/sgmn
|
MergeModule
| false
| 16,447
|
[
"MIT"
] | 130
|
00731b4f2202246d40a36d2a6727c599e6e649aa
|
https://github.com/sibeiyang/sgmn/tree/00731b4f2202246d40a36d2a6727c599e6e649aa
|
GSympNet
|
from torch.nn import Module
import torch
import torch.nn as nn
class Module(torch.nn.Module):
"""Standard module format.
"""
def __init__(self):
super(Module, self).__init__()
self.activation = None
self.initializer = None
self.__device = None
self.__dtype = None
@property
def device(self):
return self.__device
@property
def dtype(self):
return self.__dtype
@device.setter
def device(self, d):
if d == 'cpu':
self.cpu()
elif d == 'gpu':
self
else:
raise ValueError
self.__device = d
@dtype.setter
def dtype(self, d):
if d == 'float':
self
elif d == 'double':
self
else:
raise ValueError
self.__dtype = d
@property
def Device(self):
if self.__device == 'cpu':
return torch.device('cpu')
elif self.__device == 'gpu':
return torch.device('cuda')
@property
def Dtype(self):
if self.__dtype == 'float':
return torch.float32
elif self.__dtype == 'double':
return torch.float64
@property
def act(self):
if self.activation == 'sigmoid':
return torch.sigmoid
elif self.activation == 'relu':
return torch.relu
elif self.activation == 'tanh':
return torch.tanh
elif self.activation == 'elu':
return torch.elu
else:
raise NotImplementedError
@property
def Act(self):
if self.activation == 'sigmoid':
return torch.nn.Sigmoid()
elif self.activation == 'relu':
return torch.nn.ReLU()
elif self.activation == 'tanh':
return torch.nn.Tanh()
elif self.activation == 'elu':
return torch.nn.ELU()
else:
raise NotImplementedError
@property
def weight_init_(self):
if self.initializer == 'He normal':
return torch.nn.init.kaiming_normal_
elif self.initializer == 'He uniform':
return torch.nn.init.kaiming_uniform_
elif self.initializer == 'Glorot normal':
return torch.nn.init.xavier_normal_
elif self.initializer == 'Glorot uniform':
return torch.nn.init.xavier_uniform_
elif self.initializer == 'orthogonal':
return torch.nn.init.orthogonal_
elif self.initializer == 'default':
if self.activation == 'relu':
return torch.nn.init.kaiming_normal_
elif self.activation == 'tanh':
return torch.nn.init.orthogonal_
else:
return lambda x: None
else:
raise NotImplementedError
class StructureNN(Module):
"""Structure-oriented neural network used as a general map based on designing architecture.
"""
def __init__(self):
super(StructureNN, self).__init__()
def predict(self, x, returnnp=False):
if not isinstance(x, torch.Tensor):
x = torch.tensor(x, dtype=self.Dtype, device=self.Device)
return self(x).cpu().detach().numpy() if returnnp else self(x)
class GradientModule(Module):
"""Gradient symplectic module.
"""
def __init__(self, dim, width, activation, mode):
super(GradientModule, self).__init__()
self.dim = dim
self.width = width
self.activation = activation
self.mode = mode
self.params = self.__init_params()
def forward(self, pqh):
p, q, h = pqh
if self.mode == 'up':
gradH = self.act(q @ self.params['K'] + self.params['b']
) * self.params['a'] @ self.params['K'].t()
return p + gradH * h, q
elif self.mode == 'low':
gradH = self.act(p @ self.params['K'] + self.params['b']
) * self.params['a'] @ self.params['K'].t()
return p, gradH * h + q
else:
raise ValueError
def __init_params(self):
d = int(self.dim / 2)
params = nn.ParameterDict()
params['K'] = nn.Parameter((torch.randn([d, self.width]) * 0.01).
requires_grad_(True))
params['a'] = nn.Parameter((torch.randn([self.width]) * 0.01).
requires_grad_(True))
params['b'] = nn.Parameter(torch.zeros([self.width]).requires_grad_
(True))
return params
class SympNet(StructureNN):
def __init__(self):
super(SympNet, self).__init__()
self.dim = None
def predict(self, xh, steps=1, keepinitx=False, returnnp=False):
dim = xh.size(-1)
size = len(xh.size())
if dim == self.dim:
pred = [xh]
for _ in range(steps):
pred.append(self(pred[-1]))
else:
x0, h = xh[..., :-1], xh[..., -1:]
pred = [x0]
for _ in range(steps):
pred.append(self(torch.cat([pred[-1], h], dim=-1)))
if keepinitx:
steps = steps + 1
else:
pred = pred[1:]
res = torch.cat(pred, dim=-1).view([-1, steps, self.dim][2 - size:])
return res.cpu().detach().numpy() if returnnp else res
class GSympNet(SympNet):
"""G-SympNet.
Input: [num, dim] or [num, dim + 1]
Output: [num, dim]
"""
def __init__(self, dim, layers=3, width=20, activation='sigmoid'):
super(GSympNet, self).__init__()
self.dim = dim
self.layers = layers
self.width = width
self.activation = activation
self.modus = self.__init_modules()
def forward(self, pqh):
d = int(self.dim / 2)
if pqh.size(-1) == self.dim + 1:
p, q, h = pqh[..., :d], pqh[..., d:-1], pqh[..., -1:]
elif pqh.size(-1) == self.dim:
p, q, h = pqh[..., :d], pqh[..., d:], torch.ones_like(pqh[..., -1:]
)
else:
raise ValueError
for i in range(self.layers):
GradM = self.modus['GradM{}'.format(i + 1)]
p, q = GradM([p, q, h])
return torch.cat([p, q], dim=-1)
def __init_modules(self):
modules = nn.ModuleDict()
for i in range(self.layers):
mode = 'up' if i % 2 == 0 else 'low'
modules['GradM{}'.format(i + 1)] = GradientModule(self.dim,
self.width, self.activation, mode)
return modules
def get_inputs():
return [torch.rand([4, 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.nn import Module
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_mul_sigmoid_0(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 1280
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 20
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = tl.sigmoid(tmp2)
tmp5 = tmp3 * tmp4
tl.store(out_ptr0 + x2, tmp5, xmask)
@triton.jit
def triton_poi_fused_add_1(in_out_ptr0, in_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_out_ptr0 + x2, xmask)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_2(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
x1 = xindex // 2
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + (2 + x0 + 4 * x1), xmask)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_cat_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
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (2 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr1 + (2 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
tmp9 = tl.where(tmp4, tmp7, tmp8)
tmp10 = tmp0 >= tmp3
tl.full([1], 4, tl.int64)
tmp13 = tl.load(in_ptr2 + (2 * x1 + (-2 + x0)), tmp10 & xmask,
eviction_policy='evict_last', other=0.0)
tmp14 = tl.where(tmp4, tmp9, tmp13)
tl.store(out_ptr0 + x2, tmp14, 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, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (2, 20), (20, 1))
assert_size_stride(primals_3, (20,), (1,))
assert_size_stride(primals_4, (20,), (1,))
assert_size_stride(primals_5, (2, 20), (20, 1))
assert_size_stride(primals_6, (20,), (1,))
assert_size_stride(primals_7, (20,), (1,))
assert_size_stride(primals_8, (2, 20), (20, 1))
assert_size_stride(primals_9, (20,), (1,))
assert_size_stride(primals_10, (20,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 20), (20, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 2), (4, 1), 2),
primals_2, out=buf0)
buf1 = empty_strided_cuda((4, 4, 4, 20), (320, 80, 20, 1), torch.
float32)
get_raw_stream(0)
triton_poi_fused_add_mul_sigmoid_0[grid(1280)](buf0, primals_3,
primals_4, buf1, 1280, XBLOCK=128, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (64, 20), (20, 1), 0),
reinterpret_tensor(primals_2, (20, 2), (1, 20), 0), out=buf2)
buf3 = reinterpret_tensor(buf2, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf2
triton_poi_fused_add_1[grid(128)](buf3, primals_1, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf4 = empty_strided_cuda((64, 20), (20, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (64, 2), (2, 1), 0),
primals_5, out=buf4)
buf5 = empty_strided_cuda((4, 4, 4, 20), (320, 80, 20, 1), torch.
float32)
triton_poi_fused_add_mul_sigmoid_0[grid(1280)](buf4, primals_6,
primals_7, buf5, 1280, XBLOCK=128, num_warps=4, num_stages=1)
buf6 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf5, (64, 20), (20, 1), 0),
reinterpret_tensor(primals_5, (20, 2), (1, 20), 0), out=buf6)
buf7 = reinterpret_tensor(buf6, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf6
triton_poi_fused_add_2[grid(128)](buf7, primals_1, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf8 = empty_strided_cuda((64, 20), (20, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf7, (64, 2), (2, 1), 0),
primals_8, out=buf8)
buf9 = empty_strided_cuda((4, 4, 4, 20), (320, 80, 20, 1), torch.
float32)
triton_poi_fused_add_mul_sigmoid_0[grid(1280)](buf8, primals_9,
primals_10, buf9, 1280, XBLOCK=128, num_warps=4, num_stages=1)
buf10 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf9, (64, 20), (20, 1), 0),
reinterpret_tensor(primals_8, (20, 2), (1, 20), 0), out=buf10)
buf11 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_cat_3[grid(256)](buf3, buf10, buf7, buf11, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del buf10
return (buf11, primals_3, primals_4, primals_6, primals_7, primals_9,
primals_10, buf0, reinterpret_tensor(buf1, (64, 20), (20, 1), 0),
buf4, reinterpret_tensor(primals_5, (20, 2), (1, 20), 0),
reinterpret_tensor(buf5, (64, 20), (20, 1), 0), buf8,
reinterpret_tensor(primals_8, (20, 2), (1, 20), 0),
reinterpret_tensor(buf9, (64, 20), (20, 1), 0), reinterpret_tensor(
buf7, (2, 64), (1, 2), 0), reinterpret_tensor(buf3, (2, 64), (1, 2),
0), primals_2, reinterpret_tensor(primals_1, (2, 64), (1, 4), 2))
class Module(torch.nn.Module):
"""Standard module format.
"""
def __init__(self):
super(Module, self).__init__()
self.activation = None
self.initializer = None
self.__device = None
self.__dtype = None
@property
def device(self):
return self.__device
@property
def dtype(self):
return self.__dtype
@device.setter
def device(self, d):
if d == 'cpu':
self.cpu()
elif d == 'gpu':
self
else:
raise ValueError
self.__device = d
@dtype.setter
def dtype(self, d):
if d == 'float':
self
elif d == 'double':
self
else:
raise ValueError
self.__dtype = d
@property
def Device(self):
if self.__device == 'cpu':
return torch.device('cpu')
elif self.__device == 'gpu':
return torch.device('cuda')
@property
def Dtype(self):
if self.__dtype == 'float':
return torch.float32
elif self.__dtype == 'double':
return torch.float64
@property
def act(self):
if self.activation == 'sigmoid':
return torch.sigmoid
elif self.activation == 'relu':
return torch.relu
elif self.activation == 'tanh':
return torch.tanh
elif self.activation == 'elu':
return torch.elu
else:
raise NotImplementedError
@property
def Act(self):
if self.activation == 'sigmoid':
return torch.nn.Sigmoid()
elif self.activation == 'relu':
return torch.nn.ReLU()
elif self.activation == 'tanh':
return torch.nn.Tanh()
elif self.activation == 'elu':
return torch.nn.ELU()
else:
raise NotImplementedError
@property
def weight_init_(self):
if self.initializer == 'He normal':
return torch.nn.init.kaiming_normal_
elif self.initializer == 'He uniform':
return torch.nn.init.kaiming_uniform_
elif self.initializer == 'Glorot normal':
return torch.nn.init.xavier_normal_
elif self.initializer == 'Glorot uniform':
return torch.nn.init.xavier_uniform_
elif self.initializer == 'orthogonal':
return torch.nn.init.orthogonal_
elif self.initializer == 'default':
if self.activation == 'relu':
return torch.nn.init.kaiming_normal_
elif self.activation == 'tanh':
return torch.nn.init.orthogonal_
else:
return lambda x: None
else:
raise NotImplementedError
class StructureNN(Module):
"""Structure-oriented neural network used as a general map based on designing architecture.
"""
def __init__(self):
super(StructureNN, self).__init__()
def predict(self, x, returnnp=False):
if not isinstance(x, torch.Tensor):
x = torch.tensor(x, dtype=self.Dtype, device=self.Device)
return self(x).cpu().detach().numpy() if returnnp else self(x)
class GradientModule(Module):
"""Gradient symplectic module.
"""
def __init__(self, dim, width, activation, mode):
super(GradientModule, self).__init__()
self.dim = dim
self.width = width
self.activation = activation
self.mode = mode
self.params = self.__init_params()
def forward(self, pqh):
p, q, h = pqh
if self.mode == 'up':
gradH = self.act(q @ self.params['K'] + self.params['b']
) * self.params['a'] @ self.params['K'].t()
return p + gradH * h, q
elif self.mode == 'low':
gradH = self.act(p @ self.params['K'] + self.params['b']
) * self.params['a'] @ self.params['K'].t()
return p, gradH * h + q
else:
raise ValueError
def __init_params(self):
d = int(self.dim / 2)
params = nn.ParameterDict()
params['K'] = nn.Parameter((torch.randn([d, self.width]) * 0.01).
requires_grad_(True))
params['a'] = nn.Parameter((torch.randn([self.width]) * 0.01).
requires_grad_(True))
params['b'] = nn.Parameter(torch.zeros([self.width]).requires_grad_
(True))
return params
class SympNet(StructureNN):
def __init__(self):
super(SympNet, self).__init__()
self.dim = None
def predict(self, xh, steps=1, keepinitx=False, returnnp=False):
dim = xh.size(-1)
size = len(xh.size())
if dim == self.dim:
pred = [xh]
for _ in range(steps):
pred.append(self(pred[-1]))
else:
x0, h = xh[..., :-1], xh[..., -1:]
pred = [x0]
for _ in range(steps):
pred.append(self(torch.cat([pred[-1], h], dim=-1)))
if keepinitx:
steps = steps + 1
else:
pred = pred[1:]
res = torch.cat(pred, dim=-1).view([-1, steps, self.dim][2 - size:])
return res.cpu().detach().numpy() if returnnp else res
class GSympNetNew(SympNet):
"""G-SympNet.
Input: [num, dim] or [num, dim + 1]
Output: [num, dim]
"""
def __init__(self, dim, layers=3, width=20, activation='sigmoid'):
super(GSympNetNew, self).__init__()
self.dim = dim
self.layers = layers
self.width = width
self.activation = activation
self.modus = self.__init_modules()
def __init_modules(self):
modules = nn.ModuleDict()
for i in range(self.layers):
mode = 'up' if i % 2 == 0 else 'low'
modules['GradM{}'.format(i + 1)] = GradientModule(self.dim,
self.width, self.activation, mode)
return modules
def forward(self, input_0):
primals_2 = self.modus.GradM1.params.K
primals_3 = self.modus.GradM1.params.a
primals_4 = self.modus.GradM1.params.b
primals_5 = self.modus.GradM2.params.K
primals_6 = self.modus.GradM2.params.a
primals_7 = self.modus.GradM2.params.b
primals_8 = self.modus.GradM3.params.K
primals_9 = self.modus.GradM3.params.a
primals_10 = self.modus.GradM3.params.b
primals_1 = 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]
|
shushu-qin/deeponet
|
GSympNet
| false
| 16,448
|
[
"Apache-2.0"
] | 140
|
5bbe066279bba055ad80e04c364140363c87634a
|
https://github.com/shushu-qin/deeponet/tree/5bbe066279bba055ad80e04c364140363c87634a
|
_TransitionUp
|
import torch
import torch.nn as nn
import torch.nn.init
class _TransitionUp(nn.Module):
def __init__(self, num_features):
super().__init__()
self.deconv = nn.ConvTranspose2d(num_features, num_features,
kernel_size=3, stride=2, padding=1)
def forward(self, x, skip):
self.deconv.padding = ((x.size(2) - 1) * self.deconv.stride[0] -
skip.size(2) + self.deconv.kernel_size[0] + 1) // 2, ((x.size(3
) - 1) * self.deconv.stride[1] - skip.size(3) + self.deconv.
kernel_size[1] + 1) // 2
up = self.deconv(x, output_size=skip.size())
return torch.cat([up, skip], 1)
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_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
import torch.nn as nn
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_cat_0(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 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
tmp9 = tl.where(tmp4, tmp7, tmp8)
tmp10 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp13 = tl.load(in_ptr2 + (x0 + 16 * (-4 + x1) + 64 * x2), tmp10 &
xmask, other=0.0)
tmp14 = tl.where(tmp4, tmp9, tmp13)
tl.store(out_ptr0 + x3, tmp14, 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, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_4, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_1, primals_3, stride=(2,
2), padding=(3, 3), dilation=(1, 1), transposed=True,
output_padding=(1, 1), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 4, 4), (64, 16, 4, 1))
buf1 = empty_strided_cuda((4, 8, 4, 4), (128, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(512)](buf0, primals_4, primals_2, buf1,
512, XBLOCK=256, num_warps=4, num_stages=1)
del buf0
del primals_2
del primals_4
return buf1, primals_1, primals_3
class _TransitionUpNew(nn.Module):
def __init__(self, num_features):
super().__init__()
self.deconv = nn.ConvTranspose2d(num_features, num_features,
kernel_size=3, stride=2, padding=1)
def forward(self, input_0, input_1):
primals_3 = self.deconv.weight
primals_4 = self.deconv.bias
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
simonmeister/pytorch-mono-depth
|
_TransitionUp
| false
| 16,449
|
[
"MIT"
] | 56
|
713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
https://github.com/simonmeister/pytorch-mono-depth/tree/713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
Downsample
|
import torch
from torch import Tensor
from torch import nn
class Downsample(nn.Module):
def __init__(self, c1, c2, patch_size):
super().__init__()
self.proj = nn.Conv2d(c1, c2, patch_size, patch_size)
def forward(self, x: 'Tensor') ->Tensor:
x = x.permute(0, 3, 1, 2)
x = self.proj(x)
x = x.permute(0, 2, 3, 1)
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'c1': 4, 'c2': 4, 'patch_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 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 = 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
y0 = yindex % 4
y1 = yindex // 4
tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask)
tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_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
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, 1, 16, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(16, 16)](primals_2, buf0, 16,
16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
buf1 = extern_kernels.convolution(reinterpret_tensor(primals_1, (4,
4, 4, 4), (64, 1, 16, 4), 0), buf0, stride=(4, 4), padding=(0,
0), dilation=(1, 1), transposed=False, output_padding=(0, 0),
groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 1, 1), (4, 1, 4, 4))
del buf0
buf2 = reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 16, 16), 0)
del buf1
triton_poi_fused_convolution_1[grid(16)](buf2, primals_3, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_3
return reinterpret_tensor(buf2, (4, 1, 1, 4), (4, 4, 4, 1), 0
), primals_2, reinterpret_tensor(primals_1, (4, 4, 4, 4), (64, 1,
16, 4), 0)
class DownsampleNew(nn.Module):
def __init__(self, c1, c2, patch_size):
super().__init__()
self.proj = nn.Conv2d(c1, c2, patch_size, patch_size)
def forward(self, input_0):
primals_1 = self.proj.weight
primals_3 = self.proj.bias
primals_2 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
sithu31296/image_classification
|
Downsample
| false
| 16,450
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
SAGEConv
|
import torch
import torch.nn.functional as F
import torch.nn as nn
class SAGEConv(nn.Module):
"""
Description
-----------
SAGE convolutional layer.
Parameters
----------
in_features : int
Dimension of input features.
pool_features : int
Dimension of pooling features.
out_features : int
Dimension of output features.
activation : func of torch.nn.functional, optional
Activation function. Default: ``None``.
dropout : float, optional
Rate of dropout. Default: ``0.0``.
mu : float, optional
Hyper-parameter, refer to original paper. Default: ``2.0``.
"""
def __init__(self, in_features, pool_features, out_features, activation
=None, mu=2.0, dropout=0.0):
super(SAGEConv, self).__init__()
self.pool_layer = nn.Linear(in_features, pool_features)
self.linear1 = nn.Linear(pool_features, out_features)
self.linear2 = nn.Linear(pool_features, out_features)
self.activation = activation
self.mu = mu
if dropout > 0.0:
self.dropout = nn.Dropout(dropout)
else:
self.dropout = None
self.reset_parameters()
def reset_parameters(self):
"""Reset parameters."""
if self.activation == F.leaky_relu:
gain = nn.init.calculate_gain('leaky_relu')
else:
gain = nn.init.calculate_gain('relu')
nn.init.xavier_normal_(self.linear1.weight, gain=gain)
nn.init.xavier_normal_(self.linear2.weight, gain=gain)
nn.init.xavier_normal_(self.pool_layer.weight, gain=gain)
def forward(self, x, adj):
"""
Parameters
----------
x : torch.Tensor
Tensor of input features.
adj : torch.SparseTensor
Sparse tensor of adjacency matrix.
Returns
-------
x : torch.Tensor
Output of layer.
"""
x = F.relu(self.pool_layer(x))
x_ = x ** self.mu
x_ = torch.spmm(adj, x_) ** (1 / self.mu)
x = self.linear1(x)
x_ = self.linear2(x_)
x = x + x_
if self.activation is not None:
x = self.activation(x)
if self.dropout is not None:
x = self.dropout(x)
return x
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'in_features': 4, 'pool_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 import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice
import torch.nn.functional as F
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_pow_relu_0(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 = tmp4 * tmp4
tl.store(in_out_ptr0 + x2, tmp4, xmask)
tl.store(out_ptr0 + x2, tmp5, xmask)
@triton.jit
def triton_poi_fused_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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = libdevice.sqrt(tmp0)
tl.store(out_ptr0 + x0, tmp1, xmask)
@triton.jit
def triton_poi_fused_add_2(in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, 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)
tmp4 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp5 = tmp3 + tmp4
tmp6 = tmp2 + tmp5
tl.store(in_out_ptr0 + x2, tmp6, 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), (4, 1))
assert_size_stride(primals_2, (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, (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((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_3, reinterpret_tensor(primals_1, (4, 4),
(1, 4), 0), out=buf0)
del primals_1
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_pow_relu_0[grid(16)](buf1, primals_2, buf2, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_2
buf3 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(primals_4, buf2, out=buf3)
buf4 = buf2
del buf2
triton_poi_fused_pow_1[grid(16)](buf3, buf4, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf1, reinterpret_tensor(primals_5, (4, 4), (1, 4
), 0), out=buf5)
buf6 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.mm(buf4, reinterpret_tensor(primals_7, (4, 4), (1, 4
), 0), out=buf6)
buf7 = buf5
del buf5
triton_poi_fused_add_2[grid(16)](buf7, primals_6, buf6, primals_8,
16, XBLOCK=16, num_warps=1, num_stages=1)
del buf6
del primals_6
del primals_8
return (buf7, primals_3, buf1, buf3, buf4, primals_7, primals_5,
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0))
class SAGEConvNew(nn.Module):
"""
Description
-----------
SAGE convolutional layer.
Parameters
----------
in_features : int
Dimension of input features.
pool_features : int
Dimension of pooling features.
out_features : int
Dimension of output features.
activation : func of torch.nn.functional, optional
Activation function. Default: ``None``.
dropout : float, optional
Rate of dropout. Default: ``0.0``.
mu : float, optional
Hyper-parameter, refer to original paper. Default: ``2.0``.
"""
def __init__(self, in_features, pool_features, out_features, activation
=None, mu=2.0, dropout=0.0):
super(SAGEConvNew, self).__init__()
self.pool_layer = nn.Linear(in_features, pool_features)
self.linear1 = nn.Linear(pool_features, out_features)
self.linear2 = nn.Linear(pool_features, out_features)
self.activation = activation
self.mu = mu
if dropout > 0.0:
self.dropout = nn.Dropout(dropout)
else:
self.dropout = None
self.reset_parameters()
def reset_parameters(self):
"""Reset parameters."""
if self.activation == F.leaky_relu:
gain = nn.init.calculate_gain('leaky_relu')
else:
gain = nn.init.calculate_gain('relu')
nn.init.xavier_normal_(self.linear1.weight, gain=gain)
nn.init.xavier_normal_(self.linear2.weight, gain=gain)
nn.init.xavier_normal_(self.pool_layer.weight, gain=gain)
def forward(self, input_0, input_1):
primals_1 = self.pool_layer.weight
primals_2 = self.pool_layer.bias
primals_3 = self.linear1.weight
primals_6 = self.linear1.bias
primals_4 = self.linear2.weight
primals_8 = self.linear2.bias
primals_5 = input_0
primals_7 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7, primals_8])
return output[0]
|
sigeisler/grb
|
SAGEConv
| false
| 16,451
|
[
"MIT"
] | 51
|
c89e21076dc05d1edb87dfe2eff20c29ba6bd0c1
|
https://github.com/sigeisler/grb/tree/c89e21076dc05d1edb87dfe2eff20c29ba6bd0c1
|
GCNConv
|
import torch
import torch.nn.functional as F
import torch.nn as nn
class GCNConv(nn.Module):
"""
Description
-----------
GCN convolutional layer.
Parameters
----------
in_features : int
Dimension of input features.
out_features : int
Dimension of output features.
activation : func of torch.nn.functional, optional
Activation function. Default: ``None``.
residual : bool, optional
Whether to use residual connection. Default: ``False``.
dropout : float, optional
Dropout rate during training. Default: ``0.0``.
"""
def __init__(self, in_features, out_features, activation=None, residual
=False, dropout=0.0):
super(GCNConv, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.linear = nn.Linear(in_features, out_features)
if residual:
self.residual = nn.Linear(in_features, out_features)
else:
self.residual = None
self.activation = activation
if dropout > 0.0:
self.dropout = nn.Dropout(dropout)
else:
self.dropout = None
self.reset_parameters()
def reset_parameters(self):
"""Reset parameters."""
if self.activation == F.leaky_relu:
gain = nn.init.calculate_gain('leaky_relu')
else:
gain = nn.init.calculate_gain('relu')
nn.init.xavier_normal_(self.linear.weight, gain=gain)
def forward(self, x, adj):
"""
Parameters
----------
x : torch.Tensor
Tensor of input features.
adj : torch.SparseTensor
Sparse tensor of adjacency matrix.
Returns
-------
x : torch.Tensor
Output of layer.
"""
x = self.linear(x)
x = torch.sparse.mm(adj, x)
if self.activation is not None:
x = self.activation(x)
if self.residual is not None:
x = x + self.residual(x)
if self.dropout is not None:
x = self.dropout(x)
return x
def get_inputs():
return [torch.rand([4, 4]), torch.rand([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
import torch.nn.functional as F
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_zeros_0(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 = 0.0
tl.store(out_ptr0 + x0, tmp0, 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, 1))
assert_size_stride(primals_4, (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.addmm(primals_2, primals_3, 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, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_zeros_0[grid(16)](buf1, 16, XBLOCK=16, num_warps=1,
num_stages=1)
buf2 = torch.ops.aten._sparse_addmm.default(reinterpret_tensor(buf1,
(4, 4), (1, 4), 0), reinterpret_tensor(buf0, (4, 4), (1, 4), 0),
reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), beta=0)
del buf0
del buf1
buf3 = buf2
del buf2
return reinterpret_tensor(buf3, (4, 4), (1, 4), 0), primals_3, primals_4
class GCNConvNew(nn.Module):
"""
Description
-----------
GCN convolutional layer.
Parameters
----------
in_features : int
Dimension of input features.
out_features : int
Dimension of output features.
activation : func of torch.nn.functional, optional
Activation function. Default: ``None``.
residual : bool, optional
Whether to use residual connection. Default: ``False``.
dropout : float, optional
Dropout rate during training. Default: ``0.0``.
"""
def __init__(self, in_features, out_features, activation=None, residual
=False, dropout=0.0):
super(GCNConvNew, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.linear = nn.Linear(in_features, out_features)
if residual:
self.residual = nn.Linear(in_features, out_features)
else:
self.residual = None
self.activation = activation
if dropout > 0.0:
self.dropout = nn.Dropout(dropout)
else:
self.dropout = None
self.reset_parameters()
def reset_parameters(self):
"""Reset parameters."""
if self.activation == F.leaky_relu:
gain = nn.init.calculate_gain('leaky_relu')
else:
gain = nn.init.calculate_gain('relu')
nn.init.xavier_normal_(self.linear.weight, gain=gain)
def forward(self, input_0, input_1):
primals_1 = self.linear.weight
primals_2 = self.linear.bias
primals_3 = input_0
primals_4 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
sigeisler/grb
|
GCNConv
| false
| 16,452
|
[
"MIT"
] | 51
|
c89e21076dc05d1edb87dfe2eff20c29ba6bd0c1
|
https://github.com/sigeisler/grb/tree/c89e21076dc05d1edb87dfe2eff20c29ba6bd0c1
|
localSubNet
|
import torch
import torch.nn as nn
class localSubNet(nn.Module):
def __init__(self, blockDepth=16, convDepth=32, scale=0.25):
super(localSubNet, self).__init__()
self.blockDepth = blockDepth
self.convDepth = convDepth
self.scale = scale
self.net = torch.nn.Sequential()
for i in range(self.blockDepth):
if i != self.blockDepth - 1:
if i == 0:
conv = torch.nn.Conv2d(3, self.convDepth, 3, padding=1)
torch.nn.init.kaiming_normal_(conv.weight)
torch.nn.init.zeros_(conv.bias)
else:
conv = torch.nn.Conv2d(self.convDepth, self.convDepth,
3, padding=1)
torch.nn.init.kaiming_normal_(conv.weight)
torch.nn.init.zeros_(conv.bias)
self.net.add_module('conv%d' % i, conv)
self.net.add_module('leakyRelu%d' % i, torch.nn.LeakyReLU(
inplace=False))
else:
conv = torch.nn.Conv2d(self.convDepth, 3, 3, padding=1)
torch.nn.init.kaiming_normal_(conv.weight)
torch.nn.init.zeros_(conv.bias)
self.net.add_module('conv%d' % i, conv)
self.net.add_module('tanh-out', torch.nn.Tanh())
def forward(self, x):
local_layer = self.net(x) * self.scale
return local_layer
def get_inputs():
return [torch.rand([4, 3, 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.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_convolution_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, 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 // 4096 % 32
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.01
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, None)
tl.store(out_ptr1 + x3, tmp7, None)
@triton.jit
def triton_poi_fused_convolution_mul_tanh_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)
x3 = xindex
x1 = xindex // 4096 % 3
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = libdevice.tanh(tmp2)
tmp4 = 0.25
tmp5 = tmp3 * tmp4
tl.store(in_out_ptr0 + x3, tmp2, None)
tl.store(out_ptr0 + x3, tmp5, None)
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
) = args
args.clear()
assert_size_stride(primals_1, (32, 3, 3, 3), (27, 9, 3, 1))
assert_size_stride(primals_2, (32,), (1,))
assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
assert_size_stride(primals_4, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_5, (32,), (1,))
assert_size_stride(primals_6, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_7, (32,), (1,))
assert_size_stride(primals_8, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_9, (32,), (1,))
assert_size_stride(primals_10, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_11, (32,), (1,))
assert_size_stride(primals_12, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_13, (32,), (1,))
assert_size_stride(primals_14, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_15, (32,), (1,))
assert_size_stride(primals_16, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_17, (32,), (1,))
assert_size_stride(primals_18, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_19, (32,), (1,))
assert_size_stride(primals_20, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_21, (32,), (1,))
assert_size_stride(primals_22, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_23, (32,), (1,))
assert_size_stride(primals_24, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_25, (32,), (1,))
assert_size_stride(primals_26, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_27, (32,), (1,))
assert_size_stride(primals_28, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_29, (32,), (1,))
assert_size_stride(primals_30, (32, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_31, (32,), (1,))
assert_size_stride(primals_32, (3, 32, 3, 3), (288, 9, 3, 1))
assert_size_stride(primals_33, (3,), (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, 32, 64, 64), (131072, 4096, 64, 1))
buf1 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf2 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf0,
primals_2, buf1, buf2, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_2
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, 32, 64, 64), (131072, 4096, 64, 1))
buf4 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf5 = buf0
del buf0
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf3,
primals_5, buf4, buf5, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_5
buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf7 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf8 = buf3
del buf3
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf6,
primals_7, buf7, buf8, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_7
buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf9, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf10 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf11 = buf6
del buf6
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf9,
primals_9, buf10, buf11, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_9
buf12 = extern_kernels.convolution(buf11, primals_10, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf12, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf13 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf14 = buf9
del buf9
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf12,
primals_11, buf13, buf14, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_11
buf15 = extern_kernels.convolution(buf14, primals_12, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf15, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf16 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf17 = buf12
del buf12
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf15,
primals_13, buf16, buf17, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_13
buf18 = extern_kernels.convolution(buf17, primals_14, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf18, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf19 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf20 = buf15
del buf15
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf18,
primals_15, buf19, buf20, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_15
buf21 = extern_kernels.convolution(buf20, primals_16, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf21, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf22 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf23 = buf18
del buf18
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf21,
primals_17, buf22, buf23, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_17
buf24 = extern_kernels.convolution(buf23, primals_18, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf24, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf25 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf26 = buf21
del buf21
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf24,
primals_19, buf25, buf26, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_19
buf27 = extern_kernels.convolution(buf26, primals_20, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf27, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf28 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf29 = buf24
del buf24
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf27,
primals_21, buf28, buf29, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_21
buf30 = extern_kernels.convolution(buf29, primals_22, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf30, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf31 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf32 = buf27
del buf27
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf30,
primals_23, buf31, buf32, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_23
buf33 = extern_kernels.convolution(buf32, primals_24, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf33, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf34 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf35 = buf30
del buf30
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf33,
primals_25, buf34, buf35, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_25
buf36 = extern_kernels.convolution(buf35, primals_26, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf36, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf37 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf38 = buf33
del buf33
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf36,
primals_27, buf37, buf38, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_27
buf39 = extern_kernels.convolution(buf38, primals_28, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf39, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf40 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf41 = buf36
del buf36
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf39,
primals_29, buf40, buf41, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_29
buf42 = extern_kernels.convolution(buf41, primals_30, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf42, (4, 32, 64, 64), (131072, 4096, 64, 1))
buf43 = empty_strided_cuda((4, 32, 64, 64), (131072, 4096, 64, 1),
torch.bool)
buf44 = buf39
del buf39
triton_poi_fused_convolution_leaky_relu_0[grid(524288)](buf42,
primals_31, buf43, buf44, 524288, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf42
del primals_31
buf45 = extern_kernels.convolution(buf44, primals_32, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf45, (4, 3, 64, 64), (12288, 4096, 64, 1))
buf46 = buf45
del buf45
buf47 = empty_strided_cuda((4, 3, 64, 64), (12288, 4096, 64, 1),
torch.float32)
triton_poi_fused_convolution_mul_tanh_1[grid(49152)](buf46,
primals_33, buf47, 49152, XBLOCK=256, num_warps=4, num_stages=1)
del primals_33
return (buf47, primals_1, primals_3, primals_4, primals_6, primals_8,
primals_10, primals_12, primals_14, primals_16, primals_18,
primals_20, primals_22, primals_24, primals_26, primals_28,
primals_30, primals_32, 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)
class localSubNetNew(nn.Module):
def __init__(self, blockDepth=16, convDepth=32, scale=0.25):
super(localSubNetNew, self).__init__()
self.blockDepth = blockDepth
self.convDepth = convDepth
self.scale = scale
self.net = torch.nn.Sequential()
for i in range(self.blockDepth):
if i != self.blockDepth - 1:
if i == 0:
conv = torch.nn.Conv2d(3, self.convDepth, 3, padding=1)
torch.nn.init.kaiming_normal_(conv.weight)
torch.nn.init.zeros_(conv.bias)
else:
conv = torch.nn.Conv2d(self.convDepth, self.convDepth,
3, padding=1)
torch.nn.init.kaiming_normal_(conv.weight)
torch.nn.init.zeros_(conv.bias)
self.net.add_module('conv%d' % i, conv)
self.net.add_module('leakyRelu%d' % i, torch.nn.LeakyReLU(
inplace=False))
else:
conv = torch.nn.Conv2d(self.convDepth, 3, 3, padding=1)
torch.nn.init.kaiming_normal_(conv.weight)
torch.nn.init.zeros_(conv.bias)
self.net.add_module('conv%d' % i, conv)
self.net.add_module('tanh-out', torch.nn.Tanh())
def forward(self, input_0):
primals_1 = self.net.conv0.weight
primals_2 = self.net.conv0.bias
primals_4 = self.net.conv1.weight
primals_5 = self.net.conv1.bias
primals_6 = self.net.conv2.weight
primals_7 = self.net.conv2.bias
primals_8 = self.net.conv3.weight
primals_9 = self.net.conv3.bias
primals_10 = self.net.conv4.weight
primals_11 = self.net.conv4.bias
primals_12 = self.net.conv5.weight
primals_13 = self.net.conv5.bias
primals_14 = self.net.conv6.weight
primals_15 = self.net.conv6.bias
primals_16 = self.net.conv7.weight
primals_17 = self.net.conv7.bias
primals_18 = self.net.conv8.weight
primals_19 = self.net.conv8.bias
primals_20 = self.net.conv9.weight
primals_21 = self.net.conv9.bias
primals_22 = self.net.conv10.weight
primals_23 = self.net.conv10.bias
primals_24 = self.net.conv11.weight
primals_25 = self.net.conv11.bias
primals_26 = self.net.conv12.weight
primals_27 = self.net.conv12.bias
primals_28 = self.net.conv13.weight
primals_29 = self.net.conv13.bias
primals_30 = self.net.conv14.weight
primals_31 = self.net.conv14.bias
primals_32 = self.net.conv15.weight
primals_33 = self.net.conv15.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])
return output[0]
|
shir-barzel-healthy/CIE_XYZ_NET
|
localSubNet
| false
| 16,453
|
[
"MIT"
] | 64
|
9aabf5222dd81efa518233340dc3313177927e27
|
https://github.com/shir-barzel-healthy/CIE_XYZ_NET/tree/9aabf5222dd81efa518233340dc3313177927e27
|
GRUStep
|
import torch
import torch.nn as nn
class GRUStep(nn.Module):
def __init__(self, hidden_size, input_size):
super(GRUStep, self).__init__()
"""GRU module"""
self.linear_z = nn.Linear(hidden_size + input_size, hidden_size,
bias=False)
self.linear_r = nn.Linear(hidden_size + input_size, hidden_size,
bias=False)
self.linear_t = nn.Linear(hidden_size + input_size, hidden_size,
bias=False)
def forward(self, h_state, input_):
z = torch.sigmoid(self.linear_z(torch.cat([h_state, input_], -1)))
r = torch.sigmoid(self.linear_r(torch.cat([h_state, input_], -1)))
t = torch.tanh(self.linear_t(torch.cat([r * h_state, input_], -1)))
h_state = (1 - z) * h_state + z * t
return h_state
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'hidden_size': 4, '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.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, 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
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_cat_1(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 % 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 = tl.sigmoid(tmp5)
tmp7 = tl.load(in_ptr1 + (4 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp8 = tmp6 * tmp7
tmp9 = tl.full(tmp8.shape, 0.0, tmp8.dtype)
tmp10 = tl.where(tmp4, tmp8, tmp9)
tmp11 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp14 = tl.load(in_ptr2 + (4 * x1 + (-4 + x0)), tmp11 & xmask,
eviction_policy='evict_last', other=0.0)
tmp15 = tl.where(tmp4, tmp10, tmp14)
tl.store(out_ptr0 + x2, tmp15, xmask)
@triton.jit
def triton_poi_fused_add_mul_rsub_sigmoid_tanh_2(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)
tmp4 = tl.load(in_ptr1 + x0, xmask)
tmp6 = tl.load(in_ptr2 + x0, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp2 = 1.0
tmp3 = tmp2 - tmp1
tmp5 = tmp3 * tmp4
tmp7 = libdevice.tanh(tmp6)
tmp8 = tmp1 * tmp7
tmp9 = tmp5 + tmp8
tl.store(out_ptr0 + x0, tmp9, 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, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (4, 8), (8, 1))
assert_size_stride(primals_4, (4, 8), (8, 1))
assert_size_stride(primals_5, (4, 8), (8, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(512)](primals_1, primals_2, buf0, 512,
XBLOCK=256, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (64, 8), (8, 1), 0),
reinterpret_tensor(primals_3, (8, 4), (1, 8), 0), out=buf1)
del primals_3
buf2 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf0, (64, 8), (8, 1), 0),
reinterpret_tensor(primals_4, (8, 4), (1, 8), 0), out=buf2)
del primals_4
buf3 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32)
triton_poi_fused_cat_1[grid(512)](buf2, primals_1, primals_2, buf3,
512, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (64, 8), (8, 1), 0),
reinterpret_tensor(primals_5, (8, 4), (1, 8), 0), out=buf4)
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_rsub_sigmoid_tanh_2[grid(256)](buf1,
primals_1, buf4, buf5, 256, XBLOCK=128, num_warps=4, num_stages=1)
return buf5, primals_1, reinterpret_tensor(buf0, (64, 8), (8, 1), 0
), buf1, buf2, reinterpret_tensor(buf3, (64, 8), (8, 1), 0
), buf4, primals_5
class GRUStepNew(nn.Module):
def __init__(self, hidden_size, input_size):
super(GRUStepNew, self).__init__()
"""GRU module"""
self.linear_z = nn.Linear(hidden_size + input_size, hidden_size,
bias=False)
self.linear_r = nn.Linear(hidden_size + input_size, hidden_size,
bias=False)
self.linear_t = nn.Linear(hidden_size + input_size, hidden_size,
bias=False)
def forward(self, input_0, input_1):
primals_3 = self.linear_z.weight
primals_4 = self.linear_r.weight
primals_5 = self.linear_t.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
siyangZhao/BAMnet
|
GRUStep
| false
| 16,454
|
[
"Apache-2.0"
] | 170
|
4c6222610c120a4a114daf40938219ea0ca57dc6
|
https://github.com/siyangZhao/BAMnet/tree/4c6222610c120a4a114daf40938219ea0ca57dc6
|
AgreementRouting
|
import torch
import torch.nn as nn
import torch.nn.functional as F
def squash(x):
lengths2 = x.pow(2).sum(dim=2)
lengths = lengths2.sqrt()
x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1)
return x
class AgreementRouting(nn.Module):
def __init__(self, input_caps, output_caps, n_iterations):
super(AgreementRouting, self).__init__()
self.n_iterations = n_iterations
self.b = nn.Parameter(torch.zeros((input_caps, output_caps)))
def forward(self, u_predict):
batch_size, input_caps, output_caps, _output_dim = u_predict.size()
c = F.softmax(self.b, dim=1)
s = (c.unsqueeze(2) * u_predict).sum(dim=1)
v = squash(s)
if self.n_iterations > 0:
b_batch = self.b.expand((batch_size, input_caps, output_caps))
for r in range(self.n_iterations):
v = v.unsqueeze(1)
b_batch = b_batch + (u_predict * v).sum(-1)
c = F.softmax(b_batch.view(-1, output_caps), dim=1).view(-1,
input_caps, output_caps, 1)
s = (c * u_predict).sum(dim=1)
v = squash(s)
return v
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_caps': 4, 'output_caps': 4, 'n_iterations': 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, 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_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_poi_fused_mul_sum_2(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
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex % 16
x4 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + (x3 + 64 * x2), xmask)
tmp3 = tl.load(in_ptr0 + (4 + x1), xmask, eviction_policy='evict_last')
tmp4 = tl.load(in_ptr1 + (16 + x3 + 64 * x2), xmask)
tmp7 = tl.load(in_ptr0 + (8 + x1), xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_ptr1 + (32 + x3 + 64 * x2), xmask)
tmp11 = tl.load(in_ptr0 + (12 + x1), xmask, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr1 + (48 + x3 + 64 * x2), xmask)
tmp2 = tmp0 * tmp1
tmp5 = tmp3 * tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 * tmp8
tmp10 = tmp6 + tmp9
tmp13 = tmp11 * tmp12
tmp14 = tmp10 + tmp13
tl.store(out_ptr0 + x4, tmp14, xmask)
@triton.jit
def triton_poi_fused_mul_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
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 = 1.0
tmp13 = tmp11 + tmp12
tmp14 = tmp11 / tmp13
tmp15 = libdevice.sqrt(tmp11)
tmp16 = tmp14 / tmp15
tmp17 = tmp0 * tmp16
tl.store(out_ptr0 + x2, tmp17, xmask)
@triton.jit
def triton_poi_fused_add_mul_sum_4(in_ptr0, in_ptr1, in_ptr2, out_ptr0,
xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex % 16
x4 = xindex
x0 = xindex % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + 4 * x4, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + (4 * x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr1 + (1 + 4 * x4), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy
='evict_last')
tmp8 = tl.load(in_ptr1 + (2 + 4 * x4), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr2 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy
='evict_last')
tmp12 = tl.load(in_ptr1 + (3 + 4 * x4), xmask, eviction_policy='evict_last'
)
tmp13 = tl.load(in_ptr2 + (3 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp3 = tmp1 * tmp2
tmp6 = tmp4 * tmp5
tmp7 = tmp3 + tmp6
tmp10 = tmp8 * tmp9
tmp11 = tmp7 + tmp10
tmp14 = tmp12 * tmp13
tmp15 = tmp11 + tmp14
tmp16 = tmp0 + tmp15
tl.store(out_ptr0 + x4, tmp16, xmask)
@triton.jit
def triton_poi_fused__softmax_5(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_6(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_mul_sum_7(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
x1 = xindex // 4 % 4
x2 = xindex // 16
x3 = xindex % 16
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr1 + (x3 + 64 * x2), xmask)
tmp3 = tl.load(in_ptr0 + (4 + x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr1 + (16 + x3 + 64 * x2), xmask)
tmp7 = tl.load(in_ptr0 + (8 + x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr1 + (32 + x3 + 64 * x2), xmask)
tmp11 = tl.load(in_ptr0 + (12 + x1 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp12 = tl.load(in_ptr1 + (48 + x3 + 64 * x2), xmask)
tmp2 = tmp0 * tmp1
tmp5 = tmp3 * tmp4
tmp6 = tmp2 + tmp5
tmp9 = tmp7 * tmp8
tmp10 = tmp6 + tmp9
tmp13 = tmp11 * tmp12
tmp14 = tmp10 + tmp13
tl.store(out_ptr0 + x4, tmp14, xmask)
@triton.jit
def triton_poi_fused_add_mul_sum_8(in_out_ptr0, in_ptr0, in_ptr1, 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 + 4 * x3, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr1 + (4 * x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (1 + 4 * x3), xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + (1 + 4 * x0 + 16 * x2), xmask, eviction_policy
='evict_last')
tmp8 = tl.load(in_ptr0 + (2 + 4 * x3), xmask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr1 + (2 + 4 * x0 + 16 * x2), xmask, eviction_policy
='evict_last')
tmp12 = tl.load(in_ptr0 + (3 + 4 * x3), xmask, eviction_policy='evict_last'
)
tmp13 = tl.load(in_ptr1 + (3 + 4 * x0 + 16 * x2), xmask,
eviction_policy='evict_last')
tmp3 = tmp1 * tmp2
tmp6 = tmp4 * tmp5
tmp7 = tmp3 + tmp6
tmp10 = tmp8 * tmp9
tmp11 = tmp7 + tmp10
tmp14 = tmp12 * tmp13
tmp15 = tmp11 + tmp14
tmp16 = tmp0 + tmp15
tl.store(in_out_ptr0 + x3, tmp16, 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), (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)](primals_2, buf0, 16, XBLOCK=
16, num_warps=1, num_stages=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
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_mul_sum_2[grid(64)](buf1, primals_1, buf2, 64,
XBLOCK=64, num_warps=1, num_stages=1)
del buf1
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_mul_3[grid(64)](buf2, buf3, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf4 = buf2
del buf2
triton_poi_fused_add_mul_sum_4[grid(64)](primals_2, primals_1, buf3,
buf4, 64, XBLOCK=64, num_warps=1, num_stages=1)
buf5 = reinterpret_tensor(buf3, (16, 4), (4, 1), 0)
del buf3
triton_poi_fused__softmax_5[grid(64)](buf4, buf5, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf6 = empty_strided_cuda((16, 4), (4, 1), torch.float32)
triton_poi_fused__softmax_6[grid(64)](buf5, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf7 = reinterpret_tensor(buf5, (4, 4, 4), (16, 4, 1), 0)
del buf5
triton_poi_fused_mul_sum_7[grid(64)](buf6, primals_1, buf7, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf8 = reinterpret_tensor(buf6, (4, 4, 4), (16, 4, 1), 0)
del buf6
triton_poi_fused_mul_3[grid(64)](buf7, buf8, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf9 = buf4
del buf4
triton_poi_fused_add_mul_sum_8[grid(64)](buf9, primals_1, buf8, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf10 = reinterpret_tensor(buf8, (16, 4), (4, 1), 0)
del buf8
triton_poi_fused__softmax_5[grid(64)](buf9, buf10, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf11 = reinterpret_tensor(buf7, (16, 4), (4, 1), 0)
del buf7
triton_poi_fused__softmax_6[grid(64)](buf10, buf11, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf12 = reinterpret_tensor(buf10, (4, 4, 4), (16, 4, 1), 0)
del buf10
triton_poi_fused_mul_sum_7[grid(64)](buf11, primals_1, buf12, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf13 = reinterpret_tensor(buf11, (4, 4, 4), (16, 4, 1), 0)
del buf11
triton_poi_fused_mul_3[grid(64)](buf12, buf13, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf14 = buf9
del buf9
triton_poi_fused_add_mul_sum_8[grid(64)](buf14, primals_1, buf13,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf15 = reinterpret_tensor(buf13, (16, 4), (4, 1), 0)
del buf13
triton_poi_fused__softmax_5[grid(64)](buf14, buf15, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf16 = reinterpret_tensor(buf12, (16, 4), (4, 1), 0)
del buf12
triton_poi_fused__softmax_6[grid(64)](buf15, buf16, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf17 = reinterpret_tensor(buf15, (4, 4, 4), (16, 4, 1), 0)
del buf15
triton_poi_fused_mul_sum_7[grid(64)](buf16, primals_1, buf17, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf18 = reinterpret_tensor(buf16, (4, 4, 4), (16, 4, 1), 0)
del buf16
triton_poi_fused_mul_3[grid(64)](buf17, buf18, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf17
buf19 = buf14
del buf14
triton_poi_fused_add_mul_sum_8[grid(64)](buf19, primals_1, buf18,
64, XBLOCK=64, num_warps=1, num_stages=1)
buf20 = reinterpret_tensor(buf18, (16, 4), (4, 1), 0)
del buf18
triton_poi_fused__softmax_5[grid(64)](buf19, buf20, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf21 = reinterpret_tensor(buf19, (16, 4), (4, 1), 0)
del buf19
triton_poi_fused__softmax_6[grid(64)](buf20, buf21, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf22 = reinterpret_tensor(buf20, (4, 4, 4), (16, 4, 1), 0)
del buf20
triton_poi_fused_mul_sum_7[grid(64)](buf21, primals_1, buf22, 64,
XBLOCK=64, num_warps=1, num_stages=1)
buf23 = reinterpret_tensor(buf21, (4, 4, 4), (16, 4, 1), 0)
del buf21
triton_poi_fused_mul_3[grid(64)](buf22, buf23, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf22
return buf23, primals_1, primals_2
def squash(x):
lengths2 = x.pow(2).sum(dim=2)
lengths = lengths2.sqrt()
x = x * (lengths2 / (1 + lengths2) / lengths).view(x.size(0), x.size(1), 1)
return x
class AgreementRoutingNew(nn.Module):
def __init__(self, input_caps, output_caps, n_iterations):
super(AgreementRoutingNew, self).__init__()
self.n_iterations = n_iterations
self.b = nn.Parameter(torch.zeros((input_caps, output_caps)))
def forward(self, input_0):
primals_2 = self.b
primals_1 = input_0
output = call([primals_1, primals_2])
return output[0]
|
shwetasrsh/MNIST-baselines
|
AgreementRouting
| false
| 16,455
|
[
"MIT"
] | 61
|
aa888e201a1dddda13e7b278cab8f940d57538db
|
https://github.com/shwetasrsh/MNIST-baselines/tree/aa888e201a1dddda13e7b278cab8f940d57538db
|
_FPNUp
|
import torch
import torch.nn as nn
import torch.nn.init
class _FPNUp(nn.Module):
def __init__(self, num_input_features, skip_channel_adjust=True):
super().__init__()
self.conv_channel_adjust = nn.Conv2d(num_input_features, 256,
kernel_size=1)
self.conv_fusion = nn.Conv2d(256, 256, kernel_size=3, padding=1)
def forward(self, x, skip):
upsample = nn.UpsamplingBilinear2d(size=skip.size()[2:])
x = upsample(x)
skip = self.conv_channel_adjust(skip)
fused = self.conv_fusion(x + skip)
return fused
def get_inputs():
return [torch.rand([4, 256, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_input_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 import triton_helpers
import torch.nn as nn
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_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
y3 = yindex
y0 = yindex % 4
y1 = yindex // 4
tmp0 = tl.load(in_ptr0 + (x2 + 16 * y3), xmask & ymask)
tl.store(out_ptr0 + (y0 + 4 * x2 + 64 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 256
y1 = yindex // 256
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_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)
x1 = xindex // 4 % 4
x0 = xindex % 4
x2 = xindex // 16
x4 = xindex
tmp0 = x1
tmp1 = tmp0.to(tl.float32)
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = 0.0
tmp5 = triton_helpers.maximum(tmp3, tmp4)
tmp6 = tmp5.to(tl.int32)
tmp7 = tl.full([1], 1, tl.int64)
tmp8 = tmp6 + tmp7
tmp9 = tl.full([1], 3, tl.int64)
tmp10 = triton_helpers.minimum(tmp8, tmp9)
tmp11 = x0
tmp12 = tmp11.to(tl.float32)
tmp13 = tmp12 * tmp2
tmp14 = triton_helpers.maximum(tmp13, tmp4)
tmp15 = tmp14.to(tl.int32)
tmp16 = tl.load(in_ptr0 + (tmp15 + 4 * tmp10 + 16 * x2), None,
eviction_policy='evict_last')
tmp17 = tmp15 + tmp7
tmp18 = triton_helpers.minimum(tmp17, tmp9)
tmp19 = tl.load(in_ptr0 + (tmp18 + 4 * tmp10 + 16 * x2), None,
eviction_policy='evict_last')
tmp20 = tmp19 - tmp16
tmp21 = tmp15.to(tl.float32)
tmp22 = tmp14 - tmp21
tmp23 = triton_helpers.maximum(tmp22, tmp4)
tmp24 = triton_helpers.minimum(tmp23, tmp2)
tmp25 = tmp20 * tmp24
tmp26 = tmp16 + tmp25
tmp27 = tl.load(in_ptr0 + (tmp15 + 4 * tmp6 + 16 * x2), None,
eviction_policy='evict_last')
tmp28 = tl.load(in_ptr0 + (tmp18 + 4 * tmp6 + 16 * x2), None,
eviction_policy='evict_last')
tmp29 = tmp28 - tmp27
tmp30 = tmp29 * tmp24
tmp31 = tmp27 + tmp30
tmp32 = tmp26 - tmp31
tmp33 = tmp6.to(tl.float32)
tmp34 = tmp5 - tmp33
tmp35 = triton_helpers.maximum(tmp34, tmp4)
tmp36 = triton_helpers.minimum(tmp35, tmp2)
tmp37 = tmp32 * tmp36
tmp38 = tmp31 + tmp37
tl.store(in_out_ptr0 + x4, tmp38, None)
@triton.jit
def triton_poi_fused_add_convolution_3(in_out_ptr0, in_ptr0, in_ptr1,
ynumel, xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 64
xnumel = 256
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 + 4096 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_out_ptr0 + (x2 + 256 * y3), xmask & ymask,
eviction_policy='evict_last')
tmp2 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tmp0 + tmp3
tl.debug_barrier()
tl.store(in_out_ptr0 + (x2 + 256 * y3), tmp4, xmask & ymask)
@triton.jit
def triton_poi_fused_convolution_4(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 256
y1 = yindex // 256
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 256 * x2 + 4096 * y1), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, 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, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (4, 256, 4, 4), (4096, 16, 4, 1))
assert_size_stride(primals_3, (256, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_4, (256,), (1,))
assert_size_stride(primals_5, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_6, (256,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
get_raw_stream(0)
triton_poi_fused_0[grid(16, 16)](primals_1, buf0, 16, 16, XBLOCK=16,
YBLOCK=16, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_1[grid(65536, 9)](primals_5, buf1, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_5
buf2 = empty_strided_cuda((4, 256, 4, 4), (4096, 16, 4, 1), torch.
float32)
buf3 = buf2
del buf2
triton_poi_fused__to_copy__unsafe_index_add_arange_clamp_mul_sub_2[grid
(16384)](buf3, primals_2, 16384, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_2
buf4 = extern_kernels.convolution(buf0, 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, 256, 4, 4), (4096, 1, 1024, 256))
buf5 = buf4
del buf4
triton_poi_fused_add_convolution_3[grid(64, 256)](buf5, buf3,
primals_4, 64, 256, XBLOCK=256, YBLOCK=1, num_warps=4, num_stages=1
)
del primals_4
buf6 = extern_kernels.convolution(buf5, buf1, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 256, 4, 4), (4096, 1, 1024, 256))
buf7 = buf3
del buf3
triton_poi_fused_convolution_4[grid(1024, 16)](buf6, primals_6,
buf7, 1024, 16, XBLOCK=16, YBLOCK=16, num_warps=4, num_stages=1)
del buf6
del primals_6
return buf7, buf0, primals_3, buf1, buf5
class _FPNUpNew(nn.Module):
def __init__(self, num_input_features, skip_channel_adjust=True):
super().__init__()
self.conv_channel_adjust = nn.Conv2d(num_input_features, 256,
kernel_size=1)
self.conv_fusion = nn.Conv2d(256, 256, kernel_size=3, padding=1)
def forward(self, input_0, input_1):
primals_3 = self.conv_channel_adjust.weight
primals_4 = self.conv_channel_adjust.bias
primals_5 = self.conv_fusion.weight
primals_6 = self.conv_fusion.bias
primals_2 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
simonmeister/pytorch-mono-depth
|
_FPNUp
| false
| 16,456
|
[
"MIT"
] | 56
|
713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
https://github.com/simonmeister/pytorch-mono-depth/tree/713c70e2fdae6d9d6e0322febadfedcaee9470d3
|
TAGConv
|
import torch
import torch.nn.functional as F
import torch.nn as nn
class TAGConv(nn.Module):
"""
Description
-----------
TAGCN convolutional layer.
Parameters
----------
in_features : int
Dimension of input features.
out_features : int
Dimension of output features.
k : int, optional
Hyper-parameter, refer to original paper. Default: ``2``.
activation : func of torch.nn.functional, optional
Activation function. Default: ``None``.
batch_norm : bool, optional
Whether to apply batch normalization. Default: ``False``.
dropout : float, optional
Rate of dropout. Default: ``0.0``.
"""
def __init__(self, in_features, out_features, k=2, activation=None,
batch_norm=False, dropout=0.0):
super(TAGConv, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.linear = nn.Linear(in_features * (k + 1), out_features)
self.batch_norm = batch_norm
if batch_norm:
self.norm_func = nn.BatchNorm1d(out_features, affine=False)
self.activation = activation
if dropout > 0.0:
self.dropout = nn.Dropout(dropout)
else:
self.dropout = None
self.k = k
self.reset_parameters()
def reset_parameters(self):
"""Reset parameters."""
if self.activation == F.leaky_relu:
gain = nn.init.calculate_gain('leaky_relu')
else:
gain = nn.init.calculate_gain('relu')
nn.init.xavier_normal_(self.linear.weight, gain=gain)
def forward(self, x, adj):
"""
Parameters
----------
x : torch.Tensor
Tensor of input features.
adj : torch.SparseTensor
Sparse tensor of adjacency matrix.
Returns
-------
x : torch.Tensor
Output of layer.
"""
fstack = [x]
for i in range(self.k):
y = torch.spmm(adj, fstack[-1])
fstack.append(y)
x = torch.cat(fstack, dim=-1)
x = self.linear(x)
if self.batch_norm:
x = self.norm_func(x)
if self.activation is not None:
x = self.activation(x)
if self.dropout is not None:
x = self.dropout(x)
return x
def get_inputs():
return [torch.rand([4, 4]), torch.rand([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
import torch.nn.functional as F
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):
xnumel = 16
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)
tl.store(out_ptr0 + (x0 + 12 * x1), tmp0, xmask)
@triton.jit
def triton_poi_fused_cat_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
x0 = xindex % 4
x1 = xindex // 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tl.store(out_ptr0 + (x0 + 12 * x1), tmp0, 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, 4), (4, 1))
assert_size_stride(primals_3, (4, 12), (12, 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), torch.float32)
extern_kernels.mm(primals_2, primals_1, out=buf0)
buf4 = empty_strided_cuda((4, 12), (12, 1), torch.float32)
buf1 = reinterpret_tensor(buf4, (4, 4), (12, 1), 8)
extern_kernels.mm(primals_2, buf0, out=buf1)
del primals_2
buf2 = reinterpret_tensor(buf4, (4, 4), (12, 1), 0)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(16)](primals_1, buf2, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_1
buf3 = reinterpret_tensor(buf4, (4, 4), (12, 1), 4)
triton_poi_fused_cat_1[grid(16)](buf0, buf3, 16, XBLOCK=16,
num_warps=1, num_stages=1)
buf5 = buf0
del buf0
extern_kernels.addmm(primals_4, buf4, reinterpret_tensor(primals_3,
(12, 4), (1, 12), 0), alpha=1, beta=1, out=buf5)
del primals_3
del primals_4
return buf5, buf4
class TAGConvNew(nn.Module):
"""
Description
-----------
TAGCN convolutional layer.
Parameters
----------
in_features : int
Dimension of input features.
out_features : int
Dimension of output features.
k : int, optional
Hyper-parameter, refer to original paper. Default: ``2``.
activation : func of torch.nn.functional, optional
Activation function. Default: ``None``.
batch_norm : bool, optional
Whether to apply batch normalization. Default: ``False``.
dropout : float, optional
Rate of dropout. Default: ``0.0``.
"""
def __init__(self, in_features, out_features, k=2, activation=None,
batch_norm=False, dropout=0.0):
super(TAGConvNew, self).__init__()
self.in_features = in_features
self.out_features = out_features
self.linear = nn.Linear(in_features * (k + 1), out_features)
self.batch_norm = batch_norm
if batch_norm:
self.norm_func = nn.BatchNorm1d(out_features, affine=False)
self.activation = activation
if dropout > 0.0:
self.dropout = nn.Dropout(dropout)
else:
self.dropout = None
self.k = k
self.reset_parameters()
def reset_parameters(self):
"""Reset parameters."""
if self.activation == F.leaky_relu:
gain = nn.init.calculate_gain('leaky_relu')
else:
gain = nn.init.calculate_gain('relu')
nn.init.xavier_normal_(self.linear.weight, gain=gain)
def forward(self, input_0, input_1):
primals_3 = self.linear.weight
primals_4 = self.linear.bias
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
sigeisler/grb
|
TAGConv
| false
| 16,457
|
[
"MIT"
] | 51
|
c89e21076dc05d1edb87dfe2eff20c29ba6bd0c1
|
https://github.com/sigeisler/grb/tree/c89e21076dc05d1edb87dfe2eff20c29ba6bd0c1
|
ResNetV2
|
import torch
from torch import nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
import torch.nn
from torch.nn import functional as F
from collections import OrderedDict
def conv1x1(in_planes, out_planes, stride=1):
"""1x1 convolution"""
return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride,
bias=False)
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=1, bias=False)
def tf2th(conv_weights):
"""Possibly convert HWIO to OIHW."""
if conv_weights.ndim == 4:
conv_weights = conv_weights.transpose([3, 2, 0, 1])
return torch.from_numpy(conv_weights)
class StdConv2d(nn.Conv2d):
def forward(self, x):
w = self.weight
v, m = torch.var_mean(w, dim=[1, 2, 3], keepdim=True, unbiased=False)
w = (w - m) / torch.sqrt(v + 1e-10)
return F.conv2d(x, w, self.bias, self.stride, self.padding, self.
dilation, self.groups)
class PreActBottleneck(nn.Module):
"""Pre-activation (v2) bottleneck block.
Follows the implementation of "Identity Mappings in Deep Residual Networks":
https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua
Except it puts the stride on 3x3 conv when available.
"""
def __init__(self, cin, cout=None, cmid=None, stride=1):
super().__init__()
cout = cout or cin
cmid = cmid or cout // 4
self.gn1 = nn.GroupNorm(32, cin)
self.conv1 = conv1x1(cin, cmid)
self.gn2 = nn.GroupNorm(32, cmid)
self.conv2 = conv3x3(cmid, cmid, stride)
self.gn3 = nn.GroupNorm(32, cmid)
self.conv3 = conv1x1(cmid, cout)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or cin != cout:
self.downsample = conv1x1(cin, cout, stride)
def forward(self, x):
out = self.relu(self.gn1(x))
residual = x
if hasattr(self, 'downsample'):
residual = self.downsample(out)
out = self.conv1(out)
out = self.conv2(self.relu(self.gn2(out)))
out = self.conv3(self.relu(self.gn3(out)))
return out + residual
def load_from(self, weights, prefix=''):
convname = 'standardized_conv2d'
with torch.no_grad():
self.conv1.weight.copy_(tf2th(weights[
f'{prefix}a/{convname}/kernel']))
self.conv2.weight.copy_(tf2th(weights[
f'{prefix}b/{convname}/kernel']))
self.conv3.weight.copy_(tf2th(weights[
f'{prefix}c/{convname}/kernel']))
self.gn1.weight.copy_(tf2th(weights[f'{prefix}a/group_norm/gamma'])
)
self.gn2.weight.copy_(tf2th(weights[f'{prefix}b/group_norm/gamma'])
)
self.gn3.weight.copy_(tf2th(weights[f'{prefix}c/group_norm/gamma'])
)
self.gn1.bias.copy_(tf2th(weights[f'{prefix}a/group_norm/beta']))
self.gn2.bias.copy_(tf2th(weights[f'{prefix}b/group_norm/beta']))
self.gn3.bias.copy_(tf2th(weights[f'{prefix}c/group_norm/beta']))
if hasattr(self, 'downsample'):
w = weights[f'{prefix}a/proj/{convname}/kernel']
self.downsample.weight.copy_(tf2th(w))
class ResNetV2(nn.Module):
"""Implementation of Pre-activation (v2) ResNet mode."""
def __init__(self, block_units, width_factor, head_size=21843,
zero_head=False):
super().__init__()
wf = width_factor
self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, 64 *
wf, kernel_size=7, stride=2, padding=3, bias=False)), ('pad',
nn.ConstantPad2d(1, 0)), ('pool', nn.MaxPool2d(kernel_size=3,
stride=2, padding=0))]))
self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential(
OrderedDict([('unit01', PreActBottleneck(cin=64 * wf, cout=256 *
wf, cmid=64 * wf))] + [(f'unit{i:02d}', PreActBottleneck(cin=
256 * wf, cout=256 * wf, cmid=64 * wf)) for i in range(2,
block_units[0] + 1)]))), ('block2', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=256 * wf, cout=512 * wf, cmid=
128 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
512 * wf, cout=512 * wf, cmid=128 * wf)) for i in range(2,
block_units[1] + 1)]))), ('block3', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=512 * wf, cout=1024 * wf, cmid=
256 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
1024 * wf, cout=1024 * wf, cmid=256 * wf)) for i in range(2,
block_units[2] + 1)]))), ('block4', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=1024 * wf, cout=2048 * wf, cmid
=512 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin
=2048 * wf, cout=2048 * wf, cmid=512 * wf)) for i in range(2,
block_units[3] + 1)])))]))
self.zero_head = zero_head
self.head = nn.Sequential(OrderedDict([('gn', nn.GroupNorm(32, 2048 *
wf)), ('relu', nn.ReLU(inplace=True)), ('avg', nn.
AdaptiveAvgPool2d(output_size=1)), ('conv', nn.Conv2d(2048 * wf,
head_size, kernel_size=1, bias=True))]))
def forward(self, x):
x = self.head(self.body(self.root(x)))
assert x.shape[-2:] == (1, 1)
return x[..., 0, 0]
def load_from(self, weights, prefix='resnet/'):
with torch.no_grad():
self.root.conv.weight.copy_(tf2th(weights[
f'{prefix}root_block/standardized_conv2d/kernel']))
self.head.gn.weight.copy_(tf2th(weights[
f'{prefix}group_norm/gamma']))
self.head.gn.bias.copy_(tf2th(weights[f'{prefix}group_norm/beta']))
if self.zero_head:
nn.init.zeros_(self.head.conv.weight)
nn.init.zeros_(self.head.conv.bias)
else:
self.head.conv.weight.copy_(tf2th(weights[
f'{prefix}head/conv2d/kernel']))
self.head.conv.bias.copy_(tf2th(weights[
f'{prefix}head/conv2d/bias']))
for bname, block in self.body.named_children():
for uname, unit in block.named_children():
unit.load_from(weights, prefix=f'{prefix}{bname}/{uname}/')
def get_inputs():
return [torch.rand([4, 3, 64, 64])]
def get_init_inputs():
return [[], {'block_units': [4, 4, 4, 4], 'width_factor': 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
from torch import nn
import torch.nn.parallel
import torch.optim
import torch.utils.data
import torch.utils.data.distributed
import torch.nn
from torch.nn import functional as F
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 768
xnumel = 49
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
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 49 * y3), xmask & ymask, eviction_policy
='evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 147 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 12
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]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_2(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 256
y1 = yindex // 256
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 256 * x2 + 2304 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_3(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 512
y1 = yindex // 512
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 512 * x2 + 4608 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_4(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 1024
y1 = yindex // 1024
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 1024 * x2 + 9216 * y1), tmp0, xmask)
@triton.jit
def triton_poi_fused_5(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
xnumel = 9
yoffset = (tl.program_id(1) + tl.program_id(2) * tl.num_programs(1)
) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y3 = yindex
y0 = yindex % 2048
y1 = yindex // 2048
tmp0 = tl.load(in_ptr0 + (x2 + 9 * y3), xmask, eviction_policy='evict_last'
)
tl.store(out_ptr0 + (y0 + 2048 * x2 + 18432 * y1), tmp0, xmask)
@triton.jit
def triton_per_fused_add_div_sqrt_sub_var_mean_6(in_out_ptr0, in_ptr0,
out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 256
rnumel = 147
RBLOCK: tl.constexpr = 256
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rindex = tl.arange(0, RBLOCK)[None, :]
rmask = rindex < rnumel
r1 = rindex
x0 = xindex
tmp0 = tl.load(in_ptr0 + (r1 + 147 * x0), rmask & xmask, other=0.0)
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(rmask & xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(rmask & xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 147, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(rmask & xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = 147.0
tmp18 = tmp16 / tmp17
tmp19 = 1e-10
tmp20 = tmp18 + tmp19
tmp21 = libdevice.sqrt(tmp20)
tmp22 = tmp0 - tmp10
tmp23 = tmp22 / tmp21
tl.debug_barrier()
tl.store(in_out_ptr0 + x0, tmp21, xmask)
tl.store(out_ptr1 + (r1 + 147 * x0), tmp23, rmask & xmask)
@triton.jit
def triton_poi_fused_constant_pad_nd_7(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 // 8704 % 34
x1 = xindex // 256 % 34
x3 = xindex // 295936
x4 = xindex % 8704
x6 = xindex
tmp0 = -1 + x2
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 32, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = -1 + x1
tmp6 = tmp5 >= tmp1
tmp7 = tmp5 < tmp3
tmp8 = tmp2 & tmp4
tmp9 = tmp8 & tmp6
tmp10 = tmp9 & tmp7
tmp11 = tl.load(in_ptr0 + (-8448 + x4 + 8192 * x2 + 262144 * x3), tmp10,
other=0.0)
tl.store(out_ptr0 + x6, tmp11, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_8(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 256
x1 = xindex // 256 % 16
x2 = xindex // 4096 % 16
x3 = xindex // 65536
x4 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 512 * x1 + 17408 * x2 + 295936 * x3), None)
tmp1 = tl.load(in_ptr0 + (256 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp3 = tl.load(in_ptr0 + (512 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp5 = tl.load(in_ptr0 + (8704 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp7 = tl.load(in_ptr0 + (8960 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp9 = tl.load(in_ptr0 + (9216 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp11 = tl.load(in_ptr0 + (17408 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp13 = tl.load(in_ptr0 + (17664 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
tmp15 = tl.load(in_ptr0 + (17920 + x0 + 512 * x1 + 17408 * x2 + 295936 *
x3), None)
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)
tmp17 = tmp1 > tmp0
tmp18 = tl.full([1], 1, tl.int8)
tmp19 = tl.full([1], 0, tl.int8)
tmp20 = tl.where(tmp17, tmp18, tmp19)
tmp21 = tmp3 > tmp2
tmp22 = tl.full([1], 2, tl.int8)
tmp23 = tl.where(tmp21, tmp22, tmp20)
tmp24 = tmp5 > tmp4
tmp25 = tl.full([1], 3, tl.int8)
tmp26 = tl.where(tmp24, tmp25, tmp23)
tmp27 = tmp7 > tmp6
tmp28 = tl.full([1], 4, tl.int8)
tmp29 = tl.where(tmp27, tmp28, tmp26)
tmp30 = tmp9 > tmp8
tmp31 = tl.full([1], 5, tl.int8)
tmp32 = tl.where(tmp30, tmp31, tmp29)
tmp33 = tmp11 > tmp10
tmp34 = tl.full([1], 6, tl.int8)
tmp35 = tl.where(tmp33, tmp34, tmp32)
tmp36 = tmp13 > tmp12
tmp37 = tl.full([1], 7, tl.int8)
tmp38 = tl.where(tmp36, tmp37, tmp35)
tmp39 = tmp15 > tmp14
tmp40 = tl.full([1], 8, tl.int8)
tmp41 = tl.where(tmp39, tmp40, tmp38)
tl.store(out_ptr0 + x4, tmp16, None)
tl.store(out_ptr1 + x4, tmp41, None)
@triton.jit
def triton_red_fused_native_group_norm_9(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 8
r3 = rindex // 8
tmp0 = tl.load(in_ptr0 + (r2 + 8 * x0 + 256 * r3 + 65536 * x1),
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_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_10(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)
x3 = xindex
x0 = xindex % 256
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 8), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 8), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 2048.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_11(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)
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_red_fused_native_group_norm_12(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 % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 32
r3 = rindex // 32
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 262144 * x1),
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_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 8192.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_13(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)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 262144
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 8192.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_14(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)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_red_fused_native_group_norm_15(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 16
r3 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * r3 + 131072 * x1),
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_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 4096.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_16(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)
x3 = xindex
x0 = xindex % 512
x2 = xindex // 131072
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 4096.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_per_fused_native_group_norm_17(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
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)
r2 = rindex % 16
r3 = rindex // 16
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 16 * x0 + 512 * r3 + 32768 * x1), None)
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], 1024, 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 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_18(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)
x3 = xindex
x0 = xindex % 512
x2 = xindex // 32768
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 16), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1024.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_19(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)
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_red_fused_native_group_norm_20(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 4096
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 64
r3 = rindex // 64
tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 131072 * x1),
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_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 4096.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_21(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)
x3 = xindex
x0 = xindex % 2048
x2 = xindex // 131072
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 4096.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_22(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)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_red_fused_native_group_norm_23(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 32
r3 = rindex // 32
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 65536 * x1),
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_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_24(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)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 2048.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_per_fused_native_group_norm_25(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 512
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)
r2 = rindex % 32
r3 = rindex // 32
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 32 * x0 + 1024 * r3 + 16384 * x1), None)
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], 512, 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 = 512.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_26(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)
x3 = xindex
x0 = xindex % 1024
x2 = xindex // 16384
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 32), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 512.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_27(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)
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_red_fused_native_group_norm_28(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):
xnumel = 128
rnumel = 2048
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
rbase = tl.arange(0, RBLOCK)[None, :]
x0 = xindex % 32
x1 = xindex // 32
tmp2_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)
tmp2_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)
x4 = xindex
for roffset in range(0, rnumel, RBLOCK):
rindex = roffset + rbase
rmask = rindex < rnumel
r2 = rindex % 128
r3 = rindex // 128
tmp0 = tl.load(in_ptr0 + (r2 + 128 * x0 + 4096 * r3 + 65536 * x1),
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_tmp[:, None]
tl.store(out_ptr0 + x4, tmp2, xmask)
tl.store(out_ptr1 + x4, tmp3, xmask)
tmp5 = 2048.0
tmp6 = tmp3 / tmp5
tmp7 = 1e-05
tmp8 = tmp6 + tmp7
tmp9 = libdevice.rsqrt(tmp8)
tl.store(out_ptr2 + x4, tmp9, xmask)
@triton.jit
def triton_poi_fused_native_group_norm_relu_29(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)
x3 = xindex
x0 = xindex % 4096
x2 = xindex // 65536
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 128), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 2048.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_30(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)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_per_fused_native_group_norm_31(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
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)
r2 = rindex % 64
r3 = rindex // 64
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 32768 * x1), None)
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], 1024, 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 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_32(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)
x3 = xindex
x0 = xindex % 2048
x2 = xindex // 32768
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1024.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_per_fused_native_group_norm_33(in_ptr0, 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)
r2 = rindex % 64
r3 = rindex // 64
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 64 * x0 + 2048 * r3 + 8192 * x1), None)
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)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_34(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)
x3 = xindex
x0 = xindex % 2048
x2 = xindex // 8192
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 64), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 256.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_35(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)
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, None)
tmp1 = tl.load(in_out_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_per_fused_native_group_norm_36(in_ptr0, out_ptr0, out_ptr1,
out_ptr2, xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
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)
r2 = rindex % 256
r3 = rindex // 256
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 256 * x0 + 8192 * r3 + 32768 * x1), None)
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], 1024, 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 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.store(out_ptr2 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
tl.store(out_ptr1 + x4, tmp13, None)
@triton.jit
def triton_poi_fused_native_group_norm_relu_37(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)
x3 = xindex
x0 = xindex % 8192
x2 = xindex // 32768
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (32 * x2 + x0 // 256), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr2 + (32 * x2 + x0 // 256), None, eviction_policy=
'evict_last')
tmp10 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp12 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = 1024.0
tmp5 = tmp3 / tmp4
tmp6 = 1e-05
tmp7 = tmp5 + tmp6
tmp8 = libdevice.rsqrt(tmp7)
tmp9 = tmp2 * tmp8
tmp11 = tmp9 * tmp10
tmp13 = tmp11 + tmp12
tmp14 = tl.full([1], 0, tl.int32)
tmp15 = triton_helpers.maximum(tmp14, tmp13)
tl.store(out_ptr0 + x3, tmp15, None)
@triton.jit
def triton_poi_fused_add_38(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)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + x0, None)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x0, tmp2, None)
@triton.jit
def triton_per_fused_native_group_norm_39(in_out_ptr0, in_ptr0, out_ptr0,
xnumel, rnumel):
XBLOCK: tl.constexpr = 1
RBLOCK: tl.constexpr = 1024
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)
r2 = rindex % 256
r3 = rindex // 256
x0 = xindex % 32
x1 = xindex // 32
x4 = xindex
tmp0 = tl.load(in_ptr0 + (r2 + 256 * x0 + 8192 * r3 + 32768 * x1), None)
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], 1024, 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 = 1024.0
tmp15 = tmp13 / tmp14
tmp16 = 1e-05
tmp17 = tmp15 + tmp16
tmp18 = libdevice.rsqrt(tmp17)
tl.debug_barrier()
tl.store(in_out_ptr0 + x4, tmp18, None)
tl.store(out_ptr0 + x4, tmp8, None)
@triton.jit
def triton_poi_fused_mean_native_group_norm_relu_40(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)
x0 = xindex % 8192
x1 = xindex // 8192
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 32768 * x1), None)
tmp1 = tl.load(in_ptr1 + x2 // 256, None, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x2 // 256, None, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x0, None, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x0, None, eviction_policy='evict_last')
tmp11 = tl.load(in_ptr0 + (8192 + x0 + 32768 * x1), None)
tmp18 = tl.load(in_ptr0 + (16384 + x0 + 32768 * x1), None)
tmp25 = tl.load(in_ptr0 + (24576 + x0 + 32768 * x1), None)
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tmp9 = tl.full([1], 0, tl.int32)
tmp10 = triton_helpers.maximum(tmp9, tmp8)
tmp12 = tmp11 - tmp1
tmp13 = tmp12 * tmp3
tmp14 = tmp13 * tmp5
tmp15 = tmp14 + tmp7
tmp16 = triton_helpers.maximum(tmp9, tmp15)
tmp17 = tmp10 + tmp16
tmp19 = tmp18 - tmp1
tmp20 = tmp19 * tmp3
tmp21 = tmp20 * tmp5
tmp22 = tmp21 + tmp7
tmp23 = triton_helpers.maximum(tmp9, tmp22)
tmp24 = tmp17 + tmp23
tmp26 = tmp25 - tmp1
tmp27 = tmp26 * tmp3
tmp28 = tmp27 * tmp5
tmp29 = tmp28 + tmp7
tmp30 = triton_helpers.maximum(tmp9, tmp29)
tmp31 = tmp24 + tmp30
tmp32 = 4.0
tmp33 = tmp31 / tmp32
tl.store(out_ptr0 + x2, tmp33, None)
@triton.jit
def triton_poi_fused_convolution_41(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 87372
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 21843
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,
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) = args
args.clear()
assert_size_stride(primals_1, (256, 3, 7, 7), (147, 49, 7, 1))
assert_size_stride(primals_2, (4, 3, 64, 64), (12288, 4096, 64, 1))
assert_size_stride(primals_3, (256,), (1,))
assert_size_stride(primals_4, (256,), (1,))
assert_size_stride(primals_5, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_6, (256, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_7, (256,), (1,))
assert_size_stride(primals_8, (256,), (1,))
assert_size_stride(primals_9, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_10, (256,), (1,))
assert_size_stride(primals_11, (256,), (1,))
assert_size_stride(primals_12, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_13, (1024,), (1,))
assert_size_stride(primals_14, (1024,), (1,))
assert_size_stride(primals_15, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_16, (256,), (1,))
assert_size_stride(primals_17, (256,), (1,))
assert_size_stride(primals_18, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_19, (256,), (1,))
assert_size_stride(primals_20, (256,), (1,))
assert_size_stride(primals_21, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_22, (1024,), (1,))
assert_size_stride(primals_23, (1024,), (1,))
assert_size_stride(primals_24, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_25, (256,), (1,))
assert_size_stride(primals_26, (256,), (1,))
assert_size_stride(primals_27, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_28, (256,), (1,))
assert_size_stride(primals_29, (256,), (1,))
assert_size_stride(primals_30, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_31, (1024,), (1,))
assert_size_stride(primals_32, (1024,), (1,))
assert_size_stride(primals_33, (256, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_34, (256,), (1,))
assert_size_stride(primals_35, (256,), (1,))
assert_size_stride(primals_36, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_37, (256,), (1,))
assert_size_stride(primals_38, (256,), (1,))
assert_size_stride(primals_39, (1024, 256, 1, 1), (256, 1, 1, 1))
assert_size_stride(primals_40, (1024,), (1,))
assert_size_stride(primals_41, (1024,), (1,))
assert_size_stride(primals_42, (2048, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_43, (512, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_44, (512,), (1,))
assert_size_stride(primals_45, (512,), (1,))
assert_size_stride(primals_46, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_47, (512,), (1,))
assert_size_stride(primals_48, (512,), (1,))
assert_size_stride(primals_49, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_50, (2048,), (1,))
assert_size_stride(primals_51, (2048,), (1,))
assert_size_stride(primals_52, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_53, (512,), (1,))
assert_size_stride(primals_54, (512,), (1,))
assert_size_stride(primals_55, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_56, (512,), (1,))
assert_size_stride(primals_57, (512,), (1,))
assert_size_stride(primals_58, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_59, (2048,), (1,))
assert_size_stride(primals_60, (2048,), (1,))
assert_size_stride(primals_61, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_62, (512,), (1,))
assert_size_stride(primals_63, (512,), (1,))
assert_size_stride(primals_64, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_65, (512,), (1,))
assert_size_stride(primals_66, (512,), (1,))
assert_size_stride(primals_67, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_68, (2048,), (1,))
assert_size_stride(primals_69, (2048,), (1,))
assert_size_stride(primals_70, (512, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_71, (512,), (1,))
assert_size_stride(primals_72, (512,), (1,))
assert_size_stride(primals_73, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_74, (512,), (1,))
assert_size_stride(primals_75, (512,), (1,))
assert_size_stride(primals_76, (2048, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_77, (2048,), (1,))
assert_size_stride(primals_78, (2048,), (1,))
assert_size_stride(primals_79, (4096, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_80, (1024, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_81, (1024,), (1,))
assert_size_stride(primals_82, (1024,), (1,))
assert_size_stride(primals_83, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_84, (1024,), (1,))
assert_size_stride(primals_85, (1024,), (1,))
assert_size_stride(primals_86, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_87, (4096,), (1,))
assert_size_stride(primals_88, (4096,), (1,))
assert_size_stride(primals_89, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_90, (1024,), (1,))
assert_size_stride(primals_91, (1024,), (1,))
assert_size_stride(primals_92, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_93, (1024,), (1,))
assert_size_stride(primals_94, (1024,), (1,))
assert_size_stride(primals_95, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_96, (4096,), (1,))
assert_size_stride(primals_97, (4096,), (1,))
assert_size_stride(primals_98, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_99, (1024,), (1,))
assert_size_stride(primals_100, (1024,), (1,))
assert_size_stride(primals_101, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_102, (1024,), (1,))
assert_size_stride(primals_103, (1024,), (1,))
assert_size_stride(primals_104, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_105, (4096,), (1,))
assert_size_stride(primals_106, (4096,), (1,))
assert_size_stride(primals_107, (1024, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_108, (1024,), (1,))
assert_size_stride(primals_109, (1024,), (1,))
assert_size_stride(primals_110, (1024, 1024, 3, 3), (9216, 9, 3, 1))
assert_size_stride(primals_111, (1024,), (1,))
assert_size_stride(primals_112, (1024,), (1,))
assert_size_stride(primals_113, (4096, 1024, 1, 1), (1024, 1, 1, 1))
assert_size_stride(primals_114, (4096,), (1,))
assert_size_stride(primals_115, (4096,), (1,))
assert_size_stride(primals_116, (8192, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_117, (2048, 4096, 1, 1), (4096, 1, 1, 1))
assert_size_stride(primals_118, (2048,), (1,))
assert_size_stride(primals_119, (2048,), (1,))
assert_size_stride(primals_120, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_121, (2048,), (1,))
assert_size_stride(primals_122, (2048,), (1,))
assert_size_stride(primals_123, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_124, (8192,), (1,))
assert_size_stride(primals_125, (8192,), (1,))
assert_size_stride(primals_126, (2048, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_127, (2048,), (1,))
assert_size_stride(primals_128, (2048,), (1,))
assert_size_stride(primals_129, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_130, (2048,), (1,))
assert_size_stride(primals_131, (2048,), (1,))
assert_size_stride(primals_132, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_133, (8192,), (1,))
assert_size_stride(primals_134, (8192,), (1,))
assert_size_stride(primals_135, (2048, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_136, (2048,), (1,))
assert_size_stride(primals_137, (2048,), (1,))
assert_size_stride(primals_138, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_139, (2048,), (1,))
assert_size_stride(primals_140, (2048,), (1,))
assert_size_stride(primals_141, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_142, (8192,), (1,))
assert_size_stride(primals_143, (8192,), (1,))
assert_size_stride(primals_144, (2048, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_145, (2048,), (1,))
assert_size_stride(primals_146, (2048,), (1,))
assert_size_stride(primals_147, (2048, 2048, 3, 3), (18432, 9, 3, 1))
assert_size_stride(primals_148, (2048,), (1,))
assert_size_stride(primals_149, (2048,), (1,))
assert_size_stride(primals_150, (8192, 2048, 1, 1), (2048, 1, 1, 1))
assert_size_stride(primals_151, (8192,), (1,))
assert_size_stride(primals_152, (8192,), (1,))
assert_size_stride(primals_153, (21843, 8192, 1, 1), (8192, 1, 1, 1))
assert_size_stride(primals_154, (21843,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch.
float32)
get_raw_stream(0)
triton_poi_fused_0[grid(768, 49)](primals_1, buf0, 768, 49, XBLOCK=
32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch
.float32)
triton_poi_fused_1[grid(12, 4096)](primals_2, buf1, 12, 4096,
XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_9, buf2, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_9
buf3 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_18, buf3, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_18
buf4 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_27, buf4, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_27
buf5 = empty_strided_cuda((256, 256, 3, 3), (2304, 1, 768, 256),
torch.float32)
triton_poi_fused_2[grid(65536, 9)](primals_36, buf5, 65536, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_36
buf6 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_46, buf6, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_46
buf7 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_55, buf7, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_55
buf8 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_64, buf8, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_64
buf9 = empty_strided_cuda((512, 512, 3, 3), (4608, 1, 1536, 512),
torch.float32)
triton_poi_fused_3[grid(262144, 9)](primals_73, buf9, 262144, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_73
buf10 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_83, buf10, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_83
buf11 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_92, buf11, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_92
buf12 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_101, buf12, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_101
buf13 = empty_strided_cuda((1024, 1024, 3, 3), (9216, 1, 3072, 1024
), torch.float32)
triton_poi_fused_4[grid(1048576, 9)](primals_110, buf13, 1048576, 9,
XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del primals_110
buf14 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_120, buf14, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_120
buf15 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_129, buf15, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_129
buf16 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_138, buf16, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_138
buf17 = empty_strided_cuda((2048, 2048, 3, 3), (18432, 1, 6144,
2048), torch.float32)
triton_poi_fused_5[grid(4194304, 9)](primals_147, buf17, 4194304, 9,
XBLOCK=16, YBLOCK=128, num_warps=8, num_stages=1)
del primals_147
buf19 = empty_strided_cuda((256, 1, 1, 1), (1, 256, 256, 256),
torch.float32)
buf21 = reinterpret_tensor(buf19, (256, 1, 1, 1), (1, 1, 1, 1), 0)
del buf19
buf22 = empty_strided_cuda((256, 3, 7, 7), (147, 1, 21, 3), torch.
float32)
triton_per_fused_add_div_sqrt_sub_var_mean_6[grid(256)](buf21, buf0,
buf22, 256, 147, XBLOCK=1, num_warps=2, num_stages=1)
buf23 = extern_kernels.convolution(buf1, buf22, stride=(2, 2),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf23, (4, 256, 32, 32), (262144, 1, 8192, 256))
buf24 = empty_strided_cuda((4, 256, 34, 34), (295936, 1, 8704, 256),
torch.float32)
triton_poi_fused_constant_pad_nd_7[grid(1183744)](buf23, buf24,
1183744, XBLOCK=1024, num_warps=4, num_stages=1)
buf25 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
buf26 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_8[grid(262144)](buf24,
buf25, buf26, 262144, XBLOCK=512, num_warps=8, num_stages=1)
buf27 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf28 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf30 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf25, buf27, buf28,
buf30, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf31 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf25,
buf27, buf28, primals_3, primals_4, buf31, 262144, XBLOCK=1024,
num_warps=4, num_stages=1)
del primals_4
buf32 = extern_kernels.convolution(buf31, primals_5, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf32, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf33 = extern_kernels.convolution(buf31, primals_6, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf33, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf34 = buf28
del buf28
buf35 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf37 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf33, buf34, buf35,
buf37, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf38 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf33,
buf34, buf35, primals_7, primals_8, buf38, 262144, XBLOCK=1024,
num_warps=4, num_stages=1)
del primals_8
buf39 = extern_kernels.convolution(buf38, buf2, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf39, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf40 = buf35
del buf35
buf41 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf43 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf39, buf40, buf41,
buf43, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf44 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf39,
buf40, buf41, primals_10, primals_11, buf44, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_11
buf45 = extern_kernels.convolution(buf44, primals_12, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf45, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf46 = buf32
del buf32
triton_poi_fused_add_11[grid(1048576)](buf46, buf45, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf47 = buf41
del buf41
buf48 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf50 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf46, buf47,
buf48, buf50, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf51 = buf45
del buf45
triton_poi_fused_native_group_norm_relu_13[grid(1048576)](buf46,
buf47, buf48, primals_13, primals_14, buf51, 1048576, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_14
buf52 = extern_kernels.convolution(buf51, primals_15, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf52, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf53 = buf48
del buf48
buf54 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf56 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf52, buf53, buf54,
buf56, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf57 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf52,
buf53, buf54, primals_16, primals_17, buf57, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_17
buf58 = extern_kernels.convolution(buf57, buf3, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf58, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf59 = buf54
del buf54
buf60 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf62 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf58, buf59, buf60,
buf62, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf63 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf58,
buf59, buf60, primals_19, primals_20, buf63, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_20
buf64 = extern_kernels.convolution(buf63, primals_21, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf64, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf65 = buf64
del buf64
triton_poi_fused_add_14[grid(1048576)](buf65, buf46, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf66 = buf60
del buf60
buf67 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf69 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf65, buf66,
buf67, buf69, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf70 = reinterpret_tensor(buf23, (4, 1024, 16, 16), (262144, 1,
16384, 1024), 0)
del buf23
triton_poi_fused_native_group_norm_relu_13[grid(1048576)](buf65,
buf66, buf67, primals_22, primals_23, buf70, 1048576, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_23
buf71 = extern_kernels.convolution(buf70, primals_24, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf71, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf72 = buf67
del buf67
buf73 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf75 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf71, buf72, buf73,
buf75, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf76 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf71,
buf72, buf73, primals_25, primals_26, buf76, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_26
buf77 = extern_kernels.convolution(buf76, buf4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf77, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf78 = buf73
del buf73
buf79 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf81 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf77, buf78, buf79,
buf81, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf82 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf77,
buf78, buf79, primals_28, primals_29, buf82, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_29
buf83 = extern_kernels.convolution(buf82, primals_30, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf83, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf84 = buf83
del buf83
triton_poi_fused_add_14[grid(1048576)](buf84, buf65, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf85 = buf79
del buf79
buf86 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf88 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_12[grid(128)](buf84, buf85,
buf86, buf88, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf89 = empty_strided_cuda((4, 1024, 16, 16), (262144, 1, 16384,
1024), torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(1048576)](buf84,
buf85, buf86, primals_31, primals_32, buf89, 1048576, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_32
buf90 = extern_kernels.convolution(buf89, primals_33, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf90, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf91 = buf86
del buf86
buf92 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf94 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
triton_red_fused_native_group_norm_9[grid(128)](buf90, buf91, buf92,
buf94, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16, num_stages=1
)
buf95 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf90,
buf91, buf92, primals_34, primals_35, buf95, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_35
buf96 = extern_kernels.convolution(buf95, buf5, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf96, (4, 256, 16, 16), (65536, 1, 4096, 256))
buf97 = buf92
del buf92
buf98 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch.
float32)
buf100 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_9[grid(128)](buf96, buf97, buf98,
buf100, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf101 = empty_strided_cuda((4, 256, 16, 16), (65536, 1, 4096, 256),
torch.float32)
triton_poi_fused_native_group_norm_relu_10[grid(262144)](buf96,
buf97, buf98, primals_37, primals_38, buf101, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_38
buf102 = extern_kernels.convolution(buf101, primals_39, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf102, (4, 1024, 16, 16), (262144, 1, 16384, 1024))
buf103 = buf102
del buf102
triton_poi_fused_add_14[grid(1048576)](buf103, buf84, 1048576,
XBLOCK=512, num_warps=8, num_stages=1)
buf104 = buf98
del buf98
buf105 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf107 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_12[grid(128)](buf103, buf104,
buf105, buf107, 128, 8192, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf108 = empty_strided_cuda((4, 1024, 16, 16), (262144, 1, 16384,
1024), torch.float32)
triton_poi_fused_native_group_norm_relu_13[grid(1048576)](buf103,
buf104, buf105, primals_40, primals_41, buf108, 1048576, XBLOCK
=512, num_warps=8, num_stages=1)
del primals_41
buf109 = extern_kernels.convolution(buf108, primals_42, stride=(2,
2), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf109, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf110 = extern_kernels.convolution(buf108, primals_43, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf110, (4, 512, 16, 16), (131072, 1, 8192, 512))
buf111 = buf105
del buf105
buf112 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf114 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_15[grid(128)](buf110, buf111,
buf112, buf114, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf115 = empty_strided_cuda((4, 512, 16, 16), (131072, 1, 8192, 512
), torch.float32)
triton_poi_fused_native_group_norm_relu_16[grid(524288)](buf110,
buf111, buf112, primals_44, primals_45, buf115, 524288, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_45
buf116 = extern_kernels.convolution(buf115, buf6, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf116, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf117 = buf112
del buf112
buf118 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf120 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf116, buf117,
buf118, buf120, 128, 1024, num_warps=8, num_stages=1)
buf121 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf116,
buf117, buf118, primals_47, primals_48, buf121, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_48
buf122 = extern_kernels.convolution(buf121, primals_49, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf122, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf123 = buf109
del buf109
triton_poi_fused_add_19[grid(524288)](buf123, buf122, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf124 = buf118
del buf118
buf125 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf127 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_20[grid(128)](buf123, buf124,
buf125, buf127, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf128 = buf122
del buf122
triton_poi_fused_native_group_norm_relu_21[grid(524288)](buf123,
buf124, buf125, primals_50, primals_51, buf128, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_51
buf129 = extern_kernels.convolution(buf128, primals_52, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf129, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf130 = buf125
del buf125
buf131 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf133 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf129, buf130,
buf131, buf133, 128, 1024, num_warps=8, num_stages=1)
buf134 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf129,
buf130, buf131, primals_53, primals_54, buf134, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_54
buf135 = extern_kernels.convolution(buf134, buf7, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf135, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf136 = buf131
del buf131
buf137 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf139 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf135, buf136,
buf137, buf139, 128, 1024, num_warps=8, num_stages=1)
buf140 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf135,
buf136, buf137, primals_56, primals_57, buf140, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_57
buf141 = extern_kernels.convolution(buf140, primals_58, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf141, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf142 = buf141
del buf141
triton_poi_fused_add_22[grid(524288)](buf142, buf123, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf143 = buf137
del buf137
buf144 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf146 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_20[grid(128)](buf142, buf143,
buf144, buf146, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf147 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_native_group_norm_relu_21[grid(524288)](buf142,
buf143, buf144, primals_59, primals_60, buf147, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_60
buf148 = extern_kernels.convolution(buf147, primals_61, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf148, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf149 = buf144
del buf144
buf150 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf152 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf148, buf149,
buf150, buf152, 128, 1024, num_warps=8, num_stages=1)
buf153 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf148,
buf149, buf150, primals_62, primals_63, buf153, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_63
buf154 = extern_kernels.convolution(buf153, buf8, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf154, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf155 = buf150
del buf150
buf156 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf158 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf154, buf155,
buf156, buf158, 128, 1024, num_warps=8, num_stages=1)
buf159 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf154,
buf155, buf156, primals_65, primals_66, buf159, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_66
buf160 = extern_kernels.convolution(buf159, primals_67, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf160, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf161 = buf160
del buf160
triton_poi_fused_add_22[grid(524288)](buf161, buf142, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf162 = buf156
del buf156
buf163 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf165 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_20[grid(128)](buf161, buf162,
buf163, buf165, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf166 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_native_group_norm_relu_21[grid(524288)](buf161,
buf162, buf163, primals_68, primals_69, buf166, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_69
buf167 = extern_kernels.convolution(buf166, primals_70, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf167, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf168 = buf163
del buf163
buf169 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf171 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf167, buf168,
buf169, buf171, 128, 1024, num_warps=8, num_stages=1)
buf172 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf167,
buf168, buf169, primals_71, primals_72, buf172, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_72
buf173 = extern_kernels.convolution(buf172, buf9, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf173, (4, 512, 8, 8), (32768, 1, 4096, 512))
buf174 = buf169
del buf169
buf175 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf177 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_17[grid(128)](buf173, buf174,
buf175, buf177, 128, 1024, num_warps=8, num_stages=1)
buf178 = empty_strided_cuda((4, 512, 8, 8), (32768, 1, 4096, 512),
torch.float32)
triton_poi_fused_native_group_norm_relu_18[grid(131072)](buf173,
buf174, buf175, primals_74, primals_75, buf178, 131072, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_75
buf179 = extern_kernels.convolution(buf178, primals_76, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf179, (4, 2048, 8, 8), (131072, 1, 16384, 2048))
buf180 = buf179
del buf179
triton_poi_fused_add_22[grid(524288)](buf180, buf161, 524288,
XBLOCK=512, num_warps=8, num_stages=1)
buf181 = buf175
del buf175
buf182 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf184 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_20[grid(128)](buf180, buf181,
buf182, buf184, 128, 4096, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf185 = empty_strided_cuda((4, 2048, 8, 8), (131072, 1, 16384,
2048), torch.float32)
triton_poi_fused_native_group_norm_relu_21[grid(524288)](buf180,
buf181, buf182, primals_77, primals_78, buf185, 524288, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_78
buf186 = extern_kernels.convolution(buf185, primals_79, stride=(2,
2), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf186, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf187 = extern_kernels.convolution(buf185, primals_80, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf187, (4, 1024, 8, 8), (65536, 1, 8192, 1024))
buf188 = buf182
del buf182
buf189 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf191 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_23[grid(128)](buf187, buf188,
buf189, buf191, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf192 = empty_strided_cuda((4, 1024, 8, 8), (65536, 1, 8192, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_24[grid(262144)](buf187,
buf188, buf189, primals_81, primals_82, buf192, 262144, XBLOCK=
512, num_warps=8, num_stages=1)
del primals_82
buf193 = extern_kernels.convolution(buf192, buf10, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf193, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf194 = buf189
del buf189
buf195 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf197 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf193, buf194,
buf195, buf197, 128, 512, num_warps=4, num_stages=1)
buf198 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf193,
buf194, buf195, primals_84, primals_85, buf198, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_85
buf199 = extern_kernels.convolution(buf198, primals_86, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf199, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf200 = buf186
del buf186
triton_poi_fused_add_27[grid(262144)](buf200, buf199, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf201 = buf195
del buf195
buf202 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf204 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf200, buf201,
buf202, buf204, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf205 = buf199
del buf199
triton_poi_fused_native_group_norm_relu_29[grid(262144)](buf200,
buf201, buf202, primals_87, primals_88, buf205, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_88
buf206 = extern_kernels.convolution(buf205, primals_89, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf206, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf207 = buf202
del buf202
buf208 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf210 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf206, buf207,
buf208, buf210, 128, 512, num_warps=4, num_stages=1)
buf211 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf206,
buf207, buf208, primals_90, primals_91, buf211, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_91
buf212 = extern_kernels.convolution(buf211, buf11, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf212, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf213 = buf208
del buf208
buf214 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf216 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf212, buf213,
buf214, buf216, 128, 512, num_warps=4, num_stages=1)
buf217 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf212,
buf213, buf214, primals_93, primals_94, buf217, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_94
buf218 = extern_kernels.convolution(buf217, primals_95, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf218, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf219 = buf218
del buf218
triton_poi_fused_add_30[grid(262144)](buf219, buf200, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf220 = buf214
del buf214
buf221 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf223 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf219, buf220,
buf221, buf223, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf224 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_native_group_norm_relu_29[grid(262144)](buf219,
buf220, buf221, primals_96, primals_97, buf224, 262144, XBLOCK=
1024, num_warps=4, num_stages=1)
del primals_97
buf225 = extern_kernels.convolution(buf224, primals_98, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf225, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf226 = buf221
del buf221
buf227 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf229 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf225, buf226,
buf227, buf229, 128, 512, num_warps=4, num_stages=1)
buf230 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf225,
buf226, buf227, primals_99, primals_100, buf230, 65536, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_100
buf231 = extern_kernels.convolution(buf230, buf12, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf231, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf232 = buf227
del buf227
buf233 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf235 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf231, buf232,
buf233, buf235, 128, 512, num_warps=4, num_stages=1)
buf236 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf231,
buf232, buf233, primals_102, primals_103, buf236, 65536, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_103
buf237 = extern_kernels.convolution(buf236, primals_104, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf237, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf238 = buf237
del buf237
triton_poi_fused_add_30[grid(262144)](buf238, buf219, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf239 = buf233
del buf233
buf240 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf242 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf238, buf239,
buf240, buf242, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf243 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_native_group_norm_relu_29[grid(262144)](buf238,
buf239, buf240, primals_105, primals_106, buf243, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
del primals_106
buf244 = extern_kernels.convolution(buf243, primals_107, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf244, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf245 = buf240
del buf240
buf246 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf248 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf244, buf245,
buf246, buf248, 128, 512, num_warps=4, num_stages=1)
buf249 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf244,
buf245, buf246, primals_108, primals_109, buf249, 65536, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_109
buf250 = extern_kernels.convolution(buf249, buf13, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf250, (4, 1024, 4, 4), (16384, 1, 4096, 1024))
buf251 = buf246
del buf246
buf252 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf254 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_25[grid(128)](buf250, buf251,
buf252, buf254, 128, 512, num_warps=4, num_stages=1)
buf255 = empty_strided_cuda((4, 1024, 4, 4), (16384, 1, 4096, 1024),
torch.float32)
triton_poi_fused_native_group_norm_relu_26[grid(65536)](buf250,
buf251, buf252, primals_111, primals_112, buf255, 65536, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_112
buf256 = extern_kernels.convolution(buf255, primals_113, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf256, (4, 4096, 4, 4), (65536, 1, 16384, 4096))
buf257 = buf256
del buf256
triton_poi_fused_add_30[grid(262144)](buf257, buf238, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
buf258 = buf252
del buf252
buf259 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf261 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_red_fused_native_group_norm_28[grid(128)](buf257, buf258,
buf259, buf261, 128, 2048, XBLOCK=1, RBLOCK=2048, num_warps=16,
num_stages=1)
buf262 = empty_strided_cuda((4, 4096, 4, 4), (65536, 1, 16384, 4096
), torch.float32)
triton_poi_fused_native_group_norm_relu_29[grid(262144)](buf257,
buf258, buf259, primals_114, primals_115, buf262, 262144,
XBLOCK=1024, num_warps=4, num_stages=1)
del primals_115
buf263 = extern_kernels.convolution(buf262, primals_116, stride=(2,
2), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf263, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf264 = extern_kernels.convolution(buf262, primals_117, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf264, (4, 2048, 4, 4), (32768, 1, 8192, 2048))
buf265 = buf259
del buf259
buf266 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf268 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_31[grid(128)](buf264, buf265,
buf266, buf268, 128, 1024, num_warps=8, num_stages=1)
buf269 = empty_strided_cuda((4, 2048, 4, 4), (32768, 1, 8192, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_32[grid(131072)](buf264,
buf265, buf266, primals_118, primals_119, buf269, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_119
buf270 = extern_kernels.convolution(buf269, buf14, stride=(2, 2),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf270, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf271 = buf266
del buf266
buf272 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf274 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf270, buf271,
buf272, buf274, 128, 256, num_warps=2, num_stages=1)
buf275 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf270,
buf271, buf272, primals_121, primals_122, buf275, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_122
buf276 = extern_kernels.convolution(buf275, primals_123, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf276, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf277 = buf263
del buf263
triton_poi_fused_add_35[grid(131072)](buf277, buf276, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
buf278 = buf272
del buf272
buf279 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf281 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_36[grid(128)](buf277, buf278,
buf279, buf281, 128, 1024, num_warps=8, num_stages=1)
buf282 = buf276
del buf276
triton_poi_fused_native_group_norm_relu_37[grid(131072)](buf277,
buf278, buf279, primals_124, primals_125, buf282, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_125
buf283 = extern_kernels.convolution(buf282, primals_126, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf283, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf284 = buf279
del buf279
buf285 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf287 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf283, buf284,
buf285, buf287, 128, 256, num_warps=2, num_stages=1)
buf288 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf283,
buf284, buf285, primals_127, primals_128, buf288, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_128
buf289 = extern_kernels.convolution(buf288, buf15, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf289, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf290 = buf285
del buf285
buf291 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf293 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf289, buf290,
buf291, buf293, 128, 256, num_warps=2, num_stages=1)
buf294 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf289,
buf290, buf291, primals_130, primals_131, buf294, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_131
buf295 = extern_kernels.convolution(buf294, primals_132, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf295, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf296 = buf295
del buf295
triton_poi_fused_add_38[grid(131072)](buf296, buf277, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
buf297 = buf291
del buf291
buf298 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf300 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_36[grid(128)](buf296, buf297,
buf298, buf300, 128, 1024, num_warps=8, num_stages=1)
buf301 = empty_strided_cuda((4, 8192, 2, 2), (32768, 1, 16384, 8192
), torch.float32)
triton_poi_fused_native_group_norm_relu_37[grid(131072)](buf296,
buf297, buf298, primals_133, primals_134, buf301, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_134
buf302 = extern_kernels.convolution(buf301, primals_135, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf302, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf303 = buf298
del buf298
buf304 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf306 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf302, buf303,
buf304, buf306, 128, 256, num_warps=2, num_stages=1)
buf307 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf302,
buf303, buf304, primals_136, primals_137, buf307, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_137
buf308 = extern_kernels.convolution(buf307, buf16, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf308, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf309 = buf304
del buf304
buf310 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf312 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf308, buf309,
buf310, buf312, 128, 256, num_warps=2, num_stages=1)
buf313 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf308,
buf309, buf310, primals_139, primals_140, buf313, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_140
buf314 = extern_kernels.convolution(buf313, primals_141, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf314, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf315 = buf314
del buf314
triton_poi_fused_add_38[grid(131072)](buf315, buf296, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
buf316 = buf310
del buf310
buf317 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf319 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_36[grid(128)](buf315, buf316,
buf317, buf319, 128, 1024, num_warps=8, num_stages=1)
buf320 = empty_strided_cuda((4, 8192, 2, 2), (32768, 1, 16384, 8192
), torch.float32)
triton_poi_fused_native_group_norm_relu_37[grid(131072)](buf315,
buf316, buf317, primals_142, primals_143, buf320, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
del primals_143
buf321 = extern_kernels.convolution(buf320, primals_144, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf321, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf322 = buf317
del buf317
buf323 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf325 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf321, buf322,
buf323, buf325, 128, 256, num_warps=2, num_stages=1)
buf326 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf321,
buf322, buf323, primals_145, primals_146, buf326, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_146
buf327 = extern_kernels.convolution(buf326, buf17, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf327, (4, 2048, 2, 2), (8192, 1, 4096, 2048))
buf328 = buf323
del buf323
buf329 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf331 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
triton_per_fused_native_group_norm_33[grid(128)](buf327, buf328,
buf329, buf331, 128, 256, num_warps=2, num_stages=1)
buf332 = empty_strided_cuda((4, 2048, 2, 2), (8192, 1, 4096, 2048),
torch.float32)
triton_poi_fused_native_group_norm_relu_34[grid(32768)](buf327,
buf328, buf329, primals_148, primals_149, buf332, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_149
buf333 = extern_kernels.convolution(buf332, primals_150, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf333, (4, 8192, 2, 2), (32768, 1, 16384, 8192))
buf334 = buf333
del buf333
triton_poi_fused_add_38[grid(131072)](buf334, buf315, 131072,
XBLOCK=512, num_warps=8, num_stages=1)
buf335 = reinterpret_tensor(buf329, (4, 32, 1, 1), (32, 1, 32, 32), 0)
del buf329
buf336 = empty_strided_cuda((4, 32, 1, 1), (32, 1, 128, 128), torch
.float32)
buf338 = reinterpret_tensor(buf336, (4, 32, 1, 1), (32, 1, 32, 32), 0)
del buf336
triton_per_fused_native_group_norm_39[grid(128)](buf338, buf334,
buf335, 128, 1024, num_warps=8, num_stages=1)
buf339 = empty_strided_cuda((4, 8192, 1, 1), (8192, 1, 8192, 8192),
torch.float32)
triton_poi_fused_mean_native_group_norm_relu_40[grid(32768)](buf334,
buf335, buf338, primals_151, primals_152, buf339, 32768, XBLOCK
=256, num_warps=4, num_stages=1)
buf340 = extern_kernels.convolution(buf339, primals_153, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf340, (4, 21843, 1, 1), (21843, 1, 21843, 21843))
buf341 = reinterpret_tensor(buf340, (4, 21843, 1, 1), (21843, 1,
87372, 87372), 0)
del buf340
triton_poi_fused_convolution_41[grid(87372)](buf341, primals_154,
87372, XBLOCK=512, num_warps=8, num_stages=1)
del primals_154
return (reinterpret_tensor(buf341, (4, 21843), (21843, 1), 0), buf0,
buf1, primals_3, primals_5, primals_6, primals_7, buf2, primals_10,
primals_12, primals_13, primals_15, primals_16, buf3, primals_19,
primals_21, primals_22, primals_24, primals_25, buf4, primals_28,
primals_30, primals_31, primals_33, primals_34, buf5, primals_37,
primals_39, primals_40, primals_42, primals_43, primals_44, buf6,
primals_47, primals_49, primals_50, primals_52, primals_53, buf7,
primals_56, primals_58, primals_59, primals_61, primals_62, buf8,
primals_65, primals_67, primals_68, primals_70, primals_71, buf9,
primals_74, primals_76, primals_77, primals_79, primals_80,
primals_81, buf10, primals_84, primals_86, primals_87, primals_89,
primals_90, buf11, primals_93, primals_95, primals_96, primals_98,
primals_99, buf12, primals_102, primals_104, primals_105,
primals_107, primals_108, buf13, primals_111, primals_113,
primals_114, primals_116, primals_117, primals_118, buf14,
primals_121, primals_123, primals_124, primals_126, primals_127,
buf15, primals_130, primals_132, primals_133, primals_135,
primals_136, buf16, primals_139, primals_141, primals_142,
primals_144, primals_145, buf17, primals_148, primals_150,
primals_151, primals_152, primals_153, buf21, buf22, buf24, buf25,
buf26, reinterpret_tensor(buf27, (4, 32), (32, 1), 0),
reinterpret_tensor(buf30, (4, 32), (32, 1), 0), buf31, buf33,
reinterpret_tensor(buf34, (4, 32), (32, 1), 0), reinterpret_tensor(
buf37, (4, 32), (32, 1), 0), buf38, buf39, reinterpret_tensor(buf40,
(4, 32), (32, 1), 0), reinterpret_tensor(buf43, (4, 32), (32, 1), 0
), buf44, buf46, reinterpret_tensor(buf47, (4, 32), (32, 1), 0),
reinterpret_tensor(buf50, (4, 32), (32, 1), 0), buf51, buf52,
reinterpret_tensor(buf53, (4, 32), (32, 1), 0), reinterpret_tensor(
buf56, (4, 32), (32, 1), 0), buf57, buf58, reinterpret_tensor(buf59,
(4, 32), (32, 1), 0), reinterpret_tensor(buf62, (4, 32), (32, 1), 0
), buf63, buf65, reinterpret_tensor(buf66, (4, 32), (32, 1), 0),
reinterpret_tensor(buf69, (4, 32), (32, 1), 0), buf70, buf71,
reinterpret_tensor(buf72, (4, 32), (32, 1), 0), reinterpret_tensor(
buf75, (4, 32), (32, 1), 0), buf76, buf77, reinterpret_tensor(buf78,
(4, 32), (32, 1), 0), reinterpret_tensor(buf81, (4, 32), (32, 1), 0
), buf82, buf84, reinterpret_tensor(buf85, (4, 32), (32, 1), 0),
reinterpret_tensor(buf88, (4, 32), (32, 1), 0), buf89, buf90,
reinterpret_tensor(buf91, (4, 32), (32, 1), 0), reinterpret_tensor(
buf94, (4, 32), (32, 1), 0), buf95, buf96, reinterpret_tensor(buf97,
(4, 32), (32, 1), 0), reinterpret_tensor(buf100, (4, 32), (32, 1),
0), buf101, buf103, reinterpret_tensor(buf104, (4, 32), (32, 1), 0),
reinterpret_tensor(buf107, (4, 32), (32, 1), 0), buf108, buf110,
reinterpret_tensor(buf111, (4, 32), (32, 1), 0), reinterpret_tensor
(buf114, (4, 32), (32, 1), 0), buf115, buf116, reinterpret_tensor(
buf117, (4, 32), (32, 1), 0), reinterpret_tensor(buf120, (4, 32), (
32, 1), 0), buf121, buf123, reinterpret_tensor(buf124, (4, 32), (32,
1), 0), reinterpret_tensor(buf127, (4, 32), (32, 1), 0), buf128,
buf129, reinterpret_tensor(buf130, (4, 32), (32, 1), 0),
reinterpret_tensor(buf133, (4, 32), (32, 1), 0), buf134, buf135,
reinterpret_tensor(buf136, (4, 32), (32, 1), 0), reinterpret_tensor
(buf139, (4, 32), (32, 1), 0), buf140, buf142, reinterpret_tensor(
buf143, (4, 32), (32, 1), 0), reinterpret_tensor(buf146, (4, 32), (
32, 1), 0), buf147, buf148, reinterpret_tensor(buf149, (4, 32), (32,
1), 0), reinterpret_tensor(buf152, (4, 32), (32, 1), 0), buf153,
buf154, reinterpret_tensor(buf155, (4, 32), (32, 1), 0),
reinterpret_tensor(buf158, (4, 32), (32, 1), 0), buf159, buf161,
reinterpret_tensor(buf162, (4, 32), (32, 1), 0), reinterpret_tensor
(buf165, (4, 32), (32, 1), 0), buf166, buf167, reinterpret_tensor(
buf168, (4, 32), (32, 1), 0), reinterpret_tensor(buf171, (4, 32), (
32, 1), 0), buf172, buf173, reinterpret_tensor(buf174, (4, 32), (32,
1), 0), reinterpret_tensor(buf177, (4, 32), (32, 1), 0), buf178,
buf180, reinterpret_tensor(buf181, (4, 32), (32, 1), 0),
reinterpret_tensor(buf184, (4, 32), (32, 1), 0), buf185, buf187,
reinterpret_tensor(buf188, (4, 32), (32, 1), 0), reinterpret_tensor
(buf191, (4, 32), (32, 1), 0), buf192, buf193, reinterpret_tensor(
buf194, (4, 32), (32, 1), 0), reinterpret_tensor(buf197, (4, 32), (
32, 1), 0), buf198, buf200, reinterpret_tensor(buf201, (4, 32), (32,
1), 0), reinterpret_tensor(buf204, (4, 32), (32, 1), 0), buf205,
buf206, reinterpret_tensor(buf207, (4, 32), (32, 1), 0),
reinterpret_tensor(buf210, (4, 32), (32, 1), 0), buf211, buf212,
reinterpret_tensor(buf213, (4, 32), (32, 1), 0), reinterpret_tensor
(buf216, (4, 32), (32, 1), 0), buf217, buf219, reinterpret_tensor(
buf220, (4, 32), (32, 1), 0), reinterpret_tensor(buf223, (4, 32), (
32, 1), 0), buf224, buf225, reinterpret_tensor(buf226, (4, 32), (32,
1), 0), reinterpret_tensor(buf229, (4, 32), (32, 1), 0), buf230,
buf231, reinterpret_tensor(buf232, (4, 32), (32, 1), 0),
reinterpret_tensor(buf235, (4, 32), (32, 1), 0), buf236, buf238,
reinterpret_tensor(buf239, (4, 32), (32, 1), 0), reinterpret_tensor
(buf242, (4, 32), (32, 1), 0), buf243, buf244, reinterpret_tensor(
buf245, (4, 32), (32, 1), 0), reinterpret_tensor(buf248, (4, 32), (
32, 1), 0), buf249, buf250, reinterpret_tensor(buf251, (4, 32), (32,
1), 0), reinterpret_tensor(buf254, (4, 32), (32, 1), 0), buf255,
buf257, reinterpret_tensor(buf258, (4, 32), (32, 1), 0),
reinterpret_tensor(buf261, (4, 32), (32, 1), 0), buf262, buf264,
reinterpret_tensor(buf265, (4, 32), (32, 1), 0), reinterpret_tensor
(buf268, (4, 32), (32, 1), 0), buf269, buf270, reinterpret_tensor(
buf271, (4, 32), (32, 1), 0), reinterpret_tensor(buf274, (4, 32), (
32, 1), 0), buf275, buf277, reinterpret_tensor(buf278, (4, 32), (32,
1), 0), reinterpret_tensor(buf281, (4, 32), (32, 1), 0), buf282,
buf283, reinterpret_tensor(buf284, (4, 32), (32, 1), 0),
reinterpret_tensor(buf287, (4, 32), (32, 1), 0), buf288, buf289,
reinterpret_tensor(buf290, (4, 32), (32, 1), 0), reinterpret_tensor
(buf293, (4, 32), (32, 1), 0), buf294, buf296, reinterpret_tensor(
buf297, (4, 32), (32, 1), 0), reinterpret_tensor(buf300, (4, 32), (
32, 1), 0), buf301, buf302, reinterpret_tensor(buf303, (4, 32), (32,
1), 0), reinterpret_tensor(buf306, (4, 32), (32, 1), 0), buf307,
buf308, reinterpret_tensor(buf309, (4, 32), (32, 1), 0),
reinterpret_tensor(buf312, (4, 32), (32, 1), 0), buf313, buf315,
reinterpret_tensor(buf316, (4, 32), (32, 1), 0), reinterpret_tensor
(buf319, (4, 32), (32, 1), 0), buf320, buf321, reinterpret_tensor(
buf322, (4, 32), (32, 1), 0), reinterpret_tensor(buf325, (4, 32), (
32, 1), 0), buf326, buf327, reinterpret_tensor(buf328, (4, 32), (32,
1), 0), reinterpret_tensor(buf331, (4, 32), (32, 1), 0), buf332,
buf334, buf335, buf338, buf339)
def conv1x1(in_planes, out_planes, stride=1):
"""1x1 convolution"""
return nn.Conv2d(in_planes, out_planes, kernel_size=1, stride=stride,
bias=False)
def conv3x3(in_planes, out_planes, stride=1):
"""3x3 convolution with padding"""
return nn.Conv2d(in_planes, out_planes, kernel_size=3, stride=stride,
padding=1, bias=False)
def tf2th(conv_weights):
"""Possibly convert HWIO to OIHW."""
if conv_weights.ndim == 4:
conv_weights = conv_weights.transpose([3, 2, 0, 1])
return torch.from_numpy(conv_weights)
class StdConv2d(nn.Conv2d):
def forward(self, x):
w = self.weight
v, m = torch.var_mean(w, dim=[1, 2, 3], keepdim=True, unbiased=False)
w = (w - m) / torch.sqrt(v + 1e-10)
return F.conv2d(x, w, self.bias, self.stride, self.padding, self.
dilation, self.groups)
class PreActBottleneck(nn.Module):
"""Pre-activation (v2) bottleneck block.
Follows the implementation of "Identity Mappings in Deep Residual Networks":
https://github.com/KaimingHe/resnet-1k-layers/blob/master/resnet-pre-act.lua
Except it puts the stride on 3x3 conv when available.
"""
def __init__(self, cin, cout=None, cmid=None, stride=1):
super().__init__()
cout = cout or cin
cmid = cmid or cout // 4
self.gn1 = nn.GroupNorm(32, cin)
self.conv1 = conv1x1(cin, cmid)
self.gn2 = nn.GroupNorm(32, cmid)
self.conv2 = conv3x3(cmid, cmid, stride)
self.gn3 = nn.GroupNorm(32, cmid)
self.conv3 = conv1x1(cmid, cout)
self.relu = nn.ReLU(inplace=True)
if stride != 1 or cin != cout:
self.downsample = conv1x1(cin, cout, stride)
def forward(self, x):
out = self.relu(self.gn1(x))
residual = x
if hasattr(self, 'downsample'):
residual = self.downsample(out)
out = self.conv1(out)
out = self.conv2(self.relu(self.gn2(out)))
out = self.conv3(self.relu(self.gn3(out)))
return out + residual
def load_from(self, weights, prefix=''):
convname = 'standardized_conv2d'
with torch.no_grad():
self.conv1.weight.copy_(tf2th(weights[
f'{prefix}a/{convname}/kernel']))
self.conv2.weight.copy_(tf2th(weights[
f'{prefix}b/{convname}/kernel']))
self.conv3.weight.copy_(tf2th(weights[
f'{prefix}c/{convname}/kernel']))
self.gn1.weight.copy_(tf2th(weights[f'{prefix}a/group_norm/gamma'])
)
self.gn2.weight.copy_(tf2th(weights[f'{prefix}b/group_norm/gamma'])
)
self.gn3.weight.copy_(tf2th(weights[f'{prefix}c/group_norm/gamma'])
)
self.gn1.bias.copy_(tf2th(weights[f'{prefix}a/group_norm/beta']))
self.gn2.bias.copy_(tf2th(weights[f'{prefix}b/group_norm/beta']))
self.gn3.bias.copy_(tf2th(weights[f'{prefix}c/group_norm/beta']))
if hasattr(self, 'downsample'):
w = weights[f'{prefix}a/proj/{convname}/kernel']
self.downsample.weight.copy_(tf2th(w))
class ResNetV2New(nn.Module):
"""Implementation of Pre-activation (v2) ResNet mode."""
def __init__(self, block_units, width_factor, head_size=21843,
zero_head=False):
super().__init__()
wf = width_factor
self.root = nn.Sequential(OrderedDict([('conv', StdConv2d(3, 64 *
wf, kernel_size=7, stride=2, padding=3, bias=False)), ('pad',
nn.ConstantPad2d(1, 0)), ('pool', nn.MaxPool2d(kernel_size=3,
stride=2, padding=0))]))
self.body = nn.Sequential(OrderedDict([('block1', nn.Sequential(
OrderedDict([('unit01', PreActBottleneck(cin=64 * wf, cout=256 *
wf, cmid=64 * wf))] + [(f'unit{i:02d}', PreActBottleneck(cin=
256 * wf, cout=256 * wf, cmid=64 * wf)) for i in range(2,
block_units[0] + 1)]))), ('block2', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=256 * wf, cout=512 * wf, cmid=
128 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
512 * wf, cout=512 * wf, cmid=128 * wf)) for i in range(2,
block_units[1] + 1)]))), ('block3', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=512 * wf, cout=1024 * wf, cmid=
256 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin=
1024 * wf, cout=1024 * wf, cmid=256 * wf)) for i in range(2,
block_units[2] + 1)]))), ('block4', nn.Sequential(OrderedDict([
('unit01', PreActBottleneck(cin=1024 * wf, cout=2048 * wf, cmid
=512 * wf, stride=2))] + [(f'unit{i:02d}', PreActBottleneck(cin
=2048 * wf, cout=2048 * wf, cmid=512 * wf)) for i in range(2,
block_units[3] + 1)])))]))
self.zero_head = zero_head
self.head = nn.Sequential(OrderedDict([('gn', nn.GroupNorm(32, 2048 *
wf)), ('relu', nn.ReLU(inplace=True)), ('avg', nn.
AdaptiveAvgPool2d(output_size=1)), ('conv', nn.Conv2d(2048 * wf,
head_size, kernel_size=1, bias=True))]))
def load_from(self, weights, prefix='resnet/'):
with torch.no_grad():
self.root.conv.weight.copy_(tf2th(weights[
f'{prefix}root_block/standardized_conv2d/kernel']))
self.head.gn.weight.copy_(tf2th(weights[
f'{prefix}group_norm/gamma']))
self.head.gn.bias.copy_(tf2th(weights[f'{prefix}group_norm/beta']))
if self.zero_head:
nn.init.zeros_(self.head.conv.weight)
nn.init.zeros_(self.head.conv.bias)
else:
self.head.conv.weight.copy_(tf2th(weights[
f'{prefix}head/conv2d/kernel']))
self.head.conv.bias.copy_(tf2th(weights[
f'{prefix}head/conv2d/bias']))
for bname, block in self.body.named_children():
for uname, unit in block.named_children():
unit.load_from(weights, prefix=f'{prefix}{bname}/{uname}/')
def forward(self, input_0):
primals_1 = self.root.conv.weight
primals_3 = self.body.block1.unit01.gn1.weight
primals_4 = self.body.block1.unit01.gn1.bias
primals_6 = self.body.block1.unit01.conv1.weight
primals_7 = self.body.block1.unit01.gn2.weight
primals_8 = self.body.block1.unit01.gn2.bias
primals_9 = self.body.block1.unit01.conv2.weight
primals_10 = self.body.block1.unit01.gn3.weight
primals_11 = self.body.block1.unit01.gn3.bias
primals_5 = self.body.block1.unit01.conv3.weight
primals_12 = self.body.block1.unit01.downsample.weight
primals_13 = self.body.block1.unit02.gn1.weight
primals_14 = self.body.block1.unit02.gn1.bias
primals_15 = self.body.block1.unit02.conv1.weight
primals_16 = self.body.block1.unit02.gn2.weight
primals_17 = self.body.block1.unit02.gn2.bias
primals_18 = self.body.block1.unit02.conv2.weight
primals_19 = self.body.block1.unit02.gn3.weight
primals_20 = self.body.block1.unit02.gn3.bias
primals_21 = self.body.block1.unit02.conv3.weight
primals_22 = self.body.block1.unit03.gn1.weight
primals_23 = self.body.block1.unit03.gn1.bias
primals_24 = self.body.block1.unit03.conv1.weight
primals_25 = self.body.block1.unit03.gn2.weight
primals_26 = self.body.block1.unit03.gn2.bias
primals_27 = self.body.block1.unit03.conv2.weight
primals_28 = self.body.block1.unit03.gn3.weight
primals_29 = self.body.block1.unit03.gn3.bias
primals_30 = self.body.block1.unit03.conv3.weight
primals_31 = self.body.block1.unit04.gn1.weight
primals_32 = self.body.block1.unit04.gn1.bias
primals_33 = self.body.block1.unit04.conv1.weight
primals_34 = self.body.block1.unit04.gn2.weight
primals_35 = self.body.block1.unit04.gn2.bias
primals_36 = self.body.block1.unit04.conv2.weight
primals_37 = self.body.block1.unit04.gn3.weight
primals_38 = self.body.block1.unit04.gn3.bias
primals_39 = self.body.block1.unit04.conv3.weight
primals_40 = self.body.block2.unit01.gn1.weight
primals_41 = self.body.block2.unit01.gn1.bias
primals_43 = self.body.block2.unit01.conv1.weight
primals_44 = self.body.block2.unit01.gn2.weight
primals_45 = self.body.block2.unit01.gn2.bias
primals_46 = self.body.block2.unit01.conv2.weight
primals_47 = self.body.block2.unit01.gn3.weight
primals_48 = self.body.block2.unit01.gn3.bias
primals_49 = self.body.block2.unit01.conv3.weight
primals_42 = self.body.block2.unit01.downsample.weight
primals_50 = self.body.block2.unit02.gn1.weight
primals_51 = self.body.block2.unit02.gn1.bias
primals_52 = self.body.block2.unit02.conv1.weight
primals_53 = self.body.block2.unit02.gn2.weight
primals_54 = self.body.block2.unit02.gn2.bias
primals_55 = self.body.block2.unit02.conv2.weight
primals_56 = self.body.block2.unit02.gn3.weight
primals_57 = self.body.block2.unit02.gn3.bias
primals_58 = self.body.block2.unit02.conv3.weight
primals_59 = self.body.block2.unit03.gn1.weight
primals_60 = self.body.block2.unit03.gn1.bias
primals_61 = self.body.block2.unit03.conv1.weight
primals_62 = self.body.block2.unit03.gn2.weight
primals_63 = self.body.block2.unit03.gn2.bias
primals_64 = self.body.block2.unit03.conv2.weight
primals_65 = self.body.block2.unit03.gn3.weight
primals_66 = self.body.block2.unit03.gn3.bias
primals_67 = self.body.block2.unit03.conv3.weight
primals_68 = self.body.block2.unit04.gn1.weight
primals_69 = self.body.block2.unit04.gn1.bias
primals_70 = self.body.block2.unit04.conv1.weight
primals_71 = self.body.block2.unit04.gn2.weight
primals_72 = self.body.block2.unit04.gn2.bias
primals_73 = self.body.block2.unit04.conv2.weight
primals_74 = self.body.block2.unit04.gn3.weight
primals_75 = self.body.block2.unit04.gn3.bias
primals_76 = self.body.block2.unit04.conv3.weight
primals_77 = self.body.block3.unit01.gn1.weight
primals_78 = self.body.block3.unit01.gn1.bias
primals_80 = self.body.block3.unit01.conv1.weight
primals_81 = self.body.block3.unit01.gn2.weight
primals_82 = self.body.block3.unit01.gn2.bias
primals_83 = self.body.block3.unit01.conv2.weight
primals_84 = self.body.block3.unit01.gn3.weight
primals_85 = self.body.block3.unit01.gn3.bias
primals_86 = self.body.block3.unit01.conv3.weight
primals_79 = self.body.block3.unit01.downsample.weight
primals_87 = self.body.block3.unit02.gn1.weight
primals_88 = self.body.block3.unit02.gn1.bias
primals_89 = self.body.block3.unit02.conv1.weight
primals_90 = self.body.block3.unit02.gn2.weight
primals_91 = self.body.block3.unit02.gn2.bias
primals_92 = self.body.block3.unit02.conv2.weight
primals_93 = self.body.block3.unit02.gn3.weight
primals_94 = self.body.block3.unit02.gn3.bias
primals_95 = self.body.block3.unit02.conv3.weight
primals_96 = self.body.block3.unit03.gn1.weight
primals_97 = self.body.block3.unit03.gn1.bias
primals_98 = self.body.block3.unit03.conv1.weight
primals_99 = self.body.block3.unit03.gn2.weight
primals_100 = self.body.block3.unit03.gn2.bias
primals_101 = self.body.block3.unit03.conv2.weight
primals_102 = self.body.block3.unit03.gn3.weight
primals_103 = self.body.block3.unit03.gn3.bias
primals_104 = self.body.block3.unit03.conv3.weight
primals_105 = self.body.block3.unit04.gn1.weight
primals_106 = self.body.block3.unit04.gn1.bias
primals_107 = self.body.block3.unit04.conv1.weight
primals_108 = self.body.block3.unit04.gn2.weight
primals_109 = self.body.block3.unit04.gn2.bias
primals_110 = self.body.block3.unit04.conv2.weight
primals_111 = self.body.block3.unit04.gn3.weight
primals_112 = self.body.block3.unit04.gn3.bias
primals_113 = self.body.block3.unit04.conv3.weight
primals_114 = self.body.block4.unit01.gn1.weight
primals_115 = self.body.block4.unit01.gn1.bias
primals_117 = self.body.block4.unit01.conv1.weight
primals_118 = self.body.block4.unit01.gn2.weight
primals_119 = self.body.block4.unit01.gn2.bias
primals_120 = self.body.block4.unit01.conv2.weight
primals_121 = self.body.block4.unit01.gn3.weight
primals_122 = self.body.block4.unit01.gn3.bias
primals_123 = self.body.block4.unit01.conv3.weight
primals_116 = self.body.block4.unit01.downsample.weight
primals_124 = self.body.block4.unit02.gn1.weight
primals_125 = self.body.block4.unit02.gn1.bias
primals_126 = self.body.block4.unit02.conv1.weight
primals_127 = self.body.block4.unit02.gn2.weight
primals_128 = self.body.block4.unit02.gn2.bias
primals_129 = self.body.block4.unit02.conv2.weight
primals_130 = self.body.block4.unit02.gn3.weight
primals_131 = self.body.block4.unit02.gn3.bias
primals_132 = self.body.block4.unit02.conv3.weight
primals_133 = self.body.block4.unit03.gn1.weight
primals_134 = self.body.block4.unit03.gn1.bias
primals_135 = self.body.block4.unit03.conv1.weight
primals_136 = self.body.block4.unit03.gn2.weight
primals_137 = self.body.block4.unit03.gn2.bias
primals_138 = self.body.block4.unit03.conv2.weight
primals_139 = self.body.block4.unit03.gn3.weight
primals_140 = self.body.block4.unit03.gn3.bias
primals_141 = self.body.block4.unit03.conv3.weight
primals_142 = self.body.block4.unit04.gn1.weight
primals_143 = self.body.block4.unit04.gn1.bias
primals_144 = self.body.block4.unit04.conv1.weight
primals_145 = self.body.block4.unit04.gn2.weight
primals_146 = self.body.block4.unit04.gn2.bias
primals_147 = self.body.block4.unit04.conv2.weight
primals_148 = self.body.block4.unit04.gn3.weight
primals_149 = self.body.block4.unit04.gn3.bias
primals_150 = self.body.block4.unit04.conv3.weight
primals_151 = self.head.gn.weight
primals_152 = self.head.gn.bias
primals_153 = self.head.conv.weight
primals_154 = self.head.conv.bias
primals_2 = 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])
return output[0]
|
bethgelab/robustness
|
ResNetV2
| false
| 16,458
|
[
"Apache-2.0"
] | 67
|
aa0a6798fe3973bae5f47561721b59b39f126ab7
|
https://github.com/bethgelab/robustness/tree/aa0a6798fe3973bae5f47561721b59b39f126ab7
|
MLP
|
import torch
from torch import Tensor
from torch import nn
class MLP(nn.Module):
def __init__(self, dim, hidden_dim, out_dim=None) ->None:
super().__init__()
out_dim = out_dim or dim
self.fc1 = nn.Conv2d(dim, hidden_dim, 1, 1, 0)
self.act = nn.ReLU6(True)
self.fc2 = nn.Conv2d(hidden_dim, out_dim, 1, 1, 0)
def forward(self, x: 'Tensor') ->Tensor:
return self.fc2(self.act(self.fc1(x)))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4, 'hidden_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 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_convolution_hardtanh_hardtanh_backward_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 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 6.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = tmp2 <= tmp3
tmp8 = tmp2 >= tmp5
tmp9 = tmp7 | tmp8
tl.store(out_ptr0 + x3, tmp6, xmask)
tl.store(out_ptr1 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused_convolution_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
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, 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, 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 = 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.float32)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
get_raw_stream(0)
triton_poi_fused_convolution_hardtanh_hardtanh_backward_0[grid(256)](
buf0, primals_2, buf1, buf4, 256, XBLOCK=128, num_warps=4,
num_stages=1)
del buf0
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, 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, 4, 4), (64, 16, 4, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_1[grid(256)](buf3, primals_5, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_5
return buf3, primals_1, primals_3, primals_4, buf1, buf4
class MLPNew(nn.Module):
def __init__(self, dim, hidden_dim, out_dim=None) ->None:
super().__init__()
out_dim = out_dim or dim
self.fc1 = nn.Conv2d(dim, hidden_dim, 1, 1, 0)
self.act = nn.ReLU6(True)
self.fc2 = nn.Conv2d(hidden_dim, out_dim, 1, 1, 0)
def forward(self, input_0):
primals_1 = self.fc1.weight
primals_2 = self.fc1.bias
primals_4 = self.fc2.weight
primals_5 = self.fc2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
sithu31296/image_classification
|
MLP
| false
| 16,459
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
BodyPoseModel
|
import torch
from collections import OrderedDict
def _make_layers(block, no_relu_layers):
layers = []
for layer_name, v in block.items():
if 'pool' in layer_name:
layer = torch.nn.MaxPool2d(kernel_size=v[0], stride=v[1],
padding=v[2])
layers.append((layer_name, layer))
else:
conv2d = torch.nn.Conv2d(in_channels=v[0], out_channels=v[1],
kernel_size=v[2], stride=v[3], padding=v[4])
layers.append((layer_name, conv2d))
if layer_name not in no_relu_layers:
layers.append(('relu_' + layer_name, torch.nn.ReLU(inplace=
True)))
return torch.nn.Sequential(OrderedDict(layers))
class BodyPoseModel(torch.nn.Module):
def __init__(self):
super(BodyPoseModel, self).__init__()
no_relu_layers = ['conv5_5_CPM_L1', 'conv5_5_CPM_L2',
'Mconv7_stage2_L1', 'Mconv7_stage2_L2', 'Mconv7_stage3_L1',
'Mconv7_stage3_L2', 'Mconv7_stage4_L1', 'Mconv7_stage4_L2',
'Mconv7_stage5_L1', 'Mconv7_stage5_L2', 'Mconv7_stage6_L1',
'Mconv7_stage6_L1']
blocks = {}
block0 = OrderedDict({'conv1_1': [3, 64, 3, 1, 1], 'conv1_2': [64,
64, 3, 1, 1], 'pool1_stage1': [2, 2, 0], 'conv2_1': [64, 128, 3,
1, 1], 'conv2_2': [128, 128, 3, 1, 1], 'pool2_stage1': [2, 2, 0
], 'conv3_1': [128, 256, 3, 1, 1], 'conv3_2': [256, 256, 3, 1,
1], 'conv3_3': [256, 256, 3, 1, 1], 'conv3_4': [256, 256, 3, 1,
1], 'pool3_stage1': [2, 2, 0], 'conv4_1': [256, 512, 3, 1, 1],
'conv4_2': [512, 512, 3, 1, 1], 'conv4_3_CPM': [512, 256, 3, 1,
1], 'conv4_4_CPM': [256, 128, 3, 1, 1]})
block1_1 = OrderedDict({'conv5_1_CPM_L1': [128, 128, 3, 1, 1],
'conv5_2_CPM_L1': [128, 128, 3, 1, 1], 'conv5_3_CPM_L1': [128,
128, 3, 1, 1], 'conv5_4_CPM_L1': [128, 512, 1, 1, 0],
'conv5_5_CPM_L1': [512, 38, 1, 1, 0]})
block1_2 = OrderedDict({'conv5_1_CPM_L2': [128, 128, 3, 1, 1],
'conv5_2_CPM_L2': [128, 128, 3, 1, 1], 'conv5_3_CPM_L2': [128,
128, 3, 1, 1], 'conv5_4_CPM_L2': [128, 512, 1, 1, 0],
'conv5_5_CPM_L2': [512, 19, 1, 1, 0]})
blocks['block1_1'] = block1_1
blocks['block1_2'] = block1_2
self.model0 = _make_layers(block0, no_relu_layers)
for i in range(2, 7):
blocks['block%d_1' % i] = OrderedDict({('Mconv1_stage%d_L1' % i
): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L1' % i): [128,
128, 7, 1, 3], ('Mconv3_stage%d_L1' % i): [128, 128, 7, 1,
3], ('Mconv4_stage%d_L1' % i): [128, 128, 7, 1, 3], (
'Mconv5_stage%d_L1' % i): [128, 128, 7, 1, 3], (
'Mconv6_stage%d_L1' % i): [128, 128, 1, 1, 0], (
'Mconv7_stage%d_L1' % i): [128, 38, 1, 1, 0]})
blocks['block%d_2' % i] = OrderedDict({('Mconv1_stage%d_L2' % i
): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L2' % i): [128,
128, 7, 1, 3], ('Mconv3_stage%d_L2' % i): [128, 128, 7, 1,
3], ('Mconv4_stage%d_L2' % i): [128, 128, 7, 1, 3], (
'Mconv5_stage%d_L2' % i): [128, 128, 7, 1, 3], (
'Mconv6_stage%d_L2' % i): [128, 128, 1, 1, 0], (
'Mconv7_stage%d_L2' % i): [128, 19, 1, 1, 0]})
for k in blocks.keys():
blocks[k] = _make_layers(blocks[k], no_relu_layers)
self.model1_1 = blocks['block1_1']
self.model2_1 = blocks['block2_1']
self.model3_1 = blocks['block3_1']
self.model4_1 = blocks['block4_1']
self.model5_1 = blocks['block5_1']
self.model6_1 = blocks['block6_1']
self.model1_2 = blocks['block1_2']
self.model2_2 = blocks['block2_2']
self.model3_2 = blocks['block3_2']
self.model4_2 = blocks['block4_2']
self.model5_2 = blocks['block5_2']
self.model6_2 = blocks['block6_2']
def forward(self, x):
out1 = self.model0(x)
out1_1 = self.model1_1(out1)
out1_2 = self.model1_2(out1)
out2 = torch.cat([out1_1, out1_2, out1], 1)
out2_1 = self.model2_1(out2)
out2_2 = self.model2_2(out2)
out3 = torch.cat([out2_1, out2_2, out1], 1)
out3_1 = self.model3_1(out3)
out3_2 = self.model3_2(out3)
out4 = torch.cat([out3_1, out3_2, out1], 1)
out4_1 = self.model4_1(out4)
out4_2 = self.model4_2(out4)
out5 = torch.cat([out4_1, out4_2, out1], 1)
out5_1 = self.model5_1(out5)
out5_2 = self.model5_2(out5)
out6 = torch.cat([out5_1, out5_2, out1], 1)
out6_1 = self.model6_1(out6)
out6_2 = self.model6_2(out6)
return out6_1, out6_2
def get_inputs():
return [torch.rand([4, 3, 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 collections import OrderedDict
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_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 // 4096 % 64
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, 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, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 32
x1 = xindex // 32
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 128 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 128 * x1), None, eviction_policy
='evict_last')
tmp3 = tl.load(in_ptr0 + (64 + 2 * x0 + 128 * x1), None,
eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (65 + 2 * x0 + 128 * x1), None,
eviction_policy='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_relu_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 // 1024 % 128
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, 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, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 16
x1 = xindex // 16
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 64 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 64 * x1), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (32 + 2 * x0 + 64 * x1), None, eviction_policy
='evict_last')
tmp5 = tl.load(in_ptr0 + (33 + 2 * x0 + 64 * x1), None, eviction_policy
='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_relu_4(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 // 256 % 256
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, 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, None)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_5(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex % 8
x1 = xindex // 8
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 32 * x1), None, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 32 * x1), None, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + 2 * x0 + 32 * x1), None, eviction_policy
='evict_last')
tmp5 = tl.load(in_ptr0 + (17 + 2 * x0 + 32 * x1), None, eviction_policy
='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + x2, tmp6, None)
tl.store(out_ptr1 + x2, tmp16, None)
@triton.jit
def triton_poi_fused_convolution_relu_6(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 // 64 % 512
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, 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, None)
@triton.jit
def triton_poi_fused_convolution_relu_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 // 64 % 256
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, 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, None)
@triton.jit
def triton_poi_fused_convolution_relu_8(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 // 64 % 128
tmp0 = tl.load(in_out_ptr0 + x3, None)
tmp1 = tl.load(in_ptr0 + x1, None, 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, None)
@triton.jit
def triton_poi_fused_cat_9(in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 47360
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 64 % 185
x0 = xindex % 64
x2 = xindex // 11840
x3 = xindex
tmp0 = x1
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 38, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (x0 + 64 * x1 + 2432 * x2), tmp4 & xmask,
other=0.0)
tmp6 = tl.load(in_ptr1 + x1, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp7 = tmp5 + tmp6
tmp8 = tl.full(tmp7.shape, 0.0, tmp7.dtype)
tmp9 = tl.where(tmp4, tmp7, tmp8)
tmp10 = tmp0 >= tmp3
tmp11 = tl.full([1], 57, tl.int64)
tmp12 = tmp0 < tmp11
tmp13 = tmp10 & tmp12
tmp14 = tl.load(in_ptr2 + (x0 + 64 * (-38 + x1) + 1216 * x2), tmp13 &
xmask, other=0.0)
tmp15 = tl.load(in_ptr3 + (-38 + x1), tmp13 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp16 = tmp14 + tmp15
tmp17 = tl.full(tmp16.shape, 0.0, tmp16.dtype)
tmp18 = tl.where(tmp13, tmp16, tmp17)
tmp19 = tmp0 >= tmp11
tl.full([1], 185, tl.int64)
tmp22 = tl.load(in_ptr4 + (x0 + 64 * (-57 + x1) + 8192 * x2), tmp19 &
xmask, other=0.0)
tmp23 = tl.where(tmp13, tmp18, tmp22)
tmp24 = tl.where(tmp4, tmp9, tmp23)
tl.store(out_ptr0 + x3, tmp24, xmask)
@triton.jit
def triton_poi_fused_convolution_10(in_out_ptr0, in_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 9728
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 64 % 38
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_convolution_relu_threshold_backward_11(in_out_ptr0,
in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 4864
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x4 = xindex
x1 = xindex // 64 % 19
x2 = xindex // 1216
x3 = xindex % 1216
tmp0 = tl.load(in_out_ptr0 + x4, 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)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x4, tmp4, xmask)
tl.store(out_ptr0 + (x3 + 1280 * x2), tmp6, 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) = args
args.clear()
assert_size_stride(primals_1, (64, 3, 3, 3), (27, 9, 3, 1))
assert_size_stride(primals_2, (64,), (1,))
assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_5, (64,), (1,))
assert_size_stride(primals_6, (128, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_7, (128,), (1,))
assert_size_stride(primals_8, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_9, (128,), (1,))
assert_size_stride(primals_10, (256, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_11, (256,), (1,))
assert_size_stride(primals_12, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_13, (256,), (1,))
assert_size_stride(primals_14, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_15, (256,), (1,))
assert_size_stride(primals_16, (256, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_17, (256,), (1,))
assert_size_stride(primals_18, (512, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_19, (512,), (1,))
assert_size_stride(primals_20, (512, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_21, (512,), (1,))
assert_size_stride(primals_22, (256, 512, 3, 3), (4608, 9, 3, 1))
assert_size_stride(primals_23, (256,), (1,))
assert_size_stride(primals_24, (128, 256, 3, 3), (2304, 9, 3, 1))
assert_size_stride(primals_25, (128,), (1,))
assert_size_stride(primals_26, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_27, (128,), (1,))
assert_size_stride(primals_28, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_29, (128,), (1,))
assert_size_stride(primals_30, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_31, (128,), (1,))
assert_size_stride(primals_32, (512, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_33, (512,), (1,))
assert_size_stride(primals_34, (38, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_35, (38,), (1,))
assert_size_stride(primals_36, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_37, (128,), (1,))
assert_size_stride(primals_38, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_39, (128,), (1,))
assert_size_stride(primals_40, (128, 128, 3, 3), (1152, 9, 3, 1))
assert_size_stride(primals_41, (128,), (1,))
assert_size_stride(primals_42, (512, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_43, (512,), (1,))
assert_size_stride(primals_44, (19, 512, 1, 1), (512, 1, 1, 1))
assert_size_stride(primals_45, (19,), (1,))
assert_size_stride(primals_46, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_47, (128,), (1,))
assert_size_stride(primals_48, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_49, (128,), (1,))
assert_size_stride(primals_50, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_51, (128,), (1,))
assert_size_stride(primals_52, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_53, (128,), (1,))
assert_size_stride(primals_54, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_55, (128,), (1,))
assert_size_stride(primals_56, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_57, (128,), (1,))
assert_size_stride(primals_58, (38, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_59, (38,), (1,))
assert_size_stride(primals_60, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_61, (128,), (1,))
assert_size_stride(primals_62, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_63, (128,), (1,))
assert_size_stride(primals_64, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_65, (128,), (1,))
assert_size_stride(primals_66, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_67, (128,), (1,))
assert_size_stride(primals_68, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_69, (128,), (1,))
assert_size_stride(primals_70, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_71, (128,), (1,))
assert_size_stride(primals_72, (19, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_73, (19,), (1,))
assert_size_stride(primals_74, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_75, (128,), (1,))
assert_size_stride(primals_76, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_77, (128,), (1,))
assert_size_stride(primals_78, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_79, (128,), (1,))
assert_size_stride(primals_80, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_81, (128,), (1,))
assert_size_stride(primals_82, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_83, (128,), (1,))
assert_size_stride(primals_84, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_85, (128,), (1,))
assert_size_stride(primals_86, (38, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_87, (38,), (1,))
assert_size_stride(primals_88, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_89, (128,), (1,))
assert_size_stride(primals_90, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_91, (128,), (1,))
assert_size_stride(primals_92, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_93, (128,), (1,))
assert_size_stride(primals_94, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_95, (128,), (1,))
assert_size_stride(primals_96, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_97, (128,), (1,))
assert_size_stride(primals_98, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_99, (128,), (1,))
assert_size_stride(primals_100, (19, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_101, (19,), (1,))
assert_size_stride(primals_102, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_103, (128,), (1,))
assert_size_stride(primals_104, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_105, (128,), (1,))
assert_size_stride(primals_106, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_107, (128,), (1,))
assert_size_stride(primals_108, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_109, (128,), (1,))
assert_size_stride(primals_110, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_111, (128,), (1,))
assert_size_stride(primals_112, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_113, (128,), (1,))
assert_size_stride(primals_114, (38, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_115, (38,), (1,))
assert_size_stride(primals_116, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_117, (128,), (1,))
assert_size_stride(primals_118, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_119, (128,), (1,))
assert_size_stride(primals_120, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_121, (128,), (1,))
assert_size_stride(primals_122, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_123, (128,), (1,))
assert_size_stride(primals_124, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_125, (128,), (1,))
assert_size_stride(primals_126, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_127, (128,), (1,))
assert_size_stride(primals_128, (19, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_129, (19,), (1,))
assert_size_stride(primals_130, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_131, (128,), (1,))
assert_size_stride(primals_132, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_133, (128,), (1,))
assert_size_stride(primals_134, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_135, (128,), (1,))
assert_size_stride(primals_136, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_137, (128,), (1,))
assert_size_stride(primals_138, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_139, (128,), (1,))
assert_size_stride(primals_140, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_141, (128,), (1,))
assert_size_stride(primals_142, (38, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_143, (38,), (1,))
assert_size_stride(primals_144, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_145, (128,), (1,))
assert_size_stride(primals_146, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_147, (128,), (1,))
assert_size_stride(primals_148, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_149, (128,), (1,))
assert_size_stride(primals_150, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_151, (128,), (1,))
assert_size_stride(primals_152, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_153, (128,), (1,))
assert_size_stride(primals_154, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_155, (128,), (1,))
assert_size_stride(primals_156, (19, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_157, (19,), (1,))
assert_size_stride(primals_158, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_159, (128,), (1,))
assert_size_stride(primals_160, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_161, (128,), (1,))
assert_size_stride(primals_162, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_163, (128,), (1,))
assert_size_stride(primals_164, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_165, (128,), (1,))
assert_size_stride(primals_166, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_167, (128,), (1,))
assert_size_stride(primals_168, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_169, (128,), (1,))
assert_size_stride(primals_170, (38, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_171, (38,), (1,))
assert_size_stride(primals_172, (128, 185, 7, 7), (9065, 49, 7, 1))
assert_size_stride(primals_173, (128,), (1,))
assert_size_stride(primals_174, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_175, (128,), (1,))
assert_size_stride(primals_176, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_177, (128,), (1,))
assert_size_stride(primals_178, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_179, (128,), (1,))
assert_size_stride(primals_180, (128, 128, 7, 7), (6272, 49, 7, 1))
assert_size_stride(primals_181, (128,), (1,))
assert_size_stride(primals_182, (128, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_183, (128,), (1,))
assert_size_stride(primals_184, (19, 128, 1, 1), (128, 1, 1, 1))
assert_size_stride(primals_185, (19,), (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, 64, 64, 64), (262144, 4096, 64, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(1048576)](buf1, primals_2,
1048576, XBLOCK=1024, 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, 64, 64, 64), (262144, 4096, 64, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_relu_0[grid(1048576)](buf3, primals_5,
1048576, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1),
torch.float32)
buf5 = empty_strided_cuda((4, 64, 32, 32), (65536, 1024, 32, 1),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_1[grid(262144)](buf3, buf4,
buf5, 262144, XBLOCK=512, num_warps=8, num_stages=1)
buf6 = extern_kernels.convolution(buf4, primals_6, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 128, 32, 32), (131072, 1024, 32, 1))
buf7 = buf6
del buf6
triton_poi_fused_convolution_relu_2[grid(524288)](buf7, primals_7,
524288, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_7
buf8 = extern_kernels.convolution(buf7, primals_8, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 128, 32, 32), (131072, 1024, 32, 1))
buf9 = buf8
del buf8
triton_poi_fused_convolution_relu_2[grid(524288)](buf9, primals_9,
524288, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_9
buf10 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1),
torch.float32)
buf11 = empty_strided_cuda((4, 128, 16, 16), (32768, 256, 16, 1),
torch.int8)
triton_poi_fused_max_pool2d_with_indices_3[grid(131072)](buf9,
buf10, buf11, 131072, XBLOCK=512, num_warps=8, num_stages=1)
buf12 = extern_kernels.convolution(buf10, primals_10, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf12, (4, 256, 16, 16), (65536, 256, 16, 1))
buf13 = buf12
del buf12
triton_poi_fused_convolution_relu_4[grid(262144)](buf13, primals_11,
262144, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_11
buf14 = extern_kernels.convolution(buf13, primals_12, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf14, (4, 256, 16, 16), (65536, 256, 16, 1))
buf15 = buf14
del buf14
triton_poi_fused_convolution_relu_4[grid(262144)](buf15, primals_13,
262144, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_13
buf16 = extern_kernels.convolution(buf15, primals_14, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf16, (4, 256, 16, 16), (65536, 256, 16, 1))
buf17 = buf16
del buf16
triton_poi_fused_convolution_relu_4[grid(262144)](buf17, primals_15,
262144, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_15
buf18 = extern_kernels.convolution(buf17, primals_16, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf18, (4, 256, 16, 16), (65536, 256, 16, 1))
buf19 = buf18
del buf18
triton_poi_fused_convolution_relu_4[grid(262144)](buf19, primals_17,
262144, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_17
buf20 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch
.float32)
buf21 = empty_strided_cuda((4, 256, 8, 8), (16384, 64, 8, 1), torch
.int8)
triton_poi_fused_max_pool2d_with_indices_5[grid(65536)](buf19,
buf20, buf21, 65536, XBLOCK=256, num_warps=4, num_stages=1)
buf22 = extern_kernels.convolution(buf20, primals_18, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf22, (4, 512, 8, 8), (32768, 64, 8, 1))
buf23 = buf22
del buf22
triton_poi_fused_convolution_relu_6[grid(131072)](buf23, primals_19,
131072, XBLOCK=512, num_warps=8, num_stages=1)
del primals_19
buf24 = extern_kernels.convolution(buf23, primals_20, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf24, (4, 512, 8, 8), (32768, 64, 8, 1))
buf25 = buf24
del buf24
triton_poi_fused_convolution_relu_6[grid(131072)](buf25, primals_21,
131072, XBLOCK=512, num_warps=8, num_stages=1)
del primals_21
buf26 = extern_kernels.convolution(buf25, primals_22, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf26, (4, 256, 8, 8), (16384, 64, 8, 1))
buf27 = buf26
del buf26
triton_poi_fused_convolution_relu_7[grid(65536)](buf27, primals_23,
65536, XBLOCK=512, num_warps=4, num_stages=1)
del primals_23
buf28 = extern_kernels.convolution(buf27, primals_24, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf28, (4, 128, 8, 8), (8192, 64, 8, 1))
buf29 = buf28
del buf28
triton_poi_fused_convolution_relu_8[grid(32768)](buf29, primals_25,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_25
buf30 = extern_kernels.convolution(buf29, primals_26, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf30, (4, 128, 8, 8), (8192, 64, 8, 1))
buf31 = buf30
del buf30
triton_poi_fused_convolution_relu_8[grid(32768)](buf31, primals_27,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_27
buf32 = extern_kernels.convolution(buf31, primals_28, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf32, (4, 128, 8, 8), (8192, 64, 8, 1))
buf33 = buf32
del buf32
triton_poi_fused_convolution_relu_8[grid(32768)](buf33, primals_29,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_29
buf34 = extern_kernels.convolution(buf33, primals_30, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf34, (4, 128, 8, 8), (8192, 64, 8, 1))
buf35 = buf34
del buf34
triton_poi_fused_convolution_relu_8[grid(32768)](buf35, primals_31,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_31
buf36 = extern_kernels.convolution(buf35, primals_32, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf36, (4, 512, 8, 8), (32768, 64, 8, 1))
buf37 = buf36
del buf36
triton_poi_fused_convolution_relu_6[grid(131072)](buf37, primals_33,
131072, XBLOCK=512, num_warps=8, num_stages=1)
del primals_33
buf38 = extern_kernels.convolution(buf37, primals_34, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf38, (4, 38, 8, 8), (2432, 64, 8, 1))
buf39 = extern_kernels.convolution(buf29, primals_36, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf39, (4, 128, 8, 8), (8192, 64, 8, 1))
buf40 = buf39
del buf39
triton_poi_fused_convolution_relu_8[grid(32768)](buf40, primals_37,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_37
buf41 = extern_kernels.convolution(buf40, primals_38, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf41, (4, 128, 8, 8), (8192, 64, 8, 1))
buf42 = buf41
del buf41
triton_poi_fused_convolution_relu_8[grid(32768)](buf42, primals_39,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_39
buf43 = extern_kernels.convolution(buf42, primals_40, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf43, (4, 128, 8, 8), (8192, 64, 8, 1))
buf44 = buf43
del buf43
triton_poi_fused_convolution_relu_8[grid(32768)](buf44, primals_41,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_41
buf45 = extern_kernels.convolution(buf44, primals_42, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf45, (4, 512, 8, 8), (32768, 64, 8, 1))
buf46 = buf45
del buf45
triton_poi_fused_convolution_relu_6[grid(131072)](buf46, primals_43,
131072, XBLOCK=512, num_warps=8, num_stages=1)
del primals_43
buf47 = extern_kernels.convolution(buf46, primals_44, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf47, (4, 19, 8, 8), (1216, 64, 8, 1))
buf48 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch
.float32)
triton_poi_fused_cat_9[grid(47360)](buf38, primals_35, buf47,
primals_45, buf29, buf48, 47360, XBLOCK=512, num_warps=4,
num_stages=1)
del buf38
del buf47
del primals_35
del primals_45
buf49 = extern_kernels.convolution(buf48, primals_46, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf49, (4, 128, 8, 8), (8192, 64, 8, 1))
buf50 = buf49
del buf49
triton_poi_fused_convolution_relu_8[grid(32768)](buf50, primals_47,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_47
buf51 = extern_kernels.convolution(buf50, primals_48, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf51, (4, 128, 8, 8), (8192, 64, 8, 1))
buf52 = buf51
del buf51
triton_poi_fused_convolution_relu_8[grid(32768)](buf52, primals_49,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_49
buf53 = extern_kernels.convolution(buf52, primals_50, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf53, (4, 128, 8, 8), (8192, 64, 8, 1))
buf54 = buf53
del buf53
triton_poi_fused_convolution_relu_8[grid(32768)](buf54, primals_51,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_51
buf55 = extern_kernels.convolution(buf54, primals_52, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf55, (4, 128, 8, 8), (8192, 64, 8, 1))
buf56 = buf55
del buf55
triton_poi_fused_convolution_relu_8[grid(32768)](buf56, primals_53,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_53
buf57 = extern_kernels.convolution(buf56, primals_54, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf57, (4, 128, 8, 8), (8192, 64, 8, 1))
buf58 = buf57
del buf57
triton_poi_fused_convolution_relu_8[grid(32768)](buf58, primals_55,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_55
buf59 = extern_kernels.convolution(buf58, primals_56, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf59, (4, 128, 8, 8), (8192, 64, 8, 1))
buf60 = buf59
del buf59
triton_poi_fused_convolution_relu_8[grid(32768)](buf60, primals_57,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_57
buf61 = extern_kernels.convolution(buf60, primals_58, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf61, (4, 38, 8, 8), (2432, 64, 8, 1))
buf62 = extern_kernels.convolution(buf48, primals_60, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf62, (4, 128, 8, 8), (8192, 64, 8, 1))
buf63 = buf62
del buf62
triton_poi_fused_convolution_relu_8[grid(32768)](buf63, primals_61,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_61
buf64 = extern_kernels.convolution(buf63, primals_62, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf64, (4, 128, 8, 8), (8192, 64, 8, 1))
buf65 = buf64
del buf64
triton_poi_fused_convolution_relu_8[grid(32768)](buf65, primals_63,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_63
buf66 = extern_kernels.convolution(buf65, primals_64, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf66, (4, 128, 8, 8), (8192, 64, 8, 1))
buf67 = buf66
del buf66
triton_poi_fused_convolution_relu_8[grid(32768)](buf67, primals_65,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_65
buf68 = extern_kernels.convolution(buf67, primals_66, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf68, (4, 128, 8, 8), (8192, 64, 8, 1))
buf69 = buf68
del buf68
triton_poi_fused_convolution_relu_8[grid(32768)](buf69, primals_67,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_67
buf70 = extern_kernels.convolution(buf69, primals_68, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf70, (4, 128, 8, 8), (8192, 64, 8, 1))
buf71 = buf70
del buf70
triton_poi_fused_convolution_relu_8[grid(32768)](buf71, primals_69,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_69
buf72 = extern_kernels.convolution(buf71, primals_70, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf72, (4, 128, 8, 8), (8192, 64, 8, 1))
buf73 = buf72
del buf72
triton_poi_fused_convolution_relu_8[grid(32768)](buf73, primals_71,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_71
buf74 = extern_kernels.convolution(buf73, primals_72, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf74, (4, 19, 8, 8), (1216, 64, 8, 1))
buf75 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1), torch
.float32)
triton_poi_fused_cat_9[grid(47360)](buf61, primals_59, buf74,
primals_73, buf29, buf75, 47360, XBLOCK=512, num_warps=4,
num_stages=1)
del buf61
del buf74
del primals_59
del primals_73
buf76 = extern_kernels.convolution(buf75, primals_74, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf76, (4, 128, 8, 8), (8192, 64, 8, 1))
buf77 = buf76
del buf76
triton_poi_fused_convolution_relu_8[grid(32768)](buf77, primals_75,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_75
buf78 = extern_kernels.convolution(buf77, primals_76, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf78, (4, 128, 8, 8), (8192, 64, 8, 1))
buf79 = buf78
del buf78
triton_poi_fused_convolution_relu_8[grid(32768)](buf79, primals_77,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_77
buf80 = extern_kernels.convolution(buf79, primals_78, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf80, (4, 128, 8, 8), (8192, 64, 8, 1))
buf81 = buf80
del buf80
triton_poi_fused_convolution_relu_8[grid(32768)](buf81, primals_79,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_79
buf82 = extern_kernels.convolution(buf81, primals_80, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf82, (4, 128, 8, 8), (8192, 64, 8, 1))
buf83 = buf82
del buf82
triton_poi_fused_convolution_relu_8[grid(32768)](buf83, primals_81,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_81
buf84 = extern_kernels.convolution(buf83, primals_82, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf84, (4, 128, 8, 8), (8192, 64, 8, 1))
buf85 = buf84
del buf84
triton_poi_fused_convolution_relu_8[grid(32768)](buf85, primals_83,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_83
buf86 = extern_kernels.convolution(buf85, primals_84, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf86, (4, 128, 8, 8), (8192, 64, 8, 1))
buf87 = buf86
del buf86
triton_poi_fused_convolution_relu_8[grid(32768)](buf87, primals_85,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_85
buf88 = extern_kernels.convolution(buf87, primals_86, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf88, (4, 38, 8, 8), (2432, 64, 8, 1))
buf89 = extern_kernels.convolution(buf75, primals_88, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf89, (4, 128, 8, 8), (8192, 64, 8, 1))
buf90 = buf89
del buf89
triton_poi_fused_convolution_relu_8[grid(32768)](buf90, primals_89,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_89
buf91 = extern_kernels.convolution(buf90, primals_90, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf91, (4, 128, 8, 8), (8192, 64, 8, 1))
buf92 = buf91
del buf91
triton_poi_fused_convolution_relu_8[grid(32768)](buf92, primals_91,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_91
buf93 = extern_kernels.convolution(buf92, primals_92, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf93, (4, 128, 8, 8), (8192, 64, 8, 1))
buf94 = buf93
del buf93
triton_poi_fused_convolution_relu_8[grid(32768)](buf94, primals_93,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_93
buf95 = extern_kernels.convolution(buf94, primals_94, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf95, (4, 128, 8, 8), (8192, 64, 8, 1))
buf96 = buf95
del buf95
triton_poi_fused_convolution_relu_8[grid(32768)](buf96, primals_95,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_95
buf97 = extern_kernels.convolution(buf96, primals_96, stride=(1, 1),
padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf97, (4, 128, 8, 8), (8192, 64, 8, 1))
buf98 = buf97
del buf97
triton_poi_fused_convolution_relu_8[grid(32768)](buf98, primals_97,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_97
buf99 = extern_kernels.convolution(buf98, primals_98, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf99, (4, 128, 8, 8), (8192, 64, 8, 1))
buf100 = buf99
del buf99
triton_poi_fused_convolution_relu_8[grid(32768)](buf100, primals_99,
32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_99
buf101 = extern_kernels.convolution(buf100, primals_100, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf101, (4, 19, 8, 8), (1216, 64, 8, 1))
buf102 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1),
torch.float32)
triton_poi_fused_cat_9[grid(47360)](buf88, primals_87, buf101,
primals_101, buf29, buf102, 47360, XBLOCK=512, num_warps=4,
num_stages=1)
del buf101
del buf88
del primals_101
del primals_87
buf103 = extern_kernels.convolution(buf102, primals_102, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf103, (4, 128, 8, 8), (8192, 64, 8, 1))
buf104 = buf103
del buf103
triton_poi_fused_convolution_relu_8[grid(32768)](buf104,
primals_103, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_103
buf105 = extern_kernels.convolution(buf104, primals_104, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf105, (4, 128, 8, 8), (8192, 64, 8, 1))
buf106 = buf105
del buf105
triton_poi_fused_convolution_relu_8[grid(32768)](buf106,
primals_105, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_105
buf107 = extern_kernels.convolution(buf106, primals_106, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf107, (4, 128, 8, 8), (8192, 64, 8, 1))
buf108 = buf107
del buf107
triton_poi_fused_convolution_relu_8[grid(32768)](buf108,
primals_107, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_107
buf109 = extern_kernels.convolution(buf108, primals_108, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf109, (4, 128, 8, 8), (8192, 64, 8, 1))
buf110 = buf109
del buf109
triton_poi_fused_convolution_relu_8[grid(32768)](buf110,
primals_109, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_109
buf111 = extern_kernels.convolution(buf110, primals_110, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf111, (4, 128, 8, 8), (8192, 64, 8, 1))
buf112 = buf111
del buf111
triton_poi_fused_convolution_relu_8[grid(32768)](buf112,
primals_111, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_111
buf113 = extern_kernels.convolution(buf112, primals_112, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf113, (4, 128, 8, 8), (8192, 64, 8, 1))
buf114 = buf113
del buf113
triton_poi_fused_convolution_relu_8[grid(32768)](buf114,
primals_113, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_113
buf115 = extern_kernels.convolution(buf114, primals_114, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf115, (4, 38, 8, 8), (2432, 64, 8, 1))
buf116 = extern_kernels.convolution(buf102, primals_116, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf116, (4, 128, 8, 8), (8192, 64, 8, 1))
buf117 = buf116
del buf116
triton_poi_fused_convolution_relu_8[grid(32768)](buf117,
primals_117, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_117
buf118 = extern_kernels.convolution(buf117, primals_118, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf118, (4, 128, 8, 8), (8192, 64, 8, 1))
buf119 = buf118
del buf118
triton_poi_fused_convolution_relu_8[grid(32768)](buf119,
primals_119, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_119
buf120 = extern_kernels.convolution(buf119, primals_120, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf120, (4, 128, 8, 8), (8192, 64, 8, 1))
buf121 = buf120
del buf120
triton_poi_fused_convolution_relu_8[grid(32768)](buf121,
primals_121, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_121
buf122 = extern_kernels.convolution(buf121, primals_122, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf122, (4, 128, 8, 8), (8192, 64, 8, 1))
buf123 = buf122
del buf122
triton_poi_fused_convolution_relu_8[grid(32768)](buf123,
primals_123, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_123
buf124 = extern_kernels.convolution(buf123, primals_124, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf124, (4, 128, 8, 8), (8192, 64, 8, 1))
buf125 = buf124
del buf124
triton_poi_fused_convolution_relu_8[grid(32768)](buf125,
primals_125, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_125
buf126 = extern_kernels.convolution(buf125, primals_126, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf126, (4, 128, 8, 8), (8192, 64, 8, 1))
buf127 = buf126
del buf126
triton_poi_fused_convolution_relu_8[grid(32768)](buf127,
primals_127, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_127
buf128 = extern_kernels.convolution(buf127, primals_128, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf128, (4, 19, 8, 8), (1216, 64, 8, 1))
buf129 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1),
torch.float32)
triton_poi_fused_cat_9[grid(47360)](buf115, primals_115, buf128,
primals_129, buf29, buf129, 47360, XBLOCK=512, num_warps=4,
num_stages=1)
del buf115
del buf128
del primals_115
del primals_129
buf130 = extern_kernels.convolution(buf129, primals_130, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf130, (4, 128, 8, 8), (8192, 64, 8, 1))
buf131 = buf130
del buf130
triton_poi_fused_convolution_relu_8[grid(32768)](buf131,
primals_131, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_131
buf132 = extern_kernels.convolution(buf131, primals_132, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf132, (4, 128, 8, 8), (8192, 64, 8, 1))
buf133 = buf132
del buf132
triton_poi_fused_convolution_relu_8[grid(32768)](buf133,
primals_133, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_133
buf134 = extern_kernels.convolution(buf133, primals_134, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf134, (4, 128, 8, 8), (8192, 64, 8, 1))
buf135 = buf134
del buf134
triton_poi_fused_convolution_relu_8[grid(32768)](buf135,
primals_135, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_135
buf136 = extern_kernels.convolution(buf135, primals_136, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf136, (4, 128, 8, 8), (8192, 64, 8, 1))
buf137 = buf136
del buf136
triton_poi_fused_convolution_relu_8[grid(32768)](buf137,
primals_137, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_137
buf138 = extern_kernels.convolution(buf137, primals_138, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf138, (4, 128, 8, 8), (8192, 64, 8, 1))
buf139 = buf138
del buf138
triton_poi_fused_convolution_relu_8[grid(32768)](buf139,
primals_139, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_139
buf140 = extern_kernels.convolution(buf139, primals_140, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf140, (4, 128, 8, 8), (8192, 64, 8, 1))
buf141 = buf140
del buf140
triton_poi_fused_convolution_relu_8[grid(32768)](buf141,
primals_141, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_141
buf142 = extern_kernels.convolution(buf141, primals_142, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf142, (4, 38, 8, 8), (2432, 64, 8, 1))
buf143 = extern_kernels.convolution(buf129, primals_144, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf143, (4, 128, 8, 8), (8192, 64, 8, 1))
buf144 = buf143
del buf143
triton_poi_fused_convolution_relu_8[grid(32768)](buf144,
primals_145, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_145
buf145 = extern_kernels.convolution(buf144, primals_146, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf145, (4, 128, 8, 8), (8192, 64, 8, 1))
buf146 = buf145
del buf145
triton_poi_fused_convolution_relu_8[grid(32768)](buf146,
primals_147, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_147
buf147 = extern_kernels.convolution(buf146, primals_148, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf147, (4, 128, 8, 8), (8192, 64, 8, 1))
buf148 = buf147
del buf147
triton_poi_fused_convolution_relu_8[grid(32768)](buf148,
primals_149, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_149
buf149 = extern_kernels.convolution(buf148, primals_150, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf149, (4, 128, 8, 8), (8192, 64, 8, 1))
buf150 = buf149
del buf149
triton_poi_fused_convolution_relu_8[grid(32768)](buf150,
primals_151, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_151
buf151 = extern_kernels.convolution(buf150, primals_152, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf151, (4, 128, 8, 8), (8192, 64, 8, 1))
buf152 = buf151
del buf151
triton_poi_fused_convolution_relu_8[grid(32768)](buf152,
primals_153, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_153
buf153 = extern_kernels.convolution(buf152, primals_154, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf153, (4, 128, 8, 8), (8192, 64, 8, 1))
buf154 = buf153
del buf153
triton_poi_fused_convolution_relu_8[grid(32768)](buf154,
primals_155, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_155
buf155 = extern_kernels.convolution(buf154, primals_156, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf155, (4, 19, 8, 8), (1216, 64, 8, 1))
buf156 = empty_strided_cuda((4, 185, 8, 8), (11840, 64, 8, 1),
torch.float32)
triton_poi_fused_cat_9[grid(47360)](buf142, primals_143, buf155,
primals_157, buf29, buf156, 47360, XBLOCK=512, num_warps=4,
num_stages=1)
del buf142
del buf155
del primals_143
del primals_157
buf157 = extern_kernels.convolution(buf156, primals_158, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf157, (4, 128, 8, 8), (8192, 64, 8, 1))
buf158 = buf157
del buf157
triton_poi_fused_convolution_relu_8[grid(32768)](buf158,
primals_159, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_159
buf159 = extern_kernels.convolution(buf158, primals_160, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf159, (4, 128, 8, 8), (8192, 64, 8, 1))
buf160 = buf159
del buf159
triton_poi_fused_convolution_relu_8[grid(32768)](buf160,
primals_161, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_161
buf161 = extern_kernels.convolution(buf160, primals_162, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf161, (4, 128, 8, 8), (8192, 64, 8, 1))
buf162 = buf161
del buf161
triton_poi_fused_convolution_relu_8[grid(32768)](buf162,
primals_163, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_163
buf163 = extern_kernels.convolution(buf162, primals_164, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf163, (4, 128, 8, 8), (8192, 64, 8, 1))
buf164 = buf163
del buf163
triton_poi_fused_convolution_relu_8[grid(32768)](buf164,
primals_165, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_165
buf165 = extern_kernels.convolution(buf164, primals_166, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf165, (4, 128, 8, 8), (8192, 64, 8, 1))
buf166 = buf165
del buf165
triton_poi_fused_convolution_relu_8[grid(32768)](buf166,
primals_167, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_167
buf167 = extern_kernels.convolution(buf166, primals_168, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf167, (4, 128, 8, 8), (8192, 64, 8, 1))
buf168 = buf167
del buf167
triton_poi_fused_convolution_relu_8[grid(32768)](buf168,
primals_169, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_169
buf169 = extern_kernels.convolution(buf168, primals_170, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf169, (4, 38, 8, 8), (2432, 64, 8, 1))
buf170 = buf169
del buf169
triton_poi_fused_convolution_10[grid(9728)](buf170, primals_171,
9728, XBLOCK=256, num_warps=4, num_stages=1)
del primals_171
buf171 = extern_kernels.convolution(buf156, primals_172, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf171, (4, 128, 8, 8), (8192, 64, 8, 1))
buf172 = buf171
del buf171
triton_poi_fused_convolution_relu_8[grid(32768)](buf172,
primals_173, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_173
buf173 = extern_kernels.convolution(buf172, primals_174, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf173, (4, 128, 8, 8), (8192, 64, 8, 1))
buf174 = buf173
del buf173
triton_poi_fused_convolution_relu_8[grid(32768)](buf174,
primals_175, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_175
buf175 = extern_kernels.convolution(buf174, primals_176, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf175, (4, 128, 8, 8), (8192, 64, 8, 1))
buf176 = buf175
del buf175
triton_poi_fused_convolution_relu_8[grid(32768)](buf176,
primals_177, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_177
buf177 = extern_kernels.convolution(buf176, primals_178, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf177, (4, 128, 8, 8), (8192, 64, 8, 1))
buf178 = buf177
del buf177
triton_poi_fused_convolution_relu_8[grid(32768)](buf178,
primals_179, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_179
buf179 = extern_kernels.convolution(buf178, primals_180, stride=(1,
1), padding=(3, 3), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf179, (4, 128, 8, 8), (8192, 64, 8, 1))
buf180 = buf179
del buf179
triton_poi_fused_convolution_relu_8[grid(32768)](buf180,
primals_181, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_181
buf181 = extern_kernels.convolution(buf180, primals_182, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf181, (4, 128, 8, 8), (8192, 64, 8, 1))
buf182 = buf181
del buf181
triton_poi_fused_convolution_relu_8[grid(32768)](buf182,
primals_183, 32768, XBLOCK=256, num_warps=4, num_stages=1)
del primals_183
buf183 = extern_kernels.convolution(buf182, primals_184, stride=(1,
1), padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf183, (4, 19, 8, 8), (1216, 64, 8, 1))
buf184 = buf183
del buf183
buf185 = empty_strided_cuda((4, 19, 8, 8), (1280, 64, 8, 1), torch.bool
)
triton_poi_fused_convolution_relu_threshold_backward_11[grid(4864)](
buf184, primals_185, buf185, 4864, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_185
return (buf170, buf184, primals_1, primals_3, primals_4, primals_6,
primals_8, primals_10, primals_12, primals_14, primals_16,
primals_18, primals_20, primals_22, primals_24, primals_26,
primals_28, primals_30, primals_32, primals_34, primals_36,
primals_38, primals_40, primals_42, primals_44, primals_46,
primals_48, primals_50, primals_52, primals_54, primals_56,
primals_58, primals_60, primals_62, primals_64, primals_66,
primals_68, primals_70, primals_72, primals_74, primals_76,
primals_78, primals_80, primals_82, primals_84, primals_86,
primals_88, primals_90, primals_92, primals_94, primals_96,
primals_98, primals_100, primals_102, primals_104, primals_106,
primals_108, primals_110, primals_112, primals_114, primals_116,
primals_118, primals_120, primals_122, primals_124, primals_126,
primals_128, primals_130, primals_132, primals_134, primals_136,
primals_138, primals_140, primals_142, primals_144, primals_146,
primals_148, primals_150, primals_152, primals_154, primals_156,
primals_158, primals_160, primals_162, primals_164, primals_166,
primals_168, primals_170, primals_172, primals_174, primals_176,
primals_178, primals_180, primals_182, primals_184, buf1, buf3,
buf4, buf5, buf7, buf9, buf10, buf11, buf13, buf15, buf17, buf19,
buf20, buf21, buf23, buf25, buf27, buf29, buf31, buf33, buf35,
buf37, buf40, buf42, buf44, buf46, buf48, buf50, buf52, buf54,
buf56, buf58, buf60, buf63, buf65, buf67, buf69, buf71, buf73,
buf75, buf77, buf79, buf81, buf83, buf85, buf87, buf90, buf92,
buf94, buf96, buf98, buf100, buf102, buf104, buf106, buf108, buf110,
buf112, buf114, buf117, buf119, buf121, buf123, buf125, buf127,
buf129, buf131, buf133, buf135, buf137, buf139, buf141, buf144,
buf146, buf148, buf150, buf152, buf154, buf156, buf158, buf160,
buf162, buf164, buf166, buf168, buf172, buf174, buf176, buf178,
buf180, buf182, buf185)
def _make_layers(block, no_relu_layers):
layers = []
for layer_name, v in block.items():
if 'pool' in layer_name:
layer = torch.nn.MaxPool2d(kernel_size=v[0], stride=v[1],
padding=v[2])
layers.append((layer_name, layer))
else:
conv2d = torch.nn.Conv2d(in_channels=v[0], out_channels=v[1],
kernel_size=v[2], stride=v[3], padding=v[4])
layers.append((layer_name, conv2d))
if layer_name not in no_relu_layers:
layers.append(('relu_' + layer_name, torch.nn.ReLU(inplace=
True)))
return torch.nn.Sequential(OrderedDict(layers))
class BodyPoseModelNew(torch.nn.Module):
def __init__(self):
super(BodyPoseModelNew, self).__init__()
no_relu_layers = ['conv5_5_CPM_L1', 'conv5_5_CPM_L2',
'Mconv7_stage2_L1', 'Mconv7_stage2_L2', 'Mconv7_stage3_L1',
'Mconv7_stage3_L2', 'Mconv7_stage4_L1', 'Mconv7_stage4_L2',
'Mconv7_stage5_L1', 'Mconv7_stage5_L2', 'Mconv7_stage6_L1',
'Mconv7_stage6_L1']
blocks = {}
block0 = OrderedDict({'conv1_1': [3, 64, 3, 1, 1], 'conv1_2': [64,
64, 3, 1, 1], 'pool1_stage1': [2, 2, 0], 'conv2_1': [64, 128, 3,
1, 1], 'conv2_2': [128, 128, 3, 1, 1], 'pool2_stage1': [2, 2, 0
], 'conv3_1': [128, 256, 3, 1, 1], 'conv3_2': [256, 256, 3, 1,
1], 'conv3_3': [256, 256, 3, 1, 1], 'conv3_4': [256, 256, 3, 1,
1], 'pool3_stage1': [2, 2, 0], 'conv4_1': [256, 512, 3, 1, 1],
'conv4_2': [512, 512, 3, 1, 1], 'conv4_3_CPM': [512, 256, 3, 1,
1], 'conv4_4_CPM': [256, 128, 3, 1, 1]})
block1_1 = OrderedDict({'conv5_1_CPM_L1': [128, 128, 3, 1, 1],
'conv5_2_CPM_L1': [128, 128, 3, 1, 1], 'conv5_3_CPM_L1': [128,
128, 3, 1, 1], 'conv5_4_CPM_L1': [128, 512, 1, 1, 0],
'conv5_5_CPM_L1': [512, 38, 1, 1, 0]})
block1_2 = OrderedDict({'conv5_1_CPM_L2': [128, 128, 3, 1, 1],
'conv5_2_CPM_L2': [128, 128, 3, 1, 1], 'conv5_3_CPM_L2': [128,
128, 3, 1, 1], 'conv5_4_CPM_L2': [128, 512, 1, 1, 0],
'conv5_5_CPM_L2': [512, 19, 1, 1, 0]})
blocks['block1_1'] = block1_1
blocks['block1_2'] = block1_2
self.model0 = _make_layers(block0, no_relu_layers)
for i in range(2, 7):
blocks['block%d_1' % i] = OrderedDict({('Mconv1_stage%d_L1' % i
): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L1' % i): [128,
128, 7, 1, 3], ('Mconv3_stage%d_L1' % i): [128, 128, 7, 1,
3], ('Mconv4_stage%d_L1' % i): [128, 128, 7, 1, 3], (
'Mconv5_stage%d_L1' % i): [128, 128, 7, 1, 3], (
'Mconv6_stage%d_L1' % i): [128, 128, 1, 1, 0], (
'Mconv7_stage%d_L1' % i): [128, 38, 1, 1, 0]})
blocks['block%d_2' % i] = OrderedDict({('Mconv1_stage%d_L2' % i
): [185, 128, 7, 1, 3], ('Mconv2_stage%d_L2' % i): [128,
128, 7, 1, 3], ('Mconv3_stage%d_L2' % i): [128, 128, 7, 1,
3], ('Mconv4_stage%d_L2' % i): [128, 128, 7, 1, 3], (
'Mconv5_stage%d_L2' % i): [128, 128, 7, 1, 3], (
'Mconv6_stage%d_L2' % i): [128, 128, 1, 1, 0], (
'Mconv7_stage%d_L2' % i): [128, 19, 1, 1, 0]})
for k in blocks.keys():
blocks[k] = _make_layers(blocks[k], no_relu_layers)
self.model1_1 = blocks['block1_1']
self.model2_1 = blocks['block2_1']
self.model3_1 = blocks['block3_1']
self.model4_1 = blocks['block4_1']
self.model5_1 = blocks['block5_1']
self.model6_1 = blocks['block6_1']
self.model1_2 = blocks['block1_2']
self.model2_2 = blocks['block2_2']
self.model3_2 = blocks['block3_2']
self.model4_2 = blocks['block4_2']
self.model5_2 = blocks['block5_2']
self.model6_2 = blocks['block6_2']
def forward(self, input_0):
primals_1 = self.model0.conv1_1.weight
primals_2 = self.model0.conv1_1.bias
primals_4 = self.model0.conv1_2.weight
primals_5 = self.model0.conv1_2.bias
primals_6 = self.model0.conv2_1.weight
primals_7 = self.model0.conv2_1.bias
primals_8 = self.model0.conv2_2.weight
primals_9 = self.model0.conv2_2.bias
primals_10 = self.model0.conv3_1.weight
primals_11 = self.model0.conv3_1.bias
primals_12 = self.model0.conv3_2.weight
primals_13 = self.model0.conv3_2.bias
primals_14 = self.model0.conv3_3.weight
primals_15 = self.model0.conv3_3.bias
primals_16 = self.model0.conv3_4.weight
primals_17 = self.model0.conv3_4.bias
primals_18 = self.model0.conv4_1.weight
primals_19 = self.model0.conv4_1.bias
primals_20 = self.model0.conv4_2.weight
primals_21 = self.model0.conv4_2.bias
primals_22 = self.model0.conv4_3_CPM.weight
primals_23 = self.model0.conv4_3_CPM.bias
primals_24 = self.model0.conv4_4_CPM.weight
primals_25 = self.model0.conv4_4_CPM.bias
primals_26 = self.model1_1.conv5_1_CPM_L1.weight
primals_27 = self.model1_1.conv5_1_CPM_L1.bias
primals_28 = self.model1_1.conv5_2_CPM_L1.weight
primals_29 = self.model1_1.conv5_2_CPM_L1.bias
primals_30 = self.model1_1.conv5_3_CPM_L1.weight
primals_31 = self.model1_1.conv5_3_CPM_L1.bias
primals_32 = self.model1_1.conv5_4_CPM_L1.weight
primals_33 = self.model1_1.conv5_4_CPM_L1.bias
primals_34 = self.model1_1.conv5_5_CPM_L1.weight
primals_35 = self.model1_1.conv5_5_CPM_L1.bias
primals_46 = self.model2_1.Mconv1_stage2_L1.weight
primals_37 = self.model2_1.Mconv1_stage2_L1.bias
primals_48 = self.model2_1.Mconv2_stage2_L1.weight
primals_39 = self.model2_1.Mconv2_stage2_L1.bias
primals_50 = self.model2_1.Mconv3_stage2_L1.weight
primals_41 = self.model2_1.Mconv3_stage2_L1.bias
primals_52 = self.model2_1.Mconv4_stage2_L1.weight
primals_47 = self.model2_1.Mconv4_stage2_L1.bias
primals_54 = self.model2_1.Mconv5_stage2_L1.weight
primals_49 = self.model2_1.Mconv5_stage2_L1.bias
primals_56 = self.model2_1.Mconv6_stage2_L1.weight
primals_51 = self.model2_1.Mconv6_stage2_L1.bias
primals_58 = self.model2_1.Mconv7_stage2_L1.weight
primals_59 = self.model2_1.Mconv7_stage2_L1.bias
primals_60 = self.model3_1.Mconv1_stage3_L1.weight
primals_53 = self.model3_1.Mconv1_stage3_L1.bias
primals_62 = self.model3_1.Mconv2_stage3_L1.weight
primals_55 = self.model3_1.Mconv2_stage3_L1.bias
primals_64 = self.model3_1.Mconv3_stage3_L1.weight
primals_57 = self.model3_1.Mconv3_stage3_L1.bias
primals_66 = self.model3_1.Mconv4_stage3_L1.weight
primals_61 = self.model3_1.Mconv4_stage3_L1.bias
primals_68 = self.model3_1.Mconv5_stage3_L1.weight
primals_63 = self.model3_1.Mconv5_stage3_L1.bias
primals_70 = self.model3_1.Mconv6_stage3_L1.weight
primals_65 = self.model3_1.Mconv6_stage3_L1.bias
primals_86 = self.model3_1.Mconv7_stage3_L1.weight
primals_87 = self.model3_1.Mconv7_stage3_L1.bias
primals_74 = self.model4_1.Mconv1_stage4_L1.weight
primals_67 = self.model4_1.Mconv1_stage4_L1.bias
primals_76 = self.model4_1.Mconv2_stage4_L1.weight
primals_69 = self.model4_1.Mconv2_stage4_L1.bias
primals_78 = self.model4_1.Mconv3_stage4_L1.weight
primals_71 = self.model4_1.Mconv3_stage4_L1.bias
primals_80 = self.model4_1.Mconv4_stage4_L1.weight
primals_75 = self.model4_1.Mconv4_stage4_L1.bias
primals_82 = self.model4_1.Mconv5_stage4_L1.weight
primals_77 = self.model4_1.Mconv5_stage4_L1.bias
primals_84 = self.model4_1.Mconv6_stage4_L1.weight
primals_79 = self.model4_1.Mconv6_stage4_L1.bias
primals_114 = self.model4_1.Mconv7_stage4_L1.weight
primals_115 = self.model4_1.Mconv7_stage4_L1.bias
primals_88 = self.model5_1.Mconv1_stage5_L1.weight
primals_81 = self.model5_1.Mconv1_stage5_L1.bias
primals_90 = self.model5_1.Mconv2_stage5_L1.weight
primals_83 = self.model5_1.Mconv2_stage5_L1.bias
primals_92 = self.model5_1.Mconv3_stage5_L1.weight
primals_85 = self.model5_1.Mconv3_stage5_L1.bias
primals_94 = self.model5_1.Mconv4_stage5_L1.weight
primals_89 = self.model5_1.Mconv4_stage5_L1.bias
primals_96 = self.model5_1.Mconv5_stage5_L1.weight
primals_91 = self.model5_1.Mconv5_stage5_L1.bias
primals_98 = self.model5_1.Mconv6_stage5_L1.weight
primals_93 = self.model5_1.Mconv6_stage5_L1.bias
primals_142 = self.model5_1.Mconv7_stage5_L1.weight
primals_143 = self.model5_1.Mconv7_stage5_L1.bias
primals_102 = self.model6_1.Mconv1_stage6_L1.weight
primals_95 = self.model6_1.Mconv1_stage6_L1.bias
primals_104 = self.model6_1.Mconv2_stage6_L1.weight
primals_97 = self.model6_1.Mconv2_stage6_L1.bias
primals_106 = self.model6_1.Mconv3_stage6_L1.weight
primals_99 = self.model6_1.Mconv3_stage6_L1.bias
primals_108 = self.model6_1.Mconv4_stage6_L1.weight
primals_103 = self.model6_1.Mconv4_stage6_L1.bias
primals_110 = self.model6_1.Mconv5_stage6_L1.weight
primals_105 = self.model6_1.Mconv5_stage6_L1.bias
primals_112 = self.model6_1.Mconv6_stage6_L1.weight
primals_107 = self.model6_1.Mconv6_stage6_L1.bias
primals_170 = self.model6_1.Mconv7_stage6_L1.weight
primals_171 = self.model6_1.Mconv7_stage6_L1.bias
primals_36 = self.model1_2.conv5_1_CPM_L2.weight
primals_109 = self.model1_2.conv5_1_CPM_L2.bias
primals_38 = self.model1_2.conv5_2_CPM_L2.weight
primals_111 = self.model1_2.conv5_2_CPM_L2.bias
primals_40 = self.model1_2.conv5_3_CPM_L2.weight
primals_113 = self.model1_2.conv5_3_CPM_L2.bias
primals_42 = self.model1_2.conv5_4_CPM_L2.weight
primals_43 = self.model1_2.conv5_4_CPM_L2.bias
primals_44 = self.model1_2.conv5_5_CPM_L2.weight
primals_45 = self.model1_2.conv5_5_CPM_L2.bias
primals_116 = self.model2_2.Mconv1_stage2_L2.weight
primals_117 = self.model2_2.Mconv1_stage2_L2.bias
primals_118 = self.model2_2.Mconv2_stage2_L2.weight
primals_119 = self.model2_2.Mconv2_stage2_L2.bias
primals_120 = self.model2_2.Mconv3_stage2_L2.weight
primals_121 = self.model2_2.Mconv3_stage2_L2.bias
primals_122 = self.model2_2.Mconv4_stage2_L2.weight
primals_123 = self.model2_2.Mconv4_stage2_L2.bias
primals_124 = self.model2_2.Mconv5_stage2_L2.weight
primals_125 = self.model2_2.Mconv5_stage2_L2.bias
primals_126 = self.model2_2.Mconv6_stage2_L2.weight
primals_127 = self.model2_2.Mconv6_stage2_L2.bias
primals_72 = self.model2_2.Mconv7_stage2_L2.weight
primals_73 = self.model2_2.Mconv7_stage2_L2.bias
primals_130 = self.model3_2.Mconv1_stage3_L2.weight
primals_131 = self.model3_2.Mconv1_stage3_L2.bias
primals_132 = self.model3_2.Mconv2_stage3_L2.weight
primals_133 = self.model3_2.Mconv2_stage3_L2.bias
primals_134 = self.model3_2.Mconv3_stage3_L2.weight
primals_135 = self.model3_2.Mconv3_stage3_L2.bias
primals_136 = self.model3_2.Mconv4_stage3_L2.weight
primals_137 = self.model3_2.Mconv4_stage3_L2.bias
primals_138 = self.model3_2.Mconv5_stage3_L2.weight
primals_139 = self.model3_2.Mconv5_stage3_L2.bias
primals_140 = self.model3_2.Mconv6_stage3_L2.weight
primals_141 = self.model3_2.Mconv6_stage3_L2.bias
primals_100 = self.model3_2.Mconv7_stage3_L2.weight
primals_101 = self.model3_2.Mconv7_stage3_L2.bias
primals_144 = self.model4_2.Mconv1_stage4_L2.weight
primals_145 = self.model4_2.Mconv1_stage4_L2.bias
primals_146 = self.model4_2.Mconv2_stage4_L2.weight
primals_147 = self.model4_2.Mconv2_stage4_L2.bias
primals_148 = self.model4_2.Mconv3_stage4_L2.weight
primals_149 = self.model4_2.Mconv3_stage4_L2.bias
primals_150 = self.model4_2.Mconv4_stage4_L2.weight
primals_151 = self.model4_2.Mconv4_stage4_L2.bias
primals_152 = self.model4_2.Mconv5_stage4_L2.weight
primals_153 = self.model4_2.Mconv5_stage4_L2.bias
primals_154 = self.model4_2.Mconv6_stage4_L2.weight
primals_155 = self.model4_2.Mconv6_stage4_L2.bias
primals_128 = self.model4_2.Mconv7_stage4_L2.weight
primals_129 = self.model4_2.Mconv7_stage4_L2.bias
primals_158 = self.model5_2.Mconv1_stage5_L2.weight
primals_159 = self.model5_2.Mconv1_stage5_L2.bias
primals_160 = self.model5_2.Mconv2_stage5_L2.weight
primals_161 = self.model5_2.Mconv2_stage5_L2.bias
primals_162 = self.model5_2.Mconv3_stage5_L2.weight
primals_163 = self.model5_2.Mconv3_stage5_L2.bias
primals_164 = self.model5_2.Mconv4_stage5_L2.weight
primals_165 = self.model5_2.Mconv4_stage5_L2.bias
primals_166 = self.model5_2.Mconv5_stage5_L2.weight
primals_167 = self.model5_2.Mconv5_stage5_L2.bias
primals_168 = self.model5_2.Mconv6_stage5_L2.weight
primals_169 = self.model5_2.Mconv6_stage5_L2.bias
primals_156 = self.model5_2.Mconv7_stage5_L2.weight
primals_157 = self.model5_2.Mconv7_stage5_L2.bias
primals_172 = self.model6_2.Mconv1_stage6_L2.weight
primals_173 = self.model6_2.Mconv1_stage6_L2.bias
primals_174 = self.model6_2.Mconv2_stage6_L2.weight
primals_175 = self.model6_2.Mconv2_stage6_L2.bias
primals_176 = self.model6_2.Mconv3_stage6_L2.weight
primals_177 = self.model6_2.Mconv3_stage6_L2.bias
primals_178 = self.model6_2.Mconv4_stage6_L2.weight
primals_179 = self.model6_2.Mconv4_stage6_L2.bias
primals_180 = self.model6_2.Mconv5_stage6_L2.weight
primals_181 = self.model6_2.Mconv5_stage6_L2.bias
primals_182 = self.model6_2.Mconv6_stage6_L2.weight
primals_183 = self.model6_2.Mconv6_stage6_L2.bias
primals_184 = self.model6_2.Mconv7_stage6_L2.weight
primals_185 = self.model6_2.Mconv7_stage6_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])
return output[0], output[1]
|
pento-group/terran
|
BodyPoseModel
| false
| 16,460
|
[
"BSD-3-Clause"
] | 62
|
983f18521b149749c944e3b29c86361cb1ecf3a5
|
https://github.com/pento-group/terran/tree/983f18521b149749c944e3b29c86361cb1ecf3a5
|
LASympNet
|
from torch.nn import Module
import torch
import torch.nn as nn
class Module(torch.nn.Module):
"""Standard module format.
"""
def __init__(self):
super(Module, self).__init__()
self.activation = None
self.initializer = None
self.__device = None
self.__dtype = None
@property
def device(self):
return self.__device
@property
def dtype(self):
return self.__dtype
@device.setter
def device(self, d):
if d == 'cpu':
self.cpu()
elif d == 'gpu':
self
else:
raise ValueError
self.__device = d
@dtype.setter
def dtype(self, d):
if d == 'float':
self
elif d == 'double':
self
else:
raise ValueError
self.__dtype = d
@property
def Device(self):
if self.__device == 'cpu':
return torch.device('cpu')
elif self.__device == 'gpu':
return torch.device('cuda')
@property
def Dtype(self):
if self.__dtype == 'float':
return torch.float32
elif self.__dtype == 'double':
return torch.float64
@property
def act(self):
if self.activation == 'sigmoid':
return torch.sigmoid
elif self.activation == 'relu':
return torch.relu
elif self.activation == 'tanh':
return torch.tanh
elif self.activation == 'elu':
return torch.elu
else:
raise NotImplementedError
@property
def Act(self):
if self.activation == 'sigmoid':
return torch.nn.Sigmoid()
elif self.activation == 'relu':
return torch.nn.ReLU()
elif self.activation == 'tanh':
return torch.nn.Tanh()
elif self.activation == 'elu':
return torch.nn.ELU()
else:
raise NotImplementedError
@property
def weight_init_(self):
if self.initializer == 'He normal':
return torch.nn.init.kaiming_normal_
elif self.initializer == 'He uniform':
return torch.nn.init.kaiming_uniform_
elif self.initializer == 'Glorot normal':
return torch.nn.init.xavier_normal_
elif self.initializer == 'Glorot uniform':
return torch.nn.init.xavier_uniform_
elif self.initializer == 'orthogonal':
return torch.nn.init.orthogonal_
elif self.initializer == 'default':
if self.activation == 'relu':
return torch.nn.init.kaiming_normal_
elif self.activation == 'tanh':
return torch.nn.init.orthogonal_
else:
return lambda x: None
else:
raise NotImplementedError
class StructureNN(Module):
"""Structure-oriented neural network used as a general map based on designing architecture.
"""
def __init__(self):
super(StructureNN, self).__init__()
def predict(self, x, returnnp=False):
if not isinstance(x, torch.Tensor):
x = torch.tensor(x, dtype=self.Dtype, device=self.Device)
return self(x).cpu().detach().numpy() if returnnp else self(x)
class LinearModule(Module):
"""Linear symplectic module.
"""
def __init__(self, dim, layers):
super(LinearModule, self).__init__()
self.dim = dim
self.layers = layers
self.params = self.__init_params()
def forward(self, pqh):
p, q, h = pqh
for i in range(self.layers):
S = self.params['S{}'.format(i + 1)]
if i % 2 == 0:
p = p + q @ (S + S.t()) * h
else:
q = p @ (S + S.t()) * h + q
return p + self.params['bp'] * h, q + self.params['bq'] * h
def __init_params(self):
"""Si is distributed N(0, 0.01), and b is set to zero.
"""
d = int(self.dim / 2)
params = nn.ParameterDict()
for i in range(self.layers):
params['S{}'.format(i + 1)] = nn.Parameter((torch.randn([d, d]) *
0.01).requires_grad_(True))
params['bp'] = nn.Parameter(torch.zeros([d]).requires_grad_(True))
params['bq'] = nn.Parameter(torch.zeros([d]).requires_grad_(True))
return params
class ActivationModule(Module):
"""Activation symplectic module.
"""
def __init__(self, dim, activation, mode):
super(ActivationModule, self).__init__()
self.dim = dim
self.activation = activation
self.mode = mode
self.params = self.__init_params()
def forward(self, pqh):
p, q, h = pqh
if self.mode == 'up':
return p + self.act(q) * self.params['a'] * h, q
elif self.mode == 'low':
return p, self.act(p) * self.params['a'] * h + q
else:
raise ValueError
def __init_params(self):
d = int(self.dim / 2)
params = nn.ParameterDict()
params['a'] = nn.Parameter((torch.randn([d]) * 0.01).requires_grad_
(True))
return params
class SympNet(StructureNN):
def __init__(self):
super(SympNet, self).__init__()
self.dim = None
def predict(self, xh, steps=1, keepinitx=False, returnnp=False):
dim = xh.size(-1)
size = len(xh.size())
if dim == self.dim:
pred = [xh]
for _ in range(steps):
pred.append(self(pred[-1]))
else:
x0, h = xh[..., :-1], xh[..., -1:]
pred = [x0]
for _ in range(steps):
pred.append(self(torch.cat([pred[-1], h], dim=-1)))
if keepinitx:
steps = steps + 1
else:
pred = pred[1:]
res = torch.cat(pred, dim=-1).view([-1, steps, self.dim][2 - size:])
return res.cpu().detach().numpy() if returnnp else res
class LASympNet(SympNet):
"""LA-SympNet.
Input: [num, dim] or [num, dim + 1]
Output: [num, dim]
"""
def __init__(self, dim, layers=3, sublayers=2, activation='sigmoid'):
super(LASympNet, self).__init__()
self.dim = dim
self.layers = layers
self.sublayers = sublayers
self.activation = activation
self.modus = self.__init_modules()
def forward(self, pqh):
d = int(self.dim / 2)
if pqh.size(-1) == self.dim + 1:
p, q, h = pqh[..., :d], pqh[..., d:-1], pqh[..., -1:]
elif pqh.size(-1) == self.dim:
p, q, h = pqh[..., :d], pqh[..., d:], torch.ones_like(pqh[..., -1:]
)
else:
raise ValueError
for i in range(self.layers - 1):
LinM = self.modus['LinM{}'.format(i + 1)]
ActM = self.modus['ActM{}'.format(i + 1)]
p, q = ActM([*LinM([p, q, h]), h])
return torch.cat(self.modus['LinMout']([p, q, h]), dim=-1)
def __init_modules(self):
modules = nn.ModuleDict()
for i in range(self.layers - 1):
modules['LinM{}'.format(i + 1)] = LinearModule(self.dim, self.
sublayers)
mode = 'up' if i % 2 == 0 else 'low'
modules['ActM{}'.format(i + 1)] = ActivationModule(self.dim,
self.activation, mode)
modules['LinMout'] = LinearModule(self.dim, self.sublayers)
return modules
def get_inputs():
return [torch.rand([4, 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.nn import Module
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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 2
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
x1 = xindex
y0 = yindex
tmp0 = tl.load(in_ptr0 + (x1 + 2 * y0), xmask & ymask)
tmp1 = tl.load(in_ptr0 + (y0 + 2 * x1), xmask & ymask)
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x1 + 2 * y0), tmp2, xmask & ymask)
@triton.jit
def triton_poi_fused_add_1(in_out_ptr0, in_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_out_ptr0 + x2, xmask)
tmp2 = tmp0 + tmp1
tl.store(in_out_ptr0 + x2, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_mul_ones_like_2(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
x1 = xindex // 2
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + (2 + x0 + 4 * x1), xmask)
tmp3 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp4 = 1.0
tmp5 = tmp3 * tmp4
tmp6 = tmp2 + tmp5
tl.store(in_out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_mul_ones_like_sigmoid_3(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr2 + x2, xmask)
tmp7 = tl.load(in_ptr3 + x0, xmask, eviction_policy='evict_last')
tmp10 = tl.load(in_out_ptr0 + x2, xmask)
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp6 = tl.sigmoid(tmp5)
tmp8 = tmp6 * tmp7
tmp9 = tmp4 + tmp8
tmp11 = tmp9 + tmp10
tl.store(in_out_ptr0 + x2, tmp11, xmask)
@triton.jit
def triton_poi_fused_add_mul_ones_like_sigmoid_4(in_out_ptr0, in_ptr0,
in_ptr1, in_ptr2, in_ptr3, in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr2 + x0, xmask, eviction_policy='evict_last')
tmp8 = tl.load(in_out_ptr0 + x2, xmask)
tmp9 = tl.load(in_ptr3 + x2, xmask)
tmp11 = tl.load(in_ptr4 + x0, xmask, eviction_policy='evict_last')
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp5 = tl.sigmoid(tmp4)
tmp7 = tmp5 * tmp6
tmp10 = tmp8 + tmp9
tmp12 = tmp11 * tmp2
tmp13 = tmp10 + tmp12
tmp14 = tmp7 + tmp13
tl.store(out_ptr0 + x2, tmp5, xmask)
tl.store(in_out_ptr0 + x2, tmp14, xmask)
@triton.jit
def triton_poi_fused_add_mul_ones_like_5(in_out_ptr0, in_ptr0, in_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 128
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 2
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_out_ptr0 + x2, xmask)
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp6 = tmp4 + tmp5
tl.store(in_out_ptr0 + x2, tmp6, xmask)
@triton.jit
def triton_poi_fused_cat_6(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
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + (2 * x1 + x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tl.load(in_ptr1 + x0, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp7 = 1.0
tmp8 = tmp6 * tmp7
tmp9 = tmp5 + tmp8
tmp10 = tl.full(tmp9.shape, 0.0, tmp9.dtype)
tmp11 = tl.where(tmp4, tmp9, tmp10)
tmp12 = tmp0 >= tmp3
tl.full([1], 4, tl.int64)
tmp15 = tl.load(in_ptr2 + (2 * x1 + (-2 + x0)), tmp12 & xmask,
eviction_policy='evict_last', other=0.0)
tmp16 = tl.load(in_ptr3 + (2 * x1 + (-2 + x0)), tmp12 & xmask,
eviction_policy='evict_last', other=0.0)
tmp17 = tmp15 + tmp16
tmp18 = tl.load(in_ptr4 + (-2 + x0), tmp12 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp19 = tmp18 * tmp7
tmp20 = tmp17 + tmp19
tmp21 = tl.full(tmp20.shape, 0.0, tmp20.dtype)
tmp22 = tl.where(tmp12, tmp20, tmp21)
tmp23 = tl.where(tmp4, tmp11, tmp22)
tl.store(out_ptr0 + x2, tmp23, 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) = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_2, (2, 2), (2, 1))
assert_size_stride(primals_3, (2, 2), (2, 1))
assert_size_stride(primals_4, (2,), (1,))
assert_size_stride(primals_5, (2,), (1,))
assert_size_stride(primals_6, (2,), (1,))
assert_size_stride(primals_7, (2, 2), (2, 1))
assert_size_stride(primals_8, (2, 2), (2, 1))
assert_size_stride(primals_9, (2,), (1,))
assert_size_stride(primals_10, (2,), (1,))
assert_size_stride(primals_11, (2,), (1,))
assert_size_stride(primals_12, (2, 2), (2, 1))
assert_size_stride(primals_13, (2, 2), (2, 1))
assert_size_stride(primals_14, (2,), (1,))
assert_size_stride(primals_15, (2,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((2, 2), (2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_0[grid(2, 2)](primals_2, buf0, 2, 2, XBLOCK=2,
YBLOCK=2, num_warps=1, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (64, 2), (4, 1), 2),
buf0, out=buf1)
buf2 = buf0
del buf0
triton_poi_fused_add_0[grid(2, 2)](primals_3, buf2, 2, 2, XBLOCK=2,
YBLOCK=2, num_warps=1, num_stages=1)
del primals_3
buf3 = reinterpret_tensor(buf1, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf1
triton_poi_fused_add_1[grid(128)](buf3, primals_1, 128, XBLOCK=128,
num_warps=4, num_stages=1)
buf4 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (64, 2), (2, 1), 0),
buf2, out=buf4)
buf5 = reinterpret_tensor(buf4, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf4
triton_poi_fused_add_mul_ones_like_2[grid(128)](buf5, primals_1,
primals_5, 128, XBLOCK=128, num_warps=4, num_stages=1)
del primals_5
buf6 = empty_strided_cuda((2, 2), (2, 1), torch.float32)
triton_poi_fused_add_0[grid(2, 2)](primals_7, buf6, 2, 2, XBLOCK=2,
YBLOCK=2, num_warps=1, num_stages=1)
del primals_7
buf7 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf5, (64, 2), (2, 1), 0),
buf6, out=buf7)
buf8 = reinterpret_tensor(buf7, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf7
triton_poi_fused_add_mul_ones_like_sigmoid_3[grid(128)](buf8, buf3,
primals_4, buf5, primals_6, 128, XBLOCK=128, num_warps=4,
num_stages=1)
del primals_4
buf9 = empty_strided_cuda((2, 2), (2, 1), torch.float32)
triton_poi_fused_add_0[grid(2, 2)](primals_8, buf9, 2, 2, XBLOCK=2,
YBLOCK=2, num_warps=1, num_stages=1)
del primals_8
buf10 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf8, (64, 2), (2, 1), 0),
buf9, out=buf10)
buf11 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
buf12 = reinterpret_tensor(buf10, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf10
triton_poi_fused_add_mul_ones_like_sigmoid_4[grid(128)](buf12, buf8,
primals_9, primals_11, buf5, primals_10, buf11, 128, XBLOCK=128,
num_warps=4, num_stages=1)
del primals_10
buf13 = empty_strided_cuda((2, 2), (2, 1), torch.float32)
triton_poi_fused_add_0[grid(2, 2)](primals_12, buf13, 2, 2, XBLOCK=
2, YBLOCK=2, num_warps=1, num_stages=1)
del primals_12
buf14 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf12, (64, 2), (2, 1), 0),
buf13, out=buf14)
buf15 = empty_strided_cuda((2, 2), (2, 1), torch.float32)
triton_poi_fused_add_0[grid(2, 2)](primals_13, buf15, 2, 2, XBLOCK=
2, YBLOCK=2, num_warps=1, num_stages=1)
del primals_13
buf16 = reinterpret_tensor(buf14, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf14
triton_poi_fused_add_mul_ones_like_5[grid(128)](buf16, buf8,
primals_9, 128, XBLOCK=128, num_warps=4, num_stages=1)
del primals_9
buf17 = empty_strided_cuda((64, 2), (2, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf16, (64, 2), (2, 1), 0),
buf15, out=buf17)
buf18 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_cat_6[grid(256)](buf16, primals_14, buf17, buf12,
primals_15, buf18, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf17
del primals_14
del primals_15
return buf18, primals_6, primals_11, buf5, buf11, reinterpret_tensor(buf16,
(2, 64), (1, 2), 0), reinterpret_tensor(buf15, (2, 2), (1, 2), 0
), reinterpret_tensor(buf12, (2, 64), (1, 2), 0), reinterpret_tensor(
buf13, (2, 2), (1, 2), 0), reinterpret_tensor(buf8, (2, 64), (1, 2), 0
), reinterpret_tensor(buf9, (2, 2), (1, 2), 0), reinterpret_tensor(buf6
, (2, 2), (1, 2), 0), reinterpret_tensor(buf3, (2, 64), (1, 2), 0
), reinterpret_tensor(buf2, (2, 2), (1, 2), 0), reinterpret_tensor(
primals_1, (2, 64), (1, 4), 2)
class Module(torch.nn.Module):
"""Standard module format.
"""
def __init__(self):
super(Module, self).__init__()
self.activation = None
self.initializer = None
self.__device = None
self.__dtype = None
@property
def device(self):
return self.__device
@property
def dtype(self):
return self.__dtype
@device.setter
def device(self, d):
if d == 'cpu':
self.cpu()
elif d == 'gpu':
self
else:
raise ValueError
self.__device = d
@dtype.setter
def dtype(self, d):
if d == 'float':
self
elif d == 'double':
self
else:
raise ValueError
self.__dtype = d
@property
def Device(self):
if self.__device == 'cpu':
return torch.device('cpu')
elif self.__device == 'gpu':
return torch.device('cuda')
@property
def Dtype(self):
if self.__dtype == 'float':
return torch.float32
elif self.__dtype == 'double':
return torch.float64
@property
def act(self):
if self.activation == 'sigmoid':
return torch.sigmoid
elif self.activation == 'relu':
return torch.relu
elif self.activation == 'tanh':
return torch.tanh
elif self.activation == 'elu':
return torch.elu
else:
raise NotImplementedError
@property
def Act(self):
if self.activation == 'sigmoid':
return torch.nn.Sigmoid()
elif self.activation == 'relu':
return torch.nn.ReLU()
elif self.activation == 'tanh':
return torch.nn.Tanh()
elif self.activation == 'elu':
return torch.nn.ELU()
else:
raise NotImplementedError
@property
def weight_init_(self):
if self.initializer == 'He normal':
return torch.nn.init.kaiming_normal_
elif self.initializer == 'He uniform':
return torch.nn.init.kaiming_uniform_
elif self.initializer == 'Glorot normal':
return torch.nn.init.xavier_normal_
elif self.initializer == 'Glorot uniform':
return torch.nn.init.xavier_uniform_
elif self.initializer == 'orthogonal':
return torch.nn.init.orthogonal_
elif self.initializer == 'default':
if self.activation == 'relu':
return torch.nn.init.kaiming_normal_
elif self.activation == 'tanh':
return torch.nn.init.orthogonal_
else:
return lambda x: None
else:
raise NotImplementedError
class StructureNN(Module):
"""Structure-oriented neural network used as a general map based on designing architecture.
"""
def __init__(self):
super(StructureNN, self).__init__()
def predict(self, x, returnnp=False):
if not isinstance(x, torch.Tensor):
x = torch.tensor(x, dtype=self.Dtype, device=self.Device)
return self(x).cpu().detach().numpy() if returnnp else self(x)
class LinearModule(Module):
"""Linear symplectic module.
"""
def __init__(self, dim, layers):
super(LinearModule, self).__init__()
self.dim = dim
self.layers = layers
self.params = self.__init_params()
def forward(self, pqh):
p, q, h = pqh
for i in range(self.layers):
S = self.params['S{}'.format(i + 1)]
if i % 2 == 0:
p = p + q @ (S + S.t()) * h
else:
q = p @ (S + S.t()) * h + q
return p + self.params['bp'] * h, q + self.params['bq'] * h
def __init_params(self):
"""Si is distributed N(0, 0.01), and b is set to zero.
"""
d = int(self.dim / 2)
params = nn.ParameterDict()
for i in range(self.layers):
params['S{}'.format(i + 1)] = nn.Parameter((torch.randn([d, d]) *
0.01).requires_grad_(True))
params['bp'] = nn.Parameter(torch.zeros([d]).requires_grad_(True))
params['bq'] = nn.Parameter(torch.zeros([d]).requires_grad_(True))
return params
class ActivationModule(Module):
"""Activation symplectic module.
"""
def __init__(self, dim, activation, mode):
super(ActivationModule, self).__init__()
self.dim = dim
self.activation = activation
self.mode = mode
self.params = self.__init_params()
def forward(self, pqh):
p, q, h = pqh
if self.mode == 'up':
return p + self.act(q) * self.params['a'] * h, q
elif self.mode == 'low':
return p, self.act(p) * self.params['a'] * h + q
else:
raise ValueError
def __init_params(self):
d = int(self.dim / 2)
params = nn.ParameterDict()
params['a'] = nn.Parameter((torch.randn([d]) * 0.01).requires_grad_
(True))
return params
class SympNet(StructureNN):
def __init__(self):
super(SympNet, self).__init__()
self.dim = None
def predict(self, xh, steps=1, keepinitx=False, returnnp=False):
dim = xh.size(-1)
size = len(xh.size())
if dim == self.dim:
pred = [xh]
for _ in range(steps):
pred.append(self(pred[-1]))
else:
x0, h = xh[..., :-1], xh[..., -1:]
pred = [x0]
for _ in range(steps):
pred.append(self(torch.cat([pred[-1], h], dim=-1)))
if keepinitx:
steps = steps + 1
else:
pred = pred[1:]
res = torch.cat(pred, dim=-1).view([-1, steps, self.dim][2 - size:])
return res.cpu().detach().numpy() if returnnp else res
class LASympNetNew(SympNet):
"""LA-SympNet.
Input: [num, dim] or [num, dim + 1]
Output: [num, dim]
"""
def __init__(self, dim, layers=3, sublayers=2, activation='sigmoid'):
super(LASympNetNew, self).__init__()
self.dim = dim
self.layers = layers
self.sublayers = sublayers
self.activation = activation
self.modus = self.__init_modules()
def __init_modules(self):
modules = nn.ModuleDict()
for i in range(self.layers - 1):
modules['LinM{}'.format(i + 1)] = LinearModule(self.dim, self.
sublayers)
mode = 'up' if i % 2 == 0 else 'low'
modules['ActM{}'.format(i + 1)] = ActivationModule(self.dim,
self.activation, mode)
modules['LinMout'] = LinearModule(self.dim, self.sublayers)
return modules
def forward(self, input_0):
primals_2 = self.modus.LinM1.params.S1
primals_3 = self.modus.LinM1.params.S2
primals_4 = self.modus.LinM1.params.bp
primals_5 = self.modus.LinM1.params.bq
primals_6 = self.modus.ActM1.params.a
primals_7 = self.modus.LinM2.params.S1
primals_8 = self.modus.LinM2.params.S2
primals_9 = self.modus.LinM2.params.bp
primals_10 = self.modus.LinM2.params.bq
primals_11 = self.modus.ActM2.params.a
primals_12 = self.modus.LinMout.params.S1
primals_13 = self.modus.LinMout.params.S2
primals_14 = self.modus.LinMout.params.bp
primals_15 = self.modus.LinMout.params.bq
primals_1 = 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])
return output[0]
|
shushu-qin/deeponet
|
LASympNet
| false
| 16,461
|
[
"Apache-2.0"
] | 140
|
5bbe066279bba055ad80e04c364140363c87634a
|
https://github.com/shushu-qin/deeponet/tree/5bbe066279bba055ad80e04c364140363c87634a
|
ClassAttention
|
import torch
from torch import Tensor
from torch import nn
class ClassAttention(nn.Module):
def __init__(self, dim, num_heads):
super().__init__()
self.num_heads = num_heads
self.scale = (dim // num_heads) ** -0.5
self.q = nn.Linear(dim, dim, bias=False)
self.kv = nn.Linear(dim, dim * 2, bias=False)
self.proj = nn.Linear(dim, dim)
def forward(self, x: 'Tensor') ->Tensor:
B, N, C = x.shape
q = self.q(x[:, :1, :]).reshape(B, self.num_heads, 1, C // self.
num_heads)
q *= self.scale
kv = self.kv(x).reshape(B, N, 2, self.num_heads, C // self.num_heads
).permute(2, 0, 3, 1, 4)
k, v = kv[0], kv[1]
attn = q @ k.transpose(-2, -1)
attn = attn.softmax(dim=-1)
cls_embed = (attn @ v).transpose(1, 2).reshape(B, 1, C)
cls_embed = self.proj(cls_embed)
return cls_embed
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 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
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_mul_0(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 = 1.0
tmp2 = tmp0 * tmp1
tl.store(in_out_ptr0 + x0, tmp2, 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 + 8 * x2 + 32 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@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 = 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_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
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_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 + (4 + y0 + 8 * x2 + 32 * 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 = 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, (8, 4), (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(reinterpret_tensor(primals_1, (4, 4), (16, 1), 0),
reinterpret_tensor(primals_2, (4, 4), (1, 4), 0), out=buf0)
del primals_2
buf1 = empty_strided_cuda((16, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_1, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 8), (1, 4), 0), out=buf1)
del primals_3
buf2 = reinterpret_tensor(buf0, (4, 4, 1, 1), (4, 1, 16, 16), 0)
del buf0
get_raw_stream(0)
triton_poi_fused_mul_0[grid(16)](buf2, 16, XBLOCK=16, num_warps=1,
num_stages=1)
buf3 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32)
triton_poi_fused_clone_1[grid(16, 4)](buf1, buf3, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf2, (16, 1, 1), (1, 0, 0),
0), reinterpret_tensor(buf3, (16, 1, 4), (4, 0, 1), 0), out=buf4)
buf5 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 64, 1), torch.float32)
triton_poi_fused__softmax_2[grid(64)](buf4, buf5, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf6 = reinterpret_tensor(buf4, (4, 4, 1, 4), (16, 4, 4, 1), 0)
del buf4
triton_poi_fused__softmax_3[grid(64)](buf5, buf6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
buf7 = reinterpret_tensor(buf5, (4, 4, 4, 1), (16, 4, 1, 1), 0)
del buf5
triton_poi_fused_clone_4[grid(16, 4)](buf1, buf7, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
del buf1
buf8 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf6, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf7, (16, 4, 1), (4, 1, 0), 0), out=buf8)
buf9 = empty_strided_cuda((4, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf8, (4, 4), (4,
1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha
=1, beta=1, out=buf9)
del primals_5
return reinterpret_tensor(buf9, (4, 1, 4), (4, 4, 1), 0
), primals_1, buf6, reinterpret_tensor(buf8, (4, 4), (4, 1), 0
), primals_4, reinterpret_tensor(buf7, (16, 1, 4), (4, 1, 1), 0
), reinterpret_tensor(buf2, (16, 1, 1), (1, 1, 1), 0
), reinterpret_tensor(buf3, (16, 4, 1), (4, 1, 4), 0)
class ClassAttentionNew(nn.Module):
def __init__(self, dim, num_heads):
super().__init__()
self.num_heads = num_heads
self.scale = (dim // num_heads) ** -0.5
self.q = nn.Linear(dim, dim, bias=False)
self.kv = nn.Linear(dim, dim * 2, bias=False)
self.proj = nn.Linear(dim, dim)
def forward(self, input_0):
primals_2 = self.q.weight
primals_3 = self.kv.weight
primals_4 = self.proj.weight
primals_5 = self.proj.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
sithu31296/image_classification
|
ClassAttention
| false
| 16,462
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
InstanceNorm
|
import torch
import torch.utils.data
import torch
from torch import nn
class InstanceNorm(nn.Module):
def __init__(self, epsilon=1e-08):
super(InstanceNorm, self).__init__()
self.epsilon = epsilon
def forward(self, x):
x = x - torch.mean(x, (2, 3), True)
tmp = torch.mul(x, x)
tmp = torch.rsqrt(torch.mean(tmp, (2, 3), True) + self.epsilon)
return x * tmp
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.utils.data
import torch
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_per_fused_add_mean_mul_rsqrt_sub_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 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tmp3 = tl.where(xmask, tmp1, 0)
tmp4 = tl.sum(tmp3, 1)[:, None]
tmp5 = 16.0
tmp6 = tmp4 / tmp5
tmp7 = tmp0 - tmp6
tmp8 = tmp7 * tmp7
tmp9 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
tmp11 = tl.where(xmask, tmp9, 0)
tmp12 = tl.sum(tmp11, 1)[:, None]
tmp13 = tmp12 / tmp5
tmp14 = 1e-08
tmp15 = tmp13 + tmp14
tmp16 = libdevice.rsqrt(tmp15)
tmp17 = tmp7 * tmp16
tl.store(out_ptr2 + (r1 + 16 * x0), 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)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_per_fused_add_mean_mul_rsqrt_sub_0[grid(16)](arg0_1, buf2,
16, 16, XBLOCK=8, num_warps=2, num_stages=1)
del arg0_1
return buf2,
class InstanceNormNew(nn.Module):
def __init__(self, epsilon=1e-08):
super(InstanceNormNew, self).__init__()
self.epsilon = epsilon
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
siyuhuang/PoseStylizer
|
InstanceNorm
| false
| 16,463
|
[
"BSD-3-Clause"
] | 75
|
d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
https://github.com/siyuhuang/PoseStylizer/tree/d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
PatchEmbedding
|
import torch
from torch import nn
class PatchEmbedding(nn.Module):
"""Image to Patch Embedding
"""
def __init__(self, patch_size=16, embed_dim=768):
super().__init__()
self.proj = nn.Conv2d(3, embed_dim, patch_size, patch_size)
def forward(self, x: 'torch.Tensor'):
x = self.proj(x)
x = x.permute(0, 2, 3, 1)
return x
def get_inputs():
return [torch.rand([4, 3, 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 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 2304
xnumel = 256
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
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 256 * y3), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 768 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 12
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]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_convolution_2(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 768
y1 = yindex // 768
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 768 * x2 + 12288 * y1), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (768, 3, 16, 16), (768, 256, 16, 1))
assert_size_stride(primals_2, (768,), (1,))
assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((768, 3, 16, 16), (768, 1, 48, 3), torch.
float32)
get_raw_stream(0)
triton_poi_fused_0[grid(2304, 256)](primals_1, buf0, 2304, 256,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch
.float32)
triton_poi_fused_1[grid(12, 4096)](primals_3, buf1, 12, 4096,
XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
del primals_3
buf2 = extern_kernels.convolution(buf1, buf0, stride=(16, 16),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 768, 4, 4), (12288, 1, 3072, 768))
buf3 = empty_strided_cuda((4, 768, 4, 4), (12288, 16, 4, 1), torch.
float32)
triton_poi_fused_convolution_2[grid(3072, 16)](buf2, primals_2,
buf3, 3072, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del buf2
del primals_2
return reinterpret_tensor(buf3, (4, 4, 4, 768), (12288, 4, 1, 16), 0
), buf0, buf1
class PatchEmbeddingNew(nn.Module):
"""Image to Patch Embedding
"""
def __init__(self, patch_size=16, embed_dim=768):
super().__init__()
self.proj = nn.Conv2d(3, embed_dim, patch_size, patch_size)
def forward(self, input_0):
primals_1 = self.proj.weight
primals_2 = self.proj.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
sithu31296/image_classification
|
PatchEmbedding
| false
| 16,464
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
PixelNorm
|
import torch
import torch.utils.data
import torch
from torch import nn
class PixelNorm(nn.Module):
def __init__(self, epsilon=1e-08):
super(PixelNorm, self).__init__()
self.epsilon = epsilon
def forward(self, x):
tmp = torch.mul(x, x)
tmp1 = torch.rsqrt(torch.mean(tmp, dim=1, keepdim=True) + self.epsilon)
return x * tmp1
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.utils.data
import torch
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_mean_mul_rsqrt_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 = 4.0
tmp13 = tmp11 / tmp12
tmp14 = 1e-08
tmp15 = tmp13 + tmp14
tmp16 = libdevice.rsqrt(tmp15)
tmp17 = tmp0 * tmp16
tl.store(out_ptr0 + x3, 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, 4, 4, 4), (64, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_add_mean_mul_rsqrt_0[grid(256)](arg0_1, buf0, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
return buf0,
class PixelNormNew(nn.Module):
def __init__(self, epsilon=1e-08):
super(PixelNormNew, self).__init__()
self.epsilon = epsilon
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
siyuhuang/PoseStylizer
|
PixelNorm
| false
| 16,465
|
[
"BSD-3-Clause"
] | 75
|
d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
https://github.com/siyuhuang/PoseStylizer/tree/d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
ApplyStyle
|
import torch
import torch.utils.data
import torch
from torch import nn
import torch.nn.functional as F
class FC(nn.Module):
def __init__(self, in_channels, out_channels, gain=2 ** 0.5, use_wscale
=False, lrmul=1.0, bias=True):
super(FC, self).__init__()
he_std = gain * in_channels ** -0.5
if use_wscale:
init_std = 1.0 / lrmul
self.w_lrmul = he_std * lrmul
else:
init_std = he_std / lrmul
self.w_lrmul = lrmul
self.weight = torch.nn.Parameter(torch.randn(out_channels,
in_channels) * init_std)
if bias:
self.bias = torch.nn.Parameter(torch.zeros(out_channels))
self.b_lrmul = lrmul
else:
self.bias = None
def forward(self, x):
if self.bias is not None:
out = F.linear(x, self.weight * self.w_lrmul, self.bias * self.
b_lrmul)
else:
out = F.linear(x, self.weight * self.w_lrmul)
out = F.leaky_relu(out, 0.2, inplace=True)
return out
class ApplyStyle(nn.Module):
def __init__(self, latent_size, channels, use_wscale):
super(ApplyStyle, self).__init__()
self.linear = FC(latent_size, channels * 2, gain=1.0, use_wscale=
use_wscale)
def forward(self, x, latent):
style = self.linear(latent)
shape = [-1, 2, x.size(1), 1, 1]
style = style.view(shape)
x = x * (style[:, 0] + 1.0) + style[:, 1]
return x
def get_inputs():
return [torch.rand([64, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'latent_size': 4, 'channels': 4, 'use_wscale': 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
import torch.utils.data
import torch
from torch import 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_mul_0(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
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_add_mul_1(in_ptr0, in_ptr1, in_ptr2, 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 % 4
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + (x1 + 8 * x2 + 32 * (x2 % 4 // 4) + 128 * ((4 *
(x2 // 4 % 4) + x2 % 4) // 16)), None, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + x1, None, eviction_policy='evict_last')
tmp13 = tl.load(in_ptr1 + (4 + x1 + 8 * x2 + 32 * (x2 % 4 // 4) + 128 *
((4 * (x2 // 4 % 4) + x2 % 4) // 16)), None, eviction_policy=
'evict_last')
tmp14 = tl.load(in_ptr2 + (4 + x1), None, eviction_policy='evict_last')
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tmp5 = tmp1 + tmp4
tmp6 = 0.0
tmp7 = tmp5 > tmp6
tmp8 = 0.2
tmp9 = tmp5 * tmp8
tmp10 = tl.where(tmp7, tmp5, tmp9)
tmp11 = tmp10 + tmp3
tmp12 = tmp0 * tmp11
tmp15 = tmp14 * tmp3
tmp16 = tmp13 + tmp15
tmp17 = tmp16 > tmp6
tmp18 = tmp16 * tmp8
tmp19 = tl.where(tmp17, tmp16, tmp18)
tmp20 = tmp12 + tmp19
tl.store(out_ptr0 + x3, tmp20, None)
@triton.jit
def triton_poi_fused_leaky_relu_backward_2(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
x0 = xindex % 8
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp5 = 0.0
tmp6 = tmp4 > tmp5
tmp7 = 0.2
tmp8 = tmp4 * tmp7
tmp9 = tl.where(tmp6, tmp4, tmp8)
tmp10 = tmp9 > tmp5
tl.store(out_ptr0 + x3, tmp10, xmask)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (8,), (1,))
assert_size_stride(primals_2, (8, 4), (4, 1))
assert_size_stride(primals_3, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_4, (64, 4, 4, 4), (64, 16, 4, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((8, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_0[grid(32)](primals_2, buf0, 32, XBLOCK=32,
num_warps=1, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((64, 8), (8, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(buf0, (4, 8), (1, 4), 0), out=buf1)
del buf0
buf2 = empty_strided_cuda((64, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_1[grid(4096)](primals_4, buf1, primals_1,
buf2, 4096, XBLOCK=256, num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.bool)
triton_poi_fused_leaky_relu_backward_2[grid(512)](buf1, primals_1,
buf3, 512, XBLOCK=256, num_warps=4, num_stages=1)
del buf1
del primals_1
return buf2, primals_4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf3
class FC(nn.Module):
def __init__(self, in_channels, out_channels, gain=2 ** 0.5, use_wscale
=False, lrmul=1.0, bias=True):
super(FC, self).__init__()
he_std = gain * in_channels ** -0.5
if use_wscale:
init_std = 1.0 / lrmul
self.w_lrmul = he_std * lrmul
else:
init_std = he_std / lrmul
self.w_lrmul = lrmul
self.weight = torch.nn.Parameter(torch.randn(out_channels,
in_channels) * init_std)
if bias:
self.bias = torch.nn.Parameter(torch.zeros(out_channels))
self.b_lrmul = lrmul
else:
self.bias = None
def forward(self, x):
if self.bias is not None:
out = F.linear(x, self.weight * self.w_lrmul, self.bias * self.
b_lrmul)
else:
out = F.linear(x, self.weight * self.w_lrmul)
out = F.leaky_relu(out, 0.2, inplace=True)
return out
class ApplyStyleNew(nn.Module):
def __init__(self, latent_size, channels, use_wscale):
super(ApplyStyleNew, self).__init__()
self.linear = FC(latent_size, channels * 2, gain=1.0, use_wscale=
use_wscale)
def forward(self, input_0, input_1):
primals_2 = self.linear.weight
primals_1 = self.linear.bias
primals_4 = input_0
primals_3 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
siyuhuang/PoseStylizer
|
ApplyStyle
| false
| 16,466
|
[
"BSD-3-Clause"
] | 75
|
d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
https://github.com/siyuhuang/PoseStylizer/tree/d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
PatchEmbedOverlap
|
import torch
from torch import Tensor
from torch import nn
class PatchEmbedOverlap(nn.Module):
"""Image to Patch Embedding with overlapping
"""
def __init__(self, patch_size=16, stride=16, padding=0, embed_dim=768):
super().__init__()
self.proj = nn.Conv2d(3, embed_dim, patch_size, stride, padding)
def forward(self, x: 'torch.Tensor') ->Tensor:
x = self.proj(x)
return x
def get_inputs():
return [torch.rand([4, 3, 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 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_0(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 2304
xnumel = 256
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
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 256 * y3), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 768 * y1), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_1(in_ptr0, out_ptr0, ynumel, xnumel, YBLOCK: tl.
constexpr, XBLOCK: tl.constexpr):
ynumel = 12
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]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
x2 = xindex
y3 = yindex
y0 = yindex % 3
y1 = yindex // 3
tmp0 = tl.load(in_ptr0 + (x2 + 4096 * y3), ymask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + (y0 + 3 * x2 + 12288 * y1), tmp0, ymask)
@triton.jit
def triton_poi_fused_convolution_2(in_ptr0, in_ptr1, out_ptr0, ynumel,
xnumel, YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
xnumel = 16
yoffset = tl.program_id(1) * YBLOCK
yindex = yoffset + tl.arange(0, YBLOCK)[None, :]
tl.full([XBLOCK, YBLOCK], True, tl.int1)
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:, None]
xmask = xindex < xnumel
x2 = xindex
y0 = yindex % 768
y1 = yindex // 768
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 768 * x2 + 12288 * y1), xmask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr1 + y0, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + (x2 + 16 * y3), tmp2, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (768, 3, 16, 16), (768, 256, 16, 1))
assert_size_stride(primals_2, (768,), (1,))
assert_size_stride(primals_3, (4, 3, 64, 64), (12288, 4096, 64, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((768, 3, 16, 16), (768, 1, 48, 3), torch.
float32)
get_raw_stream(0)
triton_poi_fused_0[grid(2304, 256)](primals_1, buf0, 2304, 256,
XBLOCK=32, YBLOCK=32, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((4, 3, 64, 64), (12288, 1, 192, 3), torch
.float32)
triton_poi_fused_1[grid(12, 4096)](primals_3, buf1, 12, 4096,
XBLOCK=64, YBLOCK=16, num_warps=4, num_stages=1)
del primals_3
buf2 = extern_kernels.convolution(buf1, buf0, stride=(16, 16),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 768, 4, 4), (12288, 1, 3072, 768))
buf3 = empty_strided_cuda((4, 768, 4, 4), (12288, 16, 4, 1), torch.
float32)
triton_poi_fused_convolution_2[grid(3072, 16)](buf2, primals_2,
buf3, 3072, 16, XBLOCK=16, YBLOCK=64, num_warps=4, num_stages=1)
del buf2
del primals_2
return buf3, buf0, buf1
class PatchEmbedOverlapNew(nn.Module):
"""Image to Patch Embedding with overlapping
"""
def __init__(self, patch_size=16, stride=16, padding=0, embed_dim=768):
super().__init__()
self.proj = nn.Conv2d(3, embed_dim, patch_size, stride, padding)
def forward(self, input_0):
primals_1 = self.proj.weight
primals_2 = self.proj.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
sithu31296/image_classification
|
PatchEmbedOverlap
| false
| 16,467
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
DistillationLoss
|
import torch
from torch import Tensor
from torch import nn
from typing import Union
class DistillationLoss(nn.Module):
"""Distilling the Knowledge in a Neural Network
https://arxiv.org/pdf/1503.02531.pdf
"""
def __init__(self, alpha: 'float'=0.95, temp: 'Union[float, int]'=6
) ->None:
super().__init__()
self.alpha = alpha
self.temp = temp
self.kd_loss = nn.KLDivLoss()
self.entropy_loss = nn.CrossEntropyLoss()
self.log_softmax = nn.LogSoftmax(dim=1)
self.softmax = nn.Softmax(dim=1)
def forward(self, pred_student: 'Tensor', pred_teacher: 'Tensor',
target: 'Tensor') ->Tensor:
loss = self.kd_loss(self.log_softmax(pred_student / self.temp),
self.softmax(pred_teacher / self.temp)) * (self.alpha * self.
temp * self.temp)
loss += self.entropy_loss(pred_student, target) * (1.0 - self.alpha)
return loss
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
from torch._inductor.runtime import triton_helpers
from torch._inductor.runtime.triton_helpers import libdevice, math as tl_math
from torch import nn
from typing import Union
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)
tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), 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.16666666666666666
tmp16 = tmp14 * tmp15
tmp17 = tl_math.exp(tmp16)
tl.store(out_ptr0 + x3, tmp17, xmask)
@triton.jit
def triton_poi_fused__log_softmax_1(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
x3 = xindex
x0 = xindex % 16
x2 = xindex // 64
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp3 = tl.load(in_ptr0 + (x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (16 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp8 = tl.load(in_ptr0 + (32 + x0 + 64 * x2), xmask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr0 + (48 + x0 + 64 * x2), 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.16666666666666666
tmp16 = tmp14 * tmp15
tmp17 = triton_helpers.maximum(tmp3, tmp5)
tmp18 = triton_helpers.maximum(tmp17, tmp8)
tmp19 = triton_helpers.maximum(tmp18, tmp11)
tmp20 = tmp0 - tmp19
tl.store(out_ptr0 + x3, tmp16, xmask)
tl.store(out_ptr1 + x3, tmp20, xmask)
@triton.jit
def triton_per_fused__log_softmax__softmax_add_div_mean_mul_neg_sub_sum_xlogy_2(
in_out_ptr0, in_ptr0, in_ptr1, in_ptr2, in_ptr3, 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)
r3 = rindex
r0 = rindex % 16
r2 = rindex // 64
tmp0 = tl.load(in_ptr0 + r3, None)
tmp1 = tl.load(in_ptr0 + (r0 + 64 * r2), None, eviction_policy='evict_last'
)
tmp2 = tl.load(in_ptr0 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp17 = tl.load(in_ptr1 + r3, None)
tmp18 = tl.load(in_ptr1 + (r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp20 = tl.load(in_ptr1 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp23 = tl.load(in_ptr1 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp26 = tl.load(in_ptr1 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp36 = tl.load(in_ptr2 + r3, None)
tmp37 = tl.load(in_ptr2 + (r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp39 = tl.load(in_ptr2 + (16 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp42 = tl.load(in_ptr2 + (32 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp45 = tl.load(in_ptr2 + (48 + r0 + 64 * r2), None, eviction_policy=
'evict_last')
tmp50 = tl.load(in_ptr3 + r3, None)
tmp3 = tmp1 + tmp2
tmp5 = tmp3 + tmp4
tmp7 = tmp5 + tmp6
tmp8 = tmp0 / tmp7
tmp9 = libdevice.isnan(tmp8).to(tl.int1)
tmp10 = 0.0
tmp11 = tmp8 == tmp10
tmp12 = tl_math.log(tmp8)
tmp13 = tmp8 * tmp12
tmp14 = tl.where(tmp11, tmp10, tmp13)
tmp15 = float('nan')
tmp16 = tl.where(tmp9, tmp15, tmp14)
tmp19 = tl_math.exp(tmp18)
tmp21 = tl_math.exp(tmp20)
tmp22 = tmp19 + tmp21
tmp24 = tl_math.exp(tmp23)
tmp25 = tmp22 + tmp24
tmp27 = tl_math.exp(tmp26)
tmp28 = tmp25 + tmp27
tmp29 = tl_math.log(tmp28)
tmp30 = tmp17 - tmp29
tmp31 = tmp8 * tmp30
tmp32 = tmp16 - tmp31
tmp33 = tl.broadcast_to(tmp32, [RBLOCK])
tmp35 = triton_helpers.promote_to_tensor(tl.sum(tmp33, 0))
tmp38 = tl_math.exp(tmp37)
tmp40 = tl_math.exp(tmp39)
tmp41 = tmp38 + tmp40
tmp43 = tl_math.exp(tmp42)
tmp44 = tmp41 + tmp43
tmp46 = tl_math.exp(tmp45)
tmp47 = tmp44 + tmp46
tmp48 = tl_math.log(tmp47)
tmp49 = tmp36 - tmp48
tmp51 = tmp49 * tmp50
tmp52 = tl.broadcast_to(tmp51, [RBLOCK])
tmp54 = triton_helpers.promote_to_tensor(tl.sum(tmp52, 0))
tmp55 = 256.0
tmp56 = tmp35 / tmp55
tmp57 = 34.199999999999996
tmp58 = tmp56 * tmp57
tmp59 = -tmp54
tmp60 = 0.015625
tmp61 = tmp59 * tmp60
tmp62 = 0.050000000000000044
tmp63 = tmp61 * tmp62
tmp64 = tmp58 + tmp63
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp64, None)
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__softmax_0[grid(256)](arg1_1, buf0, 256, XBLOCK=
256, num_warps=4, num_stages=1)
del arg1_1
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused__log_softmax_1[grid(256)](arg0_1, buf2, buf4, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del arg0_1
buf3 = empty_strided_cuda((), (), torch.float32)
buf6 = buf3
del buf3
triton_per_fused__log_softmax__softmax_add_div_mean_mul_neg_sub_sum_xlogy_2[
grid(1)](buf6, buf0, buf2, buf4, arg2_1, 1, 256, num_warps=2,
num_stages=1)
del arg2_1
del buf0
del buf2
del buf4
return buf6,
class DistillationLossNew(nn.Module):
"""Distilling the Knowledge in a Neural Network
https://arxiv.org/pdf/1503.02531.pdf
"""
def __init__(self, alpha: 'float'=0.95, temp: 'Union[float, int]'=6
) ->None:
super().__init__()
self.alpha = alpha
self.temp = temp
self.kd_loss = nn.KLDivLoss()
self.entropy_loss = nn.CrossEntropyLoss()
self.log_softmax = nn.LogSoftmax(dim=1)
self.softmax = nn.Softmax(dim=1)
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]
|
sithu31296/image_classification
|
DistillationLoss
| false
| 16,468
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
DepthGTLoss
|
import torch
import numpy as np
class DepthGTLoss(torch.nn.Module):
"""
A simple L1 loss, but restricted to the cropped center of the image.
It also does not count pixels outside of a given range of values (in target).
Additionally, there is also an L1 loss on the gradient.
"""
def __init__(self, crop_fraction=0.25, vmin=0, vmax=1, limit=10):
"""
The input should be (batch x channels x height x width).
We L1-penalize the inner portion of the image,
with crop_fraction cut off from all borders.
Keyword arguments:
crop_fraction -- fraction to cut off from all sides (defaults to 0.25)
vmin -- minimal (GT!) value to supervise
vmax -- maximal (GT!) value to supervise
limit -- anything higher than this is wrong, and should be ignored
"""
super().__init__()
self.crop_fraction = crop_fraction
"""Cut-off fraction"""
self.vmin = vmin
"""Lower bound for valid target pixels"""
self.vmax = vmax
"""Upper bound for valid target pixels"""
self.sobel_x = torch.nn.Conv2d(1, 1, kernel_size=3, stride=1,
padding=1, bias=False)
self.sobel_x.weight = torch.nn.Parameter(torch.from_numpy(np.array(
[[1, 0, -1], [2, 0, -2], [1, 0, -1]]) / 8.0).float().unsqueeze(
0).unsqueeze(0))
self.sobel_y = torch.nn.Conv2d(1, 1, kernel_size=3, stride=1,
padding=1, bias=False)
self.sobel_y.weight = torch.nn.Parameter(torch.from_numpy(np.array(
[[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) / 8.0).float().unsqueeze(
0).unsqueeze(0))
torch.device('cuda')
self.sobel_x = self.sobel_x
self.sobel_y = self.sobel_y
self.limit = limit
def forward(self, input, target):
height = input.size(2)
heightcrop = int(height * self.crop_fraction)
width = input.size(3)
widthcrop = int(width * self.crop_fraction)
if self.crop_fraction > 0:
input_crop = input[:, :, heightcrop:height - heightcrop,
widthcrop:width - widthcrop]
target_crop = target[:, :, heightcrop:height - heightcrop,
widthcrop:width - widthcrop]
else:
input_crop = input
target_crop = target
valid_mask = (target_crop.le(self.vmax) * target_crop.ge(self.vmin)
).float()
loss = torch.abs((input_crop - target_crop) * valid_mask).sum()
loss = loss / valid_mask.sum().clamp(min=1)
input_gradx = self.sobel_x(input_crop)
input_grady = self.sobel_y(input_crop)
target_gradx = self.sobel_x(target_crop)
target_grady = self.sobel_y(target_crop)
grad_maskx = self.sobel_x(valid_mask)
grad_masky = self.sobel_y(valid_mask)
grad_valid_mask = (grad_maskx.eq(0) * grad_masky.eq(0)).float(
) * valid_mask
gradloss = torch.abs(input_gradx - target_gradx) + torch.abs(
input_grady - target_grady)
gradloss = (gradloss * grad_valid_mask).sum()
gradloss = gradloss / grad_valid_mask.sum().clamp(min=1)
loss = loss + gradloss
if self.limit is not None and loss > self.limit:
loss = torch.clamp(loss, max=self.limit)
if loss.ne(loss).item():
None
return loss
def get_inputs():
return [torch.rand([4, 1, 1, 1]), torch.rand([4, 1, 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 numpy as np
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__to_copy_abs_ge_le_mul_sub_sum_0(in_ptr0, in_ptr1,
out_ptr0, out_ptr1, out_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 + 16 * r0, None, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr1 + r0, None)
tmp1 = 1.0
tmp2 = tmp0 <= tmp1
tmp3 = 0.0
tmp4 = tmp0 >= tmp3
tmp5 = tmp2 & tmp4
tmp6 = tmp5.to(tl.float32)
tmp8 = tmp7 - tmp0
tmp9 = tmp8 * tmp6
tmp10 = tl_math.abs(tmp9)
tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])
tmp13 = tl.sum(tmp11, 1)[:, None]
tmp14 = tl.broadcast_to(tmp6, [XBLOCK, RBLOCK])
tmp16 = tl.sum(tmp14, 1)[:, None]
tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp6, None)
tl.store(out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp13, None)
tl.store(out_ptr2 + tl.full([XBLOCK, 1], 0, tl.int32), tmp16, None)
@triton.jit
def triton_per_fused__to_copy_abs_add_clamp_div_eq_gt_mul_sgn_sub_sum_1(
in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3, in_ptr4,
in_ptr5, in_ptr6, out_ptr2, out_ptr3, out_ptr4, 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)
tmp7 = tl.load(in_out_ptr0 + r0, None)
tmp9 = tl.load(in_ptr2 + r0, None)
tmp10 = tl.load(in_ptr3 + r0, None)
tmp13 = tl.load(in_ptr4 + r0, None)
tmp14 = tl.load(in_ptr5 + r0, None)
tmp38 = tl.load(in_out_ptr1 + 0)
tmp39 = tl.broadcast_to(tmp38, [XBLOCK, 1])
tmp40 = tl.load(in_ptr6 + 0)
tmp41 = tl.broadcast_to(tmp40, [XBLOCK, 1])
tmp1 = 0.0
tmp2 = tmp0 == tmp1
tmp4 = tmp3 == tmp1
tmp5 = tmp2 & tmp4
tmp6 = tmp5.to(tl.float32)
tmp8 = tmp6 * tmp7
tmp11 = tmp9 - tmp10
tmp12 = tl_math.abs(tmp11)
tmp15 = tmp13 - tmp14
tmp16 = tl_math.abs(tmp15)
tmp17 = tmp12 + tmp16
tmp18 = tmp17 * tmp8
tmp19 = tl.broadcast_to(tmp18, [XBLOCK, RBLOCK])
tmp21 = tl.sum(tmp19, 1)[:, None]
tmp22 = tl.broadcast_to(tmp8, [XBLOCK, RBLOCK])
tmp24 = tl.sum(tmp22, 1)[:, None]
tmp25 = tl.full([1, 1], 0, tl.int32)
tmp26 = tmp25 < tmp15
tmp27 = tmp26.to(tl.int8)
tmp28 = tmp15 < tmp25
tmp29 = tmp28.to(tl.int8)
tmp30 = tmp27 - tmp29
tmp31 = tmp30.to(tmp15.dtype)
tmp32 = tmp25 < tmp11
tmp33 = tmp32.to(tl.int8)
tmp34 = tmp11 < tmp25
tmp35 = tmp34.to(tl.int8)
tmp36 = tmp33 - tmp35
tmp37 = tmp36.to(tmp11.dtype)
tmp42 = 1.0
tmp43 = triton_helpers.maximum(tmp41, tmp42)
tmp44 = tmp39 / tmp43
tmp45 = triton_helpers.maximum(tmp24, tmp42)
tmp46 = tmp21 / tmp45
tmp47 = tmp44 + tmp46
tmp48 = 10.0
tmp49 = tmp47 > tmp48
tl.store(in_out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp8, None)
tl.store(out_ptr2 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp31, None)
tl.store(out_ptr3 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp37, None)
tl.debug_barrier()
tl.store(in_out_ptr1 + tl.full([XBLOCK, 1], 0, tl.int32), tmp47, None)
tl.store(out_ptr4 + tl.full([XBLOCK, 1], 0, tl.int32), tmp49, None)
def call(args):
primals_1, primals_2, primals_3, primals_4 = args
args.clear()
assert_size_stride(primals_1, (4, 1, 1, 1), (1, 1, 1, 1))
assert_size_stride(primals_2, (4, 1, 4, 4), (16, 16, 4, 1))
assert_size_stride(primals_3, (1, 1, 3, 3), (9, 9, 3, 1))
assert_size_stride(primals_4, (1, 1, 3, 3), (9, 9, 3, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32)
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = empty_strided_cuda((), (), torch.float32)
get_raw_stream(0)
triton_per_fused__to_copy_abs_ge_le_mul_sub_sum_0[grid(1)](primals_2,
primals_1, buf0, buf1, buf2, 1, 4, XBLOCK=1, num_warps=2,
num_stages=1)
buf3 = extern_kernels.convolution(primals_1, primals_3, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 1, 1, 1), (1, 1, 1, 1))
buf4 = extern_kernels.convolution(primals_1, primals_4, stride=(1,
1), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf4, (4, 1, 1, 1), (1, 1, 1, 1))
buf5 = extern_kernels.convolution(reinterpret_tensor(primals_2, (4,
1, 1, 1), (16, 16, 4, 1), 0), primals_3, stride=(1, 1), padding
=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0,
0), groups=1, bias=None)
assert_size_stride(buf5, (4, 1, 1, 1), (1, 1, 1, 1))
buf6 = extern_kernels.convolution(reinterpret_tensor(primals_2, (4,
1, 1, 1), (16, 16, 4, 1), 0), primals_4, stride=(1, 1), padding
=(1, 1), dilation=(1, 1), transposed=False, output_padding=(0,
0), groups=1, bias=None)
assert_size_stride(buf6, (4, 1, 1, 1), (1, 1, 1, 1))
buf7 = 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(buf7, (4, 1, 1, 1), (1, 1, 1, 1))
buf8 = extern_kernels.convolution(buf0, primals_4, stride=(1, 1),
padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf8, (4, 1, 1, 1), (1, 1, 1, 1))
buf9 = buf0
del buf0
buf13 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32)
buf14 = empty_strided_cuda((4, 1, 1, 1), (1, 1, 1, 1), torch.float32)
buf12 = buf1
del buf1
buf15 = empty_strided_cuda((), (), torch.bool)
triton_per_fused__to_copy_abs_add_clamp_div_eq_gt_mul_sgn_sub_sum_1[
grid(1)](buf9, buf12, buf7, buf8, buf3, buf5, buf4, buf6, buf2,
buf13, buf14, buf15, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
del buf2
del buf3
del buf4
del buf5
del buf6
del buf7
del buf8
return buf12, buf15, primals_1, primals_3, primals_4, reinterpret_tensor(
primals_2, (4, 1, 1, 1), (16, 16, 4, 1), 0), buf9, buf13, buf14
class DepthGTLossNew(torch.nn.Module):
"""
A simple L1 loss, but restricted to the cropped center of the image.
It also does not count pixels outside of a given range of values (in target).
Additionally, there is also an L1 loss on the gradient.
"""
def __init__(self, crop_fraction=0.25, vmin=0, vmax=1, limit=10):
"""
The input should be (batch x channels x height x width).
We L1-penalize the inner portion of the image,
with crop_fraction cut off from all borders.
Keyword arguments:
crop_fraction -- fraction to cut off from all sides (defaults to 0.25)
vmin -- minimal (GT!) value to supervise
vmax -- maximal (GT!) value to supervise
limit -- anything higher than this is wrong, and should be ignored
"""
super().__init__()
self.crop_fraction = crop_fraction
"""Cut-off fraction"""
self.vmin = vmin
"""Lower bound for valid target pixels"""
self.vmax = vmax
"""Upper bound for valid target pixels"""
self.sobel_x = torch.nn.Conv2d(1, 1, kernel_size=3, stride=1,
padding=1, bias=False)
self.sobel_x.weight = torch.nn.Parameter(torch.from_numpy(np.array(
[[1, 0, -1], [2, 0, -2], [1, 0, -1]]) / 8.0).float().unsqueeze(
0).unsqueeze(0))
self.sobel_y = torch.nn.Conv2d(1, 1, kernel_size=3, stride=1,
padding=1, bias=False)
self.sobel_y.weight = torch.nn.Parameter(torch.from_numpy(np.array(
[[1, 2, 1], [0, 0, 0], [-1, -2, -1]]) / 8.0).float().unsqueeze(
0).unsqueeze(0))
torch.device('cuda')
self.sobel_x = self.sobel_x
self.sobel_y = self.sobel_y
self.limit = limit
def forward(self, input_0, input_1):
primals_3 = self.sobel_x.weight
primals_4 = self.sobel_y.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
simon-donne/defusr
|
DepthGTLoss
| false
| 16,469
|
[
"MIT"
] | 65
|
fa4275070af4024eea128e99d7c6df2358d129a5
|
https://github.com/simon-donne/defusr/tree/fa4275070af4024eea128e99d7c6df2358d129a5
|
FC
|
import torch
import torch.utils.data
import torch
from torch import nn
import torch.nn.functional as F
class FC(nn.Module):
def __init__(self, in_channels, out_channels, gain=2 ** 0.5, use_wscale
=False, lrmul=1.0, bias=True):
super(FC, self).__init__()
he_std = gain * in_channels ** -0.5
if use_wscale:
init_std = 1.0 / lrmul
self.w_lrmul = he_std * lrmul
else:
init_std = he_std / lrmul
self.w_lrmul = lrmul
self.weight = torch.nn.Parameter(torch.randn(out_channels,
in_channels) * init_std)
if bias:
self.bias = torch.nn.Parameter(torch.zeros(out_channels))
self.b_lrmul = lrmul
else:
self.bias = None
def forward(self, x):
if self.bias is not None:
out = F.linear(x, self.weight * self.w_lrmul, self.bias * self.
b_lrmul)
else:
out = F.linear(x, self.weight * self.w_lrmul)
out = F.leaky_relu(out, 0.2, inplace=True)
return out
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.utils.data
import torch
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_mul_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 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_poi_fused_leaky_relu_leaky_relu_backward_view_1(in_out_ptr0,
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
x4 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_out_ptr0 + x4, xmask)
tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
tmp2 = 1.0
tmp3 = tmp1 * tmp2
tmp4 = tmp0 + tmp3
tmp5 = 0.0
tmp6 = tmp4 > tmp5
tmp7 = 0.2
tmp8 = tmp4 * tmp7
tmp9 = tl.where(tmp6, tmp4, tmp8)
tmp10 = tmp9 > tmp5
tl.store(out_ptr0 + x4, tmp9, xmask)
tl.store(out_ptr1 + x4, tmp10, xmask)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4, 4), (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((4, 4), (4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_mul_0[grid(16)](primals_2, buf0, 16, XBLOCK=16,
num_warps=1, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(buf0, (4, 4), (1, 4), 0), out=buf1)
del buf0
buf2 = reinterpret_tensor(buf1, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf1
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_leaky_relu_leaky_relu_backward_view_1[grid(256)](buf2,
primals_1, buf3, buf4, 256, XBLOCK=256, num_warps=4, num_stages=1)
del buf2
del primals_1
return buf3, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0), buf4
class FCNew(nn.Module):
def __init__(self, in_channels, out_channels, gain=2 ** 0.5, use_wscale
=False, lrmul=1.0, bias=True):
super(FCNew, self).__init__()
he_std = gain * in_channels ** -0.5
if use_wscale:
init_std = 1.0 / lrmul
self.w_lrmul = he_std * lrmul
else:
init_std = he_std / lrmul
self.w_lrmul = lrmul
self.weight = torch.nn.Parameter(torch.randn(out_channels,
in_channels) * init_std)
if bias:
self.bias = torch.nn.Parameter(torch.zeros(out_channels))
self.b_lrmul = lrmul
else:
self.bias = None
def forward(self, input_0):
primals_2 = self.weight
primals_1 = self.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
siyuhuang/PoseStylizer
|
FC
| false
| 16,470
|
[
"BSD-3-Clause"
] | 75
|
d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
https://github.com/siyuhuang/PoseStylizer/tree/d1d832781ddfd3efde24bf32b36a4074fafebcc1
|
FCUDown
|
import torch
from torch import nn
class FCUDown(nn.Module):
def __init__(self, c1, c2, dw_stride):
super().__init__()
self.conv_project = nn.Conv2d(c1, c2, 1, 1, 0)
self.sample_pooling = nn.AvgPool2d(dw_stride, dw_stride)
self.ln = nn.LayerNorm(c2)
self.act = nn.GELU()
def forward(self, x, x_t):
x = self.conv_project(x)
x = self.sample_pooling(x).flatten(2).transpose(1, 2)
x = self.ln(x)
x = self.act(x)
x = torch.cat([x_t[:, 0][:, None, :], x], dim=1)
return x
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'c1': 4, 'c2': 4, 'dw_stride': 1}]
|
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_avg_pool2d_convolution_0(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
x2 = xindex
x1 = xindex // 16
tmp0 = tl.load(in_out_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tl.store(in_out_ptr0 + x2, tmp2, xmask)
tl.store(out_ptr0 + x2, tmp4, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_1(in_ptr0, 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 % 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)
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_2(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_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
x1 = xindex // 4 % 4
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp3 = tl.load(in_ptr2 + (x0 + 4 * x2), xmask, eviction_policy='evict_last'
)
tmp5 = tl.load(in_ptr3 + x1, xmask, eviction_policy='evict_last')
tmp7 = tl.load(in_ptr4 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 - tmp1
tmp4 = tmp2 * tmp3
tmp6 = tmp4 * tmp5
tmp8 = tmp6 + tmp7
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_poi_fused_cat_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl.
constexpr):
xnumel = 80
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x1 = xindex // 4 % 5
x0 = xindex % 4
x2 = xindex // 20
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], 5, tl.int64)
tmp9 = tl.load(in_ptr1 + (4 * x0 + 16 * x2 + (-1 + x1)), tmp6 & xmask,
eviction_policy='evict_last', other=0.0)
tmp10 = 0.5
tmp11 = tmp9 * tmp10
tmp12 = 0.7071067811865476
tmp13 = tmp9 * tmp12
tmp14 = libdevice.erf(tmp13)
tmp15 = 1.0
tmp16 = tmp14 + tmp15
tmp17 = tmp11 * tmp16
tmp18 = tl.full(tmp17.shape, 0.0, tmp17.dtype)
tmp19 = tl.where(tmp6, tmp17, tmp18)
tmp20 = tl.where(tmp4, tmp5, tmp19)
tl.store(out_ptr0 + x3, tmp20, 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, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_4, (4,), (1,))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 4), (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), (64, 16, 4, 1), 0), 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, (1, 4, 4, 4), (64, 16, 4, 1))
buf1 = buf0
del buf0
buf2 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_avg_pool2d_convolution_0[grid(64)](buf1, primals_2,
buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
del primals_2
buf3 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf4 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
triton_poi_fused_native_layer_norm_1[grid(16)](buf2, buf3, buf4, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((4, 4, 4), (16, 1, 4), torch.float32)
triton_poi_fused_native_layer_norm_2[grid(64)](buf2, buf3, buf4,
primals_4, primals_5, buf5, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del buf3
del buf4
buf6 = empty_strided_cuda((4, 5, 4), (20, 4, 1), torch.float32)
triton_poi_fused_cat_3[grid(80)](primals_6, buf5, buf6, 80, XBLOCK=
128, num_warps=4, num_stages=1)
del buf5
del primals_6
return buf6, primals_1, primals_4, primals_5, reinterpret_tensor(primals_3,
(1, 4, 4, 4), (64, 16, 4, 1), 0), reinterpret_tensor(buf1, (4, 4, 4
), (16, 4, 1), 0), buf2
class FCUDownNew(nn.Module):
def __init__(self, c1, c2, dw_stride):
super().__init__()
self.conv_project = nn.Conv2d(c1, c2, 1, 1, 0)
self.sample_pooling = nn.AvgPool2d(dw_stride, dw_stride)
self.ln = nn.LayerNorm(c2)
self.act = nn.GELU()
def forward(self, input_0, input_1):
primals_1 = self.conv_project.weight
primals_2 = self.conv_project.bias
primals_4 = self.ln.weight
primals_5 = self.ln.bias
primals_3 = input_0
primals_6 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
sithu31296/image_classification
|
FCUDown
| false
| 16,471
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
LocalNet
|
import torch
import torch.nn as nn
class LocalNet(nn.Module):
def forward(self, x_in):
"""Defines a double convolution
:param x_in: input convolutional features
:returns: convolutional features
:rtype: Tensor
"""
x = self.lrelu(self.conv1(self.refpad(x_in)))
x = self.lrelu(self.conv2(self.refpad(x)))
return x
def __init__(self, in_channels=16, out_channels=64):
"""Initialisation function
:param in_channels: number of input channels
:param out_channels: number of output channels
:returns: N/A
:rtype: N/A
"""
super(LocalNet, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, 3, 1, 0, 1)
self.conv2 = nn.Conv2d(out_channels, out_channels, 3, 1, 0, 1)
self.lrelu = nn.LeakyReLU()
self.refpad = nn.ReflectionPad2d(1)
def get_inputs():
return [torch.rand([4, 16, 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.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_reflection_pad2d_0(in_ptr0, out_ptr0, xnumel, XBLOCK:
tl.constexpr):
xnumel = 2304
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6 % 6
x2 = xindex // 36
x3 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x2),
xmask, eviction_policy='evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_1(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 % 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tl.store(out_ptr0 + x3, tmp4, None)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_reflection_pad2d_2(in_ptr0,
in_ptr1, in_ptr2, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 9216
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 6
x1 = xindex // 6 % 6
x4 = xindex // 36
x2 = xindex // 36 % 64
x5 = xindex
tmp0 = tl.load(in_ptr0 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4),
xmask, eviction_policy='evict_last').to(tl.int1)
tmp1 = tl.load(in_ptr1 + (15 + -1 * tl_math.abs(-3 + tl_math.abs(-1 +
x0)) + -4 * tl_math.abs(-3 + tl_math.abs(-1 + x1)) + 16 * x4),
xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr2 + x2, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = 0.01
tmp5 = tmp3 * tmp4
tmp6 = tl.where(tmp0, tmp3, tmp5)
tl.store(out_ptr0 + x5, tmp6, xmask)
@triton.jit
def triton_poi_fused_convolution_leaky_relu_3(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, 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 % 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.01
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, None)
tl.store(out_ptr1 + x3, tmp7, None)
def call(args):
primals_1, primals_2, primals_3, primals_4, primals_5 = args
args.clear()
assert_size_stride(primals_1, (4, 16, 4, 4), (256, 16, 4, 1))
assert_size_stride(primals_2, (64, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_3, (64,), (1,))
assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_5, (64,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 16, 6, 6), (576, 36, 6, 1), torch.float32
)
get_raw_stream(0)
triton_poi_fused_reflection_pad2d_0[grid(2304)](primals_1, buf0,
2304, XBLOCK=256, num_warps=4, num_stages=1)
del primals_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, 64, 4, 4), (1024, 16, 4, 1))
buf2 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_leaky_relu_1[grid(4096)](buf1,
primals_3, buf2, 4096, XBLOCK=128, num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((4, 64, 6, 6), (2304, 36, 6, 1), torch.
float32)
triton_poi_fused_convolution_leaky_relu_reflection_pad2d_2[grid(9216)](
buf2, buf1, primals_3, buf3, 9216, XBLOCK=256, num_warps=4,
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, 64, 4, 4), (1024, 16, 4, 1))
buf5 = empty_strided_cuda((4, 64, 4, 4), (1024, 16, 4, 1), torch.bool)
buf6 = buf1
del buf1
triton_poi_fused_convolution_leaky_relu_3[grid(4096)](buf4,
primals_5, buf5, buf6, 4096, XBLOCK=256, num_warps=4, num_stages=1)
del buf4
del primals_5
return buf6, primals_2, primals_4, buf0, buf2, buf3, buf5
class LocalNetNew(nn.Module):
def __init__(self, in_channels=16, out_channels=64):
"""Initialisation function
:param in_channels: number of input channels
:param out_channels: number of output channels
:returns: N/A
:rtype: N/A
"""
super(LocalNetNew, self).__init__()
self.conv1 = nn.Conv2d(in_channels, out_channels, 3, 1, 0, 1)
self.conv2 = nn.Conv2d(out_channels, out_channels, 3, 1, 0, 1)
self.lrelu = nn.LeakyReLU()
self.refpad = nn.ReflectionPad2d(1)
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]
|
sjmoran/CURL
|
LocalNet
| false
| 16,472
|
[
"BSD-3-Clause"
] | 125
|
919e519717b66e14d92ac6fa404c328ee3f254a5
|
https://github.com/sjmoran/CURL/tree/919e519717b66e14d92ac6fa404c328ee3f254a5
|
MidNet4
|
import torch
import torch.nn as nn
class MidNet4(nn.Module):
def forward(self, x_in):
"""Network with dilation rate 4
:param x_in: input convolutional features
:returns: processed convolutional features
:rtype: Tensor
"""
x = self.lrelu(self.conv1(x_in))
x = self.lrelu(self.conv2(x))
x = self.lrelu(self.conv3(x))
x = self.conv4(x)
return x
def __init__(self, in_channels=16):
"""FIXME! briefly describe function
:param in_channels: Input channels
:returns: N/A
:rtype: N/A
"""
super(MidNet4, self).__init__()
self.lrelu = nn.LeakyReLU()
self.conv1 = nn.Conv2d(in_channels, 64, 3, 1, 4, 4)
self.conv2 = nn.Conv2d(64, 64, 3, 1, 4, 4)
self.conv3 = nn.Conv2d(64, 64, 3, 1, 4, 4)
self.conv4 = nn.Conv2d(64, 64, 3, 1, 4, 4)
def get_inputs():
return [torch.rand([4, 16, 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
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, 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 // 4096 % 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.01
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, None)
tl.store(out_ptr1 + 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 // 4096 % 64
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)
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, (64, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_2, (64,), (1,))
assert_size_stride(primals_3, (4, 16, 64, 64), (65536, 4096, 64, 1))
assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_5, (64,), (1,))
assert_size_stride(primals_6, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_7, (64,), (1,))
assert_size_stride(primals_8, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_9, (64,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(4, 4), dilation=(4, 4), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf1 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.bool)
buf2 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf0,
primals_2, buf1, buf2, 1048576, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_2
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(4, 4), dilation=(4, 4), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf4 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.bool)
buf5 = buf0
del buf0
triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf3,
primals_5, buf4, buf5, 1048576, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_5
buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
padding=(4, 4), dilation=(4, 4), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf7 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.bool)
buf8 = buf3
del buf3
triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf6,
primals_7, buf7, buf8, 1048576, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf6
del primals_7
buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1),
padding=(4, 4), dilation=(4, 4), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf9, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf10 = buf9
del buf9
triton_poi_fused_convolution_1[grid(1048576)](buf10, primals_9,
1048576, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_9
return (buf10, primals_1, primals_3, primals_4, primals_6, primals_8,
buf1, buf2, buf4, buf5, buf7, buf8)
class MidNet4New(nn.Module):
def __init__(self, in_channels=16):
"""FIXME! briefly describe function
:param in_channels: Input channels
:returns: N/A
:rtype: N/A
"""
super(MidNet4New, self).__init__()
self.lrelu = nn.LeakyReLU()
self.conv1 = nn.Conv2d(in_channels, 64, 3, 1, 4, 4)
self.conv2 = nn.Conv2d(64, 64, 3, 1, 4, 4)
self.conv3 = nn.Conv2d(64, 64, 3, 1, 4, 4)
self.conv4 = nn.Conv2d(64, 64, 3, 1, 4, 4)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_8 = self.conv4.weight
primals_9 = self.conv4.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]
|
sjmoran/CURL
|
MidNet4
| false
| 16,473
|
[
"BSD-3-Clause"
] | 125
|
919e519717b66e14d92ac6fa404c328ee3f254a5
|
https://github.com/sjmoran/CURL/tree/919e519717b66e14d92ac6fa404c328ee3f254a5
|
XCA
|
import torch
from torch import Tensor
from torch import nn
from torch.nn import functional as F
class XCA(nn.Module):
""" Cross-Covariance Attention (XCA) operation where the channels are updated using a weighted
sum. The weights are obtained from the (softmax normalized) Cross-covariance
matrix (Q^T K \\in d_h \\times d_h)
"""
def __init__(self, dim: 'int', heads: 'int'):
super().__init__()
self.num_heads = heads
self.temperature = nn.Parameter(torch.ones(heads, 1, 1))
self.qkv = nn.Linear(dim, dim * 3)
self.proj = nn.Linear(dim, dim)
def forward(self, x: 'Tensor') ->Tensor:
B, N, C = x.shape
q, k, v = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.
num_heads).permute(2, 0, 3, 1, 4)
q, k, v = q.transpose(-2, -1), k.transpose(-2, -1), v.transpose(-2, -1)
q = F.normalize(q, dim=-1)
k = F.normalize(k, dim=-1)
attn = q @ k.transpose(-2, -1) * self.temperature
attn = attn.softmax(dim=-1)
x = (attn @ v).permute(0, 3, 1, 2).reshape(B, N, C)
x = self.proj(x)
return x
@torch.jit.ignore
def no_weight_decay(self):
return {'temperature'}
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4, '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
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_div_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 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (12 + y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (24 + y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (36 + y0 + 48 * y1), ymask, 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-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + (x2 + 4 * y3), tmp15, xmask & ymask)
@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 + (4 + y0 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (4 + y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (16 + y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (28 + y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (40 + y0 + 48 * y1), ymask, 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-12
tmp14 = triton_helpers.maximum(tmp12, tmp13)
tmp15 = tmp0 / tmp14
tl.store(out_ptr0 + (x2 + 4 * y3), tmp15, xmask & ymask)
@triton.jit
def triton_poi_fused__softmax_2(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
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = 0.0
tmp3 = tmp1 >= tmp2
tmp4 = 1.0
tmp5 = -1.0
tmp6 = tl.where(tmp3, tmp4, tmp5)
tmp7 = tmp0 * tmp6
tmp8 = tmp7 - tmp7
tmp9 = tmp6 * tmp1
tmp10 = tmp8 * tmp9
tmp11 = tl_math.exp(tmp10)
tmp12 = tmp11 / tmp11
tl.store(out_ptr0 + x2, tmp12, xmask)
@triton.jit
def triton_poi_fused_clone_3(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 + (8 + y0 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@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)
@triton.jit
def triton_poi_fused_add_5(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 % 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 = args
args.clear()
assert_size_stride(primals_1, (4, 4, 4), (16, 4, 1))
assert_size_stride(primals_2, (12, 4), (4, 1))
assert_size_stride(primals_3, (12,), (1,))
assert_size_stride(primals_4, (4, 1, 1), (1, 1, 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((16, 12), (12, 1), torch.float32)
extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16,
4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 12), (1, 4),
0), alpha=1, beta=1, out=buf0)
del primals_2
del primals_3
buf1 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_clone_div_0[grid(16, 4)](buf0, buf1, 16, 4, XBLOCK
=4, YBLOCK=16, num_warps=1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
triton_poi_fused_clone_1[grid(16, 4)](buf0, buf2, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((16, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf1, (16, 1, 4), (4, 0, 1),
0), reinterpret_tensor(buf2, (16, 4, 1), (4, 1, 0), 0), out=buf3)
buf4 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.float32)
triton_poi_fused__softmax_2[grid(16)](buf3, primals_4, buf4, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf5 = empty_strided_cuda((4, 4, 1, 4), (16, 4, 4, 1), torch.float32)
triton_poi_fused_clone_3[grid(16, 4)](buf0, buf5, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf6 = empty_strided_cuda((16, 1, 4), (4, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf4, (16, 1, 1), (1, 1, 1),
0), reinterpret_tensor(buf5, (16, 1, 4), (4, 0, 1), 0), out=buf6)
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_clone_4[grid(16, 4)](buf6, buf7, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf8 = reinterpret_tensor(buf6, (16, 4), (4, 1), 0)
del buf6
extern_kernels.mm(reinterpret_tensor(buf7, (16, 4), (4, 1), 0),
reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf8)
buf9 = reinterpret_tensor(buf8, (4, 4, 4), (16, 4, 1), 0)
del buf8
triton_poi_fused_add_5[grid(64)](buf9, primals_6, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_6
return buf9, primals_4, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), reinterpret_tensor(buf0, (4, 4, 1, 4), (48, 1, 1, 12), 0
), reinterpret_tensor(buf0, (4, 4, 1, 4), (48, 1, 1, 12), 4
), buf3, buf4, reinterpret_tensor(buf7, (16, 4), (4, 1), 0
), primals_5, reinterpret_tensor(buf5, (16, 4, 1), (4, 1, 4), 0
), reinterpret_tensor(buf1, (16, 4, 1), (4, 1, 4), 0
), reinterpret_tensor(buf2, (16, 1, 4), (4, 1, 1), 0)
class XCANew(nn.Module):
""" Cross-Covariance Attention (XCA) operation where the channels are updated using a weighted
sum. The weights are obtained from the (softmax normalized) Cross-covariance
matrix (Q^T K \\in d_h \\times d_h)
"""
def __init__(self, dim: 'int', heads: 'int'):
super().__init__()
self.num_heads = heads
self.temperature = nn.Parameter(torch.ones(heads, 1, 1))
self.qkv = nn.Linear(dim, dim * 3)
self.proj = nn.Linear(dim, dim)
@torch.jit.ignore
def no_weight_decay(self):
return {'temperature'}
def forward(self, input_0):
primals_4 = self.temperature
primals_2 = self.qkv.weight
primals_3 = self.qkv.bias
primals_5 = self.proj.weight
primals_6 = self.proj.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
sithu31296/image_classification
|
XCA
| false
| 16,474
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
ConvBlock
|
import torch
import torch.nn as nn
class Block(nn.Module):
def __init__(self):
"""Initialisation for a lower-level DeepLPF conv block
:returns: N/A
:rtype: N/A
"""
super(Block, self).__init__()
def conv3x3(self, in_channels, out_channels, stride=1):
"""Represents a convolution of shape 3x3
:param in_channels: number of input channels
:param out_channels: number of output channels
:param stride: the convolution stride
:returns: convolution function with the specified parameterisation
:rtype: function
"""
return nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=
stride, padding=1, bias=True)
class ConvBlock(Block, nn.Module):
def __init__(self, num_in_channels, num_out_channels, stride=1):
"""Initialise function for the higher level convolution block
:param in_channels:
:param out_channels:
:param stride:
:param padding:
:returns:
:rtype:
"""
super(Block, self).__init__()
self.conv = self.conv3x3(num_in_channels, num_out_channels, stride=2)
self.lrelu = nn.LeakyReLU()
def forward(self, x):
""" Forward function for the higher level convolution block
:param x: Tensor representing the input BxCxWxH, where B is the batch size, C is the number of channels, W and H are the width and image height
:returns: Tensor representing the output of the block
:rtype: Tensor
"""
img_out = self.lrelu(self.conv(x))
return img_out
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_in_channels': 4, 'num_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
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 = 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_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.01
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=(2,
2), padding=(1, 1), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 2, 2), (16, 4, 2, 1))
buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.bool)
buf2 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(64)](buf0, primals_2,
buf1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
del buf0
del primals_2
return buf2, primals_1, primals_3, buf1
class Block(nn.Module):
def __init__(self):
"""Initialisation for a lower-level DeepLPF conv block
:returns: N/A
:rtype: N/A
"""
super(Block, self).__init__()
def conv3x3(self, in_channels, out_channels, stride=1):
"""Represents a convolution of shape 3x3
:param in_channels: number of input channels
:param out_channels: number of output channels
:param stride: the convolution stride
:returns: convolution function with the specified parameterisation
:rtype: function
"""
return nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=
stride, padding=1, bias=True)
class ConvBlockNew(Block, nn.Module):
def __init__(self, num_in_channels, num_out_channels, stride=1):
"""Initialise function for the higher level convolution block
:param in_channels:
:param out_channels:
:param stride:
:param padding:
:returns:
:rtype:
"""
super(Block, self).__init__()
self.conv = self.conv3x3(num_in_channels, num_out_channels, stride=2)
self.lrelu = nn.LeakyReLU()
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]
|
sjmoran/CURL
|
ConvBlock
| false
| 16,475
|
[
"BSD-3-Clause"
] | 125
|
919e519717b66e14d92ac6fa404c328ee3f254a5
|
https://github.com/sjmoran/CURL/tree/919e519717b66e14d92ac6fa404c328ee3f254a5
|
PoolFormerBlock
|
import torch
from torch import Tensor
from torch import nn
class DropPath(nn.Module):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Copied from timm
This is the same as the DropConnect impl I created for EfficientNet, etc networks, however,
the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper...
See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for
changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use
'survival rate' as the argument.
"""
def __init__(self, p: 'float'=None):
super().__init__()
self.p = p
def forward(self, x: 'Tensor') ->Tensor:
if self.p == 0.0 or not self.training:
return x
kp = 1 - self.p
shape = (x.shape[0],) + (1,) * (x.ndim - 1)
random_tensor = kp + torch.rand(shape, dtype=x.dtype, device=x.device)
random_tensor.floor_()
return x.div(kp) * random_tensor
class MLP(nn.Module):
def __init__(self, dim, hidden_dim, out_dim=None) ->None:
super().__init__()
out_dim = out_dim or dim
self.fc1 = nn.Conv2d(dim, hidden_dim, 1, 1, 0)
self.act = nn.ReLU6(True)
self.fc2 = nn.Conv2d(hidden_dim, out_dim, 1, 1, 0)
def forward(self, x: 'Tensor') ->Tensor:
return self.fc2(self.act(self.fc1(x)))
class Pooling(nn.Module):
def __init__(self, pool_size=3) ->None:
super().__init__()
self.pool = nn.AvgPool2d(pool_size, 1, pool_size // 2,
count_include_pad=False)
def forward(self, x: 'Tensor') ->Tensor:
return self.pool(x) - x
class PoolFormerBlock(nn.Module):
def __init__(self, dim, pool_size=3, dpr=0.0, layer_scale_init_value=1e-05
):
super().__init__()
self.norm1 = nn.GroupNorm(1, dim)
self.token_mixer = Pooling(pool_size)
self.norm2 = nn.GroupNorm(1, dim)
self.drop_path = DropPath(dpr) if dpr > 0.0 else nn.Identity()
self.mlp = MLP(dim, int(dim * 4))
self.layer_scale_1 = nn.Parameter(layer_scale_init_value * torch.
ones(dim), requires_grad=True)
self.layer_scale_2 = nn.Parameter(layer_scale_init_value * torch.
ones(dim), requires_grad=True)
def forward(self, x: 'Tensor') ->Tensor:
x = x + self.drop_path(self.layer_scale_1.unsqueeze(-1).unsqueeze(-
1) * self.token_mixer(self.norm1(x)))
x = x + self.drop_path(self.layer_scale_2.unsqueeze(-1).unsqueeze(-
1) * self.mlp(self.norm2(x)))
return x
def get_inputs():
return [torch.rand([4, 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
from torch import Tensor
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_native_group_norm_0(in_ptr0, in_ptr1, in_ptr2,
out_ptr0, out_ptr2, out_ptr3, xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
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
r3 = rindex // 16
tmp0 = tl.load(in_ptr0 + (r1 + 64 * x0), xmask, other=0.0)
tmp24 = tl.load(in_ptr1 + r3, None, eviction_policy='evict_last')
tmp26 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last')
tmp1 = tl.broadcast_to(tmp0, [XBLOCK, RBLOCK])
tl.where(xmask, tmp1, 0)
tmp4 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp6 = tl.where(xmask, tmp4, 0)
tmp7 = tl.sum(tmp6, 1)[:, None]
tmp8 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp9 = tmp8.to(tl.float32)
tmp10 = tmp7 / tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp11 * tmp11
tmp13 = tl.broadcast_to(tmp12, [XBLOCK, RBLOCK])
tmp15 = tl.where(xmask, tmp13, 0)
tmp16 = tl.sum(tmp15, 1)[:, None]
tmp17 = tmp0 - tmp10
tmp18 = 64.0
tmp19 = tmp16 / tmp18
tmp20 = 1e-05
tmp21 = tmp19 + tmp20
tmp22 = libdevice.rsqrt(tmp21)
tmp23 = tmp17 * tmp22
tmp25 = tmp23 * tmp24
tmp27 = tmp25 + tmp26
tl.store(out_ptr2 + (r1 + 64 * x0), tmp27, xmask)
tl.store(out_ptr3 + x0, tmp22, xmask)
tl.store(out_ptr0 + x0, tmp10, xmask)
@triton.jit
def triton_per_fused_avg_pool2d_native_group_norm_1(in_ptr0, in_ptr1,
in_ptr2, in_ptr3, in_ptr4, out_ptr0, out_ptr1, out_ptr3, out_ptr4,
xnumel, rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
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)
r2 = rindex // 4 % 4
r1 = rindex % 4
r6 = rindex
x0 = xindex
r3 = rindex // 16
tmp54 = tl.load(in_ptr1 + (r6 + 64 * x0), xmask, other=0.0)
tmp55 = tl.load(in_ptr2 + r3, None, eviction_policy='evict_last')
tmp56 = tl.load(in_ptr0 + (r6 + 64 * x0), xmask, other=0.0)
tmp83 = tl.load(in_ptr3 + r3, None, eviction_policy='evict_last')
tmp85 = tl.load(in_ptr4 + r3, None, eviction_policy='evict_last')
tmp0 = -1 + r2
tmp1 = tl.full([1, 1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1, 1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + r1
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (-5 + r6 + 64 * x0), tmp10 & xmask, other=0.0)
tmp12 = r1
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp13 & tmp14
tmp16 = tmp5 & tmp15
tmp17 = tl.load(in_ptr0 + (-4 + r6 + 64 * x0), tmp16 & xmask, other=0.0)
tmp18 = tmp17 + tmp11
tmp19 = 1 + r1
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp20 & tmp21
tmp23 = tmp5 & tmp22
tmp24 = tl.load(in_ptr0 + (-3 + r6 + 64 * x0), tmp23 & xmask, other=0.0)
tmp25 = tmp24 + tmp18
tmp26 = r2
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp29 & tmp9
tmp31 = tl.load(in_ptr0 + (-1 + r6 + 64 * x0), tmp30 & xmask, other=0.0)
tmp32 = tmp31 + tmp25
tmp33 = tmp29 & tmp15
tmp34 = tl.load(in_ptr0 + (r6 + 64 * x0), tmp33 & xmask, other=0.0)
tmp35 = tmp34 + tmp32
tmp36 = tmp29 & tmp22
tmp37 = tl.load(in_ptr0 + (1 + r6 + 64 * x0), tmp36 & xmask, other=0.0)
tmp38 = tmp37 + tmp35
tmp39 = 1 + r2
tmp40 = tmp39 >= tmp1
tmp41 = tmp39 < tmp3
tmp42 = tmp40 & tmp41
tmp43 = tmp42 & tmp9
tmp44 = tl.load(in_ptr0 + (3 + r6 + 64 * x0), tmp43 & xmask, other=0.0)
tmp45 = tmp44 + tmp38
tmp46 = tmp42 & tmp15
tmp47 = tl.load(in_ptr0 + (4 + r6 + 64 * x0), tmp46 & xmask, other=0.0)
tmp48 = tmp47 + tmp45
tmp49 = tmp42 & tmp22
tmp50 = tl.load(in_ptr0 + (5 + r6 + 64 * x0), tmp49 & xmask, other=0.0)
tmp51 = tmp50 + tmp48
tmp52 = (0 * (0 >= -1 + r1) + (-1 + r1) * (-1 + r1 > 0)) * (0 * (0 >= -
1 + r2) + (-1 + r2) * (-1 + r2 > 0)) + (4 * (4 <= 2 + r1) + (2 + r1
) * (2 + r1 < 4)) * (4 * (4 <= 2 + r2) + (2 + r2) * (2 + r2 < 4)
) + -1 * (0 * (0 >= -1 + r1) + (-1 + r1) * (-1 + r1 > 0)) * (4 * (4 <=
2 + r2) + (2 + r2) * (2 + r2 < 4)) + -1 * (0 * (0 >= -1 + r2) + (-1 +
r2) * (-1 + r2 > 0)) * (4 * (4 <= 2 + r1) + (2 + r1) * (2 + r1 < 4))
tmp53 = tmp51 / tmp52
tmp57 = tmp53 - tmp56
tmp58 = tmp55 * tmp57
tmp59 = tmp54 + tmp58
tmp60 = tl.broadcast_to(tmp59, [XBLOCK, RBLOCK])
tl.where(xmask, tmp60, 0)
tmp63 = tl.broadcast_to(tmp60, [XBLOCK, RBLOCK])
tmp65 = tl.where(xmask, tmp63, 0)
tmp66 = tl.sum(tmp65, 1)[:, None]
tmp67 = tl.full([XBLOCK, 1], 64, tl.int32)
tmp68 = tmp67.to(tl.float32)
tmp69 = tmp66 / tmp68
tmp70 = tmp60 - tmp69
tmp71 = tmp70 * tmp70
tmp72 = tl.broadcast_to(tmp71, [XBLOCK, RBLOCK])
tmp74 = tl.where(xmask, tmp72, 0)
tmp75 = tl.sum(tmp74, 1)[:, None]
tmp76 = tmp59 - tmp69
tmp77 = 64.0
tmp78 = tmp75 / tmp77
tmp79 = 1e-05
tmp80 = tmp78 + tmp79
tmp81 = libdevice.rsqrt(tmp80)
tmp82 = tmp76 * tmp81
tmp84 = tmp82 * tmp83
tmp86 = tmp84 + tmp85
tl.store(out_ptr0 + (r6 + 64 * x0), tmp53, xmask)
tl.store(out_ptr3 + (r6 + 64 * x0), tmp86, xmask)
tl.store(out_ptr4 + x0, tmp81, xmask)
tl.store(out_ptr1 + x0, tmp69, xmask)
@triton.jit
def triton_poi_fused_convolution_hardtanh_hardtanh_backward_2(in_ptr0,
in_ptr1, out_ptr0, out_ptr1, 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_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 6.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = tmp2 <= tmp3
tmp8 = tmp2 >= tmp5
tmp9 = tmp7 | tmp8
tl.store(out_ptr0 + x3, tmp6, xmask)
tl.store(out_ptr1 + x3, tmp9, xmask)
@triton.jit
def triton_poi_fused_add_convolution_mul_sub_3(in_out_ptr0, 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
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)
tmp4 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp5 = tl.load(in_ptr3 + x3, xmask)
tmp6 = tl.load(in_ptr4 + x3, xmask)
tmp10 = tl.load(in_ptr5 + x1, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp7 = tmp5 - tmp6
tmp8 = tmp4 * tmp7
tmp9 = tmp3 + tmp8
tmp11 = tmp10 * tmp2
tmp12 = tmp9 + tmp11
tl.store(in_out_ptr0 + x3, tmp2, xmask)
tl.store(out_ptr0 + x3, tmp12, 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) = args
args.clear()
assert_size_stride(primals_1, (4,), (1,))
assert_size_stride(primals_2, (4,), (1,))
assert_size_stride(primals_3, (4,), (1,))
assert_size_stride(primals_4, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4,), (1,))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (16, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_9, (16,), (1,))
assert_size_stride(primals_10, (4, 16, 1, 1), (16, 1, 1, 1))
assert_size_stride(primals_11, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf16 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
get_raw_stream(0)
triton_per_fused_native_group_norm_0[grid(4)](primals_4, primals_2,
primals_3, buf0, buf3, buf16, 4, 64, XBLOCK=1, num_warps=2,
num_stages=1)
del primals_2
del primals_3
buf4 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf5 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf9 = empty_strided_cuda((4, 1, 1, 1), (1, 4, 4, 4), torch.float32)
triton_per_fused_avg_pool2d_native_group_norm_1[grid(4)](buf3,
primals_4, primals_1, primals_6, primals_7, buf4, buf5, buf8,
buf9, 4, 64, XBLOCK=1, num_warps=2, num_stages=1)
del primals_7
buf10 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf10, (4, 16, 4, 4), (256, 16, 4, 1))
buf11 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.
float32)
buf15 = empty_strided_cuda((4, 16, 4, 4), (256, 16, 4, 1), torch.bool)
triton_poi_fused_convolution_hardtanh_hardtanh_backward_2[grid(1024)](
buf10, primals_9, buf11, buf15, 1024, XBLOCK=128, num_warps=4,
num_stages=1)
del buf10
del primals_9
buf12 = extern_kernels.convolution(buf11, primals_10, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf12, (4, 4, 4, 4), (64, 16, 4, 1))
buf13 = buf12
del buf12
buf14 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_convolution_mul_sub_3[grid(256)](buf13,
primals_11, primals_4, primals_1, buf4, buf3, primals_5, buf14,
256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_11
return (buf14, primals_1, primals_4, primals_5, primals_6, primals_8,
primals_10, buf3, buf4, buf8, reinterpret_tensor(buf5, (4, 1), (1,
1), 0), reinterpret_tensor(buf9, (4, 1), (1, 1), 0), buf11, buf13,
buf15, reinterpret_tensor(buf0, (4, 1, 1), (1, 1, 1), 0),
reinterpret_tensor(buf16, (4, 1, 1), (1, 1, 1), 0))
class DropPath(nn.Module):
"""Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).
Copied from timm
This is the same as the DropConnect impl I created for EfficientNet, etc networks, however,
the original name is misleading as 'Drop Connect' is a different form of dropout in a separate paper...
See discussion: https://github.com/tensorflow/tpu/issues/494#issuecomment-532968956 ... I've opted for
changing the layer and argument names to 'drop path' rather than mix DropConnect as a layer name and use
'survival rate' as the argument.
"""
def __init__(self, p: 'float'=None):
super().__init__()
self.p = p
def forward(self, x: 'Tensor') ->Tensor:
if self.p == 0.0 or not self.training:
return x
kp = 1 - self.p
shape = (x.shape[0],) + (1,) * (x.ndim - 1)
random_tensor = kp + torch.rand(shape, dtype=x.dtype, device=x.device)
random_tensor.floor_()
return x.div(kp) * random_tensor
class MLP(nn.Module):
def __init__(self, dim, hidden_dim, out_dim=None) ->None:
super().__init__()
out_dim = out_dim or dim
self.fc1 = nn.Conv2d(dim, hidden_dim, 1, 1, 0)
self.act = nn.ReLU6(True)
self.fc2 = nn.Conv2d(hidden_dim, out_dim, 1, 1, 0)
def forward(self, x: 'Tensor') ->Tensor:
return self.fc2(self.act(self.fc1(x)))
class Pooling(nn.Module):
def __init__(self, pool_size=3) ->None:
super().__init__()
self.pool = nn.AvgPool2d(pool_size, 1, pool_size // 2,
count_include_pad=False)
def forward(self, x: 'Tensor') ->Tensor:
return self.pool(x) - x
class PoolFormerBlockNew(nn.Module):
def __init__(self, dim, pool_size=3, dpr=0.0, layer_scale_init_value=1e-05
):
super().__init__()
self.norm1 = nn.GroupNorm(1, dim)
self.token_mixer = Pooling(pool_size)
self.norm2 = nn.GroupNorm(1, dim)
self.drop_path = DropPath(dpr) if dpr > 0.0 else nn.Identity()
self.mlp = MLP(dim, int(dim * 4))
self.layer_scale_1 = nn.Parameter(layer_scale_init_value * torch.
ones(dim), requires_grad=True)
self.layer_scale_2 = nn.Parameter(layer_scale_init_value * torch.
ones(dim), requires_grad=True)
def forward(self, input_0):
primals_1 = self.layer_scale_1
primals_2 = self.layer_scale_2
primals_3 = self.norm1.weight
primals_5 = self.norm1.bias
primals_6 = self.norm2.weight
primals_7 = self.norm2.bias
primals_8 = self.mlp.fc1.weight
primals_9 = self.mlp.fc1.bias
primals_10 = self.mlp.fc2.weight
primals_11 = self.mlp.fc2.bias
primals_4 = 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])
return output[0]
|
sithu31296/image_classification
|
PoolFormerBlock
| false
| 16,476
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
stack_pool
|
import torch
import torch.nn as nn
class stack_pool(nn.Module):
def __init__(self):
super(stack_pool, self).__init__()
self.pool2 = nn.MaxPool2d(2, stride=2)
self.pool2s1 = nn.MaxPool2d(2, stride=1)
self.pool3s1 = nn.MaxPool2d(3, stride=1, padding=1)
self.padding = nn.ReplicationPad2d((0, 1, 0, 1))
def forward(self, x):
x1 = self.pool2(x)
x2 = self.pool2s1(self.padding(x1))
x3 = self.pool3s1(x2)
y = (x1 + x2 + x3) / 3.0
return y
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_max_pool2d_with_indices_replication_pad2d_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
x0 = xindex % 3
x1 = xindex // 3 % 3
x2 = xindex // 9
x3 = xindex
tmp0 = tl.load(in_ptr0 + (2 * (1 * (1 <= x0) + x0 * (x0 < 1)) + 8 * (1 *
(1 <= x1) + x1 * (x1 < 1)) + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * (1 * (1 <= x0) + x0 * (x0 < 1)) + 8 *
(1 * (1 <= x1) + x1 * (x1 < 1)) + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (4 + 2 * (1 * (1 <= x0) + x0 * (x0 < 1)) + 8 *
(1 * (1 <= x1) + x1 * (x1 < 1)) + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp5 = tl.load(in_ptr0 + (5 + 2 * (1 * (1 <= x0) + x0 * (x0 < 1)) + 8 *
(1 * (1 <= x1) + x1 * (x1 < 1)) + 16 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tl.store(out_ptr0 + x3, tmp6, xmask)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_replication_pad2d_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 + (x0 + 3 * x1 + 9 * x2), xmask)
tmp1 = tl.load(in_ptr0 + (1 + x0 + 3 * x1 + 9 * x2), xmask)
tmp3 = tl.load(in_ptr0 + (3 + x0 + 3 * x1 + 9 * x2), xmask)
tmp5 = tl.load(in_ptr0 + (4 + x0 + 3 * x1 + 9 * x2), xmask)
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tl.store(out_ptr0 + x3, tmp6, xmask)
@triton.jit
def triton_poi_fused_add_div_max_pool2d_with_indices_replication_pad2d_2(
in_out_ptr0, in_ptr0, in_ptr1, 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
x4 = xindex
x3 = xindex // 2
tmp52 = tl.load(in_ptr1 + (2 * x0 + 8 * x3), xmask, eviction_policy=
'evict_last')
tmp53 = tl.load(in_ptr1 + (1 + 2 * x0 + 8 * x3), xmask, eviction_policy
='evict_last')
tmp55 = tl.load(in_ptr1 + (4 + 2 * x0 + 8 * x3), xmask, eviction_policy
='evict_last')
tmp57 = tl.load(in_ptr1 + (5 + 2 * x0 + 8 * x3), xmask, eviction_policy
='evict_last')
tmp59 = tl.load(in_ptr0 + x4, xmask)
tmp0 = -1 + x1
tmp1 = tl.full([1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1], 2, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tmp2 & tmp4
tmp6 = -1 + x0
tmp7 = tmp6 >= tmp1
tmp8 = tmp6 < tmp3
tmp9 = tmp7 & tmp8
tmp10 = tmp5 & tmp9
tmp11 = tl.load(in_ptr0 + (-3 + x4), tmp10 & xmask, other=float('-inf'))
tmp12 = x0
tmp13 = tmp12 >= tmp1
tmp14 = tmp12 < tmp3
tmp15 = tmp13 & tmp14
tmp16 = tmp5 & tmp15
tmp17 = tl.load(in_ptr0 + (-2 + x4), tmp16 & xmask, other=float('-inf'))
tmp18 = triton_helpers.maximum(tmp17, tmp11)
tmp19 = 1 + x0
tmp20 = tmp19 >= tmp1
tmp21 = tmp19 < tmp3
tmp22 = tmp20 & tmp21
tmp23 = tmp5 & tmp22
tmp24 = tl.load(in_ptr0 + (-1 + x4), tmp23 & xmask, other=float('-inf'))
tmp25 = triton_helpers.maximum(tmp24, tmp18)
tmp26 = x1
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp29 & tmp9
tmp31 = tl.load(in_ptr0 + (-1 + x4), tmp30 & xmask, other=float('-inf'))
tmp32 = triton_helpers.maximum(tmp31, tmp25)
tmp33 = tmp29 & tmp15
tmp34 = tl.load(in_ptr0 + x4, tmp33 & xmask, other=float('-inf'))
tmp35 = triton_helpers.maximum(tmp34, tmp32)
tmp36 = tmp29 & tmp22
tmp37 = tl.load(in_ptr0 + (1 + x4), tmp36 & xmask, other=float('-inf'))
tmp38 = triton_helpers.maximum(tmp37, tmp35)
tmp39 = 1 + x1
tmp40 = tmp39 >= tmp1
tmp41 = tmp39 < tmp3
tmp42 = tmp40 & tmp41
tmp43 = tmp42 & tmp9
tmp44 = tl.load(in_ptr0 + (1 + x4), tmp43 & xmask, other=float('-inf'))
tmp45 = triton_helpers.maximum(tmp44, tmp38)
tmp46 = tmp42 & tmp15
tmp47 = tl.load(in_ptr0 + (2 + x4), tmp46 & xmask, other=float('-inf'))
tmp48 = triton_helpers.maximum(tmp47, tmp45)
tmp49 = tmp42 & tmp22
tmp50 = tl.load(in_ptr0 + (3 + x4), tmp49 & xmask, other=float('-inf'))
tmp51 = triton_helpers.maximum(tmp50, tmp48)
tmp54 = triton_helpers.maximum(tmp53, tmp52)
tmp56 = triton_helpers.maximum(tmp55, tmp54)
tmp58 = triton_helpers.maximum(tmp57, tmp56)
tmp60 = tmp58 + tmp59
tmp61 = tmp60 + tmp51
tmp62 = 0.3333333333333333
tmp63 = tmp61 * tmp62
tl.store(in_out_ptr0 + x4, tmp63, 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_replication_pad2d_0[grid(144)
](arg0_1, buf0, 144, XBLOCK=128, num_warps=4, num_stages=1)
buf1 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
triton_poi_fused_max_pool2d_with_indices_replication_pad2d_1[grid(64)](
buf0, buf1, 64, XBLOCK=64, num_warps=1, num_stages=1)
del buf0
buf2 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
buf3 = buf2
del buf2
triton_poi_fused_add_div_max_pool2d_with_indices_replication_pad2d_2[
grid(64)](buf3, buf1, arg0_1, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del arg0_1
del buf1
return buf3,
class stack_poolNew(nn.Module):
def __init__(self):
super(stack_poolNew, self).__init__()
self.pool2 = nn.MaxPool2d(2, stride=2)
self.pool2s1 = nn.MaxPool2d(2, stride=1)
self.pool3s1 = nn.MaxPool2d(3, stride=1, padding=1)
self.padding = nn.ReplicationPad2d((0, 1, 0, 1))
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
siyuhuang/crowdcount-stackedpool
|
stack_pool
| false
| 16,477
|
[
"MIT"
] | 93
|
bbba3d9e91a5a89642b4bd3638ae8e68801ea7bf
|
https://github.com/siyuhuang/crowdcount-stackedpool/tree/bbba3d9e91a5a89642b4bd3638ae8e68801ea7bf
|
multi_pool
|
import torch
import torch.nn as nn
class multi_pool(nn.Module):
def __init__(self):
super(multi_pool, self).__init__()
self.pool2 = nn.MaxPool2d(2, stride=2)
self.pool4 = nn.MaxPool2d(4, stride=2, padding=1)
self.pool8 = nn.MaxPool2d(8, stride=2, padding=3)
def forward(self, x):
x1 = self.pool2(x)
x2 = self.pool4(x)
x3 = self.pool8(x)
y = (x1 + x2 + x3) / 3.0
return y
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_max_pool2d_with_indices_0(in_out_ptr0, in_ptr0,
in_ptr1, 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
tmp81 = tl.load(in_ptr0 + (2 * x0 + 8 * x3), xmask, eviction_policy=
'evict_last')
tmp82 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x3), xmask, eviction_policy
='evict_last')
tmp84 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x3), xmask, eviction_policy
='evict_last')
tmp86 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x3), xmask, eviction_policy
='evict_last')
tmp89 = tl.load(in_ptr1 + x4, xmask)
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=float('-inf'))
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=float('-inf'))
tmp18 = triton_helpers.maximum(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=float('-inf'))
tmp25 = triton_helpers.maximum(tmp24, tmp18)
tmp26 = 2 + 2 * x0
tmp27 = tmp26 >= tmp1
tmp28 = tmp26 < tmp3
tmp29 = tmp27 & tmp28
tmp30 = tmp5 & tmp29
tmp31 = tl.load(in_ptr0 + (-2 + 2 * x0 + 8 * x3), tmp30 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp32 = triton_helpers.maximum(tmp31, tmp25)
tmp33 = 2 * x1
tmp34 = tmp33 >= tmp1
tmp35 = tmp33 < tmp3
tmp36 = tmp34 & tmp35
tmp37 = tmp36 & tmp9
tmp38 = tl.load(in_ptr0 + (-1 + 2 * x0 + 8 * x3), tmp37 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp39 = triton_helpers.maximum(tmp38, tmp32)
tmp40 = tmp36 & tmp15
tmp41 = tl.load(in_ptr0 + (2 * x0 + 8 * x3), tmp40 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp42 = triton_helpers.maximum(tmp41, tmp39)
tmp43 = tmp36 & tmp22
tmp44 = tl.load(in_ptr0 + (1 + 2 * x0 + 8 * x3), tmp43 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp45 = triton_helpers.maximum(tmp44, tmp42)
tmp46 = tmp36 & tmp29
tmp47 = tl.load(in_ptr0 + (2 + 2 * x0 + 8 * x3), tmp46 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp48 = triton_helpers.maximum(tmp47, tmp45)
tmp49 = 1 + 2 * x1
tmp50 = tmp49 >= tmp1
tmp51 = tmp49 < tmp3
tmp52 = tmp50 & tmp51
tmp53 = tmp52 & tmp9
tmp54 = tl.load(in_ptr0 + (3 + 2 * x0 + 8 * x3), tmp53 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp55 = triton_helpers.maximum(tmp54, tmp48)
tmp56 = tmp52 & tmp15
tmp57 = tl.load(in_ptr0 + (4 + 2 * x0 + 8 * x3), tmp56 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp58 = triton_helpers.maximum(tmp57, tmp55)
tmp59 = tmp52 & tmp22
tmp60 = tl.load(in_ptr0 + (5 + 2 * x0 + 8 * x3), tmp59 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp61 = triton_helpers.maximum(tmp60, tmp58)
tmp62 = tmp52 & tmp29
tmp63 = tl.load(in_ptr0 + (6 + 2 * x0 + 8 * x3), tmp62 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp64 = triton_helpers.maximum(tmp63, tmp61)
tmp65 = 2 + 2 * x1
tmp66 = tmp65 >= tmp1
tmp67 = tmp65 < tmp3
tmp68 = tmp66 & tmp67
tmp69 = tmp68 & tmp9
tmp70 = tl.load(in_ptr0 + (7 + 2 * x0 + 8 * x3), tmp69 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp71 = triton_helpers.maximum(tmp70, tmp64)
tmp72 = tmp68 & tmp15
tmp73 = tl.load(in_ptr0 + (8 + 2 * x0 + 8 * x3), tmp72 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp74 = triton_helpers.maximum(tmp73, tmp71)
tmp75 = tmp68 & tmp22
tmp76 = tl.load(in_ptr0 + (9 + 2 * x0 + 8 * x3), tmp75 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp77 = triton_helpers.maximum(tmp76, tmp74)
tmp78 = tmp68 & tmp29
tmp79 = tl.load(in_ptr0 + (10 + 2 * x0 + 8 * x3), tmp78 & xmask,
eviction_policy='evict_last', other=float('-inf'))
tmp80 = triton_helpers.maximum(tmp79, tmp77)
tmp83 = triton_helpers.maximum(tmp82, tmp81)
tmp85 = triton_helpers.maximum(tmp84, tmp83)
tmp87 = triton_helpers.maximum(tmp86, tmp85)
tmp88 = tmp87 + tmp80
tmp90 = tmp88 + tmp89
tmp91 = 0.3333333333333333
tmp92 = tmp90 * tmp91
tl.store(in_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)
buf1 = torch.ops.aten.max_pool2d_with_indices.default(arg0_1, [8, 8
], [2, 2], [3, 3])
buf2 = buf1[0]
del buf1
buf0 = empty_strided_cuda((4, 4, 2, 2), (16, 4, 2, 1), torch.float32)
buf4 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_add_div_max_pool2d_with_indices_0[grid(64)](buf4,
arg0_1, buf2, 64, XBLOCK=64, num_warps=1, num_stages=1)
del arg0_1
del buf2
return buf4,
class multi_poolNew(nn.Module):
def __init__(self):
super(multi_poolNew, self).__init__()
self.pool2 = nn.MaxPool2d(2, stride=2)
self.pool4 = nn.MaxPool2d(4, stride=2, padding=1)
self.pool8 = nn.MaxPool2d(8, stride=2, padding=3)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
siyuhuang/crowdcount-stackedpool
|
multi_pool
| false
| 16,478
|
[
"MIT"
] | 93
|
bbba3d9e91a5a89642b4bd3638ae8e68801ea7bf
|
https://github.com/siyuhuang/crowdcount-stackedpool/tree/bbba3d9e91a5a89642b4bd3638ae8e68801ea7bf
|
ClipLayer
|
import torch
import torch.nn as nn
def clip_data(data, max_norm):
norms = torch.norm(data.reshape(data.shape[0], -1), dim=-1)
scale = (max_norm / norms).clamp(max=1.0)
data *= scale.reshape(-1, 1, 1, 1)
return data
class ClipLayer(nn.Module):
def __init__(self, max_norm):
super(ClipLayer, self).__init__()
self.max_norm = max_norm
def forward(self, x):
return clip_data(x, self.max_norm)
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'max_norm': 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
import torch.nn as nn
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
@triton.jit
def triton_per_fused_linalg_vector_norm_mul_0(in_ptr0, out_ptr2, xnumel,
rnumel, XBLOCK: tl.constexpr):
xnumel = 4
RBLOCK: tl.constexpr = 64
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 = tmp0 * tmp0
tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
tmp4 = tl.where(xmask, tmp2, 0)
tmp5 = tl.sum(tmp4, 1)[:, None]
tmp6 = libdevice.sqrt(tmp5)
tmp7 = tl.full([1, 1], 1, tl.int32)
tmp8 = tmp7 / tmp6
tmp9 = 4.0
tmp10 = tmp8 * tmp9
tmp11 = 1.0
tmp12 = triton_helpers.minimum(tmp10, tmp11)
tmp13 = tmp0 * tmp12
tl.store(out_ptr2 + (r1 + 64 * x0), tmp13, 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)
get_raw_stream(0)
triton_per_fused_linalg_vector_norm_mul_0[grid(4)](arg0_1, arg0_1,
4, 64, XBLOCK=1, num_warps=2, num_stages=1)
return arg0_1,
def clip_data(data, max_norm):
norms = torch.norm(data.reshape(data.shape[0], -1), dim=-1)
scale = (max_norm / norms).clamp(max=1.0)
data *= scale.reshape(-1, 1, 1, 1)
return data
class ClipLayerNew(nn.Module):
def __init__(self, max_norm):
super(ClipLayerNew, self).__init__()
self.max_norm = max_norm
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
skat00sh/Handcrafted-DP
|
ClipLayer
| false
| 16,479
|
[
"MIT"
] | 48
|
d1f8bc004adc240d5c424a10bdcc30fc266c8218
|
https://github.com/skat00sh/Handcrafted-DP/tree/d1f8bc004adc240d5c424a10bdcc30fc266c8218
|
MidNet2
|
import torch
import torch.nn as nn
class MidNet2(nn.Module):
def forward(self, x_in):
"""Network with dilation rate 2
:param x_in: input convolutional features
:returns: processed convolutional features
:rtype: Tensor
"""
x = self.lrelu(self.conv1(x_in))
x = self.lrelu(self.conv2(x))
x = self.lrelu(self.conv3(x))
x = self.conv4(x)
return x
def __init__(self, in_channels=16):
"""FIXME! briefly describe function
:param in_channels: Input channels
:returns: N/A
:rtype: N/A
"""
super(MidNet2, self).__init__()
self.lrelu = nn.LeakyReLU()
self.conv1 = nn.Conv2d(in_channels, 64, 3, 1, 2, 2)
self.conv2 = nn.Conv2d(64, 64, 3, 1, 2, 2)
self.conv3 = nn.Conv2d(64, 64, 3, 1, 2, 2)
self.conv4 = nn.Conv2d(64, 64, 3, 1, 2, 2)
def get_inputs():
return [torch.rand([4, 16, 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
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_leaky_relu_0(in_ptr0, in_ptr1, out_ptr0,
out_ptr1, 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 // 4096 % 64
tmp0 = tl.load(in_ptr0 + x3, None)
tmp1 = tl.load(in_ptr1 + x1, None, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = 0.0
tmp4 = tmp2 > tmp3
tmp5 = 0.01
tmp6 = tmp2 * tmp5
tmp7 = tl.where(tmp4, tmp2, tmp6)
tl.store(out_ptr0 + x3, tmp4, None)
tl.store(out_ptr1 + 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 // 4096 % 64
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)
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, (64, 16, 3, 3), (144, 9, 3, 1))
assert_size_stride(primals_2, (64,), (1,))
assert_size_stride(primals_3, (4, 16, 64, 64), (65536, 4096, 64, 1))
assert_size_stride(primals_4, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_5, (64,), (1,))
assert_size_stride(primals_6, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_7, (64,), (1,))
assert_size_stride(primals_8, (64, 64, 3, 3), (576, 9, 3, 1))
assert_size_stride(primals_9, (64,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(2, 2), dilation=(2, 2), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf1 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.bool)
buf2 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.float32)
get_raw_stream(0)
triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf0,
primals_2, buf1, buf2, 1048576, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_2
buf3 = extern_kernels.convolution(buf2, primals_4, stride=(1, 1),
padding=(2, 2), dilation=(2, 2), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf3, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf4 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.bool)
buf5 = buf0
del buf0
triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf3,
primals_5, buf4, buf5, 1048576, XBLOCK=1024, num_warps=4,
num_stages=1)
del primals_5
buf6 = extern_kernels.convolution(buf5, primals_6, stride=(1, 1),
padding=(2, 2), dilation=(2, 2), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf7 = empty_strided_cuda((4, 64, 64, 64), (262144, 4096, 64, 1),
torch.bool)
buf8 = buf3
del buf3
triton_poi_fused_convolution_leaky_relu_0[grid(1048576)](buf6,
primals_7, buf7, buf8, 1048576, XBLOCK=1024, num_warps=4,
num_stages=1)
del buf6
del primals_7
buf9 = extern_kernels.convolution(buf8, primals_8, stride=(1, 1),
padding=(2, 2), dilation=(2, 2), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf9, (4, 64, 64, 64), (262144, 4096, 64, 1))
buf10 = buf9
del buf9
triton_poi_fused_convolution_1[grid(1048576)](buf10, primals_9,
1048576, XBLOCK=1024, num_warps=4, num_stages=1)
del primals_9
return (buf10, primals_1, primals_3, primals_4, primals_6, primals_8,
buf1, buf2, buf4, buf5, buf7, buf8)
class MidNet2New(nn.Module):
def __init__(self, in_channels=16):
"""FIXME! briefly describe function
:param in_channels: Input channels
:returns: N/A
:rtype: N/A
"""
super(MidNet2New, self).__init__()
self.lrelu = nn.LeakyReLU()
self.conv1 = nn.Conv2d(in_channels, 64, 3, 1, 2, 2)
self.conv2 = nn.Conv2d(64, 64, 3, 1, 2, 2)
self.conv3 = nn.Conv2d(64, 64, 3, 1, 2, 2)
self.conv4 = nn.Conv2d(64, 64, 3, 1, 2, 2)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_8 = self.conv4.weight
primals_9 = self.conv4.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]
|
sjmoran/CURL
|
MidNet2
| false
| 16,480
|
[
"BSD-3-Clause"
] | 125
|
919e519717b66e14d92ac6fa404c328ee3f254a5
|
https://github.com/sjmoran/CURL/tree/919e519717b66e14d92ac6fa404c328ee3f254a5
|
Actor
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Actor(nn.Module):
"""Initialize parameters and build model.
An nn.Module contains layers, and a method
forward(input)that returns the output.
Weights (learnable params) are inherently defined here.
Args:
state_dim (int): Dimension of each state
action_dim (int): Dimension of each action
max_action (float): highest action to take
Return:
action output of network with tanh activation
"""
def __init__(self, state_dim, action_dim, max_action):
super(Actor, self).__init__()
self.fc1 = nn.Linear(state_dim, 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, action_dim)
self.max_action = max_action
def forward(self, state):
a = F.relu(self.fc1(state))
a = F.relu(self.fc2(a))
return self.max_action * torch.tanh(self.fc3(a))
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'state_dim': 4, 'action_dim': 4, 'max_action': 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_relu_threshold_backward_0(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 % 256
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_mul_tanh_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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = libdevice.tanh(tmp0)
tmp2 = 4.0
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,
primals_7) = 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, 256), (256, 1))
assert_size_stride(primals_5, (256,), (1,))
assert_size_stride(primals_6, (4, 256), (256, 1))
assert_size_stride(primals_7, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((64, 256), (256, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(primals_3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_1, (4, 256), (1, 4), 0), out=buf0)
del primals_1
buf1 = reinterpret_tensor(buf0, (4, 4, 4, 256), (4096, 1024, 256, 1), 0
)
del buf0
buf7 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1),
torch.bool)
get_raw_stream(0)
triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf1,
primals_2, buf7, 16384, XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((64, 256), (256, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf1, (64, 256), (256, 1), 0),
reinterpret_tensor(primals_4, (256, 256), (1, 256), 0), out=buf2)
buf3 = reinterpret_tensor(buf2, (4, 4, 4, 256), (4096, 1024, 256, 1), 0
)
del buf2
buf6 = empty_strided_cuda((4, 4, 4, 256), (4096, 1024, 256, 1),
torch.bool)
triton_poi_fused_relu_threshold_backward_0[grid(16384)](buf3,
primals_5, buf6, 16384, XBLOCK=128, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 256),
(256, 1), 0), reinterpret_tensor(primals_6, (256, 4), (1, 256),
0), alpha=1, beta=1, out=buf4)
del primals_7
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_mul_tanh_1[grid(256)](buf4, buf5, 256, XBLOCK=256,
num_warps=4, num_stages=1)
return buf5, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 256), (256, 1), 0
), reinterpret_tensor(buf3, (64, 256), (256, 1), 0
), buf4, primals_6, buf6, primals_4, buf7
class ActorNew(nn.Module):
"""Initialize parameters and build model.
An nn.Module contains layers, and a method
forward(input)that returns the output.
Weights (learnable params) are inherently defined here.
Args:
state_dim (int): Dimension of each state
action_dim (int): Dimension of each action
max_action (float): highest action to take
Return:
action output of network with tanh activation
"""
def __init__(self, state_dim, action_dim, max_action):
super(ActorNew, self).__init__()
self.fc1 = nn.Linear(state_dim, 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, action_dim)
self.max_action = max_action
def forward(self, input_0):
primals_1 = self.fc1.weight
primals_2 = self.fc1.bias
primals_4 = self.fc2.weight
primals_5 = self.fc2.bias
primals_6 = self.fc3.weight
primals_7 = self.fc3.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6, primals_7])
return output[0]
|
sofya-pugach/spot_mini_mini
|
Actor
| false
| 16,481
|
[
"MIT"
] | 323
|
42770145e91ed2625ccc7e4f4d7016ce14a61464
|
https://github.com/sofya-pugach/spot_mini_mini/tree/42770145e91ed2625ccc7e4f4d7016ce14a61464
|
CA
|
import torch
from torch import Tensor
from torch import nn
class CA(nn.Module):
"""ClassAttention as in CaiT
"""
def __init__(self, dim: 'int', heads: 'int'):
super().__init__()
self.num_heads = heads
self.scale = (dim // heads) ** -0.5
self.qkv = nn.Linear(dim, dim * 3)
self.proj = nn.Linear(dim, dim)
def forward(self, x: 'Tensor') ->Tensor:
B, N, C = x.shape
q, k, v = self.qkv(x).reshape(B, N, 3, self.num_heads, C // self.
num_heads).permute(2, 0, 3, 1, 4)
qc = q[:, :, :1]
attn_cls = (qc * k).sum(dim=-1) * self.scale
attn_cls = attn_cls.softmax(dim=-1)
cls_token = (attn_cls.unsqueeze(2) @ v).transpose(1, 2).reshape(B, 1, C
)
cls_token = self.proj(cls_token)
x = torch.cat([cls_token, x[:, 1:]], dim=1)
return x
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 4, '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
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__softmax_mul_sum_0(in_ptr0, 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 % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 48 * x1), xmask)
tmp1 = tl.load(in_ptr0 + (4 + x0 + 48 * x1), xmask)
tmp5 = tl.load(in_ptr0 + (16 + x0 + 48 * x1), xmask)
tmp9 = tl.load(in_ptr0 + (28 + x0 + 48 * x1), xmask)
tmp13 = tl.load(in_ptr0 + (40 + x0 + 48 * x1), xmask)
tmp2 = tmp0 * tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tmp6 = tmp0 * tmp5
tmp7 = tmp6 * tmp3
tmp8 = triton_helpers.maximum(tmp4, tmp7)
tmp10 = tmp0 * tmp9
tmp11 = tmp10 * tmp3
tmp12 = triton_helpers.maximum(tmp8, tmp11)
tmp14 = tmp0 * tmp13
tmp15 = tmp14 * tmp3
tmp16 = triton_helpers.maximum(tmp12, tmp15)
tmp17 = tmp4 - tmp16
tmp18 = tmp17 * tmp3
tmp19 = tl_math.exp(tmp18)
tmp20 = tmp7 - tmp16
tmp21 = tmp20 * tmp3
tmp22 = tl_math.exp(tmp21)
tmp23 = tmp19 + tmp22
tmp24 = tmp11 - tmp16
tmp25 = tmp24 * tmp3
tmp26 = tl_math.exp(tmp25)
tmp27 = tmp23 + tmp26
tmp28 = tmp15 - tmp16
tmp29 = tmp28 * tmp3
tmp30 = tl_math.exp(tmp29)
tmp31 = tmp27 + tmp30
tl.store(out_ptr0 + x2, tmp16, xmask)
tl.store(out_ptr1 + x2, tmp31, xmask)
@triton.jit
def triton_poi_fused__softmax_mul_sum_1(in_ptr0, in_ptr1, in_ptr2, 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
y0 = yindex % 4
y1 = yindex // 4
x2 = xindex
y3 = yindex
tmp0 = tl.load(in_ptr0 + (y0 + 48 * y1), ymask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (4 + y0 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tmp5 = tl.load(in_ptr1 + y3, ymask, eviction_policy='evict_last')
tmp9 = tl.load(in_ptr2 + y3, ymask, eviction_policy='evict_last')
tmp2 = tmp0 * tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tmp6 = tmp4 - tmp5
tmp7 = tmp6 * tmp3
tmp8 = tl_math.exp(tmp7)
tmp10 = tmp8 / tmp9
tl.store(out_ptr0 + (x2 + 4 * y3), tmp10, xmask & ymask)
@triton.jit
def triton_poi_fused_clone_2(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 + (8 + y0 + 12 * x2 + 48 * y1), xmask & ymask,
eviction_policy='evict_last')
tl.store(out_ptr0 + (x2 + 4 * y3), tmp0, xmask & ymask)
@triton.jit
def triton_poi_fused_cat_3(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
x1 = xindex // 4 % 4
x0 = xindex % 4
x2 = xindex // 16
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 + 4 * x2), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 4, tl.int64)
tmp9 = tl.load(in_ptr1 + (4 + x0 + 4 * (-1 + x1) + 16 * x2), tmp6 &
xmask, other=0.0)
tmp10 = tl.where(tmp4, tmp5, tmp9)
tl.store(out_ptr0 + x3, tmp10, 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, (12, 4), (4, 1))
assert_size_stride(primals_3, (12,), (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((16, 12), (12, 1), torch.float32)
extern_kernels.addmm(primals_3, reinterpret_tensor(primals_1, (16,
4), (4, 1), 0), reinterpret_tensor(primals_2, (4, 12), (1, 4),
0), alpha=1, beta=1, out=buf0)
del primals_2
del primals_3
buf1 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
buf2 = empty_strided_cuda((4, 4, 1), (4, 1, 16), torch.float32)
get_raw_stream(0)
triton_poi_fused__softmax_mul_sum_0[grid(16)](buf0, buf1, buf2, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf3 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused__softmax_mul_sum_1[grid(16, 4)](buf0, buf1, buf2,
buf3, 16, 4, XBLOCK=2, YBLOCK=16, num_warps=1, num_stages=1)
buf4 = empty_strided_cuda((4, 4, 4, 1), (16, 4, 1, 1), torch.float32)
triton_poi_fused_clone_2[grid(16, 4)](buf0, buf4, 16, 4, XBLOCK=4,
YBLOCK=16, num_warps=1, num_stages=1)
buf5 = reinterpret_tensor(buf2, (16, 1, 1), (1, 1, 1), 0)
del buf2
extern_kernels.bmm(reinterpret_tensor(buf3, (16, 1, 4), (4, 4, 1),
0), reinterpret_tensor(buf4, (16, 4, 1), (4, 1, 0), 0), out=buf5)
buf6 = reinterpret_tensor(buf1, (4, 4), (4, 1), 0)
del buf1
extern_kernels.addmm(primals_5, reinterpret_tensor(buf5, (4, 4), (4,
1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0), alpha
=1, beta=1, out=buf6)
del primals_5
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_cat_3[grid(64)](buf6, primals_1, buf7, 64, XBLOCK=
64, num_warps=1, num_stages=1)
del buf6
return buf7, reinterpret_tensor(primals_1, (16, 4), (4, 1), 0
), reinterpret_tensor(buf0, (4, 4, 4, 1), (48, 1, 12, 1), 4
), reinterpret_tensor(buf0, (4, 4, 1, 1), (48, 1, 12, 1), 0
), buf3, reinterpret_tensor(buf5, (4, 4), (4, 1), 0
), primals_4, reinterpret_tensor(buf4, (16, 1, 4), (4, 1, 1), 0)
class CANew(nn.Module):
"""ClassAttention as in CaiT
"""
def __init__(self, dim: 'int', heads: 'int'):
super().__init__()
self.num_heads = heads
self.scale = (dim // heads) ** -0.5
self.qkv = nn.Linear(dim, dim * 3)
self.proj = nn.Linear(dim, dim)
def forward(self, input_0):
primals_2 = self.qkv.weight
primals_3 = self.qkv.bias
primals_4 = self.proj.weight
primals_5 = self.proj.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
sithu31296/image_classification
|
CA
| false
| 16,482
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
OutlookAttention
|
import math
import torch
from torch import Tensor
from torch import nn
from torch.nn import functional as F
class OutlookAttention(nn.Module):
def __init__(self, dim, num_heads, k=3, s=1, p=1):
super().__init__()
self.s = s
self.k = k
self.p = p
self.num_heads = num_heads
self.scale = (dim // num_heads) ** -0.5
self.v = nn.Linear(dim, dim, bias=False)
self.attn = nn.Linear(dim, k ** 4 * num_heads)
self.proj = nn.Linear(dim, dim)
self.unfold = nn.Unfold(k, padding=p, stride=s)
self.pool = nn.AvgPool2d(s, s, ceil_mode=True)
def forward(self, x: 'Tensor') ->Tensor:
B, H, W, C = x.shape
v = self.v(x).permute(0, 3, 1, 2)
h, w = math.ceil(H / self.s), math.ceil(W / self.s)
v = self.unfold(v).reshape(B, self.num_heads, C // self.num_heads,
self.k * self.k, h * w).permute(0, 1, 4, 3, 2)
attn = self.pool(x.permute(0, 3, 1, 2)).permute(0, 2, 3, 1)
attn = self.attn(attn).reshape(B, h * w, self.num_heads, self.k *
self.k, self.k * self.k).permute(0, 2, 1, 3, 4)
attn *= self.scale
attn = attn.softmax(dim=-1)
x = (attn @ v).permute(0, 1, 4, 3, 2).reshape(B, C * self.k * self.
k, h * w)
x = F.fold(x, (H, W), self.k, padding=self.p, stride=self.s)
x = self.proj(x.permute(0, 2, 3, 1))
return x
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'dim': 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
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_im2col_0(out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 12
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 4
x1 = xindex // 4
x2 = xindex
tmp0 = x0 + x1
tl.store(out_ptr0 + x2, tmp0, xmask)
@triton.jit
def triton_poi_fused_avg_pool2d_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
x0 = xindex
tmp0 = tl.load(in_ptr0 + x0, xmask)
tmp1 = 1.0
tmp2 = tmp0 * tmp1
tl.store(out_ptr0 + x0, tmp2, xmask)
@triton.jit
def triton_per_fused__softmax_2(in_ptr0, in_ptr1, out_ptr2, xnumel, rnumel,
XBLOCK: tl.constexpr):
xnumel = 2304
rnumel = 9
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, :]
rmask = rindex < rnumel
r4 = rindex
x0 = xindex % 9
x1 = xindex // 9 % 4
x2 = xindex // 36 % 16
x3 = xindex // 576
tmp0 = tl.load(in_ptr0 + (r4 + 9 * x0 + 81 * x1 + 81 * ((r4 + 9 * x0) //
81) + 324 * x2 + 2592 * (x2 % 4 // 4) + 5184 * x3 + 5184 *
triton_helpers.div_floor_integer(4 * (x2 // 4) + x2 % 4, 16)),
rmask & xmask, eviction_policy='evict_last', other=0.0)
tmp1 = tl.load(in_ptr1 + (r4 + 9 * x0 + 81 * x1 + 81 * ((r4 + 9 * x0) //
81)), rmask & xmask, eviction_policy='evict_last', other=0.0)
tmp2 = tmp0 + tmp1
tmp3 = 1.0
tmp4 = tmp2 * tmp3
tmp5 = tl.broadcast_to(tmp4, [XBLOCK, RBLOCK])
tmp7 = tl.where(rmask & 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(rmask & xmask, tmp11, 0)
tmp14 = tl.sum(tmp13, 1)[:, None]
tmp15 = tmp10 / tmp14
tl.store(out_ptr2 + (r4 + 9 * x0 + 81 * x2 + 1312 * x1 + 5248 * x3),
tmp15, rmask & xmask)
@triton.jit
def triton_poi_fused_clone_3(in_ptr0, in_ptr1, out_ptr0, xnumel, XBLOCK: tl
.constexpr):
xnumel = 2304
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 9
x1 = xindex // 9 % 16
x2 = xindex // 144 % 4
x3 = xindex // 576
x5 = xindex
tmp0 = tl.load(in_ptr0 + (4 * (x0 // 3) + x1 // 4), xmask,
eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (4 * (x0 % 3) + x1 % 4), xmask,
eviction_policy='evict_last')
tmp1 = tl.full([XBLOCK], 6, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tl.device_assert((0 <= tmp4) & (tmp4 < 6) | ~xmask,
'index out of bounds: 0 <= tmp4 < 6')
tmp7 = tmp6 + tmp1
tmp8 = tmp6 < 0
tmp9 = tl.where(tmp8, tmp7, tmp6)
tl.device_assert((0 <= tmp9) & (tmp9 < 6) | ~xmask,
'index out of bounds: 0 <= tmp9 < 6')
tmp11 = -1 + tmp4
tmp12 = tl.full([1], 0, tl.int64)
tmp13 = tmp11 >= tmp12
tmp14 = tl.full([1], 4, tl.int64)
tmp15 = tmp11 < tmp14
tmp16 = -1 + tmp9
tmp17 = tmp16 >= tmp12
tmp18 = tmp16 < tmp14
tmp19 = tmp13 & tmp15
tmp20 = tmp19 & tmp17
tmp21 = tmp20 & tmp18
tmp22 = tl.load(in_ptr1 + (-20 + x2 + 4 * tmp9 + 16 * tmp4 + 64 * x3),
tmp21 & xmask, eviction_policy='evict_last', other=0.0)
tl.store(out_ptr0 + x5, tmp22, xmask)
@triton.jit
def triton_poi_fused_bmm_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 20736
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 81
x1 = xindex // 81
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 81 * (x1 % 16) + 1312 * (x1 // 16)), xmask)
tl.store(out_ptr0 + x2, tmp0, xmask)
@triton.jit
def triton_poi_fused_col2im_5(out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 576
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex
tmp0 = 0.0
tl.store(out_ptr0 + x0, tmp0, xmask)
@triton.jit
def triton_poi_fused_col2im_6(in_ptr0, in_ptr1, out_ptr0, ynumel, xnumel,
YBLOCK: tl.constexpr, XBLOCK: tl.constexpr):
ynumel = 576
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
y5 = yindex // 3 % 12
x4 = xindex
y0 = yindex % 3
y1 = yindex // 3 % 4
y2 = yindex // 12 % 3
y3 = yindex // 36
tmp0 = tl.load(in_ptr0 + y5, ymask, eviction_policy='evict_last')
tmp6 = tl.load(in_ptr0 + (x4 + 4 * y0), xmask & ymask, eviction_policy=
'evict_last')
tmp11 = tl.load(in_ptr1 + (y0 + 3 * y2 + 9 * x4 + 36 * y1 + 144 * y3 +
144 * ((y0 + 3 * y2) // 9)), xmask & ymask, eviction_policy=
'evict_last')
tmp1 = tl.full([XBLOCK, YBLOCK], 6, tl.int32)
tmp2 = tmp0 + tmp1
tmp3 = tmp0 < 0
tmp4 = tl.where(tmp3, tmp2, tmp0)
tl.device_assert((0 <= tmp4) & (tmp4 < 6) | ~ymask,
'index out of bounds: 0 <= tmp4 < 6')
tmp7 = tmp6 + tmp1
tmp8 = tmp6 < 0
tmp9 = tl.where(tmp8, tmp7, tmp6)
tl.device_assert((0 <= tmp9) & (tmp9 < 6) | ~(xmask & ymask),
'index out of bounds: 0 <= tmp9 < 6')
tl.atomic_add(out_ptr0 + tl.broadcast_to(tmp9 + 6 * tmp4 + 36 * y3, [
XBLOCK, YBLOCK]), tmp11, xmask & ymask, sem='relaxed')
@triton.jit
def triton_poi_fused_clone_7(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
y1 = yindex // 4 % 4
y0 = yindex % 4
x3 = xindex
y2 = yindex // 16
y5 = yindex
tmp0 = 1 + y1
tmp1 = tl.full([1, 1], 0, tl.int64)
tmp2 = tmp0 >= tmp1
tmp3 = tl.full([1, 1], 6, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = 1 + y0
tmp6 = tmp5 >= tmp1
tmp7 = tmp5 < tmp3
tmp8 = tmp2 & tmp4
tmp9 = tmp8 & tmp6
tmp10 = tmp9 & tmp7
tmp11 = tl.load(in_ptr0 + (7 + y0 + 6 * y1 + 36 * x3 + 144 * y2), tmp10 &
xmask & ymask, eviction_policy='evict_last', other=0.0)
tl.store(out_ptr0 + (x3 + 4 * y5), tmp11, xmask & ymask)
@triton.jit
def triton_poi_fused_add_8(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 = 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, (324, 4), (4, 1))
assert_size_stride(primals_4, (324,), (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.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((3, 4), (4, 1), torch.int64)
get_raw_stream(0)
triton_poi_fused_im2col_0[grid(12)](buf1, 12, XBLOCK=16, num_warps=
1, num_stages=1)
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 1, 16, 4), torch.float32)
triton_poi_fused_avg_pool2d_1[grid(256)](primals_1, buf2, 256,
XBLOCK=256, num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((64, 324), (324, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf2, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_3, (4, 324), (1, 4), 0), out=buf3)
del primals_3
buf6 = empty_strided_cuda((4, 4, 16, 9, 9), (5248, 1312, 81, 9, 1),
torch.float32)
triton_per_fused__softmax_2[grid(2304)](buf3, primals_4, buf6, 2304,
9, XBLOCK=32, num_warps=4, num_stages=1)
del primals_4
buf7 = empty_strided_cuda((4, 4, 16, 9, 1), (576, 144, 9, 1, 1),
torch.float32)
triton_poi_fused_clone_3[grid(2304)](buf1, buf0, buf7, 2304, XBLOCK
=256, num_warps=4, num_stages=1)
buf8 = reinterpret_tensor(buf3, (256, 9, 9), (81, 9, 1), 0)
del buf3
triton_poi_fused_bmm_4[grid(20736)](buf6, buf8, 20736, XBLOCK=256,
num_warps=4, num_stages=1)
buf9 = empty_strided_cuda((256, 9, 1), (9, 1, 1), torch.float32)
extern_kernels.bmm(buf8, reinterpret_tensor(buf7, (256, 9, 1), (9,
1, 0), 0), out=buf9)
del buf8
buf10 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32
)
triton_poi_fused_col2im_5[grid(576)](buf10, 576, XBLOCK=256,
num_warps=4, num_stages=1)
buf11 = empty_strided_cuda((4, 4, 6, 6), (144, 36, 6, 1), torch.float32
)
triton_poi_fused_col2im_5[grid(576)](buf11, 576, XBLOCK=256,
num_warps=4, num_stages=1)
triton_poi_fused_col2im_6[grid(576, 4)](buf1, buf9, buf11, 576, 4,
XBLOCK=1, YBLOCK=256, num_warps=4, num_stages=1)
del buf9
buf13 = reinterpret_tensor(buf0, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf0
triton_poi_fused_clone_7[grid(64, 4)](buf11, buf13, 64, 4, XBLOCK=4,
YBLOCK=32, num_warps=4, num_stages=1)
del buf11
buf14 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf13, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_5, (4, 4), (1, 4), 0), out=buf14)
buf15 = reinterpret_tensor(buf14, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf14
triton_poi_fused_add_8[grid(256)](buf15, primals_6, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del primals_6
return buf15, reinterpret_tensor(primals_1, (64, 4), (4, 1), 0
), buf1, reinterpret_tensor(buf2, (64, 4), (4, 1), 0
), buf6, buf10, reinterpret_tensor(buf13, (64, 4), (4, 1), 0
), primals_5, reinterpret_tensor(buf7, (256, 1, 9), (9, 1, 1), 0)
class OutlookAttentionNew(nn.Module):
def __init__(self, dim, num_heads, k=3, s=1, p=1):
super().__init__()
self.s = s
self.k = k
self.p = p
self.num_heads = num_heads
self.scale = (dim // num_heads) ** -0.5
self.v = nn.Linear(dim, dim, bias=False)
self.attn = nn.Linear(dim, k ** 4 * num_heads)
self.proj = nn.Linear(dim, dim)
self.unfold = nn.Unfold(k, padding=p, stride=s)
self.pool = nn.AvgPool2d(s, s, ceil_mode=True)
def forward(self, input_0):
primals_2 = self.v.weight
primals_3 = self.attn.weight
primals_4 = self.attn.bias
primals_5 = self.proj.weight
primals_6 = self.proj.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0]
|
sithu31296/image_classification
|
OutlookAttention
| false
| 16,483
|
[
"MIT"
] | 57
|
6b8cbce96100225621cee3166a73e852ba216cc3
|
https://github.com/sithu31296/image_classification/tree/6b8cbce96100225621cee3166a73e852ba216cc3
|
GlobalAvgPool2d
|
import torch
import torch.nn as nn
import torch.utils
class GlobalAvgPool2d(nn.Module):
def __init__(self):
"""Global average pooling over the input's spatial dimensions"""
super(GlobalAvgPool2d, self).__init__()
def forward(self, inputs):
in_size = inputs.size()
inputs = inputs.view((in_size[0], in_size[1], -1)).mean(dim=2)
inputs = inputs.view(in_size[0], in_size[1], 1, 1)
return inputs
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
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)
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, 1), torch.float32)
buf1 = buf0
del buf0
get_raw_stream(0)
triton_per_fused_mean_0[grid(16)](buf1, arg0_1, 16, 16, XBLOCK=1,
num_warps=2, num_stages=1)
del arg0_1
return reinterpret_tensor(buf1, (4, 4, 1, 1), (4, 1, 1, 1), 0),
class GlobalAvgPool2dNew(nn.Module):
def __init__(self):
"""Global average pooling over the input's spatial dimensions"""
super(GlobalAvgPool2dNew, self).__init__()
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
songzijiang/FasterSeg
|
GlobalAvgPool2d
| false
| 16,484
|
[
"MIT"
] | 334
|
1a14ef6dd665afd229a16ab43b532b5a406512f8
|
https://github.com/songzijiang/FasterSeg/tree/1a14ef6dd665afd229a16ab43b532b5a406512f8
|
Critic
|
import torch
import torch.nn as nn
import torch.nn.functional as F
class Critic(nn.Module):
"""Initialize parameters and build model.
Args:
state_dim (int): Dimension of each state
action_dim (int): Dimension of each action
Return:
value output of network
"""
def __init__(self, state_dim, action_dim):
super(Critic, self).__init__()
self.fc1 = nn.Linear(state_dim + action_dim, 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, 1)
self.fc4 = nn.Linear(state_dim + action_dim, 256)
self.fc5 = nn.Linear(256, 256)
self.fc6 = nn.Linear(256, 1)
def forward(self, state, action):
sa = torch.cat([state, action], 1)
q1 = F.relu(self.fc1(sa))
q1 = F.relu(self.fc2(q1))
q1 = self.fc3(q1)
q2 = F.relu(self.fc4(sa))
q2 = F.relu(self.fc5(q2))
q2 = self.fc6(q2)
return q1, q2
def Q1(self, state, action):
sa = torch.cat([state, action], 1)
q1 = F.relu(self.fc1(sa))
q1 = F.relu(self.fc2(q1))
q1 = self.fc3(q1)
return q1
def get_inputs():
return [torch.rand([4, 4]), torch.rand([4, 4])]
def get_init_inputs():
return [[], {'state_dim': 4, 'action_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
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_cat_0(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 % 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_relu_1(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
x2 = xindex
x0 = xindex % 256
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)
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) = 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, (256, 8), (8, 1))
assert_size_stride(primals_4, (256,), (1,))
assert_size_stride(primals_5, (256, 256), (256, 1))
assert_size_stride(primals_6, (256,), (1,))
assert_size_stride(primals_7, (1, 256), (256, 1))
assert_size_stride(primals_8, (1,), (1,))
assert_size_stride(primals_9, (256, 8), (8, 1))
assert_size_stride(primals_10, (256,), (1,))
assert_size_stride(primals_11, (256, 256), (256, 1))
assert_size_stride(primals_12, (256,), (1,))
assert_size_stride(primals_13, (1, 256), (256, 1))
assert_size_stride(primals_14, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 8), (8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(32)](primals_1, primals_2, buf0, 32,
XBLOCK=32, num_warps=1, num_stages=1)
del primals_1
del primals_2
buf1 = empty_strided_cuda((4, 256), (256, 1), torch.float32)
extern_kernels.mm(buf0, reinterpret_tensor(primals_3, (8, 256), (1,
8), 0), out=buf1)
del primals_3
buf2 = buf1
del buf1
triton_poi_fused_relu_1[grid(1024)](buf2, primals_4, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_4
buf3 = empty_strided_cuda((4, 256), (256, 1), torch.float32)
extern_kernels.mm(buf2, reinterpret_tensor(primals_5, (256, 256), (
1, 256), 0), out=buf3)
buf4 = buf3
del buf3
triton_poi_fused_relu_1[grid(1024)](buf4, primals_6, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_6
buf6 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_8, buf4, reinterpret_tensor(primals_7,
(256, 1), (1, 256), 0), alpha=1, beta=1, out=buf6)
del primals_8
buf7 = empty_strided_cuda((4, 256), (256, 1), torch.float32)
extern_kernels.mm(buf0, reinterpret_tensor(primals_9, (8, 256), (1,
8), 0), out=buf7)
del primals_9
buf8 = buf7
del buf7
triton_poi_fused_relu_1[grid(1024)](buf8, primals_10, 1024, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_10
buf9 = empty_strided_cuda((4, 256), (256, 1), torch.float32)
extern_kernels.mm(buf8, reinterpret_tensor(primals_11, (256, 256),
(1, 256), 0), out=buf9)
buf10 = buf9
del buf9
triton_poi_fused_relu_1[grid(1024)](buf10, primals_12, 1024, XBLOCK
=256, num_warps=4, num_stages=1)
del primals_12
buf12 = empty_strided_cuda((4, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_14, buf10, reinterpret_tensor(
primals_13, (256, 1), (1, 256), 0), alpha=1, beta=1, out=buf12)
del primals_14
return (buf6, buf12, buf0, buf2, buf4, buf8, buf10, primals_13,
primals_11, primals_7, primals_5)
class CriticNew(nn.Module):
"""Initialize parameters and build model.
Args:
state_dim (int): Dimension of each state
action_dim (int): Dimension of each action
Return:
value output of network
"""
def __init__(self, state_dim, action_dim):
super(CriticNew, self).__init__()
self.fc1 = nn.Linear(state_dim + action_dim, 256)
self.fc2 = nn.Linear(256, 256)
self.fc3 = nn.Linear(256, 1)
self.fc4 = nn.Linear(state_dim + action_dim, 256)
self.fc5 = nn.Linear(256, 256)
self.fc6 = nn.Linear(256, 1)
def Q1(self, state, action):
sa = torch.cat([state, action], 1)
q1 = F.relu(self.fc1(sa))
q1 = F.relu(self.fc2(q1))
q1 = self.fc3(q1)
return q1
def forward(self, input_0, input_1):
primals_3 = self.fc1.weight
primals_4 = self.fc1.bias
primals_5 = self.fc2.weight
primals_6 = self.fc2.bias
primals_7 = self.fc3.weight
primals_8 = self.fc3.bias
primals_9 = self.fc4.weight
primals_10 = self.fc4.bias
primals_11 = self.fc5.weight
primals_12 = self.fc5.bias
primals_13 = self.fc6.weight
primals_14 = self.fc6.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])
return output[0], output[1]
|
sofya-pugach/spot_mini_mini
|
Critic
| false
| 16,485
|
[
"MIT"
] | 323
|
42770145e91ed2625ccc7e4f4d7016ce14a61464
|
https://github.com/sofya-pugach/spot_mini_mini/tree/42770145e91ed2625ccc7e4f4d7016ce14a61464
|
USConv2d
|
import torch
import torch.nn as nn
import torch.utils
def make_divisible(v, divisor=8, min_value=1):
"""
forked from slim:
https://github.com/tensorflow/models/blob/ 0344c5503ee55e24f0de7f37336a6e08f10976fd/ research/slim/nets/mobilenet/mobilenet.py#L62-L69
"""
if min_value is None:
min_value = divisor
new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
if new_v < 0.9 * v:
new_v += divisor
return new_v
class USConv2d(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, depthwise=False, bias=True,
width_mult_list=[1.0]):
super(USConv2d, self).__init__(in_channels, out_channels,
kernel_size, stride=stride, padding=padding, dilation=dilation,
groups=groups, bias=bias)
self.depthwise = depthwise
self.in_channels_max = in_channels
self.out_channels_max = out_channels
self.width_mult_list = width_mult_list
self.ratio = 1.0, 1.0
def set_ratio(self, ratio):
self.ratio = ratio
def forward(self, input):
assert self.ratio[0] in self.width_mult_list, str(self.ratio[0]
) + ' in? ' + str(self.width_mult_list)
self.in_channels = make_divisible(self.in_channels_max * self.ratio[0])
assert self.ratio[1] in self.width_mult_list, str(self.ratio[1]
) + ' in? ' + str(self.width_mult_list)
self.out_channels = make_divisible(self.out_channels_max * self.
ratio[1])
self.groups = self.in_channels if self.depthwise else 1
weight = self.weight[:self.out_channels, :self.in_channels, :, :]
if self.bias is not None:
bias = self.bias[:self.out_channels]
else:
bias = self.bias
y = nn.functional.conv2d(input, weight, bias, self.stride, self.
padding, self.dilation, self.groups)
return y
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
import torch.nn as nn
import torch.utils
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 = 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,), (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=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf0, (4, 4, 1, 1), (4, 1, 1, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(16)](buf1, primals_2, 16,
XBLOCK=16, num_warps=1, num_stages=1)
del primals_2
return buf1, primals_3, primals_1
def make_divisible(v, divisor=8, min_value=1):
"""
forked from slim:
https://github.com/tensorflow/models/blob/ 0344c5503ee55e24f0de7f37336a6e08f10976fd/ research/slim/nets/mobilenet/mobilenet.py#L62-L69
"""
if min_value is None:
min_value = divisor
new_v = max(min_value, int(v + divisor / 2) // divisor * divisor)
if new_v < 0.9 * v:
new_v += divisor
return new_v
class USConv2dNew(nn.Conv2d):
def __init__(self, in_channels, out_channels, kernel_size, stride=1,
padding=0, dilation=1, groups=1, depthwise=False, bias=True,
width_mult_list=[1.0]):
super(USConv2dNew, self).__init__(in_channels, out_channels,
kernel_size, stride=stride, padding=padding, dilation=dilation,
groups=groups, bias=bias)
self.depthwise = depthwise
self.in_channels_max = in_channels
self.out_channels_max = out_channels
self.width_mult_list = width_mult_list
self.ratio = 1.0, 1.0
def set_ratio(self, ratio):
self.ratio = ratio
def forward(self, input_0):
primals_1 = self.weight
primals_2 = self.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
songzijiang/FasterSeg
|
USConv2d
| false
| 16,486
|
[
"MIT"
] | 334
|
1a14ef6dd665afd229a16ab43b532b5a406512f8
|
https://github.com/songzijiang/FasterSeg/tree/1a14ef6dd665afd229a16ab43b532b5a406512f8
|
PolicyNetwork
|
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.distributions import Normal
class PolicyNetwork(nn.Module):
def __init__(self, num_inputs, num_actions, hidden_size, init_w=0.003,
log_std_min=-20, log_std_max=2):
super(PolicyNetwork, self).__init__()
self.log_std_min = log_std_min
self.log_std_max = log_std_max
self.linear1 = nn.Linear(num_inputs, hidden_size)
self.linear2 = nn.Linear(hidden_size, hidden_size)
self.mean_linear = nn.Linear(hidden_size, num_actions)
self.mean_linear.weight.data.uniform_(-init_w, init_w)
self.mean_linear.bias.data.uniform_(-init_w, init_w)
self.log_std_linear1 = nn.Linear(hidden_size, hidden_size)
self.log_std_linear2 = nn.Linear(hidden_size, num_actions)
self.log_std_linear2.weight.data.uniform_(-init_w, init_w)
self.log_std_linear2.bias.data.uniform_(-init_w, init_w)
def forward(self, state):
x = F.relu(self.linear1(state))
x = F.relu(self.linear2(x))
mean = self.mean_linear(x)
log_std = self.log_std_linear2(F.relu(self.log_std_linear1(x)))
log_std = torch.clamp(log_std, self.log_std_min, self.log_std_max)
return mean, log_std
def evaluate(self, state, epsilon=1e-06):
mean, log_std = self.forward(state)
std = log_std.exp()
normal = Normal(mean, std)
z = normal.rsample()
action = torch.tanh(z)
log_prob = normal.log_prob(z) - torch.log(1 - action.pow(2) + epsilon)
log_prob = log_prob.sum(-1, keepdim=True)
return action, log_prob, z, mean, log_std
def get_action(self, state):
state = torch.FloatTensor(state).unsqueeze(0)
mean, log_std = self.forward(state)
std = log_std.exp()
normal = Normal(mean, std)
z = normal.sample()
action = torch.tanh(z)
action = action.detach().cpu().numpy()
return action[0]
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'num_inputs': 4, 'num_actions': 4, '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
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
from torch.distributions import Normal
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_clamp_ge_le_logical_and_1(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
x2 = xindex
x0 = xindex % 4
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tmp3 = -20.0
tmp4 = triton_helpers.maximum(tmp2, tmp3)
tmp5 = 2.0
tmp6 = triton_helpers.minimum(tmp4, tmp5)
tmp7 = tmp2 >= tmp3
tmp8 = tmp2 <= tmp5
tmp9 = tmp7 & tmp8
tl.store(out_ptr0 + x2, tmp6, xmask)
tl.store(out_ptr1 + x2, tmp9, 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) = 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,))
assert_size_stride(primals_6, (4, 4), (4, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4), (4, 1))
assert_size_stride(primals_9, (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_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
buf12 = 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_2, buf12, 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
buf11 = 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, buf11, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
buf4 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.addmm(primals_7, reinterpret_tensor(buf3, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_6, (4, 4), (1, 4), 0),
alpha=1, beta=1, out=buf4)
del primals_7
buf5 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf3, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_8, (4, 4), (1, 4), 0), out=buf5)
buf6 = reinterpret_tensor(buf5, (4, 4, 4, 4), (64, 16, 4, 1), 0)
del buf5
buf10 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_0[grid(256)](buf6,
primals_9, buf10, 256, XBLOCK=256, num_warps=4, num_stages=1)
del primals_9
buf7 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf6, (64, 4), (4, 1), 0),
reinterpret_tensor(primals_10, (4, 4), (1, 4), 0), out=buf7)
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_clamp_ge_le_logical_and_1[grid(256)](buf7,
primals_11, buf8, buf9, 256, XBLOCK=128, num_warps=4, num_stages=1)
del buf7
del primals_11
return reinterpret_tensor(buf4, (4, 4, 4, 4), (64, 16, 4, 1), 0
), buf8, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), reinterpret_tensor(buf1, (64, 4), (4, 1), 0), reinterpret_tensor(
buf3, (64, 4), (4, 1), 0), reinterpret_tensor(buf6, (64, 4), (4, 1), 0
), buf9, primals_10, buf10, primals_8, primals_6, buf11, primals_4, buf12
class PolicyNetworkNew(nn.Module):
def __init__(self, num_inputs, num_actions, hidden_size, init_w=0.003,
log_std_min=-20, log_std_max=2):
super(PolicyNetworkNew, self).__init__()
self.log_std_min = log_std_min
self.log_std_max = log_std_max
self.linear1 = nn.Linear(num_inputs, hidden_size)
self.linear2 = nn.Linear(hidden_size, hidden_size)
self.mean_linear = nn.Linear(hidden_size, num_actions)
self.mean_linear.weight.data.uniform_(-init_w, init_w)
self.mean_linear.bias.data.uniform_(-init_w, init_w)
self.log_std_linear1 = nn.Linear(hidden_size, hidden_size)
self.log_std_linear2 = nn.Linear(hidden_size, num_actions)
self.log_std_linear2.weight.data.uniform_(-init_w, init_w)
self.log_std_linear2.bias.data.uniform_(-init_w, init_w)
def evaluate(self, state, epsilon=1e-06):
mean, log_std = self.forward(state)
std = log_std.exp()
normal = Normal(mean, std)
z = normal.rsample()
action = torch.tanh(z)
log_prob = normal.log_prob(z) - torch.log(1 - action.pow(2) + epsilon)
log_prob = log_prob.sum(-1, keepdim=True)
return action, log_prob, z, mean, log_std
def get_action(self, state):
state = torch.FloatTensor(state).unsqueeze(0)
mean, log_std = self.forward(state)
std = log_std.exp()
normal = Normal(mean, std)
z = normal.sample()
action = torch.tanh(z)
action = action.detach().cpu().numpy()
return action[0]
def forward(self, input_0):
primals_1 = self.linear1.weight
primals_2 = self.linear1.bias
primals_4 = self.linear2.weight
primals_5 = self.linear2.bias
primals_6 = self.mean_linear.weight
primals_7 = self.mean_linear.bias
primals_8 = self.log_std_linear1.weight
primals_9 = self.log_std_linear1.bias
primals_10 = self.log_std_linear2.weight
primals_11 = self.log_std_linear2.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])
return output[0], output[1]
|
sofya-pugach/spot_mini_mini
|
PolicyNetwork
| false
| 16,487
|
[
"MIT"
] | 323
|
42770145e91ed2625ccc7e4f4d7016ce14a61464
|
https://github.com/sofya-pugach/spot_mini_mini/tree/42770145e91ed2625ccc7e4f4d7016ce14a61464
|
SplitAndConcat
|
import torch
import torch.nn as nn
import torch.utils.data
class SplitAndConcat(nn.Module):
"""Split the data from split_dim and concatenate in concat_dim.
@param split_dim from which axis the data will be chunk
@param concat_dim to which axis the data will be concatenated
@param chunk size of the data to be chunk/concatenated
"""
def __init__(self, split_dim: 'int'=1, concat_dim: 'int'=0, chunk: 'int'=2
):
super(SplitAndConcat, self).__init__()
self.split_dim = split_dim
self.concat_dim = concat_dim
self.chunk = chunk
def forward(self, x):
x = torch.chunk(x, self.chunk, dim=self.split_dim)
x = torch.cat(x, dim=self.concat_dim)
return x
def extra_repr(self):
return (
f'split_dim={self.split_dim}, concat_dim={self.concat_dim}, chunk={self.chunk}'
)
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_cat_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
x1 = xindex // 32
x0 = xindex % 32
x2 = 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 + 64 * x1), tmp4 & xmask, other=0.0)
tmp6 = tmp0 >= tmp3
tl.full([1], 8, tl.int64)
tmp9 = tl.load(in_ptr0 + (32 + x0 + 64 * (-4 + x1)), tmp6 & xmask,
other=0.0)
tmp10 = tl.where(tmp4, tmp5, 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((8, 2, 4, 4), (32, 16, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(256)](arg0_1, buf0, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del arg0_1
return buf0,
class SplitAndConcatNew(nn.Module):
"""Split the data from split_dim and concatenate in concat_dim.
@param split_dim from which axis the data will be chunk
@param concat_dim to which axis the data will be concatenated
@param chunk size of the data to be chunk/concatenated
"""
def __init__(self, split_dim: 'int'=1, concat_dim: 'int'=0, chunk: 'int'=2
):
super(SplitAndConcatNew, self).__init__()
self.split_dim = split_dim
self.concat_dim = concat_dim
self.chunk = chunk
def extra_repr(self):
return (
f'split_dim={self.split_dim}, concat_dim={self.concat_dim}, chunk={self.chunk}'
)
def forward(self, input_0):
arg0_1 = input_0
output = call([arg0_1])
return output[0]
|
sstsai-adl/d2go
|
SplitAndConcat
| false
| 16,488
|
[
"Apache-2.0"
] | 687
|
6cff773797b14698043589afe57ea67cd76286f9
|
https://github.com/sstsai-adl/d2go/tree/6cff773797b14698043589afe57ea67cd76286f9
|
conv_head_pooling
|
import torch
import torch.nn as nn
import torch.utils.data
class conv_head_pooling(nn.Module):
def __init__(self, in_feature, out_feature, stride, conv_type,
padding_mode='zeros', dilation=1):
super(conv_head_pooling, self).__init__()
if conv_type == 'depthwise':
_groups = in_feature
else:
_groups = 1
None
self.conv = nn.Conv2d(in_feature, out_feature, kernel_size=3,
padding=dilation, dilation=dilation, stride=stride,
padding_mode=padding_mode, groups=_groups)
self.fc = nn.Linear(in_feature, out_feature)
def forward(self, x, cls_token):
x = self.conv(x)
cls_token = self.fc(cls_token)
return x, cls_token
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'in_feature': 4, 'out_feature': 4, 'stride': 1,
'conv_type': 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_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
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 = 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, 4), (4, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (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 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_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.addmm(primals_5, reinterpret_tensor(primals_6, (64,
4), (4, 1), 0), reinterpret_tensor(primals_4, (4, 4), (1, 4), 0
), alpha=1, beta=1, out=buf2)
del primals_4
del primals_5
return buf1, reinterpret_tensor(buf2, (4, 4, 4, 4), (64, 16, 4, 1), 0
), primals_1, primals_3, reinterpret_tensor(primals_6, (64, 4), (4,
1), 0)
class conv_head_poolingNew(nn.Module):
def __init__(self, in_feature, out_feature, stride, conv_type,
padding_mode='zeros', dilation=1):
super(conv_head_poolingNew, self).__init__()
if conv_type == 'depthwise':
_groups = in_feature
else:
_groups = 1
None
self.conv = nn.Conv2d(in_feature, out_feature, kernel_size=3,
padding=dilation, dilation=dilation, stride=stride,
padding_mode=padding_mode, groups=_groups)
self.fc = nn.Linear(in_feature, out_feature)
def forward(self, input_0, input_1):
primals_1 = self.conv.weight
primals_2 = self.conv.bias
primals_4 = self.fc.weight
primals_5 = self.fc.bias
primals_3 = input_0
primals_6 = input_1
output = call([primals_1, primals_2, primals_3, primals_4,
primals_5, primals_6])
return output[0], output[1]
|
sstsai-adl/d2go
|
conv_head_pooling
| false
| 16,489
|
[
"Apache-2.0"
] | 687
|
6cff773797b14698043589afe57ea67cd76286f9
|
https://github.com/sstsai-adl/d2go/tree/6cff773797b14698043589afe57ea67cd76286f9
|
GCNLayer
|
import torch
import torch.nn as nn
class GCNLayer(nn.Module):
def __init__(self, input_dim, output_dim, prop_depth=1, act=torch.relu,
dropout=0.0, layer_i=0):
super(GCNLayer, self).__init__()
self.prop_depth = 1
self.weight = nn.Parameter(torch.empty(input_dim, output_dim, dtype
=torch.float), requires_grad=True)
nn.init.xavier_uniform_(self.weight.data)
self.act = act
self.dropout = nn.Dropout(p=dropout)
self.layer_i = layer_i
self.last_layer_flag = False
def layer(self, x, adj_batch):
x = x.transpose(0, 1)
adj_batch = adj_batch[:, 1, :, :]
x = torch.matmul(x, self.weight)
x = torch.matmul(adj_batch, x)
x = x.transpose(0, 1)
return x
def forward(self, x, adj_batch):
x = self.layer(x, adj_batch)
x = self.act(x)
x = self.dropout(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}]
|
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__unsafe_view_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 % 4
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 4 * (x1 % 4) + 16 * (x1 // 16) + 64 * (
x1 // 4 % 4)), xmask)
tl.store(out_ptr0 + x2, tmp0, xmask)
@triton.jit
def triton_poi_fused_clone_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
x0 = xindex % 16
x1 = xindex // 16 % 4
x3 = xindex
tmp0 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_relu_threshold_backward_2(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, 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, 4), (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__unsafe_view_clone_0[grid(256)](primals_1, buf0,
256, XBLOCK=128, num_warps=4, num_stages=1)
del primals_1
buf1 = empty_strided_cuda((64, 4), (4, 1), torch.float32)
extern_kernels.mm(buf0, primals_3, out=buf1)
del primals_3
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_clone_1[grid(256)](primals_2, buf2, 256, XBLOCK=
128, num_warps=4, num_stages=1)
del primals_2
buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1),
0), reinterpret_tensor(buf1, (16, 4, 4), (16, 4, 1), 0), out=buf3)
del buf1
buf4 = reinterpret_tensor(buf3, (4, 4, 4, 4), (16, 64, 4, 1), 0)
del buf3
buf5 = empty_strided_cuda((4, 4, 4, 4), (16, 64, 4, 1), torch.bool)
triton_poi_fused_relu_threshold_backward_2[grid(256)](buf4, buf5,
256, XBLOCK=128, num_warps=4, num_stages=1)
return buf4, buf5, reinterpret_tensor(buf2, (16, 4, 4), (16, 1, 4), 0
), reinterpret_tensor(buf0, (4, 64), (1, 4), 0)
class GCNLayerNew(nn.Module):
def __init__(self, input_dim, output_dim, prop_depth=1, act=torch.relu,
dropout=0.0, layer_i=0):
super(GCNLayerNew, self).__init__()
self.prop_depth = 1
self.weight = nn.Parameter(torch.empty(input_dim, output_dim, dtype
=torch.float), requires_grad=True)
nn.init.xavier_uniform_(self.weight.data)
self.act = act
self.dropout = nn.Dropout(p=dropout)
self.layer_i = layer_i
self.last_layer_flag = False
def layer(self, x, adj_batch):
x = x.transpose(0, 1)
adj_batch = adj_batch[:, 1, :, :]
x = torch.matmul(x, self.weight)
x = torch.matmul(adj_batch, x)
x = x.transpose(0, 1)
return x
def forward(self, input_0, input_1):
primals_3 = self.weight
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3])
return output[0]
|
snap-stanford/distance-encoding
|
GCNLayer
| false
| 16,490
|
[
"MIT"
] | 177
|
b9ccb1b59422b11b40883d0284d7fc9ba88efdb6
|
https://github.com/snap-stanford/distance-encoding/tree/b9ccb1b59422b11b40883d0284d7fc9ba88efdb6
|
SigmoidFocalLoss
|
import torch
import torch.nn as nn
import torch.utils
class SigmoidFocalLoss(nn.Module):
def __init__(self, ignore_label, gamma=2.0, alpha=0.25, reduction='mean'):
super(SigmoidFocalLoss, self).__init__()
self.ignore_label = ignore_label
self.gamma = gamma
self.alpha = alpha
self.reduction = reduction
def forward(self, pred, target):
b, _h, _w = target.size()
pred = pred.view(b, -1, 1)
pred_sigmoid = pred.sigmoid()
target = target.view(b, -1).float()
mask = target.ne(self.ignore_label).float()
target = mask * target
onehot = target.view(b, -1, 1)
max_val = (-pred_sigmoid).clamp(min=0)
pos_part = (1 - pred_sigmoid) ** self.gamma * (pred_sigmoid -
pred_sigmoid * onehot)
neg_part = pred_sigmoid ** self.gamma * (max_val + ((-max_val).exp(
) + (-pred_sigmoid - max_val).exp()).log())
loss = -(self.alpha * pos_part + (1 - self.alpha) * neg_part).sum(dim
=-1) * mask
if self.reduction == 'mean':
loss = loss.mean()
return loss
def get_inputs():
return [torch.rand([4, 16]), torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'ignore_label': 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
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__to_copy_add_clamp_exp_log_mean_mul_ne_neg_pow_rsub_sigmoid_sub_sum_0(
in_out_ptr0, in_ptr0, in_ptr1, 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
tmp0 = tl.load(in_ptr0 + r0, None)
tmp5 = tl.load(in_ptr1 + r0, None)
tmp1 = tl.sigmoid(tmp0)
tmp2 = 1.0
tmp3 = tmp2 - tmp1
tmp4 = tmp3 * tmp3
tmp6 = 4.0
tmp7 = tmp5 != tmp6
tmp8 = tmp7.to(tl.float32)
tmp9 = tmp8 * tmp5
tmp10 = tmp1 * tmp9
tmp11 = tmp1 - tmp10
tmp12 = tmp4 * tmp11
tmp13 = 0.25
tmp14 = tmp12 * tmp13
tmp15 = tmp1 * tmp1
tmp16 = -tmp1
tmp17 = 0.0
tmp18 = triton_helpers.maximum(tmp16, tmp17)
tmp19 = -tmp18
tmp20 = tl_math.exp(tmp19)
tmp21 = tmp16 - tmp18
tmp22 = tl_math.exp(tmp21)
tmp23 = tmp20 + tmp22
tmp24 = tl_math.log(tmp23)
tmp25 = tmp18 + tmp24
tmp26 = tmp15 * tmp25
tmp27 = 0.75
tmp28 = tmp26 * tmp27
tmp29 = tmp14 + tmp28
tmp30 = -tmp29
tmp31 = tmp30 * tmp8
tmp32 = tl.broadcast_to(tmp31, [XBLOCK, RBLOCK])
tmp34 = tl.sum(tmp32, 1)[:, None]
tmp35 = 64.0
tmp36 = tmp34 / tmp35
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp36, None)
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, 16), (16, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf1 = empty_strided_cuda((), (), torch.float32)
buf2 = buf1
del buf1
get_raw_stream(0)
triton_per_fused__to_copy_add_clamp_exp_log_mean_mul_ne_neg_pow_rsub_sigmoid_sub_sum_0[
grid(1)](buf2, arg1_1, arg0_1, 1, 64, XBLOCK=1, num_warps=2,
num_stages=1)
del arg0_1
del arg1_1
return buf2,
class SigmoidFocalLossNew(nn.Module):
def __init__(self, ignore_label, gamma=2.0, alpha=0.25, reduction='mean'):
super(SigmoidFocalLossNew, self).__init__()
self.ignore_label = ignore_label
self.gamma = gamma
self.alpha = alpha
self.reduction = reduction
def forward(self, input_0, input_1):
arg1_1 = input_0
arg0_1 = input_1
output = call([arg0_1, arg1_1])
return output[0]
|
songzijiang/FasterSeg
|
SigmoidFocalLoss
| false
| 16,491
|
[
"MIT"
] | 334
|
1a14ef6dd665afd229a16ab43b532b5a406512f8
|
https://github.com/songzijiang/FasterSeg/tree/1a14ef6dd665afd229a16ab43b532b5a406512f8
|
MLP
|
import random
import torch
import numpy as np
from torch import nn
class MLP(nn.Module):
def __init__(self, kernels, num_features, num_hiddens, normalize=True,
num_updates=3000, batch_size=128, weight_decay=0.0001, soft_preds=False
):
super().__init__()
self.kernels = kernels
num_kernels = len(kernels)
self.linear_1 = nn.Linear(num_features, num_hiddens)
self.act = nn.Tanh()
self.linear_2 = nn.Linear(num_hiddens, num_kernels)
self.softmax = nn.LogSoftmax(dim=1)
self.mean = None
self.std = None
self._normalize = normalize
self.num_updates = num_updates
self.batch_size = batch_size
self.soft_preds = soft_preds
self.weight_decay = weight_decay
def forward(self, x):
y1 = self.linear_1.forward(x)
y = self.act.forward(y1)
y = self.linear_2.forward(y)
return self.softmax.forward(y)
def normalize(self, X):
if self._normalize:
return (X - self.mean) / self.std
return X
def predict_proba(self, x):
x = self.normalize(x)
tx = torch.from_numpy(x).float()
y = self.forward(tx)
return np.exp(y.detach().numpy())
def predict(self, x):
y = self.predict_proba(x)
return y.argmax(axis=1)
def fit(self, X, y):
if self._normalize:
self.mean = X.mean(axis=0, keepdims=True)
self.std = X.std(axis=0, keepdims=True)
self.std[self.std < 0.0001] = 0.0001
X = self.normalize(X)
updates = 0
optimizer = torch.optim.AdamW(self.parameters(), lr=0.001,
weight_decay=self.weight_decay)
loss = torch.nn.KLDivLoss(reduction='batchmean'
) if self.soft_preds else torch.nn.NLLLoss()
indices = list(range(X.shape[0]))
num_batches = len(indices) // self.batch_size
prev_loss = None
num_iter_no_impr = 0
while updates < self.num_updates:
random.shuffle(indices)
total_loss = 0
batches_seen = 0
for bnum in range(num_batches):
bb = self.batch_size * bnum
be = bb + self.batch_size
Xb = X[indices[bb:be]]
yb = y[indices[bb:be]]
tx = torch.from_numpy(Xb).float()
if self.soft_preds:
ty = torch.from_numpy(yb).float()
else:
ty = torch.from_numpy(yb).long()
optimizer.zero_grad()
z = self.forward(tx)
loss_val = loss(z, ty)
loss_val.backward()
optimizer.step()
sloss = loss_val.detach().numpy()
total_loss += sloss
updates += 1
batches_seen += 1
if updates > self.num_updates:
break
total_loss /= batches_seen
if prev_loss is not None:
impr = (prev_loss - total_loss) / prev_loss
if impr < 0.0001:
num_iter_no_impr += 1
else:
num_iter_no_impr = 0
prev_loss = total_loss
if num_iter_no_impr > 4:
break
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'kernels': [4, 4], 'num_features': 4, 'num_hiddens': 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 random
import numpy as np
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_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__log_softmax_1(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
x3 = xindex
x0 = xindex % 8
x2 = xindex // 32
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp2 = tl.load(in_ptr0 + (8 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp4 = tl.load(in_ptr0 + (16 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (24 + x0 + 32 * 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
tl.store(out_ptr0 + x3, tmp8, xmask)
@triton.jit
def triton_poi_fused__log_softmax_2(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
x3 = xindex
x0 = xindex % 8
x2 = xindex // 32
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr0 + (x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp3 = tl.load(in_ptr0 + (8 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp6 = tl.load(in_ptr0 + (16 + x0 + 32 * x2), xmask, eviction_policy=
'evict_last')
tmp9 = tl.load(in_ptr0 + (24 + x0 + 32 * x2), xmask, 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
tl.store(out_ptr0 + x3, tmp13, 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, (2, 4), (4, 1))
assert_size_stride(primals_5, (2,), (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, 2), (2, 1), torch.float32)
extern_kernels.addmm(primals_5, reinterpret_tensor(buf1, (64, 4), (
4, 1), 0), reinterpret_tensor(primals_4, (4, 2), (1, 4), 0),
alpha=1, beta=1, out=buf2)
del primals_5
buf3 = empty_strided_cuda((4, 4, 4, 2), (32, 8, 2, 1), torch.float32)
triton_poi_fused__log_softmax_1[grid(128)](buf2, buf3, 128, XBLOCK=
128, num_warps=4, num_stages=1)
buf4 = reinterpret_tensor(buf2, (4, 4, 4, 2), (32, 8, 2, 1), 0)
del buf2
triton_poi_fused__log_softmax_2[grid(128)](buf3, buf4, 128, XBLOCK=
128, num_warps=4, num_stages=1)
del buf3
return buf4, reinterpret_tensor(primals_3, (64, 4), (4, 1), 0
), buf1, buf4, primals_4
class MLPNew(nn.Module):
def __init__(self, kernels, num_features, num_hiddens, normalize=True,
num_updates=3000, batch_size=128, weight_decay=0.0001, soft_preds=False
):
super().__init__()
self.kernels = kernels
num_kernels = len(kernels)
self.linear_1 = nn.Linear(num_features, num_hiddens)
self.act = nn.Tanh()
self.linear_2 = nn.Linear(num_hiddens, num_kernels)
self.softmax = nn.LogSoftmax(dim=1)
self.mean = None
self.std = None
self._normalize = normalize
self.num_updates = num_updates
self.batch_size = batch_size
self.soft_preds = soft_preds
self.weight_decay = weight_decay
def normalize(self, X):
if self._normalize:
return (X - self.mean) / self.std
return X
def predict_proba(self, x):
x = self.normalize(x)
tx = torch.from_numpy(x).float()
y = self.forward(tx)
return np.exp(y.detach().numpy())
def predict(self, x):
y = self.predict_proba(x)
return y.argmax(axis=1)
def fit(self, X, y):
if self._normalize:
self.mean = X.mean(axis=0, keepdims=True)
self.std = X.std(axis=0, keepdims=True)
self.std[self.std < 0.0001] = 0.0001
X = self.normalize(X)
updates = 0
optimizer = torch.optim.AdamW(self.parameters(), lr=0.001,
weight_decay=self.weight_decay)
loss = torch.nn.KLDivLoss(reduction='batchmean'
) if self.soft_preds else torch.nn.NLLLoss()
indices = list(range(X.shape[0]))
num_batches = len(indices) // self.batch_size
prev_loss = None
num_iter_no_impr = 0
while updates < self.num_updates:
random.shuffle(indices)
total_loss = 0
batches_seen = 0
for bnum in range(num_batches):
bb = self.batch_size * bnum
be = bb + self.batch_size
Xb = X[indices[bb:be]]
yb = y[indices[bb:be]]
tx = torch.from_numpy(Xb).float()
if self.soft_preds:
ty = torch.from_numpy(yb).float()
else:
ty = torch.from_numpy(yb).long()
optimizer.zero_grad()
z = self.forward(tx)
loss_val = loss(z, ty)
loss_val.backward()
optimizer.step()
sloss = loss_val.detach().numpy()
total_loss += sloss
updates += 1
batches_seen += 1
if updates > self.num_updates:
break
total_loss /= batches_seen
if prev_loss is not None:
impr = (prev_loss - total_loss) / prev_loss
if impr < 0.0001:
num_iter_no_impr += 1
else:
num_iter_no_impr = 0
prev_loss = total_loss
if num_iter_no_impr > 4:
break
def forward(self, input_0):
primals_1 = self.linear_1.weight
primals_2 = self.linear_1.bias
primals_4 = self.linear_2.weight
primals_5 = self.linear_2.bias
primals_3 = input_0
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
snipsco/tract
|
MLP
| false
| 16,492
|
[
"ECL-2.0",
"Apache-2.0",
"MIT-0",
"MIT"
] | 588
|
7a54972764292bccf1737ff8bbcfa1e1736e3fad
|
https://github.com/snipsco/tract/tree/7a54972764292bccf1737ff8bbcfa1e1736e3fad
|
Residual_Covolution
|
import torch
import torch.nn as nn
class Residual_Covolution(nn.Module):
def __init__(self, icol, ocol, num_classes):
super(Residual_Covolution, self).__init__()
self.conv1 = nn.Conv2d(icol, ocol, kernel_size=3, stride=1, padding
=12, dilation=12, bias=True)
self.conv2 = nn.Conv2d(ocol, num_classes, kernel_size=3, stride=1,
padding=12, dilation=12, bias=True)
self.conv3 = nn.Conv2d(num_classes, ocol, kernel_size=1, stride=1,
padding=0, dilation=1, bias=True)
self.conv4 = nn.Conv2d(ocol, icol, kernel_size=1, stride=1, padding
=0, dilation=1, bias=True)
self.relu = nn.ReLU(inplace=True)
def forward(self, x):
dow1 = self.conv1(x)
dow1 = self.relu(dow1)
seg = self.conv2(dow1)
inc1 = self.conv3(seg)
add1 = dow1 + self.relu(inc1)
inc2 = self.conv4(add1)
out = x + self.relu(inc2)
return out, seg
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'icol': 4, 'ocol': 4, 'num_classes': 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_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_convolution_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
tl.store(in_out_ptr0 + x3, tmp2, xmask)
@triton.jit
def triton_poi_fused_add_convolution_relu_threshold_backward_2(in_ptr0,
in_ptr1, in_ptr2, 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 + x3, xmask)
tmp2 = tl.load(in_ptr2 + x1, xmask, eviction_policy='evict_last')
tmp3 = tmp1 + tmp2
tmp4 = tl.full([1], 0, tl.int32)
tmp5 = triton_helpers.maximum(tmp4, tmp3)
tmp6 = tmp0 + tmp5
tmp7 = 0.0
tmp8 = tmp5 <= tmp7
tl.store(out_ptr0 + x3, tmp6, xmask)
tl.store(out_ptr1 + x3, tmp8, 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, (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, 4, 3, 3), (36, 9, 3, 1))
assert_size_stride(primals_5, (4,), (1,))
assert_size_stride(primals_6, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_7, (4,), (1,))
assert_size_stride(primals_8, (4, 4, 1, 1), (4, 1, 1, 1))
assert_size_stride(primals_9, (4,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = extern_kernels.convolution(primals_3, primals_1, stride=(1,
1), padding=(12, 12), dilation=(12, 12), 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
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(256)](buf1, primals_2, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_2
buf2 = extern_kernels.convolution(buf1, primals_4, stride=(1, 1),
padding=(12, 12), dilation=(12, 12), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf2, (4, 4, 4, 4), (64, 16, 4, 1))
buf3 = buf2
del buf2
triton_poi_fused_convolution_1[grid(256)](buf3, primals_5, 256,
XBLOCK=128, num_warps=4, num_stages=1)
del primals_5
buf4 = extern_kernels.convolution(buf3, primals_6, 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, 4, 4), (64, 16, 4, 1))
buf5 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
buf9 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_add_convolution_relu_threshold_backward_2[grid(256)](
buf1, buf4, primals_7, buf5, buf9, 256, XBLOCK=256, num_warps=4,
num_stages=1)
del primals_7
buf6 = extern_kernels.convolution(buf5, primals_8, stride=(1, 1),
padding=(0, 0), dilation=(1, 1), transposed=False,
output_padding=(0, 0), groups=1, bias=None)
assert_size_stride(buf6, (4, 4, 4, 4), (64, 16, 4, 1))
buf7 = buf4
del buf4
buf8 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.bool)
triton_poi_fused_add_convolution_relu_threshold_backward_2[grid(256)](
primals_3, buf6, primals_9, buf7, buf8, 256, XBLOCK=256,
num_warps=4, num_stages=1)
del buf6
del primals_9
return (buf7, buf3, primals_1, primals_3, primals_4, primals_6,
primals_8, buf1, buf3, buf5, buf8, buf9)
class Residual_CovolutionNew(nn.Module):
def __init__(self, icol, ocol, num_classes):
super(Residual_CovolutionNew, self).__init__()
self.conv1 = nn.Conv2d(icol, ocol, kernel_size=3, stride=1, padding
=12, dilation=12, bias=True)
self.conv2 = nn.Conv2d(ocol, num_classes, kernel_size=3, stride=1,
padding=12, dilation=12, bias=True)
self.conv3 = nn.Conv2d(num_classes, ocol, kernel_size=1, stride=1,
padding=0, dilation=1, bias=True)
self.conv4 = nn.Conv2d(ocol, icol, kernel_size=1, stride=1, padding
=0, dilation=1, bias=True)
self.relu = nn.ReLU(inplace=True)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.conv3.weight
primals_7 = self.conv3.bias
primals_8 = self.conv4.weight
primals_9 = self.conv4.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], output[1]
|
speedinghzl/Pytorch-Deeplab
|
Residual_Covolution
| false
| 16,493
|
[
"MIT"
] | 310
|
14f2b81c676a6eb19f34940efb1297855f8fa05e
|
https://github.com/speedinghzl/Pytorch-Deeplab/tree/14f2b81c676a6eb19f34940efb1297855f8fa05e
|
MyWcploss
|
import torch
from torch import nn
class MyWcploss(nn.Module):
def __init__(self):
super(MyWcploss, self).__init__()
def forward(self, pred, gt):
eposion = 1e-10
torch.sigmoid(pred)
count_pos = torch.sum(gt) * 1.0 + eposion
count_neg = torch.sum(1.0 - gt) * 1.0
beta = count_neg / count_pos
beta_back = count_pos / (count_pos + count_neg)
bce1 = nn.BCEWithLogitsLoss(pos_weight=beta)
loss = beta_back * bce1(pred, gt)
return loss
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
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_per_fused_add_binary_cross_entropy_with_logits_div_mul_rsub_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)
tmp9 = tl.load(in_ptr1 + r0, None)
tmp1 = tl.broadcast_to(tmp0, [RBLOCK])
tmp3 = triton_helpers.promote_to_tensor(tl.sum(tmp1, 0))
tmp4 = 1.0
tmp5 = tmp4 - tmp0
tmp6 = tl.broadcast_to(tmp5, [RBLOCK])
tmp8 = triton_helpers.promote_to_tensor(tl.sum(tmp6, 0))
tmp10 = tmp5 * tmp9
tmp11 = tmp8 * tmp4
tmp12 = tmp3 * tmp4
tmp13 = 1e-10
tmp14 = tmp12 + tmp13
tmp15 = tmp11 / tmp14
tmp16 = tmp15 - tmp4
tmp17 = tmp16 * tmp0
tmp18 = tmp17 + tmp4
tmp19 = 0.0
tmp20 = triton_helpers.minimum(tmp19, tmp9)
tmp21 = tl_math.abs(tmp9)
tmp22 = -tmp21
tmp23 = tl_math.exp(tmp22)
tmp24 = libdevice.log1p(tmp23)
tmp25 = tmp20 - tmp24
tmp26 = tmp18 * tmp25
tmp27 = tmp10 - tmp26
tmp28 = tl.broadcast_to(tmp27, [RBLOCK])
tmp30 = triton_helpers.promote_to_tensor(tl.sum(tmp28, 0))
tmp31 = tmp14 + tmp11
tmp32 = tmp14 / tmp31
tmp33 = 256.0
tmp34 = tmp30 / tmp33
tmp35 = tmp32 * tmp34
tl.debug_barrier()
tl.store(in_out_ptr0 + tl.full([1], 0, tl.int32), tmp35, 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)
buf2 = empty_strided_cuda((), (), torch.float32)
buf3 = buf2
del buf2
get_raw_stream(0)
triton_per_fused_add_binary_cross_entropy_with_logits_div_mul_rsub_sum_0[
grid(1)](buf3, arg1_1, arg0_1, 1, 256, num_warps=2, num_stages=1)
del arg0_1
del arg1_1
return buf3,
class MyWcplossNew(nn.Module):
def __init__(self):
super(MyWcplossNew, 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]
|
stevewongv/DSC-PyTorch
|
MyWcploss
| false
| 16,494
|
[
"MIT"
] | 75
|
4318225ce4fa5343db2cc723d8bcae4c884b23f4
|
https://github.com/stevewongv/DSC-PyTorch/tree/4318225ce4fa5343db2cc723d8bcae4c884b23f4
|
DistanceNetwork
|
import torch
import torch.nn as nn
class DistanceNetwork(nn.Module):
def __init__(self):
super(DistanceNetwork, self).__init__()
def forward(self, support_set, input_image):
"""
Produces pdfs over the support set classes for the target set image.
:param support_set: The embeddings of the support set images, tensor of shape [sequence_length, batch_size, 64]
:param input_image: The embedding of the target image, tensor of shape [batch_size, 64]
:return: Softmax pdf. Tensor with cosine similarities of shape [batch_size, sequence_length]
"""
eps = 1e-10
similarities = []
for support_image in support_set:
sum_support = torch.sum(torch.pow(support_image, 2), 1)
support_magnitude = sum_support.clamp(eps, float('inf')).rsqrt()
dot_product = input_image.unsqueeze(1).bmm(support_image.
unsqueeze(2)).squeeze()
cosine_similarity = dot_product * support_magnitude
similarities.append(cosine_similarity)
similarities = torch.stack(similarities)
return similarities
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([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
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_stack_0(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
x0 = xindex
tmp0 = x0
tl.full([1], 0, tl.int64)
tmp3 = tl.full([1], 4, tl.int64)
tmp4 = tmp0 < tmp3
tmp5 = tl.load(in_ptr0 + x0, tmp4 & xmask, eviction_policy='evict_last',
other=0.0)
tmp6 = tl.load(in_ptr1 + 4 * x0, tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp7 = tmp6 * tmp6
tmp8 = tl.load(in_ptr1 + (1 + 4 * x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp9 = tmp8 * tmp8
tmp10 = tmp7 + tmp9
tmp11 = tl.load(in_ptr1 + (2 + 4 * x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp12 = tmp11 * tmp11
tmp13 = tmp10 + tmp12
tmp14 = tl.load(in_ptr1 + (3 + 4 * x0), tmp4 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp15 = tmp14 * tmp14
tmp16 = tmp13 + tmp15
tmp17 = 1e-10
tmp18 = triton_helpers.maximum(tmp16, tmp17)
tmp19 = float('inf')
tmp20 = triton_helpers.minimum(tmp18, tmp19)
tmp21 = libdevice.rsqrt(tmp20)
tmp22 = tmp5 * tmp21
tmp23 = tl.full(tmp22.shape, 0.0, tmp22.dtype)
tmp24 = tl.where(tmp4, tmp22, tmp23)
tmp25 = tmp0 >= tmp3
tmp26 = tl.full([1], 8, tl.int64)
tmp27 = tmp0 < tmp26
tmp28 = tmp25 & tmp27
tmp29 = tl.load(in_ptr2 + (-4 + x0), tmp28 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp30 = tl.load(in_ptr1 + (16 + 4 * (-4 + x0)), tmp28 & xmask,
eviction_policy='evict_last', other=0.0)
tmp31 = tmp30 * tmp30
tmp32 = tl.load(in_ptr1 + (17 + 4 * (-4 + x0)), tmp28 & xmask,
eviction_policy='evict_last', other=0.0)
tmp33 = tmp32 * tmp32
tmp34 = tmp31 + tmp33
tmp35 = tl.load(in_ptr1 + (18 + 4 * (-4 + x0)), tmp28 & xmask,
eviction_policy='evict_last', other=0.0)
tmp36 = tmp35 * tmp35
tmp37 = tmp34 + tmp36
tmp38 = tl.load(in_ptr1 + (19 + 4 * (-4 + x0)), tmp28 & xmask,
eviction_policy='evict_last', other=0.0)
tmp39 = tmp38 * tmp38
tmp40 = tmp37 + tmp39
tmp41 = triton_helpers.maximum(tmp40, tmp17)
tmp42 = triton_helpers.minimum(tmp41, tmp19)
tmp43 = libdevice.rsqrt(tmp42)
tmp44 = tmp29 * tmp43
tmp45 = tl.full(tmp44.shape, 0.0, tmp44.dtype)
tmp46 = tl.where(tmp28, tmp44, tmp45)
tmp47 = tmp0 >= tmp26
tmp48 = tl.full([1], 12, tl.int64)
tmp49 = tmp0 < tmp48
tmp50 = tmp47 & tmp49
tmp51 = tl.load(in_ptr3 + (-8 + x0), tmp50 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp52 = tl.load(in_ptr1 + (32 + 4 * (-8 + x0)), tmp50 & xmask,
eviction_policy='evict_last', other=0.0)
tmp53 = tmp52 * tmp52
tmp54 = tl.load(in_ptr1 + (33 + 4 * (-8 + x0)), tmp50 & xmask,
eviction_policy='evict_last', other=0.0)
tmp55 = tmp54 * tmp54
tmp56 = tmp53 + tmp55
tmp57 = tl.load(in_ptr1 + (34 + 4 * (-8 + x0)), tmp50 & xmask,
eviction_policy='evict_last', other=0.0)
tmp58 = tmp57 * tmp57
tmp59 = tmp56 + tmp58
tmp60 = tl.load(in_ptr1 + (35 + 4 * (-8 + x0)), tmp50 & xmask,
eviction_policy='evict_last', other=0.0)
tmp61 = tmp60 * tmp60
tmp62 = tmp59 + tmp61
tmp63 = triton_helpers.maximum(tmp62, tmp17)
tmp64 = triton_helpers.minimum(tmp63, tmp19)
tmp65 = libdevice.rsqrt(tmp64)
tmp66 = tmp51 * tmp65
tmp67 = tl.full(tmp66.shape, 0.0, tmp66.dtype)
tmp68 = tl.where(tmp50, tmp66, tmp67)
tmp69 = tmp0 >= tmp48
tl.full([1], 16, tl.int64)
tmp72 = tl.load(in_ptr4 + (-12 + x0), tmp69 & xmask, eviction_policy=
'evict_last', other=0.0)
tmp73 = tl.load(in_ptr1 + (48 + 4 * (-12 + x0)), tmp69 & xmask,
eviction_policy='evict_last', other=0.0)
tmp74 = tmp73 * tmp73
tmp75 = tl.load(in_ptr1 + (49 + 4 * (-12 + x0)), tmp69 & xmask,
eviction_policy='evict_last', other=0.0)
tmp76 = tmp75 * tmp75
tmp77 = tmp74 + tmp76
tmp78 = tl.load(in_ptr1 + (50 + 4 * (-12 + x0)), tmp69 & xmask,
eviction_policy='evict_last', other=0.0)
tmp79 = tmp78 * tmp78
tmp80 = tmp77 + tmp79
tmp81 = tl.load(in_ptr1 + (51 + 4 * (-12 + x0)), tmp69 & xmask,
eviction_policy='evict_last', other=0.0)
tmp82 = tmp81 * tmp81
tmp83 = tmp80 + tmp82
tmp84 = triton_helpers.maximum(tmp83, tmp17)
tmp85 = triton_helpers.minimum(tmp84, tmp19)
tmp86 = libdevice.rsqrt(tmp85)
tmp87 = tmp72 * tmp86
tmp88 = tl.full(tmp87.shape, 0.0, tmp87.dtype)
tmp89 = tl.where(tmp69, tmp87, tmp88)
tmp90 = tl.where(tmp50, tmp68, tmp89)
tmp91 = tl.where(tmp28, tmp46, tmp90)
tmp92 = tl.where(tmp4, tmp24, tmp91)
tl.store(out_ptr0 + x0, tmp92, 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, 1))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg1_1, (4, 1, 4), (4, 4, 1),
0), reinterpret_tensor(arg0_1, (4, 4, 1), (4, 1, 1), 0), out=buf0)
buf1 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg1_1, (4, 1, 4), (4, 4, 1),
0), reinterpret_tensor(arg0_1, (4, 4, 1), (4, 1, 1), 16), out=buf1)
buf2 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg1_1, (4, 1, 4), (4, 4, 1),
0), reinterpret_tensor(arg0_1, (4, 4, 1), (4, 1, 1), 32), out=buf2)
buf3 = empty_strided_cuda((4, 1, 1), (1, 1, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(arg1_1, (4, 1, 4), (4, 4, 1),
0), reinterpret_tensor(arg0_1, (4, 4, 1), (4, 1, 1), 48), out=buf3)
del arg1_1
buf4 = empty_strided_cuda((16,), (1,), torch.float32)
get_raw_stream(0)
triton_poi_fused_stack_0[grid(16)](buf0, arg0_1, buf1, buf2, buf3,
buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
del arg0_1
del buf0
del buf1
del buf2
del buf3
return reinterpret_tensor(buf4, (4, 4), (4, 1), 0),
class DistanceNetworkNew(nn.Module):
def __init__(self):
super(DistanceNetworkNew, 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]
|
stamatiad/MatchingNetworks
|
DistanceNetwork
| false
| 16,495
|
[
"MIT"
] | 316
|
07c4567c15578664a550903c222c7eaa2abfe113
|
https://github.com/stamatiad/MatchingNetworks/tree/07c4567c15578664a550903c222c7eaa2abfe113
|
ConvNet
|
import torch
import torch.optim
import torch.nn as nn
import torch.nn.functional as F
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 1000)
self.fc2 = nn.Linear(1000, 10)
def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return x
def get_inputs():
return [torch.rand([4, 3, 32, 32])]
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.optim
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_relu_0(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 18816
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 784 % 6
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_max_pool2d_with_indices_1(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 4704
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 14
x3 = xindex // 14
x2 = xindex // 1176
x4 = xindex % 1176
tmp0 = tl.load(in_ptr0 + (2 * x0 + 56 * x3), xmask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 56 * x3), xmask, eviction_policy
='evict_last')
tmp3 = tl.load(in_ptr0 + (28 + 2 * x0 + 56 * x3), xmask,
eviction_policy='evict_last')
tmp5 = tl.load(in_ptr0 + (29 + 2 * x0 + 56 * x3), xmask,
eviction_policy='evict_last')
tmp2 = triton_helpers.maximum(tmp1, tmp0)
tmp4 = triton_helpers.maximum(tmp3, tmp2)
tmp6 = triton_helpers.maximum(tmp5, tmp4)
tmp7 = tmp1 > tmp0
tmp8 = tl.full([1], 1, tl.int8)
tmp9 = tl.full([1], 0, tl.int8)
tmp10 = tl.where(tmp7, tmp8, tmp9)
tmp11 = tmp3 > tmp2
tmp12 = tl.full([1], 2, tl.int8)
tmp13 = tl.where(tmp11, tmp12, tmp10)
tmp14 = tmp5 > tmp4
tmp15 = tl.full([1], 3, tl.int8)
tmp16 = tl.where(tmp14, tmp15, tmp13)
tl.store(out_ptr0 + (x4 + 1184 * x2), tmp6, xmask)
tl.store(out_ptr1 + (x4 + 1280 * x2), tmp16, xmask)
@triton.jit
def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel,
XBLOCK: tl.constexpr):
xnumel = 6400
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x1 = xindex // 100 % 16
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_max_pool2d_with_indices_3(in_ptr0, out_ptr0, out_ptr1,
xnumel, XBLOCK: tl.constexpr):
xnumel = 1600
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x0 = xindex % 5
x1 = xindex // 5
x2 = xindex
tmp0 = tl.load(in_ptr0 + (2 * x0 + 20 * x1), xmask, eviction_policy=
'evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0 + 20 * x1), xmask, eviction_policy
='evict_last')
tmp7 = tl.load(in_ptr0 + (10 + 2 * x0 + 20 * x1), xmask,
eviction_policy='evict_last')
tmp12 = tl.load(in_ptr0 + (11 + 2 * x0 + 20 * x1), xmask,
eviction_policy='evict_last')
tmp2 = tmp1 > tmp0
tmp3 = tl.full([1], 1, tl.int8)
tmp4 = tl.full([1], 0, tl.int8)
tmp5 = tl.where(tmp2, tmp3, tmp4)
tmp6 = triton_helpers.maximum(tmp1, tmp0)
tmp8 = tmp7 > tmp6
tmp9 = tl.full([1], 2, tl.int8)
tmp10 = tl.where(tmp8, tmp9, tmp5)
tmp11 = triton_helpers.maximum(tmp7, tmp6)
tmp13 = tmp12 > tmp11
tmp14 = tl.full([1], 3, tl.int8)
tmp15 = tl.where(tmp13, tmp14, tmp10)
tmp16 = triton_helpers.maximum(tmp12, tmp11)
tl.store(out_ptr0 + x2, tmp15, xmask)
tl.store(out_ptr1 + x2, tmp16, xmask)
@triton.jit
def triton_poi_fused_relu_4(in_out_ptr0, in_ptr0, xnumel, XBLOCK: tl.constexpr
):
xnumel = 4000
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x2 = xindex
x0 = xindex % 1000
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)
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, (6, 3, 5, 5), (75, 25, 5, 1))
assert_size_stride(primals_2, (6,), (1,))
assert_size_stride(primals_3, (4, 3, 32, 32), (3072, 1024, 32, 1))
assert_size_stride(primals_4, (16, 6, 5, 5), (150, 25, 5, 1))
assert_size_stride(primals_5, (16,), (1,))
assert_size_stride(primals_6, (1000, 400), (400, 1))
assert_size_stride(primals_7, (1000,), (1,))
assert_size_stride(primals_8, (10, 1000), (1000, 1))
assert_size_stride(primals_9, (10,), (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, 6, 28, 28), (4704, 784, 28, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_relu_0[grid(18816)](buf1, primals_2,
18816, XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
buf2 = empty_strided_cuda((4, 6, 14, 14), (1184, 196, 14, 1), torch
.float32)
buf3 = empty_strided_cuda((4, 6, 14, 14), (1280, 196, 14, 1), torch
.int8)
triton_poi_fused_max_pool2d_with_indices_1[grid(4704)](buf1, buf2,
buf3, 4704, XBLOCK=256, num_warps=4, num_stages=1)
buf4 = 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(buf4, (4, 16, 10, 10), (1600, 100, 10, 1))
buf5 = buf4
del buf4
triton_poi_fused_convolution_relu_2[grid(6400)](buf5, primals_5,
6400, XBLOCK=256, num_warps=4, num_stages=1)
del primals_5
buf6 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.int8)
buf7 = empty_strided_cuda((4, 16, 5, 5), (400, 25, 5, 1), torch.float32
)
triton_poi_fused_max_pool2d_with_indices_3[grid(1600)](buf5, buf6,
buf7, 1600, XBLOCK=128, num_warps=4, num_stages=1)
buf8 = empty_strided_cuda((4, 1000), (1000, 1), torch.float32)
extern_kernels.mm(reinterpret_tensor(buf7, (4, 400), (400, 1), 0),
reinterpret_tensor(primals_6, (400, 1000), (1, 400), 0), out=buf8)
buf9 = buf8
del buf8
triton_poi_fused_relu_4[grid(4000)](buf9, primals_7, 4000, XBLOCK=
256, num_warps=4, num_stages=1)
del primals_7
buf10 = empty_strided_cuda((4, 10), (10, 1), torch.float32)
extern_kernels.addmm(primals_9, buf9, reinterpret_tensor(primals_8,
(1000, 10), (1, 1000), 0), alpha=1, beta=1, out=buf10)
del primals_9
return (buf10, primals_1, primals_3, primals_4, buf1, buf2, buf3, buf5,
buf6, reinterpret_tensor(buf7, (4, 400), (400, 1), 0), buf9,
primals_8, primals_6)
class ConvNetNew(nn.Module):
def __init__(self):
super(ConvNetNew, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 1000)
self.fc2 = nn.Linear(1000, 10)
def forward(self, input_0):
primals_1 = self.conv1.weight
primals_2 = self.conv1.bias
primals_4 = self.conv2.weight
primals_5 = self.conv2.bias
primals_6 = self.fc1.weight
primals_7 = self.fc1.bias
primals_8 = self.fc2.weight
primals_9 = self.fc2.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]
|
stanbiryukov/PyTorch-LBFGS
|
ConvNet
| false
| 16,496
|
[
"MIT"
] | 451
|
ea0ca553797b38d47682ce8ff553a4f53ec8c15c
|
https://github.com/stanbiryukov/PyTorch-LBFGS/tree/ea0ca553797b38d47682ce8ff553a4f53ec8c15c
|
ShallowCombination
|
from _paritybench_helpers import _mock_config
import torch
import torch.nn as nn
class ShallowCombination(nn.Module):
"""This Module can be used to generate a shallow combination from two embeddings using a gate."""
def __init__(self, bertram_config: 'BertramConfig'):
super(ShallowCombination, self).__init__()
self.linear = nn.Linear(2 * bertram_config.output_size, 1)
self.sigmoid = torch.nn.Sigmoid()
self.mode = bertram_config.mode
def forward(self, embs1, embs2):
embs_combined = torch.cat([embs1, embs2], dim=-1)
a = self.sigmoid(self.linear(embs_combined))
return a * embs1 + (1 - a) * embs2
def get_inputs():
return [torch.rand([4, 4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'bertram_config': _mock_config(output_size=4, mode=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_cat_0(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
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_add_mul_rsub_sigmoid_1(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
x1 = xindex // 4
x2 = xindex
tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
tmp2 = tl.load(in_ptr1 + x2, xmask)
tmp6 = tl.load(in_ptr2 + x2, xmask)
tmp1 = tl.sigmoid(tmp0)
tmp3 = tmp1 * tmp2
tmp4 = 1.0
tmp5 = tmp4 - tmp1
tmp7 = tmp5 * tmp6
tmp8 = tmp3 + tmp7
tl.store(out_ptr0 + x2, tmp8, 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, (4, 4, 4, 4), (64, 16, 4, 1))
assert_size_stride(primals_3, (1, 8), (8, 1))
assert_size_stride(primals_4, (1,), (1,))
with torch.cuda._DeviceGuard(0):
torch.cuda.set_device(0)
buf0 = empty_strided_cuda((4, 4, 4, 8), (128, 32, 8, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_cat_0[grid(512)](primals_1, primals_2, buf0, 512,
XBLOCK=256, num_warps=4, num_stages=1)
buf2 = empty_strided_cuda((64, 1), (1, 1), torch.float32)
extern_kernels.addmm(primals_4, reinterpret_tensor(buf0, (64, 8), (
8, 1), 0), reinterpret_tensor(primals_3, (8, 1), (1, 8), 0),
alpha=1, beta=1, out=buf2)
del primals_3
del primals_4
buf3 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_add_mul_rsub_sigmoid_1[grid(256)](buf2, primals_1,
primals_2, buf3, 256, XBLOCK=128, num_warps=4, num_stages=1)
return buf3, primals_1, primals_2, reinterpret_tensor(buf0, (64, 8), (8,
1), 0), buf2
class ShallowCombinationNew(nn.Module):
"""This Module can be used to generate a shallow combination from two embeddings using a gate."""
def __init__(self, bertram_config: 'BertramConfig'):
super(ShallowCombinationNew, self).__init__()
self.linear = nn.Linear(2 * bertram_config.output_size, 1)
self.sigmoid = torch.nn.Sigmoid()
self.mode = bertram_config.mode
def forward(self, input_0, input_1):
primals_3 = self.linear.weight
primals_4 = self.linear.bias
primals_1 = input_0
primals_2 = input_1
output = call([primals_1, primals_2, primals_3, primals_4])
return output[0]
|
stefan-it/bertram
|
ShallowCombination
| false
| 16,497
|
[
"Apache-2.0"
] | 50
|
2e449cdc677577d1ca8b9daf852f324be4074940
|
https://github.com/stefan-it/bertram/tree/2e449cdc677577d1ca8b9daf852f324be4074940
|
PEGCNLayer
|
import torch
import torch.nn as nn
class PEGCNLayer(nn.Module):
def __init__(self, input_dim, output_dim, prop_depth, act=torch.relu,
dropout=0.0, layer_i=0):
super(PEGCNLayer, self).__init__()
self.prop_depth = prop_depth
self.act = act
self.weight = nn.Parameter(torch.empty(1, prop_depth, input_dim,
output_dim, dtype=torch.float), requires_grad=True)
nn.init.uniform_(self.weight.data)
self.dropout = nn.Dropout(p=dropout)
self.layer_norm = nn.LayerNorm(output_dim)
self.layer_i = layer_i
self.last_layer_flag = False
def layer(self, x, adj_batch):
if adj_batch.dim() < 4:
adj_batch = adj_batch.unsqueeze(0)
x = x.transpose(0, 1).unsqueeze(dim=1).repeat(1, self.prop_depth, 1, 1)
x = torch.matmul(x, self.weight)
x = torch.matmul(adj_batch, x)
x = x.sum(dim=1)
x = x.transpose(0, 1)
return x
def forward(self, x, adj_batch):
x = self.layer(x, adj_batch)
x = self.act(x)
x = self.dropout(x)
x = self.layer_norm(x)
return x
def get_inputs():
return [torch.rand([4, 4, 4]), torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'input_dim': 4, 'output_dim': 4, 'prop_depth': 1}]
|
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_repeat_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 % 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)
@triton.jit
def triton_poi_fused_clone_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
x0 = xindex % 16
x2 = xindex // 64
x3 = xindex
tmp0 = tl.load(in_ptr0 + (x0 + 16 * x2), xmask, eviction_policy=
'evict_last')
tl.store(out_ptr0 + x3, tmp0, xmask)
@triton.jit
def triton_poi_fused_relu_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
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 = tl.full([1], 0, tl.int32)
tmp8 = triton_helpers.maximum(tmp7, tmp6)
tl.store(out_ptr0 + x2, tmp8, xmask)
@triton.jit
def triton_poi_fused_native_layer_norm_3(in_ptr0, 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_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-05
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_4(in_ptr0, in_ptr1, in_ptr2, in_ptr3,
in_ptr4, out_ptr0, xnumel, XBLOCK: tl.constexpr):
xnumel = 64
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
xmask = xindex < xnumel
x3 = xindex
x4 = xindex // 4
x0 = xindex % 4
x1 = xindex // 4 % 4
x2 = xindex // 16
tmp0 = tl.load(in_ptr0 + x3, xmask)
tmp1 = tl.load(in_ptr1 + x4, xmask, eviction_policy='evict_last')
tmp3 = tl.load(in_ptr2 + x4, 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 + (x0 + 4 * x2 + 16 * x1), tmp8, 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), (16, 4, 1))
assert_size_stride(primals_3, (1, 1, 4, 4), (16, 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, 1, 4, 4), (16, 1, 4, 1), torch.float32)
get_raw_stream(0)
triton_poi_fused_repeat_0[grid(64)](primals_2, buf0, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del primals_2
buf1 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(buf0, (4, 4, 4), (16, 4, 1),
0), reinterpret_tensor(primals_3, (4, 4, 4), (0, 4, 1), 0), out
=buf1)
del primals_3
buf2 = empty_strided_cuda((4, 4, 4, 4), (64, 16, 4, 1), torch.float32)
triton_poi_fused_clone_1[grid(256)](buf1, buf2, 256, XBLOCK=128,
num_warps=4, num_stages=1)
buf3 = empty_strided_cuda((16, 4, 4), (16, 4, 1), torch.float32)
extern_kernels.bmm(reinterpret_tensor(primals_1, (16, 4, 4), (16, 4,
1), 0), reinterpret_tensor(buf2, (16, 4, 4), (16, 4, 1), 0),
out=buf3)
del buf2
buf4 = reinterpret_tensor(buf1, (4, 4, 4), (4, 16, 1), 0)
del buf1
triton_poi_fused_relu_2[grid(64)](buf3, buf4, 64, XBLOCK=64,
num_warps=1, num_stages=1)
del buf3
buf5 = empty_strided_cuda((4, 4, 1), (1, 4, 16), torch.float32)
buf6 = empty_strided_cuda((4, 4, 1), (1, 4, 16), torch.float32)
triton_poi_fused_native_layer_norm_3[grid(16)](buf4, buf5, buf6, 16,
XBLOCK=16, num_warps=1, num_stages=1)
buf7 = empty_strided_cuda((4, 4, 4), (16, 4, 1), torch.float32)
triton_poi_fused_native_layer_norm_4[grid(64)](buf4, buf5, buf6,
primals_4, primals_5, buf7, 64, XBLOCK=64, num_warps=1,
num_stages=1)
del buf5
del buf6
del primals_5
return buf7, primals_4, buf4, reinterpret_tensor(primals_1, (16, 4, 4),
(16, 1, 4), 0), reinterpret_tensor(buf0, (4, 4, 4), (16, 1, 4), 0)
class PEGCNLayerNew(nn.Module):
def __init__(self, input_dim, output_dim, prop_depth, act=torch.relu,
dropout=0.0, layer_i=0):
super(PEGCNLayerNew, self).__init__()
self.prop_depth = prop_depth
self.act = act
self.weight = nn.Parameter(torch.empty(1, prop_depth, input_dim,
output_dim, dtype=torch.float), requires_grad=True)
nn.init.uniform_(self.weight.data)
self.dropout = nn.Dropout(p=dropout)
self.layer_norm = nn.LayerNorm(output_dim)
self.layer_i = layer_i
self.last_layer_flag = False
def layer(self, x, adj_batch):
if adj_batch.dim() < 4:
adj_batch = adj_batch.unsqueeze(0)
x = x.transpose(0, 1).unsqueeze(dim=1).repeat(1, self.prop_depth, 1, 1)
x = torch.matmul(x, self.weight)
x = torch.matmul(adj_batch, x)
x = x.sum(dim=1)
x = x.transpose(0, 1)
return x
def forward(self, input_0, input_1):
primals_3 = self.weight
primals_4 = self.layer_norm.weight
primals_5 = self.layer_norm.bias
primals_2 = input_0
primals_1 = input_1
output = call([primals_1, primals_2, primals_3, primals_4, primals_5])
return output[0]
|
snap-stanford/distance-encoding
|
PEGCNLayer
| false
| 16,498
|
[
"MIT"
] | 177
|
b9ccb1b59422b11b40883d0284d7fc9ba88efdb6
|
https://github.com/snap-stanford/distance-encoding/tree/b9ccb1b59422b11b40883d0284d7fc9ba88efdb6
|
Predict
|
import torch
from torch import nn
class Predict(nn.Module):
def __init__(self, in_planes=32, out_planes=1, kernel_size=1):
super(Predict, self).__init__()
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size)
def forward(self, x):
y = self.conv(x)
return y
def get_inputs():
return [torch.rand([4, 32, 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 import nn
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):
xoffset = tl.program_id(0) * XBLOCK
xindex = xoffset + tl.arange(0, XBLOCK)[:]
tl.full([XBLOCK], True, tl.int1)
x0 = xindex
tmp0 = tl.load(in_out_ptr0 + x0, None)
tmp1 = tl.load(in_ptr0 + 0)
tmp2 = tl.broadcast_to(tmp1, [XBLOCK])
tmp3 = tmp0 + tmp2
tl.store(in_out_ptr0 + x0, tmp3, None)
def call(args):
primals_1, primals_2, primals_3 = args
args.clear()
assert_size_stride(primals_1, (1, 32, 1, 1), (32, 1, 1, 1))
assert_size_stride(primals_2, (1,), (1,))
assert_size_stride(primals_3, (4, 32, 64, 64), (131072, 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, 1, 64, 64), (4096, 4096, 64, 1))
buf1 = buf0
del buf0
get_raw_stream(0)
triton_poi_fused_convolution_0[grid(16384)](buf1, primals_2, 16384,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_2
return buf1, primals_1, primals_3
class PredictNew(nn.Module):
def __init__(self, in_planes=32, out_planes=1, kernel_size=1):
super(PredictNew, self).__init__()
self.conv = nn.Conv2d(in_planes, out_planes, kernel_size)
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]
|
stevewongv/DSC-PyTorch
|
Predict
| false
| 16,499
|
[
"MIT"
] | 75
|
4318225ce4fa5343db2cc723d8bcae4c884b23f4
|
https://github.com/stevewongv/DSC-PyTorch/tree/4318225ce4fa5343db2cc723d8bcae4c884b23f4
|
LearnedPositionalEmbedding1D
|
import torch
from torch import nn
class LearnedPositionalEmbedding1D(nn.Module):
"""Adds (optionally learned) positional embeddings to the inputs."""
def __init__(self, seq_len, dim):
super().__init__()
self.pos_embedding = nn.Parameter(torch.zeros(1, seq_len, dim))
def forward(self, x):
"""Input has shape `(batch_size, seq_len, emb_dim)`"""
return x + self.pos_embedding
def get_inputs():
return [torch.rand([4, 4, 4, 4])]
def get_init_inputs():
return [[], {'seq_len': 4, 'dim': 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 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_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 % 16
tmp0 = tl.load(in_ptr0 + x2, xmask)
tmp1 = tl.load(in_ptr1 + x0, xmask, eviction_policy='evict_last')
tmp2 = tmp0 + tmp1
tl.store(out_ptr0 + x2, tmp2, xmask)
def call(args):
primals_1, primals_2 = args
args.clear()
assert_size_stride(primals_1, (1, 4, 4), (16, 4, 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_add_0[grid(256)](primals_2, primals_1, buf0, 256,
XBLOCK=256, num_warps=4, num_stages=1)
del primals_1
del primals_2
return buf0,
class LearnedPositionalEmbedding1DNew(nn.Module):
"""Adds (optionally learned) positional embeddings to the inputs."""
def __init__(self, seq_len, dim):
super().__init__()
self.pos_embedding = nn.Parameter(torch.zeros(1, seq_len, dim))
def forward(self, input_0):
primals_1 = self.pos_embedding
primals_2 = input_0
output = call([primals_1, primals_2])
return output[0]
|
styler00dollar/Colab-animesion
|
LearnedPositionalEmbedding1D
| false
| 16,500
|
[
"MIT"
] | 67
|
0fa603689fec3ed4ede098fd7c15b519dbb76a09
|
https://github.com/styler00dollar/Colab-animesion/tree/0fa603689fec3ed4ede098fd7c15b519dbb76a09
|
CNN
|
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.nn.utils
class CNN(nn.Module):
def __init__(self, e_char, filters, padding=1, kernel_size=5):
super(CNN, self).__init__()
self.e_char = e_char
self.filters = filters
self.padding = padding
self.k = kernel_size
self.conv1d = None
self.maxpool = None
self.conv1d = nn.Conv1d(in_channels=self.e_char, out_channels=self.
filters, kernel_size=self.k, stride=1, padding=self.padding,
padding_mode='zeros', bias=True)
def forward(self, xemb: 'torch.Tensor'):
m_word = xemb.shape[1]
x_reshaped = xemb.permute(0, 2, 1)
x_conv = self.conv1d(x_reshaped)
x_conv = F.relu(x_conv)
maxpool = nn.MaxPool1d(kernel_size=m_word + 2 * self.padding - self
.k + 1)
x_conv_out = maxpool(x_conv).squeeze(2)
return x_conv_out
def get_inputs():
return [torch.rand([4, 4, 4])]
def get_init_inputs():
return [[], {'e_char': 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
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.nn.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_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_threshold_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
x3 = xindex
x1 = xindex // 2 % 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)
tmp5 = 0.0
tmp6 = tmp4 <= tmp5
tl.store(in_out_ptr0 + x3, tmp4, xmask)
tl.store(out_ptr0 + x3, tmp6, xmask)
@triton.jit
def triton_poi_fused_max_pool2d_with_indices_2(in_ptr0, 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 + 2 * x0, xmask, eviction_policy='evict_last')
tmp1 = tl.load(in_ptr0 + (1 + 2 * x0), xmask, eviction_policy='evict_last')
tmp2 = tmp1 > tmp0
tmp3 = tl.full([1], 1, tl.int8)
tmp4 = tl.full([1], 0, tl.int8)
tmp5 = tl.where(tmp2, tmp3, tmp4)
tmp6 = triton_helpers.maximum(tmp1, tmp0)
tl.store(out_ptr0 + x0, tmp5, xmask)
tl.store(out_ptr1 + x0, tmp6, 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, 5), (20, 5, 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), (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=(1,), dilation=(1,), transposed=False, output_padding=(
0,), groups=1, bias=None)
assert_size_stride(buf1, (4, 4, 2), (8, 2, 1))
del buf0
buf2 = buf1
del buf1
buf5 = empty_strided_cuda((4, 4, 2), (8, 2, 1), torch.bool)
triton_poi_fused_convolution_relu_threshold_backward_1[grid(32)](buf2,
primals_3, buf5, 32, XBLOCK=32, num_warps=1, num_stages=1)
del primals_3
buf3 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 1, 1), torch.int8)
buf4 = empty_strided_cuda((4, 4, 1, 1), (4, 1, 16, 16), torch.float32)
triton_poi_fused_max_pool2d_with_indices_2[grid(16)](buf2, buf3,
buf4, 16, XBLOCK=16, num_warps=1, num_stages=1)
return reinterpret_tensor(buf4, (4, 4), (4, 1), 0
), primals_2, reinterpret_tensor(primals_1, (4, 4, 4), (16, 1, 4), 0
), reinterpret_tensor(buf2, (4, 4, 1, 2), (8, 2, 2, 1), 0), buf3, buf5
class CNNNew(nn.Module):
def __init__(self, e_char, filters, padding=1, kernel_size=5):
super(CNNNew, self).__init__()
self.e_char = e_char
self.filters = filters
self.padding = padding
self.k = kernel_size
self.conv1d = None
self.maxpool = None
self.conv1d = nn.Conv1d(in_channels=self.e_char, out_channels=self.
filters, kernel_size=self.k, stride=1, padding=self.padding,
padding_mode='zeros', bias=True)
def forward(self, input_0):
primals_2 = self.conv1d.weight
primals_3 = self.conv1d.bias
primals_1 = input_0
output = call([primals_1, primals_2, primals_3])
return output[0]
|
stxxllbu/CS224n-winter-together
|
CNN
| false
| 16,501
|
[
"Apache-2.0"
] | 468
|
eae158ed8e88dc7c8638e25bac4c4fc8eeddcc8c
|
https://github.com/stxxllbu/CS224n-winter-together/tree/eae158ed8e88dc7c8638e25bac4c4fc8eeddcc8c
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.